1 // Copyright (C) 2007-2011 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
29 #include "GEOM_OCCReader.h"
32 #include <vtkPoints.h>
33 #include <vtkCellArray.h>
35 #include <vtkObjectFactory.h>
36 #include <vtkPolyData.h>
38 // OpenCASCADE Includes
39 #include <TopExp_Explorer.hxx>
40 #include <Poly_Triangulation.hxx>
41 #include <Poly_Polygon3D.hxx>
42 #include <Poly_PolygonOnTriangulation.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Edge.hxx>
46 #include <Precision.hxx>
47 #include <BRepTools.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Geom2dAdaptor_Curve.hxx>
50 #include <Geom2dHatch_Intersector.hxx>
51 #include <Geom2dHatch_Hatcher.hxx>
52 #include <Geom2d_Curve.hxx>
53 #include <Geom2d_Line.hxx>
54 #include <Geom2d_TrimmedCurve.hxx>
55 #include <HatchGen_Domain.hxx>
56 #include <TopAbs_ShapeEnum.hxx>
57 #include <gp_Dir2d.hxx>
58 #include <gp_Pnt2d.hxx>
59 #include <TColStd_Array1OfInteger.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <Adaptor3d_HCurve.hxx>
63 #include "utilities.h"
66 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
67 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
69 // Constante for iso building
70 static Standard_Real IntersectorConfusion = 1.e-10 ; // -8 ;
71 static Standard_Real IntersectorTangency = 1.e-10 ; // -8 ;
72 static Standard_Real HatcherConfusion2d = 1.e-8 ;
73 static Standard_Real HatcherConfusion3d = 1.e-8 ;
75 static Standard_Integer lastVTKpoint = 0;
76 static Standard_Integer PlotCount = 0;
77 static Standard_Real IsoRatio = 1.001;
78 static Standard_Integer MaxPlotCount = 5;
80 //=======================================================================
83 //=======================================================================
85 GEOM_OCCReader* GEOM_OCCReader::New()
87 vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_OCCReader");
89 return (GEOM_OCCReader*)ret;
91 return new GEOM_OCCReader;
94 //=======================================================================
95 // Function : GEOM_OCCReader
97 //=======================================================================
99 GEOM_OCCReader::GEOM_OCCReader()
101 //this->myShape = NULL;
103 this->forced = Standard_False;
104 this->discretiso = 15;
107 //=======================================================================
108 // Function : ~GEOM_OCCReader
110 //=======================================================================
112 GEOM_OCCReader::~GEOM_OCCReader()
117 //=======================================================================
118 // Function : Execute
120 //=======================================================================
123 void GEOM_OCCReader::Execute() {
125 vtkPolyData* output = this->GetOutput();
126 vtkPoints* Pts = NULL;
127 vtkCellArray* Cells = NULL;
128 TopLoc_Location aLoc;
131 Pts = vtkPoints::New();
132 Cells = vtkCellArray::New();
134 //Compute number of triangles and points
135 Standard_Integer nbpoly=0,nbpts=0;
140 if(myShape.ShapeType() == TopAbs_FACE) {
142 const TopoDS_Face& aFace = TopoDS::Face(myShape);
143 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
150 nbpts = aPoly->NbNodes();
151 nbpoly = aPoly->NbTriangles();
153 Pts->SetNumberOfPoints(nbpts);
154 Cells->Allocate(Cells->EstimateSize(nbpoly,3));
165 ComputeWireframe(Pts,Cells);
166 output->SetPoints(Pts);
167 output->SetLines(Cells);
171 if(myShape.ShapeType() == TopAbs_FACE) {
172 ComputeShading(Pts,Cells);
174 output->SetPoints(Pts);
175 output->SetPolys(Cells);
184 //=======================================================================
185 // Function : ComputeWireframe
186 // Purpose : Compute the shape in CAD wireframe mode
187 //=======================================================================
189 void GEOM_OCCReader::ComputeWireframe(vtkPoints* Pts,vtkCellArray* Cells){
191 // Check the type of the shape:
192 if(myShape.ShapeType() == TopAbs_FACE) {
194 TransferFaceWData(TopoDS::Face(myShape),Pts,Cells);
195 } else if(myShape.ShapeType() == TopAbs_EDGE) {
197 TransferEdgeWData(TopoDS::Edge(myShape),Pts,Cells);
199 if(myShape.ShapeType() == TopAbs_VERTEX) {
201 TransferVertexWData(TopoDS::Vertex(myShape),Pts,Cells);
206 //=======================================================================
207 // Function : TransferFaceWData
208 // Purpose : Transfert wireframe data for FACE
209 //=======================================================================
211 void GEOM_OCCReader::TransferFaceWData(const TopoDS_Face& aFace,
215 TopoDS_Face aCopyFace = aFace;
216 aCopyFace.Orientation (TopAbs_FORWARD);
217 createISO(aCopyFace,Precision::Infinite(),1,Pts,Cells);
220 //=======================================================================
221 // Function : createISO
222 // Purpose : Create ISO for Face Wireframe representation
223 //=======================================================================
225 void GEOM_OCCReader::createISO (const TopoDS_Face& TopologicalFace,
226 const Standard_Real Infinite,
227 const Standard_Integer NbIsos,
231 Geom2dHatch_Hatcher aHatcher (Geom2dHatch_Intersector (IntersectorConfusion,
232 IntersectorTangency),
238 Standard_Real myInfinite,myUMin,myUMax,myVMin,myVMax;
239 //myInfinite = Precision::Infinite();
240 myInfinite = 1e38; // VTK uses float numbers - Precision::Infinite() is double and can not be accepted.
242 Standard_Integer myNbDom;
243 TColStd_Array1OfReal myUPrm(1, NbIsos),myVPrm(1, NbIsos);
244 TColStd_Array1OfInteger myUInd(1, NbIsos),myVInd(1, NbIsos);
249 //-----------------------------------------------------------------------
250 // If the Min Max bounds are infinite, there are bounded to Infinite
252 //-----------------------------------------------------------------------
254 BRepTools::UVBounds (TopologicalFace, myUMin, myUMax, myVMin, myVMax) ;
255 Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (myUMin) ;
256 Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (myUMax) ;
257 Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (myVMin) ;
258 Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (myVMax) ;
259 if (InfiniteUMin && InfiniteUMax) {
260 myUMin = - myInfinite ;
261 myUMax = myInfinite ;
262 } else if (InfiniteUMin) {
263 myUMin = myUMax - myInfinite ;
264 } else if (InfiniteUMax) {
265 myUMax = myUMin + myInfinite ;
267 if (InfiniteVMin && InfiniteVMax) {
268 myVMin = - myInfinite ;
269 myVMax = myInfinite ;
270 } else if (InfiniteVMin) {
271 myVMin = myVMax - myInfinite ;
272 } else if (InfiniteVMax) {
273 myVMax = myVMin + myInfinite ;
276 //-----------------------------------------------------------------------
277 // Retreiving the edges and loading them into the hatcher.
278 //-----------------------------------------------------------------------
280 TopExp_Explorer ExpEdges ;
281 for (ExpEdges.Init (TopologicalFace, TopAbs_EDGE) ; ExpEdges.More() ; ExpEdges.Next()) {
282 const TopoDS_Edge& TopologicalEdge = TopoDS::Edge (ExpEdges.Current()) ;
283 Standard_Real U1, U2 ;
284 const Handle(Geom2d_Curve) PCurve = BRep_Tool::CurveOnSurface (TopologicalEdge, TopologicalFace, U1, U2) ;
286 if ( PCurve.IsNull() ) {
294 //-- Test if a TrimmedCurve is necessary
295 if( Abs(PCurve->FirstParameter()-U1)<= Precision::PConfusion()
296 && Abs(PCurve->LastParameter()-U2)<= Precision::PConfusion()) {
297 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
300 if (!PCurve->IsPeriodic()) {
301 Handle (Geom2d_TrimmedCurve) TrimPCurve =Handle(Geom2d_TrimmedCurve)::DownCast(PCurve);
302 if (!TrimPCurve.IsNull()) {
303 if (TrimPCurve->BasisCurve()->FirstParameter()-U1 > Precision::PConfusion() ||
304 U2-TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion()) {
305 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
310 if (PCurve->FirstParameter()-U1 > Precision::PConfusion()){
311 U1=PCurve->FirstParameter();
313 if (U2-PCurve->LastParameter() > Precision::PConfusion()){
314 U2=PCurve->LastParameter();
318 Handle (Geom2d_TrimmedCurve) TrimPCurve = new Geom2d_TrimmedCurve (PCurve, U1, U2) ;
319 aHatcher.AddElement (TrimPCurve, TopologicalEdge.Orientation()) ;
324 //-----------------------------------------------------------------------
325 // Loading and trimming the hatchings.
326 //-----------------------------------------------------------------------
328 Standard_Integer IIso ;
329 Standard_Real DeltaU = Abs (myUMax - myUMin) ;
330 Standard_Real DeltaV = Abs (myVMax - myVMin) ;
331 Standard_Real confusion = Min (DeltaU, DeltaV) * HatcherConfusion3d ;
332 aHatcher.Confusion3d (confusion) ;
334 Standard_Real StepU = DeltaU / (Standard_Real) NbIsos ;
335 if (StepU > confusion) {
336 Standard_Real UPrm = myUMin + StepU / 2. ;
337 gp_Dir2d Dir (0., 1.) ;
338 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
339 myUPrm(IIso) = UPrm ;
340 gp_Pnt2d Ori (UPrm, 0.) ;
341 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
342 myUInd(IIso) = aHatcher.AddHatching (HCur) ;
347 Standard_Real StepV = DeltaV / (Standard_Real) NbIsos ;
348 if (StepV > confusion) {
349 Standard_Real VPrm = myVMin + StepV / 2. ;
350 gp_Dir2d Dir (1., 0.) ;
351 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
352 myVPrm(IIso) = VPrm ;
353 gp_Pnt2d Ori (0., VPrm) ;
354 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
355 myVInd(IIso) = aHatcher.AddHatching (HCur) ;
360 //-----------------------------------------------------------------------
362 //-----------------------------------------------------------------------
367 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
368 Standard_Integer Index ;
370 Index = myUInd(IIso) ;
372 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
373 aHatcher.ComputeDomains (Index);
374 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
378 Index = myVInd(IIso) ;
380 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
381 aHatcher.ComputeDomains (Index);
382 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
387 //-----------------------------------------------------------------------
388 // Push iso lines in vtk kernel
389 //-----------------------------------------------------------------------
392 Standard_Integer pt_start_idx = 0;
394 for (Standard_Integer UIso = myUPrm.Lower() ; UIso <= myUPrm.Upper() ; UIso++) {
395 Standard_Integer UInd = myUInd.Value (UIso) ;
397 Standard_Real UPrm = myUPrm.Value (UIso) ;
398 if (!aHatcher.IsDone (UInd)) {
399 MESSAGE("DBRep_IsoBuilder:: U iso of parameter: "<<UPrm)
400 switch (aHatcher.Status (UInd)) {
401 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
402 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
403 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
404 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
405 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
408 Standard_Integer NbDom = aHatcher.NbDomains (UInd) ;
409 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
410 const HatchGen_Domain& Dom = aHatcher.Domain (UInd, IDom) ;
411 Standard_Real V1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
412 Standard_Real V2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
413 DrawIso(GeomAbs_IsoU, UPrm, V1, V2, Pts, Cell,pt_start_idx);
419 for (Standard_Integer VIso = myVPrm.Lower() ; VIso <= myVPrm.Upper() ; VIso++) {
420 Standard_Integer VInd = myVInd.Value (VIso) ;
422 Standard_Real VPrm = myVPrm.Value (VIso) ;
423 if (!aHatcher.IsDone (VInd)) {
424 MESSAGE("DBRep_IsoBuilder:: V iso of parameter: "<<VPrm)
425 switch (aHatcher.Status (VInd)) {
426 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
427 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
428 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
429 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
430 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
433 Standard_Integer NbDom = aHatcher.NbDomains (VInd) ;
434 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
435 const HatchGen_Domain& Dom = aHatcher.Domain (VInd, IDom) ;
436 Standard_Real U1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
437 Standard_Real U2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
438 DrawIso(GeomAbs_IsoV, VPrm, U1, U2, Pts, Cell,pt_start_idx) ;
446 //=======================================================================
448 // Purpose : Init VTK ISO PLOT
449 //=======================================================================
450 void GEOM_OCCReader::MoveTo(gp_Pnt P,
455 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
456 lastVTKpoint = Pts->InsertNextPoint(coord);
460 //=======================================================================
462 // Purpose : Plot point in VTK
463 //=======================================================================
464 void GEOM_OCCReader::DrawTo(gp_Pnt P,
469 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
470 Standard_Integer NewVTKpoint = Pts->InsertNextPoint(coord);
473 pts[0] = lastVTKpoint;
474 pts[1] = NewVTKpoint;
476 Cells->InsertNextCell(2,pts);
478 lastVTKpoint = NewVTKpoint;
482 //=======================================================================
483 // Function : DrawIso
484 // Purpose : Draw an iso on vtk
485 //=======================================================================
486 void GEOM_OCCReader::DrawIso(GeomAbs_IsoType T,
492 Standard_Integer& startidx)
495 Standard_Boolean halt = Standard_False;
496 Standard_Integer j,myDiscret = discretiso;
497 Standard_Real U1,U2,V1,V2,stepU=0.,stepV=0.;
501 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(myShape),l);
503 BRepAdaptor_Surface S(TopoDS::Face(myShape),Standard_False);
505 GeomAbs_SurfaceType SurfType = S.GetType();
507 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
509 Standard_Integer Intrv, nbIntv;
510 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
511 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
512 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
515 if (T == GeomAbs_IsoU) {
516 S.VIntervals(TI, GeomAbs_CN);
525 S.UIntervals(TI, GeomAbs_CN);
537 for (Intrv = 1; Intrv <= nbIntv; Intrv++) {
539 if (TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
541 if (TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
543 if (T == GeomAbs_IsoU) {
544 V1 = Max(T1, TI(Intrv));
545 V2 = Min(T2, TI(Intrv + 1));
546 stepV = (V2 - V1) / myDiscret;
549 U1 = Max(T1, TI(Intrv));
550 U2 = Min(T2, TI(Intrv + 1));
551 stepU = (U2 - U1) / myDiscret;
555 //-------------GeomAbs_Plane---------------
558 //----GeomAbs_Cylinder GeomAbs_Cone------
559 case GeomAbs_Cylinder :
561 if (T == GeomAbs_IsoV) {
562 for (j = 1; j < myDiscret; j++) {
570 //---GeomAbs_Sphere GeomAbs_Torus--------
571 //GeomAbs_BezierSurface GeomAbs_BezierSurface
572 case GeomAbs_Sphere :
574 case GeomAbs_OffsetSurface :
575 case GeomAbs_OtherSurface :
576 for (j = 1; j < myDiscret; j++) {
583 //-------------GeomAbs_BSplineSurface------
584 case GeomAbs_BezierSurface :
585 case GeomAbs_BSplineSurface :
586 for (j = 1; j <= myDiscret/2; j++) {
590 PlotIso ( S, T, U1, V1, (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
595 //-------------GeomAbs_SurfaceOfExtrusion--
596 //-------------GeomAbs_SurfaceOfRevolution-
597 case GeomAbs_SurfaceOfExtrusion :
598 case GeomAbs_SurfaceOfRevolution :
599 if ((T == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
600 (T == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) {
601 if (SurfType == GeomAbs_SurfaceOfExtrusion) break;
602 for (j = 1; j < myDiscret; j++) {
609 CurvType = (S.BasisCurve())->GetType();
613 case GeomAbs_Circle :
614 case GeomAbs_Ellipse :
615 for (j = 1; j < myDiscret; j++) {
622 case GeomAbs_Parabola :
623 case GeomAbs_Hyperbola :
624 case GeomAbs_BezierCurve :
625 case GeomAbs_BSplineCurve :
626 case GeomAbs_OtherCurve :
627 for (j = 1; j <= myDiscret/2; j++) {
631 PlotIso ( S, T, U1, V1,(T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
645 //=======================================================================
646 // Function : PlotIso
647 // Purpose : Plot iso for other surface
648 //=======================================================================
650 void GEOM_OCCReader::PlotIso (BRepAdaptor_Surface& S,
655 Standard_Boolean& halt,
664 if (T == GeomAbs_IsoU) {
666 S.D0(U, V + Step/2., Pm);
667 S.D0(U, V + Step, Pr);
670 S.D0(U + Step/2., V, Pm);
671 S.D0(U + Step, V, Pr);
674 if (PlotCount > MaxPlotCount) {
675 DrawTo(Pr,Pts,Cells);
679 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
680 DrawTo(Pr,Pts,Cells);
682 if (T == GeomAbs_IsoU) {
683 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
684 Standard_Real aLocalV = V + Step/2 ;
685 PlotIso ( S, T, U, aLocalV , Step/2, halt, Pts, Cells);
687 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
688 Standard_Real aLocalU = U + Step/2 ;
689 PlotIso ( S, T, aLocalU , V, Step/2, halt, Pts, Cells);
693 //=======================================================================
694 // Function : TransferEdgeWData
695 // Purpose : Transfert wireframe data for EDGE
696 //=======================================================================
698 void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
700 vtkCellArray* Cells) {
703 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
704 Standard_Integer i = 1;
705 Handle(Poly_Triangulation) T;
706 TopLoc_Location aEdgeLoc;
707 BRep_Tool::PolygonOnTriangulation(aEdge, aEdgePoly, T, aEdgeLoc, i);
709 Handle(Poly_Polygon3D) P;
710 if(aEdgePoly.IsNull()) {
711 P = BRep_Tool::Polygon3D(aEdge, aEdgeLoc);
714 if(P.IsNull() && aEdgePoly.IsNull())
721 Standard_Boolean isidtrsf = true;
722 if(!aEdgeLoc.IsIdentity()) {
724 edgeTransf = aEdgeLoc.Transformation();
729 Standard_Integer nbnodes;
730 if (aEdgePoly.IsNull()) {
731 nbnodes = P->NbNodes();
732 const TColgp_Array1OfPnt& theNodesP = P->Nodes();
735 aP2 = theNodesP(nbnodes);
740 for(int j=1;j<nbnodes;j++) {
741 gp_Pnt pt1 = theNodesP(j);
742 gp_Pnt pt2 = theNodesP(j+1);
745 // apply edge transformation
746 pt1.Transform(edgeTransf);
747 pt2.Transform(edgeTransf);
751 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
752 pts[0] = Pts->InsertNextPoint(coord);
755 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
756 pts[1] = Pts->InsertNextPoint(coord);
758 // insert line (pt1,pt2)
759 Cells->InsertNextCell(2,pts);
762 nbnodes = aEdgePoly->NbNodes();
763 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
764 const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
766 aP1 = theNodesPoly(1);
767 aP2 = theNodesPoly(nbnodes);
772 for(int j=1;j<nbnodes;j++) {
773 Standard_Integer id1 = Nodesidx(j);
774 Standard_Integer id2 = Nodesidx(j+1);
776 gp_Pnt pt1 = theNodesPoly(id1);
777 gp_Pnt pt2 = theNodesPoly(id2);
780 // apply edge transformation
781 pt1.Transform(edgeTransf);
782 pt2.Transform(edgeTransf);
786 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
787 pts[0] = Pts->InsertNextPoint(coord);
790 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
791 pts[1] = Pts->InsertNextPoint(coord);
793 // insert line (pt1,pt2)
794 Cells->InsertNextCell(2,pts);
798 // vector representation has an arrow on its end
802 // apply edge transformation
803 aP1.Transform(edgeTransf);
804 aP2.Transform(edgeTransf);
808 gp_Vec aDirVec (aP1, aP2);
809 Standard_Real aDist = aDirVec.Magnitude();
810 if (aDist < gp::Resolution()) return;
811 gp_Dir aDirection (aDirVec);
813 Standard_Real anAngle = PI/180.*5.;
814 Standard_Real aLength = aDist/10.;
816 Standard_Real dx,dy,dz;
817 aDirection.Coord(dx,dy,dz);
819 // Pointe de la fleche
820 Standard_Real xo,yo,zo;
823 // Centre du cercle base de la fleche
824 gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
826 // Construction d'un repere i,j pour le cercle
828 if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
829 else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
830 else aDirN = gp::DZ();
832 gp_Dir aDirI = aDirection ^ aDirN;
833 gp_Dir aDirJ = aDirection ^ aDirI;
835 // Add points and segments, composing the arrow
836 Standard_Real cosinus, sinus, Tg = tan(anAngle);
839 coord[0] = xo; coord[1] = yo; coord[2] = zo;
841 int ptLoc = Pts->InsertNextPoint(coord);
849 for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
851 cosinus = cos(2. * PI / NbPoints * (i-1));
852 sinus = sin(2. * PI / NbPoints * (i-1));
854 gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
860 ptCur = Pts->InsertNextPoint(coord);
867 // insert line (ptCur,ptPrev)
869 Cells->InsertNextCell(2,pts);
872 // insert line (ptCur,ptLoc)
874 Cells->InsertNextCell(2,pts);
877 // insert line (ptCur,ptFirst)
880 Cells->InsertNextCell(2,pts);
884 /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
885 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
886 const TColgp_Array1OfPnt& theNodes = T->Nodes();
893 for(i=1;i<=nbnodes;i++) {
894 Standard_Integer id = Nodesidx(i);
895 gp_Pnt pt = theNodes(id);
898 if(!isidtrsf) pt.Transform(edgeTransf);
900 coord[0] = pt.X(); coord[1] = pt.Y(); coord[2] = pt.Z();
902 Pts->SetPoint(id-1,coord);
907 for(i=1;i<nbnodes;i++) {
909 Standard_Integer id1 = Nodesidx(i);
910 Standard_Integer id2 = Nodesidx(i+1);
913 pts[0] = id1-1; pts[1] = id2-1;
915 // insert line (pt1,pt2)
916 Cells->InsertNextCell(2,pts);
922 //=======================================================================
923 // Function : TransferVertexWData
924 // Purpose : Transfert wireframe data for VERTEX
925 //=======================================================================
927 void GEOM_OCCReader::TransferVertexWData(const TopoDS_Vertex& aVertex,
929 vtkCellArray* Cells) {
930 #define ZERO_COORD coord[0] = 0.0; coord[1] = 0.0; coord[2] = 0.0
932 gp_Pnt P = BRep_Tool::Pnt( aVertex );
933 float delta = 1, coord[3];
936 ZERO_COORD; coord[0] = +delta;
937 pts[0] = Pts->InsertNextPoint(coord);
939 pts[1] = Pts->InsertNextPoint(coord);
940 // insert line (pt1,pt2)
941 Cells->InsertNextCell(2,pts);
943 ZERO_COORD; coord[1] = +delta;
944 pts[0] = Pts->InsertNextPoint(coord);
946 pts[1] = Pts->InsertNextPoint(coord);
947 // insert line (pt1,pt2)
948 Cells->InsertNextCell(2,pts);
950 ZERO_COORD; coord[2] = +delta;
951 pts[0] = Pts->InsertNextPoint(coord);
953 pts[1] = Pts->InsertNextPoint(coord);
954 // insert line (pt1,pt2)
955 Cells->InsertNextCell(2,pts);
960 //=======================================================================
961 // Function : TransferEdgeSData(
962 // Purpose : Transfert shading data for EDGE
963 //=======================================================================
965 void GEOM_OCCReader::TransferEdgeSData(const TopoDS_Edge& aFace,
972 //=======================================================================
973 // Function : TransferFaceSData
974 // Purpose : Transfert shading data for FACE
975 //=======================================================================
976 void GEOM_OCCReader::TransferFaceSData(const TopoDS_Face& aFace,
978 vtkCellArray* Cells) {
980 TopLoc_Location aLoc;
981 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
982 if(aPoly.IsNull()) return;
986 Standard_Boolean identity = true;
987 if(!aLoc.IsIdentity()) {
989 myTransf = aLoc.Transformation();
992 Standard_Integer nbNodesInFace = aPoly->NbNodes();
993 Standard_Integer nbTriInFace = aPoly->NbTriangles();
995 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
996 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
999 for(i=1;i<=nbNodesInFace;i++) {
1000 gp_Pnt P = Nodes(i);
1002 if(!identity) P.Transform(myTransf);
1003 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
1004 Pts->SetPoint(i-1,coord);
1007 for(i=1;i<=nbTriInFace;i++) {
1010 Standard_Integer N1,N2,N3;
1011 Triangles(i).Get(N1,N2,N3);
1014 pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
1015 Cells->InsertNextCell(3,pts);
1021 //=======================================================================
1022 // Function : ComputeShading
1023 // Purpose : Compute the shape in shading mode
1024 //=======================================================================
1025 void GEOM_OCCReader::ComputeShading(vtkPoints* Pts,vtkCellArray* Cells){
1027 // Check the type of the shape:
1028 if(myShape.ShapeType() == TopAbs_FACE) {
1030 TransferFaceSData(TopoDS::Face(myShape),Pts,Cells);
1033 if(myShape.ShapeType() == TopAbs_EDGE) {
1035 TransferEdgeSData(TopoDS::Edge(myShape),Pts,Cells);
1044 //=======================================================================
1046 // Purpose : Set parameters
1047 //=======================================================================
1048 void GEOM_OCCReader::setDisplayMode(int thenewmode) {
1052 void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape, bool isVector) {
1054 myIsVector = isVector;
1057 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
1061 //=======================================================================
1063 // Purpose : Get parameters
1064 //=======================================================================
1065 const TopoDS_Shape& GEOM_OCCReader::getTopo() {
1069 int GEOM_OCCReader::getDisplayMode() {