Open CASCADE学习|分割曲线

1、通过参数进行分割

分别获得曲线的 FirstParameter 和 LastParameter ,然后对参数进行分割,获得n个ui,并对每个ui调用D0(获得这个点的坐标值)或D1(获得这个点的坐标值和切向量)。这个方法的优点是,简单易行,好操作,缺点均分参数轴获得的曲线的分割可能不是均匀的。

cpp 复制代码
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
​
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
​
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
​
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    gp_Pnt p1(-5, 0, 0.0);
    gp_Pnt p2(5, 0, 0.0);
    gp_Ax2  sr(center, Z);
    gp_Circ  bcircle(sr, 5);
    Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p1, p2, 0);
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(bc);
    Standard_Integer splitN = 10;
    Standard_Real firstParam = bc->FirstParameter();
    Standard_Real lastParam = bc->LastParameter();
    Viewer vout(50, 50, 500, 500);
    for (Standard_Integer i = 0; i < splitN + 1; ++i)
    {
        Standard_Real ui = i * (lastParam - firstParam) / splitN;
        gp_Pnt pi;
        gp_Vec veci;
        bc->D1(ui, pi, veci);
        TopoDS_Vertex verti = BRepBuilderAPI_MakeVertex(pi);
        vout << verti;
    }
    vout << anEdge;
    vout << xline;
    vout << yline;
    vout << zline;
    vout.StartMessageLoop();
    return 0;
}
​

2、直接对曲线分割

通过类 GCPnts_UniformAbscissa 实现对一个Geom_Curve对象的平均分割,获得分割点的坐标及对应的参数,将坐标和参数存入一个列表中,供其他操作使用。

cpp 复制代码
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
​
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
​
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <GCPnts_UniformAbscissa.hxx>
​
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    gp_Pnt p1(-5, 0, 0.0);
    gp_Pnt p2(5, 0, 0.0);
    gp_Ax2  sr(center, Z);
    gp_Circ  bcircle(sr, 5);
    Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p1, p2, 0);
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(bc);
    Standard_Integer splitN = 10;
    GeomAdaptor_Curve GAC(bc);
    GCPnts_UniformAbscissa UA(GAC, splitN + 1);
    gp_Pnt* pnts = new gp_Pnt[splitN + 1];
    Standard_Real* params = new Standard_Real[splitN + 1];
    Viewer vout(50, 50, 500, 500);
    if (UA.IsDone())
    {
        Standard_Real n = UA.NbPoints();
        Standard_Integer index = 0;
        for (; index < n + 1; index++)
        {
            Standard_Real parami = UA.Parameter(index + 1);
            params[index] = parami;
            gp_Pnt tpnt;
            bc->D0(parami, tpnt);
            pnts[index] = tpnt;
            TopoDS_Vertex verti = BRepBuilderAPI_MakeVertex(tpnt);
            vout << verti;
        }
    }
    vout << anEdge;
    vout << xline;
    vout << yline;
    vout << zline;
    vout.StartMessageLoop();
    return 0;
}
​
相关推荐
唐诺3 小时前
几种广泛使用的 C++ 编译器
c++·编译器
南宫生4 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
sanguine__4 小时前
Web APIs学习 (操作DOM BOM)
学习
冷眼看人间恩怨4 小时前
【Qt笔记】QDockWidget控件详解
c++·笔记·qt·qdockwidget
红龙创客4 小时前
某狐畅游24校招-C++开发岗笔试(单选题)
开发语言·c++
Lenyiin4 小时前
第146场双周赛:统计符合条件长度为3的子数组数目、统计异或值为给定值的路径数目、判断网格图能否被切割成块、唯一中间众数子序列 Ⅰ
c++·算法·leetcode·周赛·lenyiin
yuanbenshidiaos6 小时前
c++---------数据类型
java·jvm·c++
数据的世界016 小时前
.NET开发人员学习书籍推荐
学习·.net
四口鲸鱼爱吃盐6 小时前
CVPR2024 | 通过集成渐近正态分布学习实现强可迁移对抗攻击
学习
十年一梦实验室6 小时前
【C++】sophus : sim_details.hpp 实现了矩阵函数 W、其导数,以及其逆 (十七)
开发语言·c++·线性代数·矩阵