OpenCascade模型解析-遍历模型

OpenCascade提供了TopExp_Explorer类,可以遍历模型中的face、edge等。

为了方便分析研究模型的构成,《OpenCascade插件化三维算法研究平台》开发了模型遍历(解析)功能。

效果如下:

如上图所示,打开一个模型时,模型是一个整体,无法按模型的几何构成一点点查看与分析。

把模型解析(遍历)后,就可以一个面一个边地查看了。

参考代码,解析(遍历)一个Box:

void ExplorerDemo()
{
    NCollection_Vector myObject3d;
  // Make a box with a corner at [0, 0, 0] and the specified sizes.
  Standard_Real aSizeX = 5.0;
  Standard_Real aSizeY = 10.0;
  Standard_Real aSizeZ = 15.0;
  TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ);

  // Explore vertex references.
  myResult << "Vertex refs. : ";
  Standard_Integer nbVertices = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_VERTEX); anExp.More(); anExp.Next(), ++nbVertices)
  {
    const TopoDS_Shape& aShape = anExp.Current();
    Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
    anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
    myObject3d.Append(anAisShape);
  }


  // Explore edge references.
  myResult << "Edge refs.   : ";
  Standard_Integer nbEdges = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_EDGE); anExp.More(); anExp.Next(), ++nbEdges)
  {
    const TopoDS_Shape& aShape = anExp.Current();
    Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
    anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
    anAisShape->SetWidth(2.5);
    myObject3d.Append(anAisShape);
  }
  myResult << nbEdges << std::endl;

  // Explore face references.

  Standard_Integer nbFaces = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_FACE); anExp.More(); anExp.Next(), ++nbFaces)
  {
    const TopoDS_Shape& aShape = anExp.Current();
    Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape);
    anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN));
    anAisShape->SetWidth(2.5);
    myObject3d.Append(anAisShape);
  }


  // Explore shell references.

  Standard_Integer nbWires = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_WIRE); anExp.More(); anExp.Next(), ++nbWires)
  {
  }


  // Explore shell references.

  Standard_Integer nbShells = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_SHELL); anExp.More(); anExp.Next(), ++nbShells)
  {
  }


  // Explore solid references.
  
  Standard_Integer nbSolids = 0;
  for (TopExp_Explorer anExp(aBox, TopAbs_SOLID); anExp.More(); anExp.Next(), ++nbSolids)
  {
  }
 
}

你可能感兴趣的:(数据库)