1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_OCCReader.h
25 // Author : Christophe ATTANASIO
28 #include "GEOM_OCCReader.h"
31 #include <vtkPoints.h>
32 #include <vtkCellArray.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkPolyData.h>
37 // OpenCASCADE Includes
38 #include <TopExp_Explorer.hxx>
39 #include <Poly_Triangulation.hxx>
40 #include <Poly_Polygon3D.hxx>
41 #include <Poly_PolygonOnTriangulation.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Edge.hxx>
45 #include <Precision.hxx>
46 #include <BRepTools.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Geom2dAdaptor_Curve.hxx>
49 #include <Geom2dHatch_Intersector.hxx>
50 #include <Geom2dHatch_Hatcher.hxx>
51 #include <Geom2d_Curve.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <Geom2d_TrimmedCurve.hxx>
54 #include <HatchGen_Domain.hxx>
55 #include <TopAbs_ShapeEnum.hxx>
56 #include <gp_Dir2d.hxx>
57 #include <gp_Pnt2d.hxx>
58 #include <TColStd_Array1OfInteger.hxx>
59 #include <TColStd_Array1OfReal.hxx>
60 #include <Adaptor3d_HCurve.hxx>
62 #include "utilities.h"
65 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
66 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
68 // Constante for iso building
69 static Standard_Real IntersectorConfusion = 1.e-10 ; // -8 ;
70 static Standard_Real IntersectorTangency = 1.e-10 ; // -8 ;
71 static Standard_Real HatcherConfusion2d = 1.e-8 ;
72 static Standard_Real HatcherConfusion3d = 1.e-8 ;
74 static Standard_Integer lastVTKpoint = 0;
75 static Standard_Integer PlotCount = 0;
76 static Standard_Real IsoRatio = 1.001;
77 static Standard_Integer MaxPlotCount = 5;
79 //=======================================================================
82 //=======================================================================
84 GEOM_OCCReader* GEOM_OCCReader::New()
86 vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_OCCReader");
88 return (GEOM_OCCReader*)ret;
90 return new GEOM_OCCReader;
93 //=======================================================================
94 // Function : GEOM_OCCReader
96 //=======================================================================
98 GEOM_OCCReader::GEOM_OCCReader()
100 //this->myShape = NULL;
102 this->forced = Standard_False;
103 this->discretiso = 15;
106 //=======================================================================
107 // Function : ~GEOM_OCCReader
109 //=======================================================================
111 GEOM_OCCReader::~GEOM_OCCReader()
116 //=======================================================================
117 // Function : Execute
119 //=======================================================================
122 void GEOM_OCCReader::Execute() {
124 vtkPolyData* output = this->GetOutput();
125 vtkPoints* Pts = NULL;
126 vtkCellArray* Cells = NULL;
127 TopLoc_Location aLoc;
130 Pts = vtkPoints::New();
131 Cells = vtkCellArray::New();
133 //Compute number of triangles and points
134 Standard_Integer nbpoly=0,nbpts=0;
139 if(myShape.ShapeType() == TopAbs_FACE) {
141 const TopoDS_Face& aFace = TopoDS::Face(myShape);
142 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
149 nbpts = aPoly->NbNodes();
150 nbpoly = aPoly->NbTriangles();
152 Pts->SetNumberOfPoints(nbpts);
153 Cells->Allocate(Cells->EstimateSize(nbpoly,3));
164 ComputeWireframe(Pts,Cells);
165 output->SetPoints(Pts);
166 output->SetLines(Cells);
170 if(myShape.ShapeType() == TopAbs_FACE) {
171 ComputeShading(Pts,Cells);
173 output->SetPoints(Pts);
174 output->SetPolys(Cells);
183 //=======================================================================
184 // Function : ComputeWireframe
185 // Purpose : Compute the shape in CAD wireframe mode
186 //=======================================================================
188 void GEOM_OCCReader::ComputeWireframe(vtkPoints* Pts,vtkCellArray* Cells){
190 // Check the type of the shape:
191 if(myShape.ShapeType() == TopAbs_FACE) {
193 TransferFaceWData(TopoDS::Face(myShape),Pts,Cells);
194 } else if(myShape.ShapeType() == TopAbs_EDGE) {
196 TransferEdgeWData(TopoDS::Edge(myShape),Pts,Cells);
198 if(myShape.ShapeType() == TopAbs_VERTEX) {
200 TransferVertexWData(TopoDS::Vertex(myShape),Pts,Cells);
205 //=======================================================================
206 // Function : TransferFaceWData
207 // Purpose : Transfert wireframe data for FACE
208 //=======================================================================
210 void GEOM_OCCReader::TransferFaceWData(const TopoDS_Face& aFace,
214 TopoDS_Face aCopyFace = aFace;
215 aCopyFace.Orientation (TopAbs_FORWARD);
216 createISO(aCopyFace,Precision::Infinite(),1,Pts,Cells);
219 //=======================================================================
220 // Function : createISO
221 // Purpose : Create ISO for Face Wireframe representation
222 //=======================================================================
224 void GEOM_OCCReader::createISO (const TopoDS_Face& TopologicalFace,
225 const Standard_Real Infinite,
226 const Standard_Integer NbIsos,
230 Geom2dHatch_Hatcher aHatcher (Geom2dHatch_Intersector (IntersectorConfusion,
231 IntersectorTangency),
237 Standard_Real myInfinite,myUMin,myUMax,myVMin,myVMax;
238 //myInfinite = Precision::Infinite();
239 myInfinite = 1e38; // VTK uses float numbers - Precision::Infinite() is double and can not be accepted.
241 Standard_Integer myNbDom;
242 TColStd_Array1OfReal myUPrm(1, NbIsos),myVPrm(1, NbIsos);
243 TColStd_Array1OfInteger myUInd(1, NbIsos),myVInd(1, NbIsos);
248 //-----------------------------------------------------------------------
249 // If the Min Max bounds are infinite, there are bounded to Infinite
251 //-----------------------------------------------------------------------
253 BRepTools::UVBounds (TopologicalFace, myUMin, myUMax, myVMin, myVMax) ;
254 Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (myUMin) ;
255 Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (myUMax) ;
256 Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (myVMin) ;
257 Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (myVMax) ;
258 if (InfiniteUMin && InfiniteUMax) {
259 myUMin = - myInfinite ;
260 myUMax = myInfinite ;
261 } else if (InfiniteUMin) {
262 myUMin = myUMax - myInfinite ;
263 } else if (InfiniteUMax) {
264 myUMax = myUMin + myInfinite ;
266 if (InfiniteVMin && InfiniteVMax) {
267 myVMin = - myInfinite ;
268 myVMax = myInfinite ;
269 } else if (InfiniteVMin) {
270 myVMin = myVMax - myInfinite ;
271 } else if (InfiniteVMax) {
272 myVMax = myVMin + myInfinite ;
275 //-----------------------------------------------------------------------
276 // Retreiving the edges and loading them into the hatcher.
277 //-----------------------------------------------------------------------
279 TopExp_Explorer ExpEdges ;
280 for (ExpEdges.Init (TopologicalFace, TopAbs_EDGE) ; ExpEdges.More() ; ExpEdges.Next()) {
281 const TopoDS_Edge& TopologicalEdge = TopoDS::Edge (ExpEdges.Current()) ;
282 Standard_Real U1, U2 ;
283 const Handle(Geom2d_Curve) PCurve = BRep_Tool::CurveOnSurface (TopologicalEdge, TopologicalFace, U1, U2) ;
285 if ( PCurve.IsNull() ) {
293 //-- Test if a TrimmedCurve is necessary
294 if( Abs(PCurve->FirstParameter()-U1)<= Precision::PConfusion()
295 && Abs(PCurve->LastParameter()-U2)<= Precision::PConfusion()) {
296 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
299 if (!PCurve->IsPeriodic()) {
300 Handle (Geom2d_TrimmedCurve) TrimPCurve =Handle(Geom2d_TrimmedCurve)::DownCast(PCurve);
301 if (!TrimPCurve.IsNull()) {
302 if (TrimPCurve->BasisCurve()->FirstParameter()-U1 > Precision::PConfusion() ||
303 U2-TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion()) {
304 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
309 if (PCurve->FirstParameter()-U1 > Precision::PConfusion()){
310 U1=PCurve->FirstParameter();
312 if (U2-PCurve->LastParameter() > Precision::PConfusion()){
313 U2=PCurve->LastParameter();
317 Handle (Geom2d_TrimmedCurve) TrimPCurve = new Geom2d_TrimmedCurve (PCurve, U1, U2) ;
318 aHatcher.AddElement (TrimPCurve, TopologicalEdge.Orientation()) ;
323 //-----------------------------------------------------------------------
324 // Loading and trimming the hatchings.
325 //-----------------------------------------------------------------------
327 Standard_Integer IIso ;
328 Standard_Real DeltaU = Abs (myUMax - myUMin) ;
329 Standard_Real DeltaV = Abs (myVMax - myVMin) ;
330 Standard_Real confusion = Min (DeltaU, DeltaV) * HatcherConfusion3d ;
331 aHatcher.Confusion3d (confusion) ;
333 Standard_Real StepU = DeltaU / (Standard_Real) NbIsos ;
334 if (StepU > confusion) {
335 Standard_Real UPrm = myUMin + StepU / 2. ;
336 gp_Dir2d Dir (0., 1.) ;
337 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
338 myUPrm(IIso) = UPrm ;
339 gp_Pnt2d Ori (UPrm, 0.) ;
340 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
341 myUInd(IIso) = aHatcher.AddHatching (HCur) ;
346 Standard_Real StepV = DeltaV / (Standard_Real) NbIsos ;
347 if (StepV > confusion) {
348 Standard_Real VPrm = myVMin + StepV / 2. ;
349 gp_Dir2d Dir (1., 0.) ;
350 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
351 myVPrm(IIso) = VPrm ;
352 gp_Pnt2d Ori (0., VPrm) ;
353 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
354 myVInd(IIso) = aHatcher.AddHatching (HCur) ;
359 //-----------------------------------------------------------------------
361 //-----------------------------------------------------------------------
366 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
367 Standard_Integer Index ;
369 Index = myUInd(IIso) ;
371 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
372 aHatcher.ComputeDomains (Index);
373 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
377 Index = myVInd(IIso) ;
379 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
380 aHatcher.ComputeDomains (Index);
381 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
386 //-----------------------------------------------------------------------
387 // Push iso lines in vtk kernel
388 //-----------------------------------------------------------------------
391 Standard_Integer pt_start_idx = 0;
393 for (Standard_Integer UIso = myUPrm.Lower() ; UIso <= myUPrm.Upper() ; UIso++) {
394 Standard_Integer UInd = myUInd.Value (UIso) ;
396 Standard_Real UPrm = myUPrm.Value (UIso) ;
397 if (!aHatcher.IsDone (UInd)) {
398 MESSAGE("DBRep_IsoBuilder:: U iso of parameter: "<<UPrm)
399 switch (aHatcher.Status (UInd)) {
400 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
401 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
402 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
403 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
404 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
407 Standard_Integer NbDom = aHatcher.NbDomains (UInd) ;
408 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
409 const HatchGen_Domain& Dom = aHatcher.Domain (UInd, IDom) ;
410 Standard_Real V1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
411 Standard_Real V2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
412 DrawIso(GeomAbs_IsoU, UPrm, V1, V2, Pts, Cell,pt_start_idx);
418 for (Standard_Integer VIso = myVPrm.Lower() ; VIso <= myVPrm.Upper() ; VIso++) {
419 Standard_Integer VInd = myVInd.Value (VIso) ;
421 Standard_Real VPrm = myVPrm.Value (VIso) ;
422 if (!aHatcher.IsDone (VInd)) {
423 MESSAGE("DBRep_IsoBuilder:: V iso of parameter: "<<VPrm)
424 switch (aHatcher.Status (VInd)) {
425 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
426 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
427 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
428 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
429 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
432 Standard_Integer NbDom = aHatcher.NbDomains (VInd) ;
433 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
434 const HatchGen_Domain& Dom = aHatcher.Domain (VInd, IDom) ;
435 Standard_Real U1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
436 Standard_Real U2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
437 DrawIso(GeomAbs_IsoV, VPrm, U1, U2, Pts, Cell,pt_start_idx) ;
445 //=======================================================================
447 // Purpose : Init VTK ISO PLOT
448 //=======================================================================
449 void GEOM_OCCReader::MoveTo(gp_Pnt P,
454 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
455 lastVTKpoint = Pts->InsertNextPoint(coord);
459 //=======================================================================
461 // Purpose : Plot point in VTK
462 //=======================================================================
463 void GEOM_OCCReader::DrawTo(gp_Pnt P,
468 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
469 Standard_Integer NewVTKpoint = Pts->InsertNextPoint(coord);
472 pts[0] = lastVTKpoint;
473 pts[1] = NewVTKpoint;
475 Cells->InsertNextCell(2,pts);
477 lastVTKpoint = NewVTKpoint;
481 //=======================================================================
482 // Function : DrawIso
483 // Purpose : Draw an iso on vtk
484 //=======================================================================
485 void GEOM_OCCReader::DrawIso(GeomAbs_IsoType T,
491 Standard_Integer& startidx)
494 Standard_Boolean halt = Standard_False;
495 Standard_Integer j,myDiscret = discretiso;
496 Standard_Real U1,U2,V1,V2,stepU=0.,stepV=0.;
500 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(myShape),l);
502 BRepAdaptor_Surface S(TopoDS::Face(myShape),Standard_False);
504 GeomAbs_SurfaceType SurfType = S.GetType();
506 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
508 Standard_Integer Intrv, nbIntv;
509 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
510 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
511 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
514 if (T == GeomAbs_IsoU) {
515 S.VIntervals(TI, GeomAbs_CN);
524 S.UIntervals(TI, GeomAbs_CN);
536 for (Intrv = 1; Intrv <= nbIntv; Intrv++) {
538 if (TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
540 if (TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
542 if (T == GeomAbs_IsoU) {
543 V1 = Max(T1, TI(Intrv));
544 V2 = Min(T2, TI(Intrv + 1));
545 stepV = (V2 - V1) / myDiscret;
548 U1 = Max(T1, TI(Intrv));
549 U2 = Min(T2, TI(Intrv + 1));
550 stepU = (U2 - U1) / myDiscret;
554 //-------------GeomAbs_Plane---------------
557 //----GeomAbs_Cylinder GeomAbs_Cone------
558 case GeomAbs_Cylinder :
560 if (T == GeomAbs_IsoV) {
561 for (j = 1; j < myDiscret; j++) {
569 //---GeomAbs_Sphere GeomAbs_Torus--------
570 //GeomAbs_BezierSurface GeomAbs_BezierSurface
571 case GeomAbs_Sphere :
573 case GeomAbs_OffsetSurface :
574 case GeomAbs_OtherSurface :
575 for (j = 1; j < myDiscret; j++) {
582 //-------------GeomAbs_BSplineSurface------
583 case GeomAbs_BezierSurface :
584 case GeomAbs_BSplineSurface :
585 for (j = 1; j <= myDiscret/2; j++) {
589 PlotIso ( S, T, U1, V1, (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
594 //-------------GeomAbs_SurfaceOfExtrusion--
595 //-------------GeomAbs_SurfaceOfRevolution-
596 case GeomAbs_SurfaceOfExtrusion :
597 case GeomAbs_SurfaceOfRevolution :
598 if ((T == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
599 (T == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) {
600 if (SurfType == GeomAbs_SurfaceOfExtrusion) break;
601 for (j = 1; j < myDiscret; j++) {
608 CurvType = (S.BasisCurve())->GetType();
612 case GeomAbs_Circle :
613 case GeomAbs_Ellipse :
614 for (j = 1; j < myDiscret; j++) {
621 case GeomAbs_Parabola :
622 case GeomAbs_Hyperbola :
623 case GeomAbs_BezierCurve :
624 case GeomAbs_BSplineCurve :
625 case GeomAbs_OtherCurve :
626 for (j = 1; j <= myDiscret/2; j++) {
630 PlotIso ( S, T, U1, V1,(T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
644 //=======================================================================
645 // Function : PlotIso
646 // Purpose : Plot iso for other surface
647 //=======================================================================
649 void GEOM_OCCReader::PlotIso (BRepAdaptor_Surface& S,
654 Standard_Boolean& halt,
663 if (T == GeomAbs_IsoU) {
665 S.D0(U, V + Step/2., Pm);
666 S.D0(U, V + Step, Pr);
669 S.D0(U + Step/2., V, Pm);
670 S.D0(U + Step, V, Pr);
673 if (PlotCount > MaxPlotCount) {
674 DrawTo(Pr,Pts,Cells);
678 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
679 DrawTo(Pr,Pts,Cells);
681 if (T == GeomAbs_IsoU) {
682 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
683 Standard_Real aLocalV = V + Step/2 ;
684 PlotIso ( S, T, U, aLocalV , Step/2, halt, Pts, Cells);
686 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
687 Standard_Real aLocalU = U + Step/2 ;
688 PlotIso ( S, T, aLocalU , V, Step/2, halt, Pts, Cells);
692 //=======================================================================
693 // Function : TransferEdgeWData
694 // Purpose : Transfert wireframe data for EDGE
695 //=======================================================================
697 void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
699 vtkCellArray* Cells) {
702 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
703 Standard_Integer i = 1;
704 Handle(Poly_Triangulation) T;
705 TopLoc_Location aEdgeLoc;
706 BRep_Tool::PolygonOnTriangulation(aEdge, aEdgePoly, T, aEdgeLoc, i);
708 Handle(Poly_Polygon3D) P;
709 if(aEdgePoly.IsNull()) {
710 P = BRep_Tool::Polygon3D(aEdge, aEdgeLoc);
713 if(P.IsNull() && aEdgePoly.IsNull())
720 Standard_Boolean isidtrsf = true;
721 if(!aEdgeLoc.IsIdentity()) {
723 edgeTransf = aEdgeLoc.Transformation();
728 Standard_Integer nbnodes;
729 if (aEdgePoly.IsNull()) {
730 nbnodes = P->NbNodes();
731 const TColgp_Array1OfPnt& theNodesP = P->Nodes();
734 aP2 = theNodesP(nbnodes);
739 for(int j=1;j<nbnodes;j++) {
740 gp_Pnt pt1 = theNodesP(j);
741 gp_Pnt pt2 = theNodesP(j+1);
744 // apply edge transformation
745 pt1.Transform(edgeTransf);
746 pt2.Transform(edgeTransf);
750 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
751 pts[0] = Pts->InsertNextPoint(coord);
754 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
755 pts[1] = Pts->InsertNextPoint(coord);
757 // insert line (pt1,pt2)
758 Cells->InsertNextCell(2,pts);
761 nbnodes = aEdgePoly->NbNodes();
762 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
763 const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
765 aP1 = theNodesPoly(1);
766 aP2 = theNodesPoly(nbnodes);
771 for(int j=1;j<nbnodes;j++) {
772 Standard_Integer id1 = Nodesidx(j);
773 Standard_Integer id2 = Nodesidx(j+1);
775 gp_Pnt pt1 = theNodesPoly(id1);
776 gp_Pnt pt2 = theNodesPoly(id2);
779 // apply edge transformation
780 pt1.Transform(edgeTransf);
781 pt2.Transform(edgeTransf);
785 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
786 pts[0] = Pts->InsertNextPoint(coord);
789 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
790 pts[1] = Pts->InsertNextPoint(coord);
792 // insert line (pt1,pt2)
793 Cells->InsertNextCell(2,pts);
797 // vector representation has an arrow on its end
801 // apply edge transformation
802 aP1.Transform(edgeTransf);
803 aP2.Transform(edgeTransf);
807 gp_Vec aDirVec (aP1, aP2);
808 Standard_Real aDist = aDirVec.Magnitude();
809 if (aDist < gp::Resolution()) return;
810 gp_Dir aDirection (aDirVec);
812 Standard_Real anAngle = M_PI/180. * 5.;
813 Standard_Real aLength = aDist/10.;
815 Standard_Real dx,dy,dz;
816 aDirection.Coord(dx,dy,dz);
818 // Pointe de la fleche
819 Standard_Real xo,yo,zo;
822 // Centre du cercle base de la fleche
823 gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
825 // Construction d'un repere i,j pour le cercle
827 if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
828 else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
829 else aDirN = gp::DZ();
831 gp_Dir aDirI = aDirection ^ aDirN;
832 gp_Dir aDirJ = aDirection ^ aDirI;
834 // Add points and segments, composing the arrow
835 Standard_Real cosinus, sinus, Tg = tan(anAngle);
838 coord[0] = xo; coord[1] = yo; coord[2] = zo;
840 int ptLoc = Pts->InsertNextPoint(coord);
848 for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
850 cosinus = cos(2. * M_PI / NbPoints * (i-1));
851 sinus = sin(2. * M_PI / NbPoints * (i-1));
853 gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
859 ptCur = Pts->InsertNextPoint(coord);
866 // insert line (ptCur,ptPrev)
868 Cells->InsertNextCell(2,pts);
871 // insert line (ptCur,ptLoc)
873 Cells->InsertNextCell(2,pts);
876 // insert line (ptCur,ptFirst)
879 Cells->InsertNextCell(2,pts);
883 /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
884 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
885 const TColgp_Array1OfPnt& theNodes = T->Nodes();
892 for(i=1;i<=nbnodes;i++) {
893 Standard_Integer id = Nodesidx(i);
894 gp_Pnt pt = theNodes(id);
897 if(!isidtrsf) pt.Transform(edgeTransf);
899 coord[0] = pt.X(); coord[1] = pt.Y(); coord[2] = pt.Z();
901 Pts->SetPoint(id-1,coord);
906 for(i=1;i<nbnodes;i++) {
908 Standard_Integer id1 = Nodesidx(i);
909 Standard_Integer id2 = Nodesidx(i+1);
912 pts[0] = id1-1; pts[1] = id2-1;
914 // insert line (pt1,pt2)
915 Cells->InsertNextCell(2,pts);
921 //=======================================================================
922 // Function : TransferVertexWData
923 // Purpose : Transfert wireframe data for VERTEX
924 //=======================================================================
926 void GEOM_OCCReader::TransferVertexWData(const TopoDS_Vertex& aVertex,
928 vtkCellArray* Cells) {
929 #define ZERO_COORD coord[0] = 0.0; coord[1] = 0.0; coord[2] = 0.0
931 gp_Pnt P = BRep_Tool::Pnt( aVertex );
932 float delta = 1, coord[3];
935 ZERO_COORD; coord[0] = +delta;
936 pts[0] = Pts->InsertNextPoint(coord);
938 pts[1] = Pts->InsertNextPoint(coord);
939 // insert line (pt1,pt2)
940 Cells->InsertNextCell(2,pts);
942 ZERO_COORD; coord[1] = +delta;
943 pts[0] = Pts->InsertNextPoint(coord);
945 pts[1] = Pts->InsertNextPoint(coord);
946 // insert line (pt1,pt2)
947 Cells->InsertNextCell(2,pts);
949 ZERO_COORD; coord[2] = +delta;
950 pts[0] = Pts->InsertNextPoint(coord);
952 pts[1] = Pts->InsertNextPoint(coord);
953 // insert line (pt1,pt2)
954 Cells->InsertNextCell(2,pts);
959 //=======================================================================
960 // Function : TransferEdgeSData(
961 // Purpose : Transfert shading data for EDGE
962 //=======================================================================
964 void GEOM_OCCReader::TransferEdgeSData(const TopoDS_Edge& aFace,
971 //=======================================================================
972 // Function : TransferFaceSData
973 // Purpose : Transfert shading data for FACE
974 //=======================================================================
975 void GEOM_OCCReader::TransferFaceSData(const TopoDS_Face& aFace,
977 vtkCellArray* Cells) {
979 TopLoc_Location aLoc;
980 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
981 if(aPoly.IsNull()) return;
985 Standard_Boolean identity = true;
986 if(!aLoc.IsIdentity()) {
988 myTransf = aLoc.Transformation();
991 Standard_Integer nbNodesInFace = aPoly->NbNodes();
992 Standard_Integer nbTriInFace = aPoly->NbTriangles();
994 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
995 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
998 for(i=1;i<=nbNodesInFace;i++) {
1001 if(!identity) P.Transform(myTransf);
1002 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
1003 Pts->SetPoint(i-1,coord);
1006 for(i=1;i<=nbTriInFace;i++) {
1009 Standard_Integer N1,N2,N3;
1010 Triangles(i).Get(N1,N2,N3);
1013 pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
1014 Cells->InsertNextCell(3,pts);
1020 //=======================================================================
1021 // Function : ComputeShading
1022 // Purpose : Compute the shape in shading mode
1023 //=======================================================================
1024 void GEOM_OCCReader::ComputeShading(vtkPoints* Pts,vtkCellArray* Cells){
1026 // Check the type of the shape:
1027 if(myShape.ShapeType() == TopAbs_FACE) {
1029 TransferFaceSData(TopoDS::Face(myShape),Pts,Cells);
1032 if(myShape.ShapeType() == TopAbs_EDGE) {
1034 TransferEdgeSData(TopoDS::Edge(myShape),Pts,Cells);
1043 //=======================================================================
1045 // Purpose : Set parameters
1046 //=======================================================================
1047 void GEOM_OCCReader::setDisplayMode(int thenewmode) {
1051 void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape, bool isVector) {
1053 myIsVector = isVector;
1056 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
1060 //=======================================================================
1062 // Purpose : Get parameters
1063 //=======================================================================
1064 const TopoDS_Shape& GEOM_OCCReader::getTopo() {
1068 int GEOM_OCCReader::getDisplayMode() {