1. 程式人生 > >OpenCascade BRep 格式描述之二

OpenCascade BRep 格式描述之二

TopoDS_Face WhiteFace, BrownFace, RedFace, PinkFace;
TopoDS_Edge Edge1, Edge2, Edge3, Edge4, Edge5, Edge6, Edge7;
TopoDS_Wire Wire1;
gp_Pnt P1, P2, P3, P4, P5, P6, P7;

gp_Sphere sphere (gp_Ax3(gp_Pnt(0,0,0),gp_Dir(1,0,0)),150);

WhiteFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9);

//////////////////////////////////

P1.SetCoord(-15,200,10);
P2.SetCoord(5,204,0);
P3.SetCoord(15,200,0);
P4.SetCoord(-15,20,15);
P5.SetCoord(-5,20,0);
P6.SetCoord(15,20,35);
TColgp_Array2OfPnt array(1,3,1,2);
array.SetValue(1,1,P1);
array.SetValue(2,1,P2);
array.SetValue(3,1,P3);
array.SetValue(1,2,P4);
array.SetValue(2,2,P5);
array.SetValue(3,2,P6);
Handle (Geom_BSplineSurface) curve = GeomAPI_PointsToBSplineSurface(array,3,8,GeomAbs_C2,0.001);

RedFace = BRepBuilderAPI_MakeFace(curve);

////////////////////

gp_Circ circle(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),80);
Edge1 = BRepBuilderAPI_MakeEdge(circle,0,PI);

Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,-80),gp_Pnt(0,-10,40));
Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,-10,40),gp_Pnt(0,0,80));

TopoDS_Wire YellowWire;
BRepBuilderAPI_MakeWire MW1(Edge1,Edge2,Edge3);
if (MW1.IsDone()) {
YellowWire = MW1;
}

BrownFace = BRepBuilderAPI_MakeFace(YellowWire);


/////////////

P1.SetCoord(35,-200,40);
P2.SetCoord(50,-204,30);
P3.SetCoord(65,-200,30);
P4.SetCoord(35,-20,45);
P5.SetCoord(45,-20,30);
P6.SetCoord(65,-20,65);
TColgp_Array2OfPnt array2(1,3,1,2);
array2.SetValue(1,1,P1);
array2.SetValue(2,1,P2);
array2.SetValue(3,1,P3);
array2.SetValue(1,2,P4);
array2.SetValue(2,2,P5);
array2.SetValue(3,2,P6);

Handle (Geom_BSplineSurface) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2,3,8,GeomAbs_C2,0.001);

TopoDS_Face aFace = BRepBuilderAPI_MakeFace(BSplineSurf);

//2d lines
gp_Pnt2d P12d(0.9,0.1);
gp_Pnt2d P22d(0.2,0.7);
gp_Pnt2d P32d(0.02,0.1);

Handle (Geom2d_Line) line1 = new Geom2d_Line(P12d,gp_Dir2d((0.2-0.9),(0.7-0.1)));
Handle (Geom2d_Line) line2 = new Geom2d_Line(P22d,gp_Dir2d((0.02-0.2),(0.1-0.7)));
Handle (Geom2d_Line) line3 = new Geom2d_Line(P32d,gp_Dir2d((0.9-0.02),(0.1-0.1)));


//Edges are on the BSpline surface
Edge1 = BRepBuilderAPI_MakeEdge(line1,BSplineSurf,0,P12d.Distance(P22d));
Edge2 = BRepBuilderAPI_MakeEdge(line2,BSplineSurf,0,P22d.Distance(P32d));
Edge3 = BRepBuilderAPI_MakeEdge(line3,BSplineSurf,0,P32d.Distance(P12d));
Wire1 = BRepBuilderAPI_MakeWire(Edge1,Edge2,Edge3);
Wire1.Reverse();
PinkFace = BRepBuilderAPI_MakeFace(aFace,Wire1);
TopExp_Explorer ex;
TopoDS_Shape s;
for(ex.Init(PinkFace,TopAbs_EDGE);ex.More(); ex.Next())
{
s=ex.Current();
Edge4=TopoDS::Edge(s);
if(Edge4.IsEqual(Edge2))
Edge3=Edge3;

}
這是在mfc例2中的部分程式碼,for迴圈式我加的,問題是PinkFace 明明由edge1、2、3 生成,為什麼explorer PinkFace 中的edge就找不到與edge2相同的邊呢?僅能找到與edge1相同的邊,這種不確定的結果讓人無法捉摸。
另外博主有沒有好辦法,在不改occ庫程式碼的情況下,給每個topods_shape一個全域性唯一標識號或標識名稱。我試用hashcode,但不知如何正確設定它的上限,似乎它有可能重複,不能當作唯一識別符號。