1 // GEOM OBJECT : interactive object for Geometry entities visualization
3 // Copyright (C) 2003 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
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>
37 #include <vtkPolyDataMapper.h>
38 #include <vtkMergePoints.h>
40 #include <vtkTransform.h>
41 #include <vtkMatrix4x4.h>
43 // OpenCASCADE Includes
44 #include <BRepAdaptor_Surface.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <BRepMesh_IncrementalMesh.hxx>
47 #include <Poly_Triangulation.hxx>
48 #include <Poly_Polygon3D.hxx>
49 #include <BRep_Tool.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Wire.hxx>
53 #include <BRepBndLib.hxx>
56 #include <Precision.hxx>
57 #include <BRepTools.hxx>
58 #include <BRep_Tool.hxx>
59 #include <Geom2dAdaptor_Curve.hxx>
60 #include <Geom2dHatch_Intersector.hxx>
61 #include <Geom2dHatch_Hatcher.hxx>
62 #include <Geom2d_Curve.hxx>
63 #include <Geom2d_Line.hxx>
64 #include <Geom2d_TrimmedCurve.hxx>
65 #include <HatchGen_Domain.hxx>
66 #include <GeomAbs_IsoType.hxx>
67 #include <Precision.hxx>
68 #include <TopAbs_ShapeEnum.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Edge.hxx>
72 #include <gp_Dir2d.hxx>
73 #include <gp_Pnt2d.hxx>
74 #include <TColStd_Array1OfInteger.hxx>
75 #include <TColStd_Array1OfReal.hxx>
76 #include <Adaptor3d_HCurve.hxx>
78 #include "utilities.h"
82 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
83 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
85 // Constante for iso building
86 static Standard_Real IntersectorConfusion = 1.e-10 ; // -8 ;
87 static Standard_Real IntersectorTangency = 1.e-10 ; // -8 ;
88 static Standard_Real HatcherConfusion2d = 1.e-8 ;
89 static Standard_Real HatcherConfusion3d = 1.e-8 ;
91 static Standard_Integer lastVTKpoint = 0;
92 static Standard_Integer PlotCount = 0;
93 static Standard_Real IsoRatio = 1.001;
94 static Standard_Integer MaxPlotCount = 5;
96 //=======================================================================
99 //=======================================================================
101 GEOM_OCCReader* GEOM_OCCReader::New()
103 vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_OCCReader");
105 return (GEOM_OCCReader*)ret;
107 return new GEOM_OCCReader;
110 //=======================================================================
111 // Function : GEOM_OCCReader
113 //=======================================================================
115 GEOM_OCCReader::GEOM_OCCReader()
117 //this->myShape = NULL;
119 this->forced = Standard_False;
120 this->discretiso = 15;
123 //=======================================================================
124 // Function : ~GEOM_OCCReader
126 //=======================================================================
128 GEOM_OCCReader::~GEOM_OCCReader()
133 //=======================================================================
134 // Function : Execute
136 //=======================================================================
139 void GEOM_OCCReader::Execute() {
141 vtkPolyData* output = this->GetOutput();
142 vtkPoints* Pts = NULL;
143 vtkCellArray* Cells = NULL;
144 TopLoc_Location aLoc;
147 Pts = vtkPoints::New();
148 Cells = vtkCellArray::New();
150 //Compute number of triangles and points
151 Standard_Integer nbpoly=0,nbpts=0;
156 if(myShape.ShapeType() == TopAbs_FACE) {
158 const TopoDS_Face& aFace = TopoDS::Face(myShape);
159 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
166 nbpts = aPoly->NbNodes();
167 nbpoly = aPoly->NbTriangles();
169 Pts->SetNumberOfPoints(nbpts);
170 Cells->Allocate(Cells->EstimateSize(nbpoly,3));
181 ComputeWireframe(Pts,Cells);
182 output->SetPoints(Pts);
183 output->SetLines(Cells);
187 if(myShape.ShapeType() == TopAbs_FACE) {
188 ComputeShading(Pts,Cells);
190 output->SetPoints(Pts);
191 output->SetPolys(Cells);
200 //=======================================================================
201 // Function : ComputeWireframe
202 // Purpose : Compute the shape in CAD wireframe mode
203 //=======================================================================
205 void GEOM_OCCReader::ComputeWireframe(vtkPoints* Pts,vtkCellArray* Cells){
207 // Check the type of the shape:
208 if(myShape.ShapeType() == TopAbs_FACE) {
210 TransferFaceWData(TopoDS::Face(myShape),Pts,Cells);
211 } else if(myShape.ShapeType() == TopAbs_EDGE) {
213 TransferEdgeWData(TopoDS::Edge(myShape),Pts,Cells);
215 if(myShape.ShapeType() == TopAbs_VERTEX) {
217 TransferVertexWData(TopoDS::Vertex(myShape),Pts,Cells);
222 //=======================================================================
223 // Function : TransferFaceWData
224 // Purpose : Transfert wireframe data for FACE
225 //=======================================================================
227 void GEOM_OCCReader::TransferFaceWData(const TopoDS_Face& aFace,
231 TopoDS_Face aCopyFace = aFace;
232 aCopyFace.Orientation (TopAbs_FORWARD);
233 createISO(aCopyFace,Precision::Infinite(),1,Pts,Cells);
236 //=======================================================================
237 // Function : createISO
238 // Purpose : Create ISO for Face Wireframe representation
239 //=======================================================================
241 void GEOM_OCCReader::createISO (const TopoDS_Face& TopologicalFace,
242 const Standard_Real Infinite,
243 const Standard_Integer NbIsos,
247 Geom2dHatch_Hatcher aHatcher (Geom2dHatch_Intersector (IntersectorConfusion,
248 IntersectorTangency),
254 Standard_Real myInfinite,myUMin,myUMax,myVMin,myVMax;
255 //myInfinite = Precision::Infinite();
256 myInfinite = 1e38; // VTK uses float numbers - Precision::Infinite() is double and can not be accepted.
258 Standard_Integer myNbDom;
259 TColStd_Array1OfReal myUPrm(1, NbIsos),myVPrm(1, NbIsos);
260 TColStd_Array1OfInteger myUInd(1, NbIsos),myVInd(1, NbIsos);
265 //-----------------------------------------------------------------------
266 // If the Min Max bounds are infinite, there are bounded to Infinite
268 //-----------------------------------------------------------------------
270 BRepTools::UVBounds (TopologicalFace, myUMin, myUMax, myVMin, myVMax) ;
271 Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (myUMin) ;
272 Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (myUMax) ;
273 Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (myVMin) ;
274 Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (myVMax) ;
275 if (InfiniteUMin && InfiniteUMax) {
276 myUMin = - myInfinite ;
277 myUMax = myInfinite ;
278 } else if (InfiniteUMin) {
279 myUMin = myUMax - myInfinite ;
280 } else if (InfiniteUMax) {
281 myUMax = myUMin + myInfinite ;
283 if (InfiniteVMin && InfiniteVMax) {
284 myVMin = - myInfinite ;
285 myVMax = myInfinite ;
286 } else if (InfiniteVMin) {
287 myVMin = myVMax - myInfinite ;
288 } else if (InfiniteVMax) {
289 myVMax = myVMin + myInfinite ;
292 //-----------------------------------------------------------------------
293 // Retreiving the edges and loading them into the hatcher.
294 //-----------------------------------------------------------------------
296 TopExp_Explorer ExpEdges ;
297 for (ExpEdges.Init (TopologicalFace, TopAbs_EDGE) ; ExpEdges.More() ; ExpEdges.Next()) {
298 const TopoDS_Edge& TopologicalEdge = TopoDS::Edge (ExpEdges.Current()) ;
299 Standard_Real U1, U2 ;
300 const Handle(Geom2d_Curve) PCurve = BRep_Tool::CurveOnSurface (TopologicalEdge, TopologicalFace, U1, U2) ;
302 if ( PCurve.IsNull() ) {
310 //-- Test if a TrimmedCurve is necessary
311 if( Abs(PCurve->FirstParameter()-U1)<= Precision::PConfusion()
312 && Abs(PCurve->LastParameter()-U2)<= Precision::PConfusion()) {
313 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
316 if (!PCurve->IsPeriodic()) {
317 Handle (Geom2d_TrimmedCurve) TrimPCurve =Handle(Geom2d_TrimmedCurve)::DownCast(PCurve);
318 if (!TrimPCurve.IsNull()) {
319 if (TrimPCurve->BasisCurve()->FirstParameter()-U1 > Precision::PConfusion() ||
320 U2-TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion()) {
321 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
326 if (PCurve->FirstParameter()-U1 > Precision::PConfusion()){
327 U1=PCurve->FirstParameter();
329 if (U2-PCurve->LastParameter() > Precision::PConfusion()){
330 U2=PCurve->LastParameter();
334 Handle (Geom2d_TrimmedCurve) TrimPCurve = new Geom2d_TrimmedCurve (PCurve, U1, U2) ;
335 aHatcher.AddElement (TrimPCurve, TopologicalEdge.Orientation()) ;
340 //-----------------------------------------------------------------------
341 // Loading and trimming the hatchings.
342 //-----------------------------------------------------------------------
344 Standard_Integer IIso ;
345 Standard_Real DeltaU = Abs (myUMax - myUMin) ;
346 Standard_Real DeltaV = Abs (myVMax - myVMin) ;
347 Standard_Real confusion = Min (DeltaU, DeltaV) * HatcherConfusion3d ;
348 aHatcher.Confusion3d (confusion) ;
350 Standard_Real StepU = DeltaU / (Standard_Real) NbIsos ;
351 if (StepU > confusion) {
352 Standard_Real UPrm = myUMin + StepU / 2. ;
353 gp_Dir2d Dir (0., 1.) ;
354 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
355 myUPrm(IIso) = UPrm ;
356 gp_Pnt2d Ori (UPrm, 0.) ;
357 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
358 myUInd(IIso) = aHatcher.AddHatching (HCur) ;
363 Standard_Real StepV = DeltaV / (Standard_Real) NbIsos ;
364 if (StepV > confusion) {
365 Standard_Real VPrm = myVMin + StepV / 2. ;
366 gp_Dir2d Dir (1., 0.) ;
367 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
368 myVPrm(IIso) = VPrm ;
369 gp_Pnt2d Ori (0., VPrm) ;
370 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
371 myVInd(IIso) = aHatcher.AddHatching (HCur) ;
376 //-----------------------------------------------------------------------
378 //-----------------------------------------------------------------------
383 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
384 Standard_Integer Index ;
386 Index = myUInd(IIso) ;
388 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
389 aHatcher.ComputeDomains (Index);
390 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
394 Index = myVInd(IIso) ;
396 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
397 aHatcher.ComputeDomains (Index);
398 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
403 //-----------------------------------------------------------------------
404 // Push iso lines in vtk kernel
405 //-----------------------------------------------------------------------
408 Standard_Integer pt_start_idx = 0;
410 for (Standard_Integer UIso = myUPrm.Lower() ; UIso <= myUPrm.Upper() ; UIso++) {
411 Standard_Integer UInd = myUInd.Value (UIso) ;
413 Standard_Real UPrm = myUPrm.Value (UIso) ;
414 if (!aHatcher.IsDone (UInd)) {
415 MESSAGE("DBRep_IsoBuilder:: U iso of parameter: "<<UPrm)
416 switch (aHatcher.Status (UInd)) {
417 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
418 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
419 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
420 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
421 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
424 Standard_Integer NbDom = aHatcher.NbDomains (UInd) ;
425 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
426 const HatchGen_Domain& Dom = aHatcher.Domain (UInd, IDom) ;
427 Standard_Real V1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
428 Standard_Real V2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
429 DrawIso(GeomAbs_IsoU, UPrm, V1, V2, Pts, Cell,pt_start_idx);
435 for (Standard_Integer VIso = myVPrm.Lower() ; VIso <= myVPrm.Upper() ; VIso++) {
436 Standard_Integer VInd = myVInd.Value (VIso) ;
438 Standard_Real VPrm = myVPrm.Value (VIso) ;
439 if (!aHatcher.IsDone (VInd)) {
440 MESSAGE("DBRep_IsoBuilder:: V iso of parameter: "<<VPrm)
441 switch (aHatcher.Status (VInd)) {
442 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
443 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
444 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
445 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
446 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
449 Standard_Integer NbDom = aHatcher.NbDomains (VInd) ;
450 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
451 const HatchGen_Domain& Dom = aHatcher.Domain (VInd, IDom) ;
452 Standard_Real U1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
453 Standard_Real U2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
454 DrawIso(GeomAbs_IsoV, VPrm, U1, U2, Pts, Cell,pt_start_idx) ;
462 //=======================================================================
464 // Purpose : Init VTK ISO PLOT
465 //=======================================================================
466 void GEOM_OCCReader::MoveTo(gp_Pnt P,
471 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
472 lastVTKpoint = Pts->InsertNextPoint(coord);
476 //=======================================================================
478 // Purpose : Plot point in VTK
479 //=======================================================================
480 void GEOM_OCCReader::DrawTo(gp_Pnt P,
485 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
486 Standard_Integer NewVTKpoint = Pts->InsertNextPoint(coord);
489 pts[0] = lastVTKpoint;
490 pts[1] = NewVTKpoint;
492 Cells->InsertNextCell(2,pts);
494 lastVTKpoint = NewVTKpoint;
498 //=======================================================================
499 // Function : DrawIso
500 // Purpose : Draw an iso on vtk
501 //=======================================================================
502 void GEOM_OCCReader::DrawIso(GeomAbs_IsoType T,
508 Standard_Integer& startidx)
511 Standard_Boolean halt = Standard_False;
512 Standard_Integer j,myDiscret = discretiso;
513 Standard_Real U1,U2,V1,V2,stepU=0.,stepV=0.;
517 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(myShape),l);
519 BRepAdaptor_Surface S(TopoDS::Face(myShape),Standard_False);
521 GeomAbs_SurfaceType SurfType = S.GetType();
523 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
525 Standard_Integer Intrv, nbIntv;
526 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
527 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
528 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
531 if (T == GeomAbs_IsoU) {
532 S.VIntervals(TI, GeomAbs_CN);
541 S.UIntervals(TI, GeomAbs_CN);
553 for (Intrv = 1; Intrv <= nbIntv; Intrv++) {
555 if (TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
557 if (TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
559 if (T == GeomAbs_IsoU) {
560 V1 = Max(T1, TI(Intrv));
561 V2 = Min(T2, TI(Intrv + 1));
562 stepV = (V2 - V1) / myDiscret;
565 U1 = Max(T1, TI(Intrv));
566 U2 = Min(T2, TI(Intrv + 1));
567 stepU = (U2 - U1) / myDiscret;
571 //-------------GeomAbs_Plane---------------
574 //----GeomAbs_Cylinder GeomAbs_Cone------
575 case GeomAbs_Cylinder :
577 if (T == GeomAbs_IsoV) {
578 for (j = 1; j < myDiscret; j++) {
586 //---GeomAbs_Sphere GeomAbs_Torus--------
587 //GeomAbs_BezierSurface GeomAbs_BezierSurface
588 case GeomAbs_Sphere :
590 case GeomAbs_OffsetSurface :
591 case GeomAbs_OtherSurface :
592 for (j = 1; j < myDiscret; j++) {
599 //-------------GeomAbs_BSplineSurface------
600 case GeomAbs_BezierSurface :
601 case GeomAbs_BSplineSurface :
602 for (j = 1; j <= myDiscret/2; j++) {
606 PlotIso ( S, T, U1, V1, (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
611 //-------------GeomAbs_SurfaceOfExtrusion--
612 //-------------GeomAbs_SurfaceOfRevolution-
613 case GeomAbs_SurfaceOfExtrusion :
614 case GeomAbs_SurfaceOfRevolution :
615 if ((T == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
616 (T == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) {
617 if (SurfType == GeomAbs_SurfaceOfExtrusion) break;
618 for (j = 1; j < myDiscret; j++) {
625 CurvType = (S.BasisCurve())->GetType();
629 case GeomAbs_Circle :
630 case GeomAbs_Ellipse :
631 for (j = 1; j < myDiscret; j++) {
638 case GeomAbs_Parabola :
639 case GeomAbs_Hyperbola :
640 case GeomAbs_BezierCurve :
641 case GeomAbs_BSplineCurve :
642 case GeomAbs_OtherCurve :
643 for (j = 1; j <= myDiscret/2; j++) {
647 PlotIso ( S, T, U1, V1,(T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
661 //=======================================================================
662 // Function : PlotIso
663 // Purpose : Plot iso for other surface
664 //=======================================================================
666 void GEOM_OCCReader::PlotIso (BRepAdaptor_Surface& S,
671 Standard_Boolean& halt,
680 if (T == GeomAbs_IsoU) {
682 S.D0(U, V + Step/2., Pm);
683 S.D0(U, V + Step, Pr);
686 S.D0(U + Step/2., V, Pm);
687 S.D0(U + Step, V, Pr);
690 if (PlotCount > MaxPlotCount) {
691 DrawTo(Pr,Pts,Cells);
695 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
696 DrawTo(Pr,Pts,Cells);
698 if (T == GeomAbs_IsoU) {
699 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
700 Standard_Real aLocalV = V + Step/2 ;
701 PlotIso ( S, T, U, aLocalV , Step/2, halt, Pts, Cells);
703 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
704 Standard_Real aLocalU = U + Step/2 ;
705 PlotIso ( S, T, aLocalU , V, Step/2, halt, Pts, Cells);
709 //=======================================================================
710 // Function : TransferEdgeWData
711 // Purpose : Transfert wireframe data for EDGE
712 //=======================================================================
714 void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
716 vtkCellArray* Cells) {
719 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
720 Standard_Integer i = 1;
721 Handle(Poly_Triangulation) T;
722 TopLoc_Location aEdgeLoc;
723 BRep_Tool::PolygonOnTriangulation(aEdge, aEdgePoly, T, aEdgeLoc, i);
725 Handle(Poly_Polygon3D) P;
726 if(aEdgePoly.IsNull()) {
727 P = BRep_Tool::Polygon3D(aEdge, aEdgeLoc);
730 if(P.IsNull() && aEdgePoly.IsNull())
737 Standard_Boolean isidtrsf = true;
738 if(!aEdgeLoc.IsIdentity()) {
740 edgeTransf = aEdgeLoc.Transformation();
745 Standard_Integer nbnodes;
746 if (aEdgePoly.IsNull()) {
747 nbnodes = P->NbNodes();
748 const TColgp_Array1OfPnt& theNodesP = P->Nodes();
751 aP2 = theNodesP(nbnodes);
756 for(int j=1;j<nbnodes;j++) {
757 gp_Pnt pt1 = theNodesP(j);
758 gp_Pnt pt2 = theNodesP(j+1);
761 // apply edge transformation
762 pt1.Transform(edgeTransf);
763 pt2.Transform(edgeTransf);
767 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
768 pts[0] = Pts->InsertNextPoint(coord);
771 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
772 pts[1] = Pts->InsertNextPoint(coord);
774 // insert line (pt1,pt2)
775 Cells->InsertNextCell(2,pts);
778 nbnodes = aEdgePoly->NbNodes();
779 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
780 const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
782 aP1 = theNodesPoly(1);
783 aP2 = theNodesPoly(nbnodes);
788 for(int j=1;j<nbnodes;j++) {
789 Standard_Integer id1 = Nodesidx(j);
790 Standard_Integer id2 = Nodesidx(j+1);
792 gp_Pnt pt1 = theNodesPoly(id1);
793 gp_Pnt pt2 = theNodesPoly(id2);
796 // apply edge transformation
797 pt1.Transform(edgeTransf);
798 pt2.Transform(edgeTransf);
802 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
803 pts[0] = Pts->InsertNextPoint(coord);
806 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
807 pts[1] = Pts->InsertNextPoint(coord);
809 // insert line (pt1,pt2)
810 Cells->InsertNextCell(2,pts);
814 // vector representation has an arrow on its end
818 // apply edge transformation
819 aP1.Transform(edgeTransf);
820 aP2.Transform(edgeTransf);
824 gp_Vec aDirVec (aP1, aP2);
825 Standard_Real aDist = aDirVec.Magnitude();
826 if (aDist < gp::Resolution()) return;
827 gp_Dir aDirection (aDirVec);
829 Standard_Real anAngle = PI/180.*5.;
830 Standard_Real aLength = aDist/10.;
832 Standard_Real dx,dy,dz;
833 aDirection.Coord(dx,dy,dz);
835 // Pointe de la fleche
836 Standard_Real xo,yo,zo;
839 // Centre du cercle base de la fleche
840 gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
842 // Construction d'un repere i,j pour le cercle
844 if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
845 else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
846 else aDirN = gp::DZ();
848 gp_Dir aDirI = aDirection ^ aDirN;
849 gp_Dir aDirJ = aDirection ^ aDirI;
851 // Add points and segments, composing the arrow
852 Standard_Real cosinus, sinus, Tg = tan(anAngle);
855 coord[0] = xo; coord[1] = yo; coord[2] = zo;
857 int ptLoc = Pts->InsertNextPoint(coord);
865 for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
867 cosinus = cos(2. * PI / NbPoints * (i-1));
868 sinus = sin(2. * PI / NbPoints * (i-1));
870 gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
876 ptCur = Pts->InsertNextPoint(coord);
883 // insert line (ptCur,ptPrev)
885 Cells->InsertNextCell(2,pts);
888 // insert line (ptCur,ptLoc)
890 Cells->InsertNextCell(2,pts);
893 // insert line (ptCur,ptFirst)
896 Cells->InsertNextCell(2,pts);
900 /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
901 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
902 const TColgp_Array1OfPnt& theNodes = T->Nodes();
909 for(i=1;i<=nbnodes;i++) {
910 Standard_Integer id = Nodesidx(i);
911 gp_Pnt pt = theNodes(id);
914 if(!isidtrsf) pt.Transform(edgeTransf);
916 coord[0] = pt.X(); coord[1] = pt.Y(); coord[2] = pt.Z();
918 Pts->SetPoint(id-1,coord);
923 for(i=1;i<nbnodes;i++) {
925 Standard_Integer id1 = Nodesidx(i);
926 Standard_Integer id2 = Nodesidx(i+1);
929 pts[0] = id1-1; pts[1] = id2-1;
931 // insert line (pt1,pt2)
932 Cells->InsertNextCell(2,pts);
938 //=======================================================================
939 // Function : TransferVertexWData
940 // Purpose : Transfert wireframe data for VERTEX
941 //=======================================================================
943 void GEOM_OCCReader::TransferVertexWData(const TopoDS_Vertex& aVertex,
945 vtkCellArray* Cells) {
946 #define ZERO_COORD coord[0] = 0.0; coord[1] = 0.0; coord[2] = 0.0
948 gp_Pnt P = BRep_Tool::Pnt( aVertex );
949 float delta = 1, coord[3];
952 ZERO_COORD; coord[0] = +delta;
953 pts[0] = Pts->InsertNextPoint(coord);
955 pts[1] = Pts->InsertNextPoint(coord);
956 // insert line (pt1,pt2)
957 Cells->InsertNextCell(2,pts);
959 ZERO_COORD; coord[1] = +delta;
960 pts[0] = Pts->InsertNextPoint(coord);
962 pts[1] = Pts->InsertNextPoint(coord);
963 // insert line (pt1,pt2)
964 Cells->InsertNextCell(2,pts);
966 ZERO_COORD; coord[2] = +delta;
967 pts[0] = Pts->InsertNextPoint(coord);
969 pts[1] = Pts->InsertNextPoint(coord);
970 // insert line (pt1,pt2)
971 Cells->InsertNextCell(2,pts);
976 //=======================================================================
977 // Function : TransferEdgeSData(
978 // Purpose : Transfert shading data for EDGE
979 //=======================================================================
981 void GEOM_OCCReader::TransferEdgeSData(const TopoDS_Edge& aFace,
988 //=======================================================================
989 // Function : TransferFaceSData
990 // Purpose : Transfert shading data for FACE
991 //=======================================================================
992 void GEOM_OCCReader::TransferFaceSData(const TopoDS_Face& aFace,
994 vtkCellArray* Cells) {
996 TopLoc_Location aLoc;
997 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
998 if(aPoly.IsNull()) return;
1002 Standard_Boolean identity = true;
1003 if(!aLoc.IsIdentity()) {
1005 myTransf = aLoc.Transformation();
1008 Standard_Integer nbNodesInFace = aPoly->NbNodes();
1009 Standard_Integer nbTriInFace = aPoly->NbTriangles();
1011 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
1012 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
1015 for(i=1;i<=nbNodesInFace;i++) {
1016 gp_Pnt P = Nodes(i);
1018 if(!identity) P.Transform(myTransf);
1019 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
1020 Pts->SetPoint(i-1,coord);
1023 for(i=1;i<=nbTriInFace;i++) {
1026 Standard_Integer N1,N2,N3;
1027 Triangles(i).Get(N1,N2,N3);
1030 pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
1031 Cells->InsertNextCell(3,pts);
1037 //=======================================================================
1038 // Function : ComputeShading
1039 // Purpose : Compute the shape in shading mode
1040 //=======================================================================
1041 void GEOM_OCCReader::ComputeShading(vtkPoints* Pts,vtkCellArray* Cells){
1043 // Check the type of the shape:
1044 if(myShape.ShapeType() == TopAbs_FACE) {
1046 TransferFaceSData(TopoDS::Face(myShape),Pts,Cells);
1049 if(myShape.ShapeType() == TopAbs_EDGE) {
1051 TransferEdgeSData(TopoDS::Edge(myShape),Pts,Cells);
1060 //=======================================================================
1062 // Purpose : Set parameters
1063 //=======================================================================
1064 void GEOM_OCCReader::setDisplayMode(int thenewmode) {
1068 void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape, bool isVector) {
1070 myIsVector = isVector;
1073 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
1077 //=======================================================================
1079 // Purpose : Get parameters
1080 //=======================================================================
1081 const TopoDS_Shape& GEOM_OCCReader::getTopo() {
1085 int GEOM_OCCReader::getDisplayMode() {