1 #include "GEOM_EdgeSource.h"
3 #include <vtkObjectFactory.h>
6 #include <vtkCellArray.h>
8 #include <BRep_Tool.hxx>
9 #include <Poly_Polygon3D.hxx>
10 #include <Poly_Triangulation.hxx>
11 #include <TColStd_Array1OfInteger.hxx>
12 #include <Poly_PolygonOnTriangulation.hxx>
14 #include <vtkStripper.h>
15 #include <vtkPolyData.h>
17 vtkStandardNewMacro(GEOM_EdgeSource);
19 GEOM_EdgeSource::GEOM_EdgeSource()
23 GEOM_EdgeSource::~GEOM_EdgeSource()
29 AddEdge(const TopoDS_Edge& theEdge)
31 myEdgeSet.Add(theEdge);
38 vtkPolyData* aPolyData = GetOutput();
39 aPolyData->Allocate();
40 vtkPoints* aPts = vtkPoints::New();
41 aPolyData->SetPoints(aPts);
44 TEdgeSet::Iterator anIter(myEdgeSet);
45 for(; anIter.More(); anIter.Next()){
46 const TopoDS_Edge& anEdge = anIter.Value();
47 OCC2VTK(anEdge,aPolyData,aPts);
53 OCC2VTK(const TopoDS_Edge& theEdge,
54 vtkPolyData* thePolyData,
57 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
58 Standard_Integer i = 1;
59 Handle(Poly_Triangulation) T;
60 TopLoc_Location aEdgeLoc;
61 BRep_Tool::PolygonOnTriangulation(theEdge, aEdgePoly, T, aEdgeLoc, i);
63 Handle(Poly_Polygon3D) P;
64 if(aEdgePoly.IsNull())
65 P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc);
67 if(P.IsNull() && aEdgePoly.IsNull())
73 Standard_Boolean isidtrsf = true;
74 if(!aEdgeLoc.IsIdentity()) {
76 edgeTransf = aEdgeLoc.Transformation();
79 if (aEdgePoly.IsNull()) {
80 Standard_Integer aNbNodes = P->NbNodes();
81 const TColgp_Array1OfPnt& aNodesP = P->Nodes();
83 for(int j = 1; j < aNbNodes; j++){
84 gp_Pnt pt1 = aNodesP(j);
85 gp_Pnt pt2 = aNodesP(j+1);
88 // apply edge transformation
89 pt1.Transform(edgeTransf);
90 pt2.Transform(edgeTransf);
93 float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
95 anIds[0] = thePts->InsertNextPoint(aCoord1);
97 float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
98 anIds[1] = thePts->InsertNextPoint(aCoord2);
100 thePolyData->InsertNextCell(VTK_LINE,2,anIds);
103 Standard_Integer aNbNodes = aEdgePoly->NbNodes();
104 const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes();
105 const TColgp_Array1OfPnt& anId2Pnts = T->Nodes();
107 for(int j = 1; j < aNbNodes; j++) {
108 Standard_Integer id1 = aNodeIds(j);
109 Standard_Integer id2 = aNodeIds(j+1);
111 gp_Pnt pt1 = anId2Pnts(id1);
112 gp_Pnt pt2 = anId2Pnts(id2);
115 // apply edge transformation
116 pt1.Transform(edgeTransf);
117 pt2.Transform(edgeTransf);
120 float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
122 anIds[0] = thePts->InsertNextPoint(aCoord1);
124 float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
125 anIds[1] = thePts->InsertNextPoint(aCoord2);
127 thePolyData->InsertNextCell(VTK_LINE,2,anIds);