事实上,并不需要直接对采用api_curve_spline生成的曲线进行离散。ACIS提供了
bs2_curve/bs3_curve(bs指的是B-Spline),你可以利用bs curve的插值函数(如
bs3_curve_interp)得到近似曲线bs3_curve,然后按一定间隔取该近似曲线上的
点,用这些点来构造橡皮筋。
 
以下代码仅供参考:
 
//----------------------------------------------------------------------
// Purpose---
//    draw to a new SPAposition
//
//----------------------------------------------------------------------
void
ah_rubberband_spline::draw(
    HEventInfo event
    )
{
    ENTER_FUNCTION("ah_rubberband_spline::draw");
 
      ah_rb_start_creation(LastView);
 
      //draw rubberband here
 
      if( m_numPoints == 2)
      {
            Display_Points[0] = (float)m_points[0].x();
            Display_Points[1] = (float)m_points[0].y();
            Display_Points[2] = (float)m_points[0].z();
 
            float* pt = Display_Points + 3;
            *(pt++) = (float)m_points[1].x();
            *(pt++) = (float)m_points[1].y();
            *pt = (float)m_points[1].z();
            m_numDisplayPoints = 2;
      }
      else if(m_numPoints > 2)
      {
            // Compute the spline
            double fitol = 0.0;
            bs3_curve bs = bs3_curve_interp(m_numPoints,m_points,
                  *(SPAunit_vector *)NULL_REF,*(SPAunit_vector *)NULL_REF,
                  fitol);
 
            // Get the number of positions to use for the display
            m_numDisplayPoints = (m_numPoints ) * m_numPosPerSeg;
            if( m_numDisplayPoints > MAX_DISPLAY_POSITIONS ) {
                  m_numDisplayPoints = MAX_DISPLAY_POSITIONS;
            } else if( m_numDisplayPoints < MIN_DISPLAY_POSITIONS ) {
                  m_numDisplayPoints = MIN_DISPLAY_POSITIONS;
            }
 
            // Get the SPAparameter range of the curve
            SPAinterval range = bs3_curve_range(bs);
            double t0 = range.start_pt();
            double t1 = range.end_pt();
            double dt = (t1-t0)/(m_numDisplayPoints - 1);
 
            // Evaluate to get the display positions
            float* pt = Display_Points + 3;
            for(int j=1; j<m_numDisplayPoints; j++) {
                  double t = t0 + j*dt;
                  SPAposition pos = bs3_curve_position(t, bs);
                  *(pt++) = (float)(pos.x());
                  *(pt++) = (float)(pos.y());
                  *(pt++) = (float)(pos.z());
            }
 
            // We are done with the curve so we can delete it
            bs3_curve_delete(bs);
      }
 
      if(m_numDisplayPoints>1)
      {
            HC_Insert_Polyline(m_numDisplayPoints,Display_Points);
      }
 
      ah_rb_end_creation();
 
}