Open CASCADE之拟合Smooth curve

简介: Open CASCADE之拟合Smooth curve

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 曲线和曲面的功能。


image.png


从接口来说:


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


https://github.com/oysteinmyrmo/bezier

相关文章
|
机器学习/深度学习 数据可视化 Serverless
ROC曲线(Receiver Operating Characteristic Curve)
ROC曲线(Receiver Operating Characteristic Curve)是一种用于评估二分类模型性能的图形工具。它以不同的分类阈值为基础,绘制出模型的真正例率(True Positive Rate,也称为召回率)与假正例率(False Positive Rate)之间的关系。
264 1
|
机器学习/深度学习 算法 PyTorch
Gradient Descent Algorithm 梯度下降算法
Gradient Descent Algorithm 梯度下降算法
119 0
|
机器学习/深度学习 算法
线性回归(Linear regression)算法
属于有监督学习、判别模型、有预测函数、有优化目标,有优化求解算法
308 0
面积曲线AUC(area under curve)
面积曲线AUC(area under curve)
232 2
面积曲线AUC(area under curve)
【线性回归】| Linear Regression实现示例
【线性回归】| Linear Regression实现示例
114 0
【线性回归】| Linear Regression实现示例
|
BI
票房线性回归 Linear regression of film box office
票房线性回归 Linear regression of film box office
296 0
票房线性回归 Linear regression of film box office
|
算法
Halcon拟合系列(2)直线/圆/椭圆/矩形拟合算子fit_line_contour_xld/fit_circle_contour_xld/...
Halcon拟合系列(2)直线/圆/椭圆/矩形拟合算子fit_line_contour_xld/fit_circle_contour_xld/...
2303 0
|
Windows Python
Algorithm:实现LDA的Gibbs Gauss采样(绘制多图subplot)
Algorithm:实现LDA的Gibbs Gauss采样(绘制多图subplot)
Algorithm:实现LDA的Gibbs Gauss采样(绘制多图subplot)
成功解决coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to inc
成功解决coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to inc
|
算法
Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCASCADE algorithms to approximate the NURBS curve to arc spline.
1538 0