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
30 #include "GEOM_OCCReader.h"
33 #include "utilities.h"
36 #include "VTKViewer_Common.h"
37 #include <vtkMergePoints.h>
39 // OpenCASCADE Includes
40 #include <BRepAdaptor_Surface.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <BRepMesh_IncrementalMesh.hxx>
43 #include <Poly_Triangulation.hxx>
44 #include <Poly_Polygon3D.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Wire.hxx>
49 #include <BRepBndLib.hxx>
52 #include <Precision.hxx>
53 #include <BRepTools.hxx>
54 #include <BRep_Tool.hxx>
55 #include <Geom2dAdaptor_Curve.hxx>
56 #include <Geom2dHatch_Intersector.hxx>
57 #include <Geom2dHatch_Hatcher.hxx>
58 #include <Geom2d_Curve.hxx>
59 #include <Geom2d_Line.hxx>
60 #include <Geom2d_TrimmedCurve.hxx>
61 #include <HatchGen_Domain.hxx>
62 #include <GeomAbs_IsoType.hxx>
63 #include <Precision.hxx>
64 #include <TopAbs_ShapeEnum.hxx>
65 #include <TopExp_Explorer.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <gp_Dir2d.hxx>
69 #include <gp_Pnt2d.hxx>
70 #include <TColStd_Array1OfInteger.hxx>
71 #include <TColStd_Array1OfReal.hxx>
72 #include <Adaptor3d_HCurve.hxx>
75 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
76 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
78 // Constante for iso building
79 static Standard_Real IntersectorConfusion = 1.e-10 ; // -8 ;
80 static Standard_Real IntersectorTangency = 1.e-10 ; // -8 ;
81 static Standard_Real HatcherConfusion2d = 1.e-8 ;
82 static Standard_Real HatcherConfusion3d = 1.e-8 ;
84 static Standard_Integer lastVTKpoint = 0;
85 static Standard_Integer PlotCount = 0;
86 static Standard_Real IsoRatio = 1.001;
87 static Standard_Integer MaxPlotCount = 5;
89 //=======================================================================
92 //=======================================================================
94 GEOM_OCCReader* GEOM_OCCReader::New()
96 vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_OCCReader");
98 return (GEOM_OCCReader*)ret;
100 return new GEOM_OCCReader;
103 //=======================================================================
104 // Function : GEOM_OCCReader
106 //=======================================================================
108 GEOM_OCCReader::GEOM_OCCReader()
110 //this->myShape = NULL;
112 this->forced = Standard_False;
113 this->discretiso = 15;
116 //=======================================================================
117 // Function : ~GEOM_OCCReader
119 //=======================================================================
121 GEOM_OCCReader::~GEOM_OCCReader()
126 //=======================================================================
127 // Function : Execute
129 //=======================================================================
132 void GEOM_OCCReader::Execute() {
134 vtkPolyData* output = this->GetOutput();
135 vtkPoints* Pts = NULL;
136 vtkCellArray* Cells = NULL;
137 TopLoc_Location aLoc;
140 Pts = vtkPoints::New();
141 Cells = vtkCellArray::New();
143 //Compute number of triangles and points
144 Standard_Integer nbpoly=0,nbpts=0;
149 if(myShape.ShapeType() == TopAbs_FACE) {
151 const TopoDS_Face& aFace = TopoDS::Face(myShape);
152 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
159 nbpts = aPoly->NbNodes();
160 nbpoly = aPoly->NbTriangles();
162 Pts->SetNumberOfPoints(nbpts);
163 Cells->Allocate(Cells->EstimateSize(nbpoly,3));
174 ComputeWireframe(Pts,Cells);
175 output->SetPoints(Pts);
176 output->SetLines(Cells);
180 if(myShape.ShapeType() == TopAbs_FACE) {
181 ComputeShading(Pts,Cells);
183 output->SetPoints(Pts);
184 output->SetPolys(Cells);
193 //=======================================================================
194 // Function : ComputeWireframe
195 // Purpose : Compute the shape in CAD wireframe mode
196 //=======================================================================
198 void GEOM_OCCReader::ComputeWireframe(vtkPoints* Pts,vtkCellArray* Cells){
200 // Check the type of the shape:
201 if(myShape.ShapeType() == TopAbs_FACE) {
203 TransferFaceWData(TopoDS::Face(myShape),Pts,Cells);
204 } else if(myShape.ShapeType() == TopAbs_EDGE) {
206 TransferEdgeWData(TopoDS::Edge(myShape),Pts,Cells);
208 if(myShape.ShapeType() == TopAbs_VERTEX) {
210 TransferVertexWData(TopoDS::Vertex(myShape),Pts,Cells);
215 //=======================================================================
216 // Function : TransferFaceWData
217 // Purpose : Transfert wireframe data for FACE
218 //=======================================================================
220 void GEOM_OCCReader::TransferFaceWData(const TopoDS_Face& aFace,
224 TopoDS_Face aCopyFace = aFace;
225 aCopyFace.Orientation (TopAbs_FORWARD);
226 createISO(aCopyFace,Precision::Infinite(),1,Pts,Cells);
229 //=======================================================================
230 // Function : createISO
231 // Purpose : Create ISO for Face Wireframe representation
232 //=======================================================================
234 void GEOM_OCCReader::createISO (const TopoDS_Face& TopologicalFace,
235 const Standard_Real Infinite,
236 const Standard_Integer NbIsos,
240 Geom2dHatch_Hatcher aHatcher (Geom2dHatch_Intersector (IntersectorConfusion,
241 IntersectorTangency),
247 Standard_Real myInfinite,myUMin,myUMax,myVMin,myVMax;
248 //myInfinite = Precision::Infinite();
249 myInfinite = 1e38; // VTK uses float numbers - Precision::Infinite() is double and can not be accepted.
251 Standard_Integer myNbDom;
252 TColStd_Array1OfReal myUPrm(1, NbIsos),myVPrm(1, NbIsos);
253 TColStd_Array1OfInteger myUInd(1, NbIsos),myVInd(1, NbIsos);
258 //-----------------------------------------------------------------------
259 // If the Min Max bounds are infinite, there are bounded to Infinite
261 //-----------------------------------------------------------------------
263 BRepTools::UVBounds (TopologicalFace, myUMin, myUMax, myVMin, myVMax) ;
264 Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (myUMin) ;
265 Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (myUMax) ;
266 Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (myVMin) ;
267 Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (myVMax) ;
268 if (InfiniteUMin && InfiniteUMax) {
269 myUMin = - myInfinite ;
270 myUMax = myInfinite ;
271 } else if (InfiniteUMin) {
272 myUMin = myUMax - myInfinite ;
273 } else if (InfiniteUMax) {
274 myUMax = myUMin + myInfinite ;
276 if (InfiniteVMin && InfiniteVMax) {
277 myVMin = - myInfinite ;
278 myVMax = myInfinite ;
279 } else if (InfiniteVMin) {
280 myVMin = myVMax - myInfinite ;
281 } else if (InfiniteVMax) {
282 myVMax = myVMin + myInfinite ;
285 //-----------------------------------------------------------------------
286 // Retreiving the edges and loading them into the hatcher.
287 //-----------------------------------------------------------------------
289 TopExp_Explorer ExpEdges ;
290 for (ExpEdges.Init (TopologicalFace, TopAbs_EDGE) ; ExpEdges.More() ; ExpEdges.Next()) {
291 const TopoDS_Edge& TopologicalEdge = TopoDS::Edge (ExpEdges.Current()) ;
292 Standard_Real U1, U2 ;
293 const Handle(Geom2d_Curve) PCurve = BRep_Tool::CurveOnSurface (TopologicalEdge, TopologicalFace, U1, U2) ;
295 if ( PCurve.IsNull() ) {
303 //-- Test if a TrimmedCurve is necessary
304 if( Abs(PCurve->FirstParameter()-U1)<= Precision::PConfusion()
305 && Abs(PCurve->LastParameter()-U2)<= Precision::PConfusion()) {
306 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
309 if (!PCurve->IsPeriodic()) {
310 Handle (Geom2d_TrimmedCurve) TrimPCurve =Handle(Geom2d_TrimmedCurve)::DownCast(PCurve);
311 if (!TrimPCurve.IsNull()) {
312 if (TrimPCurve->BasisCurve()->FirstParameter()-U1 > Precision::PConfusion() ||
313 U2-TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion()) {
314 aHatcher.AddElement (PCurve, TopologicalEdge.Orientation()) ;
319 if (PCurve->FirstParameter()-U1 > Precision::PConfusion()){
320 U1=PCurve->FirstParameter();
322 if (U2-PCurve->LastParameter() > Precision::PConfusion()){
323 U2=PCurve->LastParameter();
327 Handle (Geom2d_TrimmedCurve) TrimPCurve = new Geom2d_TrimmedCurve (PCurve, U1, U2) ;
328 aHatcher.AddElement (TrimPCurve, TopologicalEdge.Orientation()) ;
333 //-----------------------------------------------------------------------
334 // Loading and trimming the hatchings.
335 //-----------------------------------------------------------------------
337 Standard_Integer IIso ;
338 Standard_Real DeltaU = Abs (myUMax - myUMin) ;
339 Standard_Real DeltaV = Abs (myVMax - myVMin) ;
340 Standard_Real confusion = Min (DeltaU, DeltaV) * HatcherConfusion3d ;
341 aHatcher.Confusion3d (confusion) ;
343 Standard_Real StepU = DeltaU / (Standard_Real) NbIsos ;
344 if (StepU > confusion) {
345 Standard_Real UPrm = myUMin + StepU / 2. ;
346 gp_Dir2d Dir (0., 1.) ;
347 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
348 myUPrm(IIso) = UPrm ;
349 gp_Pnt2d Ori (UPrm, 0.) ;
350 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
351 myUInd(IIso) = aHatcher.AddHatching (HCur) ;
356 Standard_Real StepV = DeltaV / (Standard_Real) NbIsos ;
357 if (StepV > confusion) {
358 Standard_Real VPrm = myVMin + StepV / 2. ;
359 gp_Dir2d Dir (1., 0.) ;
360 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
361 myVPrm(IIso) = VPrm ;
362 gp_Pnt2d Ori (0., VPrm) ;
363 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
364 myVInd(IIso) = aHatcher.AddHatching (HCur) ;
369 //-----------------------------------------------------------------------
371 //-----------------------------------------------------------------------
376 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
377 Standard_Integer Index ;
379 Index = myUInd(IIso) ;
381 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
382 aHatcher.ComputeDomains (Index);
383 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
387 Index = myVInd(IIso) ;
389 if (aHatcher.TrimDone (Index) && !aHatcher.TrimFailed (Index)) {
390 aHatcher.ComputeDomains (Index);
391 if (aHatcher.IsDone (Index)) myNbDom = myNbDom + aHatcher.NbDomains (Index) ;
396 //-----------------------------------------------------------------------
397 // Push iso lines in vtk kernel
398 //-----------------------------------------------------------------------
401 Standard_Integer pt_start_idx = 0;
403 for (Standard_Integer UIso = myUPrm.Lower() ; UIso <= myUPrm.Upper() ; UIso++) {
404 Standard_Integer UInd = myUInd.Value (UIso) ;
406 Standard_Real UPrm = myUPrm.Value (UIso) ;
407 if (!aHatcher.IsDone (UInd)) {
408 MESSAGE("DBRep_IsoBuilder:: U iso of parameter: "<<UPrm)
409 switch (aHatcher.Status (UInd)) {
410 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
411 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
412 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
413 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
414 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
417 Standard_Integer NbDom = aHatcher.NbDomains (UInd) ;
418 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
419 const HatchGen_Domain& Dom = aHatcher.Domain (UInd, IDom) ;
420 Standard_Real V1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
421 Standard_Real V2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
422 DrawIso(GeomAbs_IsoU, UPrm, V1, V2, Pts, Cell,pt_start_idx);
428 for (Standard_Integer VIso = myVPrm.Lower() ; VIso <= myVPrm.Upper() ; VIso++) {
429 Standard_Integer VInd = myVInd.Value (VIso) ;
431 Standard_Real VPrm = myVPrm.Value (VIso) ;
432 if (!aHatcher.IsDone (VInd)) {
433 MESSAGE("DBRep_IsoBuilder:: V iso of parameter: "<<VPrm)
434 switch (aHatcher.Status (VInd)) {
435 case HatchGen_NoProblem : MESSAGE("No Problem") ; break ;
436 case HatchGen_TrimFailure : MESSAGE("Trim Failure") ; break ;
437 case HatchGen_TransitionFailure : MESSAGE("Transition Failure") ; break ;
438 case HatchGen_IncoherentParity : MESSAGE("Incoherent Parity") ; break ;
439 case HatchGen_IncompatibleStates : MESSAGE("Incompatible States") ; break ;
442 Standard_Integer NbDom = aHatcher.NbDomains (VInd) ;
443 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
444 const HatchGen_Domain& Dom = aHatcher.Domain (VInd, IDom) ;
445 Standard_Real U1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
446 Standard_Real U2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
447 DrawIso(GeomAbs_IsoV, VPrm, U1, U2, Pts, Cell,pt_start_idx) ;
455 //=======================================================================
457 // Purpose : Init VTK ISO PLOT
458 //=======================================================================
459 void GEOM_OCCReader::MoveTo(gp_Pnt P,
464 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
465 lastVTKpoint = Pts->InsertNextPoint(coord);
469 //=======================================================================
471 // Purpose : Plot point in VTK
472 //=======================================================================
473 void GEOM_OCCReader::DrawTo(gp_Pnt P,
478 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
479 Standard_Integer NewVTKpoint = Pts->InsertNextPoint(coord);
482 pts[0] = lastVTKpoint;
483 pts[1] = NewVTKpoint;
485 Cells->InsertNextCell(2,pts);
487 lastVTKpoint = NewVTKpoint;
491 //=======================================================================
492 // Function : DrawIso
493 // Purpose : Draw an iso on vtk
494 //=======================================================================
495 void GEOM_OCCReader::DrawIso(GeomAbs_IsoType T,
501 Standard_Integer& startidx)
504 Standard_Boolean halt = Standard_False;
505 Standard_Integer j,myDiscret = discretiso;
506 Standard_Real U1,U2,V1,V2,stepU=0.,stepV=0.;
510 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(myShape),l);
512 BRepAdaptor_Surface S(TopoDS::Face(myShape),Standard_False);
514 GeomAbs_SurfaceType SurfType = S.GetType();
516 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
518 Standard_Integer Intrv, nbIntv;
519 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
520 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
521 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
524 if (T == GeomAbs_IsoU) {
525 S.VIntervals(TI, GeomAbs_CN);
534 S.UIntervals(TI, GeomAbs_CN);
546 for (Intrv = 1; Intrv <= nbIntv; Intrv++) {
548 if (TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
550 if (TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
552 if (T == GeomAbs_IsoU) {
553 V1 = Max(T1, TI(Intrv));
554 V2 = Min(T2, TI(Intrv + 1));
555 stepV = (V2 - V1) / myDiscret;
558 U1 = Max(T1, TI(Intrv));
559 U2 = Min(T2, TI(Intrv + 1));
560 stepU = (U2 - U1) / myDiscret;
564 //-------------GeomAbs_Plane---------------
567 //----GeomAbs_Cylinder GeomAbs_Cone------
568 case GeomAbs_Cylinder :
570 if (T == GeomAbs_IsoV) {
571 for (j = 1; j < myDiscret; j++) {
579 //---GeomAbs_Sphere GeomAbs_Torus--------
580 //GeomAbs_BezierSurface GeomAbs_BezierSurface
581 case GeomAbs_Sphere :
583 case GeomAbs_OffsetSurface :
584 case GeomAbs_OtherSurface :
585 for (j = 1; j < myDiscret; j++) {
592 //-------------GeomAbs_BSplineSurface------
593 case GeomAbs_BezierSurface :
594 case GeomAbs_BSplineSurface :
595 for (j = 1; j <= myDiscret/2; j++) {
599 PlotIso ( S, T, U1, V1, (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
604 //-------------GeomAbs_SurfaceOfExtrusion--
605 //-------------GeomAbs_SurfaceOfRevolution-
606 case GeomAbs_SurfaceOfExtrusion :
607 case GeomAbs_SurfaceOfRevolution :
608 if ((T == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
609 (T == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) {
610 if (SurfType == GeomAbs_SurfaceOfExtrusion) break;
611 for (j = 1; j < myDiscret; j++) {
618 CurvType = (S.BasisCurve())->GetType();
622 case GeomAbs_Circle :
623 case GeomAbs_Ellipse :
624 for (j = 1; j < myDiscret; j++) {
631 case GeomAbs_Parabola :
632 case GeomAbs_Hyperbola :
633 case GeomAbs_BezierCurve :
634 case GeomAbs_BSplineCurve :
635 case GeomAbs_OtherCurve :
636 for (j = 1; j <= myDiscret/2; j++) {
640 PlotIso ( S, T, U1, V1,(T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt, Pts, Cells);
654 //=======================================================================
655 // Function : PlotIso
656 // Purpose : Plot iso for other surface
657 //=======================================================================
659 void GEOM_OCCReader::PlotIso (BRepAdaptor_Surface& S,
664 Standard_Boolean& halt,
673 if (T == GeomAbs_IsoU) {
675 S.D0(U, V + Step/2., Pm);
676 S.D0(U, V + Step, Pr);
679 S.D0(U + Step/2., V, Pm);
680 S.D0(U + Step, V, Pr);
683 if (PlotCount > MaxPlotCount) {
684 DrawTo(Pr,Pts,Cells);
688 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
689 DrawTo(Pr,Pts,Cells);
691 if (T == GeomAbs_IsoU) {
692 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
693 Standard_Real aLocalV = V + Step/2 ;
694 PlotIso ( S, T, U, aLocalV , Step/2, halt, Pts, Cells);
696 PlotIso ( S, T, U, V, Step/2, halt, Pts, Cells);
697 Standard_Real aLocalU = U + Step/2 ;
698 PlotIso ( S, T, aLocalU , V, Step/2, halt, Pts, Cells);
702 //=======================================================================
703 // Function : TransferEdgeWData
704 // Purpose : Transfert wireframe data for EDGE
705 //=======================================================================
707 void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
709 vtkCellArray* Cells) {
712 Handle(Poly_PolygonOnTriangulation) aEdgePoly;
713 Standard_Integer i = 1;
714 Handle(Poly_Triangulation) T;
715 TopLoc_Location aEdgeLoc;
716 BRep_Tool::PolygonOnTriangulation(aEdge, aEdgePoly, T, aEdgeLoc, i);
718 Handle(Poly_Polygon3D) P;
719 if(aEdgePoly.IsNull()) {
720 P = BRep_Tool::Polygon3D(aEdge, aEdgeLoc);
723 if(P.IsNull() && aEdgePoly.IsNull())
730 Standard_Boolean isidtrsf = true;
731 if(!aEdgeLoc.IsIdentity()) {
733 edgeTransf = aEdgeLoc.Transformation();
736 Standard_Integer nbnodes;
737 if (aEdgePoly.IsNull()) {
738 nbnodes = P->NbNodes();
739 const TColgp_Array1OfPnt& theNodesP = P->Nodes();
744 for(int j=1;j<nbnodes;j++) {
745 gp_Pnt pt1 = theNodesP(j);
746 gp_Pnt pt2 = theNodesP(j+1);
749 // apply edge transformation
750 pt1.Transform(edgeTransf);
751 pt2.Transform(edgeTransf);
755 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
756 pts[0] = Pts->InsertNextPoint(coord);
759 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
760 pts[1] = Pts->InsertNextPoint(coord);
762 // insert line (pt1,pt2)
763 Cells->InsertNextCell(2,pts);
766 nbnodes = aEdgePoly->NbNodes();
767 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
768 const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
773 for(int j=1;j<nbnodes;j++) {
774 Standard_Integer id1 = Nodesidx(j);
775 Standard_Integer id2 = Nodesidx(j+1);
777 gp_Pnt pt1 = theNodesPoly(id1);
778 gp_Pnt pt2 = theNodesPoly(id2);
781 // apply edge transformation
782 pt1.Transform(edgeTransf);
783 pt2.Transform(edgeTransf);
787 coord[0] = pt1.X(); coord[1] = pt1.Y(); coord[2] = pt1.Z();
788 pts[0] = Pts->InsertNextPoint(coord);
791 coord[0] = pt2.X(); coord[1] = pt2.Y(); coord[2] = pt2.Z();
792 pts[1] = Pts->InsertNextPoint(coord);
794 // insert line (pt1,pt2)
795 Cells->InsertNextCell(2,pts);
800 /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
801 const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
802 const TColgp_Array1OfPnt& theNodes = T->Nodes();
809 for(i=1;i<=nbnodes;i++) {
810 Standard_Integer id = Nodesidx(i);
811 gp_Pnt pt = theNodes(id);
814 if(!isidtrsf) pt.Transform(edgeTransf);
816 coord[0] = pt.X(); coord[1] = pt.Y(); coord[2] = pt.Z();
818 Pts->SetPoint(id-1,coord);
823 for(i=1;i<nbnodes;i++) {
825 Standard_Integer id1 = Nodesidx(i);
826 Standard_Integer id2 = Nodesidx(i+1);
829 pts[0] = id1-1; pts[1] = id2-1;
831 // insert line (pt1,pt2)
832 Cells->InsertNextCell(2,pts);
838 //=======================================================================
839 // Function : TransferVertexWData
840 // Purpose : Transfert wireframe data for VERTEX
841 //=======================================================================
843 void GEOM_OCCReader::TransferVertexWData(const TopoDS_Vertex& aVertex,
845 vtkCellArray* Cells) {
846 #define ZERO_COORD coord[0] = 0.0; coord[1] = 0.0; coord[2] = 0.0
848 gp_Pnt P = BRep_Tool::Pnt( aVertex );
849 float delta = 1, coord[3];
852 ZERO_COORD; coord[0] = +delta;
853 pts[0] = Pts->InsertNextPoint(coord);
855 pts[1] = Pts->InsertNextPoint(coord);
856 // insert line (pt1,pt2)
857 Cells->InsertNextCell(2,pts);
859 ZERO_COORD; coord[1] = +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[2] = +delta;
867 pts[0] = Pts->InsertNextPoint(coord);
869 pts[1] = Pts->InsertNextPoint(coord);
870 // insert line (pt1,pt2)
871 Cells->InsertNextCell(2,pts);
876 //=======================================================================
877 // Function : TransferEdgeSData(
878 // Purpose : Transfert shading data for EDGE
879 //=======================================================================
881 void GEOM_OCCReader::TransferEdgeSData(const TopoDS_Edge& aFace,
888 //=======================================================================
889 // Function : TransferFaceSData
890 // Purpose : Transfert shading data for FACE
891 //=======================================================================
892 void GEOM_OCCReader::TransferFaceSData(const TopoDS_Face& aFace,
894 vtkCellArray* Cells) {
896 TopLoc_Location aLoc;
897 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
898 if(aPoly.IsNull()) return;
902 Standard_Boolean identity = true;
903 if(!aLoc.IsIdentity()) {
905 myTransf = aLoc.Transformation();
908 Standard_Integer nbNodesInFace = aPoly->NbNodes();
909 Standard_Integer nbTriInFace = aPoly->NbTriangles();
911 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
912 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
915 for(i=1;i<=nbNodesInFace;i++) {
918 if(!identity) P.Transform(myTransf);
919 coord[0] = P.X(); coord[1] = P.Y(); coord[2] = P.Z();
920 Pts->SetPoint(i-1,coord);
923 for(i=1;i<=nbTriInFace;i++) {
926 Standard_Integer N1,N2,N3;
927 Triangles(i).Get(N1,N2,N3);
930 pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
931 Cells->InsertNextCell(3,pts);
937 //=======================================================================
938 // Function : ComputeShading
939 // Purpose : Compute the shape in shading mode
940 //=======================================================================
941 void GEOM_OCCReader::ComputeShading(vtkPoints* Pts,vtkCellArray* Cells){
943 // Check the type of the shape:
944 if(myShape.ShapeType() == TopAbs_FACE) {
946 TransferFaceSData(TopoDS::Face(myShape),Pts,Cells);
949 if(myShape.ShapeType() == TopAbs_EDGE) {
951 TransferEdgeSData(TopoDS::Edge(myShape),Pts,Cells);
960 //=======================================================================
962 // Purpose : Set parameters
963 //=======================================================================
964 void GEOM_OCCReader::setDisplayMode(int thenewmode) {
968 void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape) {
972 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
976 //=======================================================================
978 // Purpose : Get parameters
979 //=======================================================================
980 const TopoDS_Shape& GEOM_OCCReader::getTopo() {
984 int GEOM_OCCReader::getDisplayMode() {