Open CASCADE Technology
http://www.cppblog.com/eryar/ OCCT精品博客,eryar@163.com
https://www.cnblogs.com/opencascade/ 同上
B样条基函数——B-Spline Basis Functions ++ B样条曲线(B-spline Curves)
OpenCASCADE Trihedron Law
OpenCASCADE Interpolations and Approximations
Convert BSpline Curve to Arc Spline in OpenCASCADE
OPEN CASCADE BSpline Curve Interpolation
https://www.cnblogs.com/yaoyu126/p/6222934.html OCCT的基础知识
OCCT提供了比较完备的 NURBS 曲线和曲面的功能。
从接口来说:
Geom_BSplineCurve
GeomAPI_Interpolate 类,实现了从一组点通过插值生成 Bspline 曲线的功能。
GeomAPI_PointsToBSpline 类,实现了从一组点通过逼近生成 Bspline 曲线的功能。
GeomAPI_PointsToBSplineSurface 类,实现了从一个二维点数组,通过逼近,生成对于 bSpline 曲面的功能
官方案例:
opencascade-7.4.0\samples\mfc\occtdemo\Offset2d\Offset2d_Presentation.cpp\void samplePBSpline()
https://blog.csdn.net/DaGeYong/article/details/81409973 OpenCasCade与NURBS——B样条曲线 TColgp_Array1OfPnt Poles(1,9); Poles.SetValue(1, gp_Pnt(0,-100,0)); Poles.SetValue(2, gp_Pnt(0,-100,50)); Poles.SetValue(3, gp_Pnt(0,-50,50)); Poles.SetValue(4, gp_Pnt(0,0,50)); Poles.SetValue(5, gp_Pnt(0,0,0)); Poles.SetValue(6, gp_Pnt(0,0,-50)); Poles.SetValue(7, gp_Pnt(0,50,-50)); Poles.SetValue(8, gp_Pnt(0,100,-50)); Poles.SetValue(9, gp_Pnt(0,100,0)); TColStd_Array1OfReal PolesWeight(1,9); PolesWeight.SetValue(1, 1.0); PolesWeight.SetValue(2, 0.707); PolesWeight.SetValue(3, 1.0); PolesWeight.SetValue(4, 0.707); PolesWeight.SetValue(5, 1.0); PolesWeight.SetValue(6, 0.707); PolesWeight.SetValue(7, 1.0); PolesWeight.SetValue(8, 0.707); PolesWeight.SetValue(9, 1.0); for(int i=0; i<9; ++i) { TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(Poles.Value(i+1)); Handle(AIS_Shape) vert = new AIS_Shape(aVertex); myAISContext->SetColor(vert,Quantity_NOC_WHITE,Standard_False); myAISContext->Display(vert,Standard_False); if(i != 8) { TopoDS_Edge tedge = BRepBuilderAPI_MakeEdge(Poles.Value(i+1), Poles.Value(i+2)); TopoDS_Wire twire= BRepBuilderAPI_MakeWire(tedge); Handle(AIS_Shape) awire = new AIS_Shape(twire); myAISContext->SetColor(awire,Quantity_NOC_WHITE,Standard_False); myAISContext->Display(awire, Standard_False); } Fit(); } Fit(); Standard_Integer curtype = 4; if(curtype == 1) { /// 均匀B样条,节点向量中的节点值成等差排布 /// 均匀B样条的基函数呈周期性,即所有的基函数有相同的形状 /// 每个后续基函数仅仅市前面基函数在新位置上的重复 Standard_Integer degree(2); Standard_Integer PNum = 9; Standard_Integer KNum = PNum + degree + 1; TColStd_Array1OfReal knots(1,KNum); for(int i=0; i<KNum; ++i) { knots.SetValue(i+1, i); } TColStd_Array1OfInteger mults(1,KNum); for(int i=0; i<KNum; ++i) { mults.SetValue(i+1, 1); std::cout << mults.Value(i+1) << std::endl; } Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(Poles, knots, mults, degree); TopoDS_Edge ed1 = BRepBuilderAPI_MakeEdge(curve); TopoDS_Wire wr1 = BRepBuilderAPI_MakeWire(ed1); Handle(AIS_Shape) red = new AIS_Shape(wr1); myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False); myAISContext->Display(red,Standard_False); Fit(); } else if(curtype == 2) { /// 准均匀B样条,节点向量中的节点值也是等差排布,但是起点和终点都有k-1的重复度,其中ke为曲线次数。 Standard_Integer degree(2); Standard_Integer PNum = 9; Standard_Integer KNum = PNum-1; TColStd_Array1OfReal knots(1,KNum); for(int i=0; i<KNum; ++i) { knots.SetValue(i+1, i); } TColStd_Array1OfInteger mults(1,KNum); for(int i=0; i<KNum; ++i) { if(i == 0 || i == KNum-1) { mults.SetValue(i+1, degree+1); } else { mults.SetValue(i+1, 1); } } Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(Poles, knots, mults, degree); TopoDS_Edge ed1 = BRepBuilderAPI_MakeEdge(curve); TopoDS_Wire wr1 = BRepBuilderAPI_MakeWire(ed1); Handle(AIS_Shape) red = new AIS_Shape(wr1); myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False); myAISContext->Display(red,Standard_False); Fit(); } else if(curtype == 3) { /// 分段Bezier曲线 Standard_Integer degree(2); Standard_Integer PNum = 9; Standard_Integer KNum = PNum - 4; TColStd_Array1OfReal knots(1,KNum); for(int i=0; i<KNum; ++i) { knots.SetValue(i+1, i); } TColStd_Array1OfInteger mults(1,KNum); for(int i=0; i<KNum; ++i) { if(i == 0 || i == KNum-1) { mults.SetValue(i+1, degree+1); } else { mults.SetValue(i+1, degree); } } Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(Poles, knots, mults, degree); TopoDS_Edge ed1 = BRepBuilderAPI_MakeEdge(curve); TopoDS_Wire wr1 = BRepBuilderAPI_MakeWire(ed1); Handle(AIS_Shape) red = new AIS_Shape(wr1); myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False); myAISContext->Display(red,Standard_False); Fit(); } else if(curtype == 4) { /// 有理B样条曲线 Standard_Integer degree(2); Standard_Integer PNum = 9; Standard_Integer KNum = PNum - 1; TColStd_Array1OfReal knots(1,KNum); for(int i=0; i<KNum; ++i) { knots.SetValue(i+1, i); } TColStd_Array1OfInteger mults(1,KNum); for(int i=0; i<KNum; ++i) { if(i == 0 || i == KNum-1) { mults.SetValue(i+1, degree+1); } else { mults.SetValue(i+1, 1); } } Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(Poles, PolesWeight, knots, mults, degree); TopoDS_Edge ed1 = BRepBuilderAPI_MakeEdge(curve); TopoDS_Wire wr1 = BRepBuilderAPI_MakeWire(ed1); Handle(AIS_Shape) red = new AIS_Shape(wr1); myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False); myAISContext->Display(red,Standard_False); Fit(); }
https://github.com/xmba15/bezier_curve