A-7 OCCT获取轮廓线,并利用VSG显示

A-7 2023/4/14

OCCT获取轮廓线,并利用VSG显示

  • 利用OCC的函数库获取给定几何体的轮廓线
  • 将轮廓线离散化并把离散化之后的信息放入VSG的数组中,以便进行下一步的绘制
  • 代码如下
void OCCGeometry::createedgeMesh(TopoDS_Shape Shape){

   //遍历几何体的每一条边,注意是几何体的边不是离散化网格的边,实际上就是获取几何体的轮廓线
    for (TopExp_Explorer explorer(Shape, TopAbs_EDGE); explorer.More(); explorer.Next()){
       
        
        TopoDS_Edge edge = TopoDS::Edge(explorer.Current());
  
        BRepAdaptor_Curve curve(edge);
        Standard_Real startParam, endParam;
        //获取曲线的开始点和结束点
        BRep_Tool::Range(edge, startParam, endParam);
        gp_Pnt startPoint = curve.Value(startParam);
        gp_Pnt endPoint = curve.Value(endParam);
        // 检查曲线是否有效
        //if (curve.GetType() != GeomAbs_Line && curve.GetType() != GeomAbs_Circle && curve.GetType() != GeomAbs_Ellipse && curve.GetType() != GeomAbs_Hyperbola && curve.GetType() != GeomAbs_Parabola){
        //    continue; // 如果曲线无效,跳过
        //}
        
        //注意不能设置的过小,不然离散化的顶点就太多了
        Standard_Real deflection = 0.5;
        
        GCPnts_TangentialDeflection thePointsOnCurve;
        thePointsOnCurve.Initialize(curve, startParam, endParam,2,0.1,deflection);
        int Pointsize= thePointsOnCurve.NbPoints();
        auto temp_edgevertices = vsg::vec3Array::create(Pointsize);
        auto temp_edgeindexes = vsg::uintArray::create(2 * Pointsize - 2);
        //将曲线离散化
        //获取曲线上的顶点
        for (Standard_Integer i = 1; i <= Pointsize; ++i){
            gp_Pnt point = thePointsOnCurve.Value(i);
            vsg::vec3 V = vsg::vec3(float(point.X()), float(point.Y()), float(point.Z()));
            temp_edgevertices->at(i-1) = V;
        }
        //设置顶点的索引
        for (int k = 0, j = 0; j < Pointsize - 1; k = k + 2, j++) {
            temp_edgeindexes->at(k) = j;
            temp_edgeindexes->at(k + 1) = j + 1;
        }
        edgevertices.push_back(temp_edgevertices);
        edgeindexes.push_back(temp_edgeindexes);
    }
   
}

效果展示

A-7-0
A-7-1
在这里插入图片描述

  • 欢迎交流,QQ:963385291
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值