developer:sdksamples:curveeditpoints


Extracting Curve Edit Points

C++

Summary: Demonstrates how to extract a curve's edit points using the Rhino SDK.

Question

I would like to extract a curve's edit points - the points you see when you run the EditPtOn commmand, but I not see any methods on ON_Curve or ON_NurbsCurve to do this. Is this possible?

Answer

Unlike control points, edit points are not part of a NURBs curve's data structure. Rather, they are calculated when needed.

The following example code demonstrates to get obtain the edit points for a NURBs curve and then create point objects at those locations.

CRhinoCommand::result CCommandFooBar::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select curve" );
  go.SetGeometryFilter( CRhinoGetObject::curve_object );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != success )
    return go.CommandResult();
 
  const ON_Curve* crv = go.Object(0).Curve();
  if( 0 == crv )
    return failure;
 
  ON_NurbsCurve nc;
  if( crv->GetNurbForm(nc) )
  {
    // For every control point, we can calculate
    // a cooresponding edit point.
    ON_SimpleArray<double> t( nc.CVCount() );
    t.SetCount( nc.CVCount() );
 
    if( nc.GetGrevilleAbcissae(t.Array()) )
    {
      int i;
      for( i = 0; i < t.Count(); i++ )
        context.m_doc.AddPointObject( nc.PointAt(t[i]) );
      context.m_doc.Redraw();
    }
  }
 
  return success;
}
developer/sdksamples/curveeditpoints.txt · Last modified: 2010/01/26 16:37 (external edit) Driven by DokuWiki Recent changes RSS feed

 © 1997-2010 

McNeel North America Europe Latin AmericaAsia