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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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();
743 Standard_Integer nbnodes;
744 if (aEdgePoly.IsNull()) {
745 nbnodes = P->NbNodes();
746 const TColgp_Array1OfPnt& theNodesP = P->Nodes();
751 for(int j=1;j<nbnodes;j++) {
752 gp_Pnt pt1 = theNodesP(j);
753 gp_Pnt pt2 = theNodesP(j+1);
756 // apply edge transformation
757 pt1.Transform(edgeTransf);
758 pt2.Transform(edgeTransf);
762 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
763 pts[0] = Pts->InsertNextPoint(coord);
766 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
767 pts[1] = Pts->InsertNextPoint(coord);
769 // insert line (pt1,pt2)
770 Cells->InsertNextCell(2,pts);
773 nbnodes = aEdgePoly->NbNodes();
774 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
775 const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
780 for(int j=1;j<nbnodes;j++) {
781 Standard_Integer id1 = Nodesidx(j);
782 Standard_Integer id2 = Nodesidx(j+1);
784 gp_Pnt pt1 = theNodesPoly(id1);
785 gp_Pnt pt2 = theNodesPoly(id2);
788 // apply edge transformation
789 pt1.Transform(edgeTransf);
790 pt2.Transform(edgeTransf);
794 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
795 pts[0] = Pts->InsertNextPoint(coord);
798 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
799 pts[1] = Pts->InsertNextPoint(coord);
801 // insert line (pt1,pt2)
802 Cells->InsertNextCell(2,pts);
807 /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
808 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
809 const TColgp_Array1OfPnt& theNodes = T->Nodes();
816 for(i=1;i<=nbnodes;i++) {
817 Standard_Integer id = Nodesidx(i);
818 gp_Pnt pt = theNodes(id);
821 if(!isidtrsf) pt.Transform(edgeTransf);
823 coord[0] = pt.X(); coord[1] = pt.Y(); coord[2] = pt.Z();
825 Pts->SetPoint(id-1,coord);
830 for(i=1;i<nbnodes;i++) {
832 Standard_Integer id1 = Nodesidx(i);
833 Standard_Integer id2 = Nodesidx(i+1);
836 pts[0] = id1-1; pts[1] = id2-1;
838 // insert line (pt1,pt2)
839 Cells->InsertNextCell(2,pts);
845 //=======================================================================
846 // Function : TransferVertexWData
847 // Purpose : Transfert wireframe data for VERTEX
848 //=======================================================================
850 void GEOM_OCCReader::TransferVertexWData(const TopoDS_Vertex& aVertex,
852 vtkCellArray* Cells) {
853 #define ZERO_COORD coord[0] = 0.0; coord[1] = 0.0; coord[2] = 0.0
855 gp_Pnt P = BRep_Tool::Pnt( aVertex );
856 float delta = 1, coord[3];
859 ZERO_COORD; coord[0] = +delta;
860 pts[0] = Pts->InsertNextPoint(coord);
862 pts[1] = Pts->InsertNextPoint(coord);
863 // insert line (pt1,pt2)
864 Cells->InsertNextCell(2,pts);
866 ZERO_COORD; coord[1] = +delta;
867 pts[0] = Pts->InsertNextPoint(coord);
869 pts[1] = Pts->InsertNextPoint(coord);
870 // insert line (pt1,pt2)
871 Cells->InsertNextCell(2,pts);
873 ZERO_COORD; coord[2] = +delta;
874 pts[0] = Pts->InsertNextPoint(coord);
876 pts[1] = Pts->InsertNextPoint(coord);
877 // insert line (pt1,pt2)
878 Cells->InsertNextCell(2,pts);
883 //=======================================================================
884 // Function : TransferEdgeSData(
885 // Purpose : Transfert shading data for EDGE
886 //=======================================================================
888 void GEOM_OCCReader::TransferEdgeSData(const TopoDS_Edge& aFace,
895 //=======================================================================
896 // Function : TransferFaceSData
897 // Purpose : Transfert shading data for FACE
898 //=======================================================================
899 void GEOM_OCCReader::TransferFaceSData(const TopoDS_Face& aFace,
901 vtkCellArray* Cells) {
903 TopLoc_Location aLoc;
904 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
905 if(aPoly.IsNull()) return;
909 Standard_Boolean identity = true;
910 if(!aLoc.IsIdentity()) {
912 myTransf = aLoc.Transformation();
915 Standard_Integer nbNodesInFace = aPoly->NbNodes();
916 Standard_Integer nbTriInFace = aPoly->NbTriangles();
918 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
919 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
922 for(i=1;i<=nbNodesInFace;i++) {
925 if(!identity) P.Transform(myTransf);
926 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
927 Pts->SetPoint(i-1,coord);
930 for(i=1;i<=nbTriInFace;i++) {
933 Standard_Integer N1,N2,N3;
934 Triangles(i).Get(N1,N2,N3);
937 pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
938 Cells->InsertNextCell(3,pts);
944 //=======================================================================
945 // Function : ComputeShading
946 // Purpose : Compute the shape in shading mode
947 //=======================================================================
948 void GEOM_OCCReader::ComputeShading(vtkPoints* Pts,vtkCellArray* Cells){
950 // Check the type of the shape:
951 if(myShape.ShapeType() == TopAbs_FACE) {
953 TransferFaceSData(TopoDS::Face(myShape),Pts,Cells);
956 if(myShape.ShapeType() == TopAbs_EDGE) {
958 TransferEdgeSData(TopoDS::Edge(myShape),Pts,Cells);
967 //=======================================================================
969 // Purpose : Set parameters
970 //=======================================================================
971 void GEOM_OCCReader::setDisplayMode(int thenewmode) {
975 void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape) {
979 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
983 //=======================================================================
985 // Purpose : Get parameters
986 //=======================================================================
987 const TopoDS_Shape& GEOM_OCCReader::getTopo() {
991 int GEOM_OCCReader::getDisplayMode() {