Salome HOME
Update GUI documentation for bugs 16559
[modules/geom.git] / src / OBJECT / GEOM_EdgeSource.cxx
1 #include "GEOM_EdgeSource.h" 
2  
3 #include <vtkObjectFactory.h> 
4
5 #include <vtkPoints.h> 
6 #include <vtkCellArray.h> 
7
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>
13  
14 #include <vtkStripper.h>  
15 #include <vtkPolyData.h>  
16  
17 vtkStandardNewMacro(GEOM_EdgeSource);
18  
19 GEOM_EdgeSource::GEOM_EdgeSource() 
20
21
22  
23 GEOM_EdgeSource::~GEOM_EdgeSource() 
24
25
26  
27 void  
28 GEOM_EdgeSource:: 
29 AddEdge(const TopoDS_Edge& theEdge) 
30
31   myEdgeSet.Add(theEdge); 
32
33  
34 void
35 GEOM_EdgeSource:: 
36 Execute()
37 {
38   vtkPolyData* aPolyData = GetOutput();
39   aPolyData->Allocate();
40   vtkPoints* aPts = vtkPoints::New();
41   aPolyData->SetPoints(aPts);
42   aPts->Delete();
43
44   TEdgeSet::Iterator anIter(myEdgeSet);
45   for(; anIter.More(); anIter.Next()){
46     const TopoDS_Edge& anEdge = anIter.Value();
47     OCC2VTK(anEdge,aPolyData,aPts);
48   }
49 }
50
51 void  
52 GEOM_EdgeSource:: 
53 OCC2VTK(const TopoDS_Edge& theEdge,  
54         vtkPolyData* thePolyData, 
55         vtkPoints* thePts) 
56 {
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);
62   
63   Handle(Poly_Polygon3D) P;
64   if(aEdgePoly.IsNull())
65     P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc);
66
67   if(P.IsNull() && aEdgePoly.IsNull())
68     return;
69   
70   // Location edges
71   //---------------
72   gp_Trsf edgeTransf;
73   Standard_Boolean isidtrsf = true;
74   if(!aEdgeLoc.IsIdentity())  {
75     isidtrsf = false;
76     edgeTransf = aEdgeLoc.Transformation();
77   }
78
79   if (aEdgePoly.IsNull()) {
80     Standard_Integer aNbNodes = P->NbNodes();
81     const TColgp_Array1OfPnt& aNodesP = P->Nodes();
82
83     for(int j = 1; j < aNbNodes; j++){
84       gp_Pnt pt1 = aNodesP(j);
85       gp_Pnt pt2 = aNodesP(j+1);
86     
87       if(!isidtrsf) {
88               // apply edge transformation
89               pt1.Transform(edgeTransf);
90               pt2.Transform(edgeTransf);
91       }
92       
93       float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
94       vtkIdType anIds[2];
95       anIds[0] = thePts->InsertNextPoint(aCoord1);
96       
97       float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
98       anIds[1] = thePts->InsertNextPoint(aCoord2);
99
100       thePolyData->InsertNextCell(VTK_LINE,2,anIds);
101     }
102   } else {
103     Standard_Integer aNbNodes = aEdgePoly->NbNodes();
104     const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes();
105     const TColgp_Array1OfPnt& anId2Pnts = T->Nodes();
106
107     for(int j = 1; j < aNbNodes; j++) {
108       Standard_Integer id1 = aNodeIds(j);
109       Standard_Integer id2 = aNodeIds(j+1);
110       
111       gp_Pnt pt1 = anId2Pnts(id1);
112       gp_Pnt pt2 = anId2Pnts(id2);
113           
114       if(!isidtrsf) {
115         // apply edge transformation
116               pt1.Transform(edgeTransf);
117               pt2.Transform(edgeTransf);
118       }
119       
120       float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
121       vtkIdType anIds[2];
122       anIds[0] = thePts->InsertNextPoint(aCoord1);
123       
124       float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
125       anIds[1] = thePts->InsertNextPoint(aCoord2);
126
127       thePolyData->InsertNextCell(VTK_LINE,2,anIds);
128     }
129   }
130 }