开放源码:
RHINO三维图形开发平台
[6]
// 自定义样条曲线绘制
CRhinoCommand::result CCommandmyDrawCurve::RunCommand( const CRhinoCommandContext& context )
{
for(;;) {
CRhinoDoc *doc = RhinoApp().ActiveDoc();
//----------------------- debug curve draw --------------------
CRhinoGetObject get;
if (get.GetObjects(1,0) != CRhinoGetObject::object)
return CRhinoCommand::cancel;
CRhinoObjRef ōbj = get.Object(0);
ON_NurbsCurve mycrv;
const ON_Curve* crv = ON_Curve::Cast(obj.Geometry());
crv->GetNurbForm(mycrv);
int dimension = mycrv.Dimension();
int cvnum = mycrv.m_cv_count;
double *cvpoint;
cvpoint = mycrv.m_cv;
double *my_knot = mycrv.m_knot;
int my_order = mycrv.m_order;
ON_3dPoint cvpt;
//得到指定的控制结点
for (int k = 0; k < cvnum; k++){
mycrv.GetCV(k,cvpt);
}
mycrv.InsertKnot(2,1);
//---------------------- debug end -------------------------
ON_NurbsCurve nurbcrv(3,0,4,7);
//nurbcrv.MakeClampedUniformKnotVector();
for(int i=0; i<7;i++)
nurbcrv.SetCV( i, ON_3dPoint( i, i*i, 0));
nurbcrv.SetCV(0, ON_3dPoint(-10,0,0));
nurbcrv.SetCV(1, ON_3dPoint(0,10,0));
nurbcrv.SetCV(2, ON_3dPoint(10,0,0));
nurbcrv.SetCV(3, ON_3dPoint(20,-10,0));
nurbcrv.SetCV(4, ON_3dPoint(30,0,0));
nurbcrv.SetCV(5, ON_3dPoint(40,10,0));
nurbcrv.SetCV(6, ON_3dPoint(50,0,0));
for(int j=0; j if( j<3)
nurbcrv.SetKnot(j,0.0);
else if(j<(nurbcrv.KnotCount()-3))
nurbcrv.SetKnot(j,j-1);
else
nurbcrv.SetKnot(j,(nurbcrv.KnotCount()-1));
};
nurbcrv.SetKnot(0,0);
nurbcrv.SetKnot(1,0);
nurbcrv.SetKnot(2,0);
nurbcrv.SetKnot(3,1);
nurbcrv.SetKnot(4,2);
nurbcrv.SetKnot(5,3);
nurbcrv.SetKnot(6,4);
nurbcrv.SetKnot(7,4);
nurbcrv.SetKnot(8,4);
ON_Interval dom = nurbcrv.Domain();
int knotcount = nurbcrv.KnotCount();
CRhinoCurveObject* my_cur_obj = new CRhinoCurveObject();
my_cur_obj->SetCurve(nurbcrv);
doc->AddObject(my_cur_obj,false,false);
doc->Redraw();
break;
}
return CRhinoCommand::success;
}
//
// END myDrawCurve command