![]() |
【转帖】我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc);,似
我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc);,似乎根本没有进入三角化的代码就退出了
// *************************************************************** // Translation version: 1.0 · date: 11/28/2007 // ------------------------------------------------------------- // OCC TopoDS_Shape类型数据导出 // ------------------------------------------------------------- // Copyright (C) 2007 - All Rights Reserved // *************************************************************** // // *************************************************************** #include <iostream> using namespace std; #define WNT #include <TopoDS_Shape.hxx> #include <BRepPrimAPI_MakeTorus.hxx> #include <BRepPrimAPI_MakeBox.hxx> #include <BRepAlgoAPI_Section.hxx> #include <gp_Pln.hxx> #include <TopoDS_Iterator.hxx> #include <BRep_Tool.hxx> #include <Poly_Triangulation.hxx> #include <TopoDS.hxx> #include <Poly_PolygonOnTriangulation.hxx> #pragma comment( lib, "TKTopAlgo" ) #pragma comment( lib, "TKernel" ) #pragma comment( lib, "TKPrim" ) #pragma comment( lib, "TKBRep" ) #pragma comment( lib, "TKBO" ) #pragma comment( lib, "TKMath" ) void translationDispatch(const TopoDS_Shape& topoShape); //************************************ // Method: topoEdgeTranslater // FullName: topoEdgeTranslater // Access: public // Returns: void // Qualifier: 转化线数据 // Parameter: const TopoDS_Shape & topoShape //************************************ void topoEdgeTranslater(const TopoDS_Shape& topoShape) { TopoDS_Edge topoEdge = TopoDS::Edge(topoShape); Handle(Poly_PolygonOnTriangulation) aEdgePoly; Standard_Integer i = 1; Handle(Poly_Triangulation) T; TopLoc_Location aEdgeLoc; BRep_Tool::PolygonOnTriangulation(topoEdge, aEdgePoly, T, aEdgeLoc, i); if(aEdgePoly.IsNull()) { return; } gp_Trsf edgeTransf; Standard_Boolean isidtrsf = true; if(!aEdgeLoc.IsIdentity()) { isidtrsf = false; edgeTransf = aEdgeLoc.Transformation(); } Standard_Integer nbnodes = aEdgePoly->NbNodes(); const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes(); const TColgp_Array1OfPnt& theNodes = T->Nodes(); float coord[3]; for(int j=1; j < nbnodes; j++) { Standard_Integer id1 = Nodesidx(j); Standard_Integer id2 = Nodesidx(j+1); gp_Pnt pt1 = theNodes(id1); gp_Pnt pt2 = theNodes(id2); if(!isidtrsf) { // apply edge transformation pt1.Transform(edgeTransf); pt2.Transform(edgeTransf); } // insert pt1 coord[0] = (float)pt1.X(); coord[1] = (float)pt1.Y(); coord[2] = (float)pt1.Z(); cout << "line: ( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << " To "; // insert pt2 coord[0] = (float)pt2.X(); coord[1] = (float)pt2.Y(); coord[2] = (float)pt2.Z(); cout << "( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << endl; } } //************************************ // Method: topoFaceTranslater // FullName: topoFaceTranslater // Access: public // Returns: void // Qualifier: 转化面数据,将其三角化为表面三角Mesh // Parameter: const TopoDS_Shape & topoShape //************************************ void topoFaceTranslater(const TopoDS_Shape& topoShape) { TopoDS_Face topoFace = TopoDS::Face(topoShape); if (topoFace.IsNull()) { return; } TopLoc_Location aLoc; Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc); if(aPoly.IsNull()) { return; } gp_Trsf myTransf; Standard_Boolean identity = true; if(!aLoc.IsIdentity()) { identity = false; myTransf = aLoc.Transformation(); } Standard_Integer nbNodesInFace = aPoly->NbNodes(); Standard_Integer nbTriInFace = aPoly->NbTriangles(); const Poly_Array1OfTriangle& Triangles = aPoly->Triangles(); const TColgp_Array1OfPnt& Nodes = aPoly->Nodes(); // 获取顶点数据 cout << "顶点数据:" << endl; for(Standard_Integer i=1;i<=nbNodesInFace;i++) { gp_Pnt P = Nodes(i); float coord[3]; if(!identity) P.Transform(myTransf); coord[0] = (float)P.X(); coord[1] = (float)P.Y(); coord[2] = (float)P.Z(); cout << i-1 << ": ( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << endl; } // 获取三角网拓扑数据 cout << "三角网拓扑数据:" << endl; for(Standard_Integer i=1;i<=nbTriInFace;i++) { // Get the triangle Standard_Integer N1,N2,N3; Triangles(i).Get(N1,N2,N3); int pts[3]; pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1; cout << i-1 << ": ( " << pts[0] << ", " << pts[1] << ", " << pts[2] << " )" << endl; } } //************************************ // Method: topoVertexTranslater // FullName: topoVertexTranslater // Access: public // Returns: void // Qualifier: 转换顶点 // Parameter: const TopoDS_Shape & topoShape //************************************ void topoVertexTranslater(const TopoDS_Shape& topoShape) { // TODO: } //************************************ // Method: translationDispatch // FullName: translationDispatch // Access: public // Returns: void // Qualifier: OCC TopoDS_Shape数据转换入口 // Parameter: const TopoDS_Shape & topoShape //************************************ void translationDispatch(const TopoDS_Shape& topoShape) { if (topoShape.IsNull()) { return; } switch(topoShape.ShapeType()) { case TopAbs_EDGE: cout << "TopAbs_EDGE" << endl; break; case TopAbs_FACE: cout << "TopAbs_FACE" << endl; break; case TopAbs_SHAPE: cout << "TopAbs_SHAPE" << endl; break; case TopAbs_SHELL: cout << "TopAbs_SHELL" << endl; break; case TopAbs_SOLID: cout << "TopAbs_SOLID" << endl; break; case TopAbs_VERTEX: cout << "TopAbs_VERTEX" << endl; break; case TopAbs_WIRE: cout << "TopAbs_WIRE" << endl; break; case TopAbs_COMPOUND: cout << "TopAbs_COMPOUND" << endl; break; case TopAbs_COMPSOLID: cout << "TopAbs_COMPSOLID" << endl; break; default: break; } switch(topoShape.ShapeType()) { case TopAbs_EDGE: topoEdgeTranslater(topoShape); break; case TopAbs_FACE: topoFaceTranslater(topoShape); break; case TopAbs_VERTEX: topoVertexTranslater(topoShape); break; case TopAbs_SHAPE: case TopAbs_SHELL: case TopAbs_SOLID: case TopAbs_WIRE: case TopAbs_COMPOUND: case TopAbs_COMPSOLID: { TopoDS_Iterator anIt; TopoDS_Shape aSTmp; anIt.Initialize(topoShape); for (; anIt.More(); anIt.Next()) { aSTmp=anIt.Value(); if (!aSTmp.IsNull()) { translationDispatch(aSTmp); } } } break; default: break; } } int main(int argc, char** argv) { TopoDS_Shape theTorus = BRepPrimAPI_MakeTorus(60.0, 20.0); gp_Pln P(1,2,1,-15); TopoDS_Shape pSection = BRepAlgoAPI_Section(theTorus,P); TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60); translationDispatch(theBox); return 0; } |
回复: 【转帖】我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc);,似
子优 11:01:02
在translationDispatch(theBox);之前 薛定谔的猫 11:01:13 嗯 子优 11:01:27 BRepMesh::Mesh(theBox, 0.5); |
所有的时间均为北京时间。 现在的时间是 05:44 AM. |