Abstract. By making a simple box to demonstrate the BRep data structure of the OpenCASCADE. The construction method is different from BRepPrimAPI_MakeBox. In the paper construct the box from vertex, edge to solid, while in BRepPrimAPI_MakeBox from solid, shell to vertex. From the construction, the BRep data structure in OpenCASCADE also can be called the Winged-Edge data structure.
Key Words. OpenCASCADE, BRep, Box, The Winged-Edge Structure
为 了理解ModelingData模块中OpenCASCADE的边界表示法BRep数据结构,决定参考其实现,自己来创建出基本图元,进而理解其中的 BRep数据结构。本文以最简单的长方体Box入手,从点、边到体的创建出一个形状。并将构造的形状在Draw Test Harness中进行显示,且进行布尔运算,来验证构造结果的正确性。
// make vertex of the box. aBuilder.MakeVertex(aVertices[0], aPoints[0], Precision::Confusion()); aBuilder.MakeVertex(aVertices[1], aPoints[1], Precision::Confusion()); aBuilder.MakeVertex(aVertices[2], aPoints[2], Precision::Confusion()); aBuilder.MakeVertex(aVertices[3], aPoints[3], Precision::Confusion()); aBuilder.MakeVertex(aVertices[4], aPoints[4], Precision::Confusion()); aBuilder.MakeVertex(aVertices[5], aPoints[5], Precision::Confusion()); aBuilder.MakeVertex(aVertices[6], aPoints[6], Precision::Confusion()); aBuilder.MakeVertex(aVertices[7], aPoints[7], Precision::Confusion());
创建边的同时,将其边中的三维曲线信息也设置进去,代码如下所示:
// make edges of the box.
aBuilder.MakeEdge(aEdges[0], new Geom_Line(aLines[0]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[1], new Geom_Line(aLines[1]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[2], new Geom_Line(aLines[2]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[3], new Geom_Line(aLines[3]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[4], new Geom_Line(aLines[4]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[5], new Geom_Line(aLines[5]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[6], new Geom_Line(aLines[6]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[7], new Geom_Line(aLines[7]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[8], new Geom_Line(aLines[8]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[9], new Geom_Line(aLines[9]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[10],new Geom_Line(aLines[10]),Precision::Confusion()); aBuilder.MakeEdge(aEdges[11],new Geom_Line(aLines[11]),Precision::Confusion());
创建的边Edge还需要与顶点Vertex关联上,且需要注意顶点的反向,示例代码如下所示:
// set the vertex info of the edges.
// edge 0:
{
TopoDS_Vertex V1 = aVertices[0];
TopoDS_Vertex V2 = aVertices[1];
// make faces of the box.
aBuilder.MakeFace(aFaces[0],new Geom_Plane(aPlanes[0]),Precision::Confusion());
aBuilder.Add(aFaces[0], aWires[0]);
// set bottom pcurve info of between the edge and surface. { // pcurve 0: double u = 0.0; double v = 0.0; double du = 0.0; double dv = 0.0; gp_Dir DX = aPlanes[0].XAxis().Direction(); gp_Dir DY = aPlanes[0].YAxis().Direction();