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);
}
}
效果展示
- 欢迎交流,QQ:963385291