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()
27 void GEOM_EdgeSource::AddEdge (const TopoDS_Edge& theEdge,
30 myEdgeSet.Add(theEdge);
31 myIsVector = theIsVector;
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,myIsVector);
51 void GEOM_EdgeSource::OCC2VTK (const TopoDS_Edge& theEdge,
52 vtkPolyData* thePolyData,
56 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
57 Standard_Integer i = 1;
58 Handle(Poly_Triangulation) T;
59 TopLoc_Location aEdgeLoc;
60 BRep_Tool::PolygonOnTriangulation(theEdge, aEdgePoly, T, aEdgeLoc, i);
62 Handle(Poly_Polygon3D) P;
63 if(aEdgePoly.IsNull())
64 P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc);
66 if(P.IsNull() && aEdgePoly.IsNull())
72 Standard_Boolean isidtrsf = true;
73 if(!aEdgeLoc.IsIdentity()) {
75 edgeTransf = aEdgeLoc.Transformation();
80 if (aEdgePoly.IsNull()) {
81 Standard_Integer aNbNodes = P->NbNodes();
82 const TColgp_Array1OfPnt& aNodesP = P->Nodes();
85 aP2 = aNodesP(aNbNodes);
87 for (int j = 1; j < aNbNodes; j++) {
88 gp_Pnt pt1 = aNodesP(j);
89 gp_Pnt pt2 = aNodesP(j+1);
92 // apply edge transformation
93 pt1.Transform(edgeTransf);
94 pt2.Transform(edgeTransf);
97 float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
99 anIds[0] = thePts->InsertNextPoint(aCoord1);
101 float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
102 anIds[1] = thePts->InsertNextPoint(aCoord2);
104 thePolyData->InsertNextCell(VTK_LINE,2,anIds);
107 Standard_Integer aNbNodes = aEdgePoly->NbNodes();
108 const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes();
109 const TColgp_Array1OfPnt& anId2Pnts = T->Nodes();
112 aP2 = anId2Pnts(aNbNodes);
114 for(int j = 1; j < aNbNodes; j++) {
115 Standard_Integer id1 = aNodeIds(j);
116 Standard_Integer id2 = aNodeIds(j+1);
118 gp_Pnt pt1 = anId2Pnts(id1);
119 gp_Pnt pt2 = anId2Pnts(id2);
122 // apply edge transformation
123 pt1.Transform(edgeTransf);
124 pt2.Transform(edgeTransf);
127 float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()};
129 anIds[0] = thePts->InsertNextPoint(aCoord1);
131 float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()};
132 anIds[1] = thePts->InsertNextPoint(aCoord2);
134 thePolyData->InsertNextCell(VTK_LINE,2,anIds);
138 // vector representation has an arrow on its end
142 // apply edge transformation
143 aP1.Transform(edgeTransf);
144 aP2.Transform(edgeTransf);
148 gp_Vec aDirVec (aP1, aP2);
149 Standard_Real aDist = aDirVec.Magnitude();
150 if (aDist < gp::Resolution()) return;
151 gp_Dir aDirection (aDirVec);
153 Standard_Real anAngle = PI/180.*5.;
154 Standard_Real aLength = aDist/10.;
156 Standard_Real dx,dy,dz;
157 aDirection.Coord(dx,dy,dz);
159 // Pointe de la fleche
160 Standard_Real xo,yo,zo;
163 // Centre du cercle base de la fleche
164 gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
166 // Construction d'un repere i,j pour le cercle
168 if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
169 else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
170 else aDirN = gp::DZ();
172 gp_Dir aDirI = aDirection ^ aDirN;
173 gp_Dir aDirJ = aDirection ^ aDirI;
175 // Add points and segments, composing the arrow
176 Standard_Real cosinus, sinus, Tg = tan(anAngle);
178 float coord[3] = {xo, yo, zo};
180 vtkIdType ptLoc = thePts->InsertNextPoint(coord);
181 vtkIdType ptFirst = 0;
182 vtkIdType ptPrev = 0;
188 for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
190 cosinus = cos(2. * PI / NbPoints * (i-1));
191 sinus = sin(2. * PI / NbPoints * (i-1));
193 gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
199 ptCur = thePts->InsertNextPoint(coord);
206 // insert line (ptCur,ptPrev)
208 thePolyData->InsertNextCell(VTK_LINE,2,pts);
211 // insert line (ptCur,ptLoc)
213 thePolyData->InsertNextCell(VTK_LINE,2,pts);
216 // insert line (ptCur,ptFirst)
219 thePolyData->InsertNextCell(VTK_LINE,2,pts);