1 // Created on: 1991-07-04
2 // Created by: Christophe MARION
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_HCurve.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepMesh_IncrementalMesh.hxx>
23 #include <BRepTools.hxx>
24 #include <DBRep_DrawableShape.hxx>
25 #include <DBRep_Edge.hxx>
26 #include <DBRep_Face.hxx>
27 #include <DBRep_HideData.hxx>
28 #include <DBRep_IsoBuilder.hxx>
29 #include <DBRep_ListIteratorOfListOfEdge.hxx>
30 #include <DBRep_ListIteratorOfListOfFace.hxx>
31 #include <DBRep_ListIteratorOfListOfHideData.hxx>
32 #include <Draw_Appli.hxx>
33 #include <Draw_Color.hxx>
34 #include <Draw_Display.hxx>
35 #include <Draw_Drawable3D.hxx>
36 #include <Geom_BSplineCurve.hxx>
37 #include <Geom_BSplineSurface.hxx>
38 #include <GeomAdaptor_HSurface.hxx>
39 #include <GeomAdaptor_Surface.hxx>
40 #include <gp_Lin2d.hxx>
41 #include <gp_Trsf.hxx>
42 #include <HLRBRep.hxx>
43 #include <Poly_Connect.hxx>
44 #include <Poly_Polygon3D.hxx>
45 #include <Poly_PolygonOnTriangulation.hxx>
46 #include <Poly_Triangulation.hxx>
47 #include <Precision.hxx>
48 #include <Standard_DomainError.hxx>
49 #include <Standard_Type.hxx>
50 #include <TColgp_HArray1OfPnt.hxx>
51 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
52 #include <TColStd_DataMapOfIntegerInteger.hxx>
53 #include <TColStd_HArray1OfInteger.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Edge.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
61 #include <TopTools_ListOfShape.hxx>
63 IMPLEMENT_STANDARD_RTTIEXT(DBRep_DrawableShape,Draw_Drawable3D)
65 static Standard_Real IsoRatio = 1.001;
67 static Standard_Integer MaxPlotCount = 5; // To avoid huge recursive calls in
68 static Standard_Integer PlotCount = 0; // PlotEdge and PlotIso for cases of "bad"
69 // curves and surfaces
70 // Set PlotCount = 0 before first call of
71 // PlotEdge or PlotIso
72 static TopoDS_Shape pickshape;
73 static Standard_Real upick,vpick;
75 extern Draw_Viewer dout;
78 //=======================================================================
79 //function : DBRep_DrawableShape
80 //purpose : constructor
81 //=======================================================================
83 DBRep_DrawableShape::DBRep_DrawableShape
84 (const TopoDS_Shape& aShape,
85 const Draw_Color& FreeCol,
86 const Draw_Color& ConnCol,
87 const Draw_Color& EdgeCol,
88 const Draw_Color& IsosCol,
89 const Standard_Real size,
90 const Standard_Integer nbisos,
91 const Standard_Integer discret) :
99 myDispOr(Standard_False),
100 mytriangulations(Standard_False),
101 mypolygons(Standard_False),
102 myHLR(Standard_False),
103 myRg1(Standard_False),
104 myRgN(Standard_False),
105 myHid(Standard_False)
110 //=======================================================================
111 //function : updateDisplayData
113 //=======================================================================
115 void DBRep_DrawableShape::updateDisplayData () const
120 if (myShape.IsNull())
123 //==============================================================
125 //==============================================================
127 TopExp_Explorer ExpFace;
130 for (ExpFace.Init (myShape,TopAbs_FACE);
133 TopoDS_Face TopologicalFace = TopoDS::Face (ExpFace.Current());
135 const Handle(Geom_Surface)& S =
136 BRep_Tool::Surface(TopologicalFace,l);
138 TopologicalFace.Orientation (TopAbs_FORWARD) ;
139 DBRep_IsoBuilder IsoBuild (TopologicalFace, mySize, myNbIsos) ;
140 myFaces.Append(new DBRep_Face (TopologicalFace,
141 IsoBuild.NbDomains(),
143 IsoBuild.LoadIsos (myFaces.Last()) ;
145 else myFaces.Append(new DBRep_Face(TopologicalFace,0, myEdgeCol));
147 else myFaces.Append(new DBRep_Face(TopologicalFace,0, myEdgeCol));
150 //==============================================================
152 //==============================================================
154 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
155 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,edgemap);
156 Standard_Integer iedge;
158 for (iedge = 1; iedge <= edgemap.Extent(); iedge++) {
160 const TopoDS_Edge& theEdge = TopoDS::Edge(edgemap.FindKey(iedge));
162 // skip degenerated edges
163 if (BRep_Tool::Degenerated(theEdge)) continue;
165 // compute the number of faces
166 Standard_Integer nbf = edgemap(iedge).Extent();
168 Draw_Color EdgeColor;
173 EdgeColor = myEdgeCol; // isolated edge
177 EdgeColor = myFreeCol; // edge in only one face
181 EdgeColor = myConnCol; // edge shared by at least two faces
184 myEdges.Append(new DBRep_Edge (theEdge,EdgeColor));
189 //=======================================================================
190 //function : ChangeNbIsos
191 //purpose : Changes the number of isoparametric curves in a shape.
192 //=======================================================================
194 void DBRep_DrawableShape::ChangeNbIsos (const Standard_Integer NbIsos)
198 TopExp_Explorer ExpFace;
201 for (ExpFace.Init (myShape, TopAbs_FACE);
204 TopoDS_Face TopologicalFace = TopoDS::Face (ExpFace.Current());
205 const Handle(Geom_Surface)& S =
206 BRep_Tool::Surface(TopologicalFace,l);
209 TopologicalFace.Orientation (TopAbs_FORWARD) ;
210 DBRep_IsoBuilder IsoBuild (TopologicalFace, mySize, myNbIsos) ;
213 (TopologicalFace, IsoBuild.NbDomains(), myIsosCol)) ;
214 IsoBuild.LoadIsos (myFaces.Last()) ;
216 else myFaces.Append(new DBRep_Face(TopologicalFace,0, myEdgeCol));
218 else myFaces.Append(new DBRep_Face(TopologicalFace,0, myEdgeCol));
222 //=======================================================================
224 // Purpose : Returns the number of isoparametric curves in a shape.
225 //=======================================================================
227 Standard_Integer DBRep_DrawableShape::NbIsos () const
232 //=======================================================================
233 // Function : Discret
235 //=======================================================================
237 Standard_Integer DBRep_DrawableShape::Discret () const
242 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
245 static void PlotIso (Draw_Display& dis,
246 Handle(DBRep_Face)& F,
247 BRepAdaptor_Surface& S,
252 Standard_Boolean& halt)
259 if (T == GeomAbs_IsoU) {
261 S.D0(U, V + Step/2., Pm);
262 S.D0(U, V + Step, Pr);
265 S.D0(U + Step/2., V, Pm);
266 S.D0(U + Step, V, Pr);
269 if (PlotCount > MaxPlotCount) {
271 if (dis.HasPicked()) {
272 pickshape = F->Face();
273 upick = (T == GeomAbs_IsoU) ? U : U + Step;
274 vpick = (T == GeomAbs_IsoU) ? V + Step : V;
275 halt = Standard_True;
280 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
282 if (dis.HasPicked()) {
283 pickshape = F->Face();
284 upick = (T == GeomAbs_IsoU) ? U : U + Step;
285 vpick = (T == GeomAbs_IsoU) ? V + Step : V;
286 halt = Standard_True;
289 if (T == GeomAbs_IsoU) {
290 PlotIso (dis, F, S, T, U, V, Step/2, halt);
291 Standard_Real aLocalV = V + Step/2 ;
292 PlotIso (dis, F, S, T, U, aLocalV , Step/2, halt);
294 PlotIso (dis, F, S, T, U, V, Step/2, halt);
295 Standard_Real aLocalU = U + Step/2 ;
296 PlotIso (dis, F, S, T, aLocalU , V, Step/2, halt);
301 static void PlotEdge (Draw_Display& dis,
302 Handle(DBRep_Edge)& E,
303 const Adaptor3d_Curve& C,
306 Standard_Boolean& halt)
314 C.D0(f + step/2., Pm);
317 if (PlotCount > MaxPlotCount) {
319 if (dis.HasPicked()) {
320 pickshape = E->Edge();
323 halt = Standard_True;
329 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= IsoRatio*Pl.Distance(Pr)) {
331 if (dis.HasPicked()) {
332 pickshape = E->Edge();
335 halt = Standard_True;
338 PlotEdge (dis, E, C, f, step/2, halt);
339 Standard_Real aLocalF = f + step/2 ;
340 PlotEdge (dis, E, C, aLocalF , step/2, halt);
344 //=======================================================================
347 //=======================================================================
349 void DBRep_DrawableShape::DrawOn(Draw_Display& dis) const
351 Standard_Boolean halt = Standard_False;
353 if (myShape.IsNull()) {
354 dis.SetColor(myConnCol);
355 dis.DrawString(gp_Pnt(0,0,0),"Null Shape");
359 if (myFaces.IsEmpty() || myEdges.IsEmpty())
364 DBRep_DrawableShape* p = (DBRep_DrawableShape*) this;
365 p->DisplayHiddenLines(dis);
370 Standard_Real Par,T1,T2;
371 Standard_Real U1,U2,V1,V2,stepU=0.,stepV=0.;
374 Standard_Integer i,j;
377 Handle(Poly_Triangulation) Tr;
378 TopLoc_Location aTempLoc;
381 DBRep_ListIteratorOfListOfFace itf(myFaces);
383 while (itf.More() && !halt) {
385 const Handle(DBRep_Face)& F = itf.Value();
386 dis.SetColor(F->Color());
388 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F->Face(), aTempLoc);
390 if (!aSurf.IsNull()) {
392 Standard_Boolean restriction = Standard_False;
393 if(aSurf->IsUPeriodic() || aSurf->IsVPeriodic()) {
394 Standard_Real SU1 = 0., SU2 = 0., SV1 = 0., SV2 = 0.;
395 Standard_Real FU1 = 0., FU2 = 0., FV1 = 0., FV2 = 0.;
396 aSurf->Bounds(SU1,SU2,SV1,SV2);
397 BRepTools::UVBounds (F->Face(),FU1,FU2,FV1,FV2);
398 if(aSurf->IsUPeriodic()) {
399 if(FU1 < SU1 || FU1 > SU2)
400 restriction = Standard_True;
401 if(!restriction && (FU2 < SU1 || FU2 > SU2))
402 restriction = Standard_True;
404 if(!restriction && aSurf->IsVPeriodic()) {
405 if(FV1 < SV1 || FV1 > SV2)
406 restriction = Standard_True;
407 if(!restriction && (FV2 < SV1 || FV2 > SV2))
408 restriction = Standard_True;
410 Standard_Boolean zeroS = (fabs(SU2-SU1) <= 1.e-9 || fabs(SV2-SV1) <= 1.e-9);
411 Standard_Boolean zeroF = (fabs(FU2-FU1) <= 1.e-9 || fabs(FV2-FV1) <= 1.e-9);
412 if(restriction && (zeroS || zeroF))
413 restriction = Standard_False;
414 if(restriction && (FU1 >= FU2 || FV1 >= FV2))
415 restriction = Standard_False;
416 if(restriction && (fabs(FU2-FU1) > 4.1e+100 || fabs(FV2-FV1) > 4.1e+100))
417 restriction = Standard_False;
420 BRepAdaptor_Surface S(F->Face(),restriction);
422 //BRepAdaptor_Surface S(F->Face(),Standard_False);
424 GeomAbs_SurfaceType SurfType = S.GetType();
426 // If the type of the surface is GeomAbs_SurfaceOfExtrusion or GeomAbs_SurfaceOfRevolution
428 GeomAbs_CurveType CurvType;
430 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
433 Standard_Integer N = F->NbIsos();
435 Standard_Integer Intrv, nbIntv;
436 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
437 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
438 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
440 for (i = 1; i <= N; i++) {
442 F->GetIso(i,T,Par,T1,T2);
443 if (T == GeomAbs_IsoU) {
444 S.VIntervals(TI, GeomAbs_CN);
453 S.UIntervals(TI, GeomAbs_CN);
465 for (Intrv = 1; Intrv <= nbIntv; Intrv++) {
467 if (TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
469 if (TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
471 if (T == GeomAbs_IsoU) {
472 V1 = Max(T1, TI(Intrv));
473 V2 = Min(T2, TI(Intrv + 1));
474 stepV = (V2 - V1) / myDiscret;
477 U1 = Max(T1, TI(Intrv));
478 U2 = Min(T2, TI(Intrv + 1));
479 stepU = (U2 - U1) / myDiscret;
483 //-------------GeomAbs_Plane---------------
486 //----GeomAbs_Cylinder GeomAbs_Cone------
487 case GeomAbs_Cylinder :
489 if (T == GeomAbs_IsoV) {
490 for (j = 1; j < myDiscret; j++) {
495 if (dis.HasPicked()) {
496 pickshape = F->Face();
499 halt = Standard_True;
504 //---GeomAbs_Sphere GeomAbs_Torus--------
505 //GeomAbs_BezierSurface GeomAbs_BezierSurface
506 case GeomAbs_Sphere :
508 case GeomAbs_OffsetSurface :
509 case GeomAbs_OtherSurface :
510 for (j = 1; j < myDiscret; j++) {
515 if (dis.HasPicked()) {
516 pickshape = F->Face();
519 halt = Standard_True;
523 //-------------GeomAbs_BSplineSurface------
524 case GeomAbs_BezierSurface :
525 case GeomAbs_BSplineSurface :
526 for (j = 1; j <= myDiscret/2; j++) {
527 Handle(DBRep_Face) aLocalFace = F;
531 PlotIso (dis, aLocalFace , S, T, U1, V1, (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt);
536 //-------------GeomAbs_SurfaceOfExtrusion--
537 //-------------GeomAbs_SurfaceOfRevolution-
538 case GeomAbs_SurfaceOfExtrusion :
539 case GeomAbs_SurfaceOfRevolution :
540 if ((T == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
541 (T == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) {
542 if (SurfType == GeomAbs_SurfaceOfExtrusion) break;
543 for (j = 1; j < myDiscret; j++) {
548 if (dis.HasPicked()) {
549 pickshape = F->Face();
552 halt = Standard_True;
556 CurvType = (S.BasisCurve())->GetType();
560 case GeomAbs_Circle :
561 case GeomAbs_Ellipse :
562 for (j = 1; j < myDiscret; j++) {
567 if (dis.HasPicked()) {
568 pickshape = F->Face();
571 halt = Standard_True;
575 case GeomAbs_Parabola :
576 case GeomAbs_Hyperbola :
577 case GeomAbs_BezierCurve :
578 case GeomAbs_BSplineCurve :
579 case GeomAbs_OffsetCurve :
580 case GeomAbs_OtherCurve :
581 for (j = 1; j <= myDiscret/2; j++) {
582 Handle(DBRep_Face) aLocalFace = F;
586 PlotIso (dis, aLocalFace, S, T, U1, V1,
587 (T == GeomAbs_IsoV) ? stepU*2. : stepV*2., halt);
598 if (dis.HasPicked()) {
599 pickshape = F->Face();
602 halt = Standard_True;
607 //=====================================
608 // trace des eventuelles triangulations.
609 //=====================================
611 if (aSurf.IsNull() || mytriangulations) {
612 Tr = BRep_Tool::Triangulation(F->Face(), loc);
614 display(Tr, loc.Transformation(), dis);
622 DBRep_ListIteratorOfListOfEdge ite(myEdges);
623 while (ite.More() && !halt) {
625 const Handle(DBRep_Edge)& E = ite.Value();
628 dis.SetColor(DBRep_ColorOrientation(E->Edge().Orientation()));
630 dis.SetColor(E->Color());
632 // display geometrical curve if exists.
633 Standard_Boolean isgeom = BRep_Tool::IsGeometric(E->Edge());
634 Standard_Real aCheckU1, aCheckU2;
637 // check the range (to report bad edges)
638 BRep_Tool::Range(E->Edge(), aCheckU1, aCheckU2);
639 if (aCheckU2 < aCheckU1) {
641 cout << "DBRep_DrawableShape : Bad parameters on edge."<<endl;
642 BRepTools::Dump(E->Edge(),cout);
647 if (BRep_Tool::Degenerated(E->Edge())) {
652 BRepAdaptor_Curve C(E->Edge());
654 Standard_Real f = C.FirstParameter();
655 Standard_Real l = C.LastParameter();
656 if (Precision::IsNegativeInfinite(f)) {
657 if (Precision::IsPositiveInfinite(l)) {
665 else if (Precision::IsPositiveInfinite(l)) {
669 Handle(Adaptor3d_HCurve) HC = C.Trim(f, l, Precision::Confusion());
670 GeomAbs_CurveType CurvType = HC->GetType();
672 Standard_Integer intrv, nbintv = HC->NbIntervals(GeomAbs_CN);
673 TColStd_Array1OfReal TI(1,nbintv+1);
674 HC->Intervals(TI,GeomAbs_CN);
676 HC->D0(HC->FirstParameter(), P);
679 for (intrv = 1; intrv <= nbintv; intrv++) {
680 Standard_Real t = TI(intrv);
681 Standard_Real step = (TI(intrv+1) - t) / myDiscret;
686 case GeomAbs_Circle :
687 case GeomAbs_Ellipse :
688 for (j = 1; j < myDiscret; j++) {
692 if (dis.HasPicked()) {
693 pickshape = E->Edge();
696 halt = Standard_True;
700 case GeomAbs_Parabola :
701 case GeomAbs_Hyperbola :
702 case GeomAbs_BezierCurve :
703 case GeomAbs_BSplineCurve :
704 case GeomAbs_OffsetCurve :
705 case GeomAbs_OtherCurve :
706 for (j = 1; j <= myDiscret/2; j++) {
707 Handle(DBRep_Edge) aLocaLEdge(E);
709 PlotEdge (dis, aLocaLEdge , HC->Curve(), t, step*2., halt);
716 C.D0(HC->LastParameter(),P);
718 if (dis.HasPicked()) {
719 pickshape = E->Edge();
722 halt = Standard_True;
726 // display an arrow at the end
731 dis.Project(aPnt,p1);
733 dis.Project(aPnt,p2);
735 if (v.Magnitude() > gp::Resolution()) {
736 Standard_Real L = 20 / dis.Zoom();
737 Standard_Real H = 10 / dis.Zoom();
739 p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
741 p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
752 //======================================
753 // trace des representations polygonales:
754 //======================================
756 if (!isgeom || mypolygons) {
759 Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(E->Edge(), loc);
760 if (!Polyg.IsNull()) {
761 const TColgp_Array1OfPnt& Points = Polyg->Nodes();
763 for (po = Points.Lower()+1; po <= Points.Upper(); po++) {
764 dis.Draw((Points.Value(po-1)).Transformed(loc),
765 (Points.Value(po)).Transformed(loc));
766 if (dis.HasPicked()) {
767 pickshape = E->Edge();
770 halt = Standard_True;
776 // Polygone sur triangulation:
777 Handle(Poly_Triangulation) PolyTr;
778 Handle(Poly_PolygonOnTriangulation) Poly;
779 BRep_Tool::PolygonOnTriangulation(E->Edge(), Poly, PolyTr, loc);
780 if (!Poly.IsNull()) {
781 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
782 const TColgp_Array1OfPnt& Nodes = PolyTr->Nodes();
783 for (i=Indices.Lower()+1; i<=Indices.Upper(); i++) {
784 dis.Draw(Nodes(Indices(i-1)).Transformed(loc),
785 Nodes(Indices(i)).Transformed(loc));
786 if (dis.HasPicked()) {
787 pickshape = E->Edge();
790 halt = Standard_True;
806 dis.SetColor(myConnCol);
808 for (exv.Init(myShape,TopAbs_VERTEX,TopAbs_EDGE);
813 dis.SetColor(DBRep_ColorOrientation(exv.Current().Orientation()));
814 dis.DrawMarker(BRep_Tool::Pnt(TopoDS::Vertex(exv.Current())),
816 if (dis.HasPicked()) {
817 pickshape = exv.Current();
820 halt = Standard_True;
827 //=======================================================================
828 //function : DisplayHiddenLines
830 //=======================================================================
832 void DBRep_DrawableShape::DisplayHiddenLines(Draw_Display& dis)
834 Standard_Integer id = dis.ViewId();
836 // get the projection
839 Standard_Real focal = -1;
840 if (!strcmp(dout.GetType(id),"PERS")) focal = dout.Focal(id);
841 Standard_Real Ang,Def;
842 HLRBRep::PolyHLRAngleAndDeflection(myAng,Ang,Def);
843 BRepMesh_FastDiscret::Parameters aMeshParams;
844 aMeshParams.Relative = Standard_True;
845 aMeshParams.Deflection = Def;
846 aMeshParams.Angle = Ang;
847 BRepMesh_IncrementalMesh MESH(myShape, aMeshParams);
848 Standard_Boolean recompute = Standard_True;
849 // find if the view must be recomputed
850 DBRep_ListIteratorOfListOfHideData it(myHidData);
853 if (it.Value().ViewId() == id) {
855 // but did we rotate it
856 Standard_Real ang = it.Value().Angle();
857 recompute = !it.Value().IsSame(T,focal) || myAng != ang;
859 myHidData.Remove(it);
861 it.Value().DrawOn(dis,myRg1,myRgN,myHid,
862 myConnCol,myIsosCol);
863 if (dis.HasPicked()) {
864 pickshape = it.Value().LastPick();
873 // recompute the hidden lines and display them
875 DBRep_HideData theData;
876 myHidData.Append(theData);
877 myHidData.Last().Set(id,T,focal,myShape,myAng);
878 myHidData.Last().DrawOn(dis,myRg1,myRgN,myHid,
879 myConnCol,myIsosCol);
880 if (dis.HasPicked()) {
881 pickshape = myHidData.Last().LastPick();
888 //=======================================================================
891 //=======================================================================
893 TopoDS_Shape DBRep_DrawableShape::Shape()const
899 //=======================================================================
902 //=======================================================================
904 Handle(Draw_Drawable3D) DBRep_DrawableShape::Copy()const
906 Handle(DBRep_DrawableShape) D =
907 new DBRep_DrawableShape(myShape,
918 //=======================================================================
919 //function : DisplayOrientation
921 //=======================================================================
923 void DBRep_DrawableShape::DisplayOrientation(const Standard_Boolean D)
928 //=======================================================================
929 //function : DisplayTriangulation
931 //=======================================================================
933 void DBRep_DrawableShape::DisplayTriangulation(const Standard_Boolean D)
935 mytriangulations = D;
938 //=======================================================================
939 //function : DisplayPolygons
941 //=======================================================================
943 void DBRep_DrawableShape::DisplayPolygons(const Standard_Boolean D)
948 //=======================================================================
949 //function : DisplayHLR
951 //=======================================================================
953 void DBRep_DrawableShape::DisplayHLR(const Standard_Boolean withHLR,
954 const Standard_Boolean withRg1,
955 const Standard_Boolean withRgN,
956 const Standard_Boolean withHid,
957 const Standard_Real ang)
966 //=======================================================================
967 //function : DisplayTriangulation
969 //=======================================================================
971 Standard_Boolean DBRep_DrawableShape::DisplayTriangulation() const
973 return mytriangulations;
976 //=======================================================================
977 //function : DisplayPolygons
979 //=======================================================================
981 Standard_Boolean DBRep_DrawableShape::DisplayPolygons()const
986 //=======================================================================
987 //function : GetDisplayHLR
989 //=======================================================================
991 void DBRep_DrawableShape::GetDisplayHLR(Standard_Boolean& withHLR,
992 Standard_Boolean& withRg1,
993 Standard_Boolean& withRgN,
994 Standard_Boolean& withHid,
995 Standard_Real& ang) const
1004 //=======================================================================
1007 //=======================================================================
1009 void DBRep_DrawableShape::Dump(Standard_OStream& S)const
1011 BRepTools::Dump(myShape,S);
1015 //=======================================================================
1018 //=======================================================================
1020 void DBRep_DrawableShape::Whatis(Draw_Interpretor& s)const
1022 if (myShape.IsNull())
1027 s << "shape " << TopAbs::ShapeTypeToString (myShape.ShapeType())
1028 << " " << TopAbs::ShapeOrientationToString(myShape.Orientation());
1030 if (myShape.Free()) s <<" Free";
1031 if (myShape.Modified()) s <<" Modified";
1032 if (myShape.Orientable()) s <<" Orientable";
1033 if (myShape.Closed()) s <<" Closed";
1034 if (myShape.Infinite()) s <<" Infinite";
1035 if (myShape.Convex()) s <<" Convex";
1038 //=======================================================================
1039 //function : LastPick
1041 //=======================================================================
1043 void DBRep_DrawableShape::LastPick(TopoDS_Shape& s,
1044 Standard_Real& u, Standard_Real& v)
1053 //=======================================================================
1054 //function : display
1056 //=======================================================================
1058 void DBRep_DrawableShape::display(const Handle(Poly_Triangulation)& T,
1060 Draw_Display& dis) const
1062 // Build the connect tool
1065 Standard_Integer i,j, nFree, nbTriangles = T->NbTriangles();
1066 Standard_Integer t[3];
1068 // count the free edges
1070 for (i = 1; i <= nbTriangles; i++) {
1071 pc.Triangles(i,t[0],t[1],t[2]);
1072 for (j = 0; j < 3; j++)
1073 if (t[j] == 0) nFree++;
1076 // allocate the arrays
1077 TColStd_Array1OfInteger Free (1, Max (1, 2 * nFree));
1079 // array is replaced on map because it is impossible
1080 // to calculate number of internal edges in advance
1081 // due to "internal edges"
1082 TColStd_DataMapOfIntegerInteger Internal;
1084 Standard_Integer fr = 1, in = 1;
1085 const Poly_Array1OfTriangle& triangles = T->Triangles();
1086 Standard_Integer n[3];
1087 for (i = 1; i <= nbTriangles; i++) {
1088 pc.Triangles(i,t[0],t[1],t[2]);
1089 triangles(i).Get(n[0],n[1],n[2]);
1090 for (j = 0; j < 3; j++) {
1091 Standard_Integer k = (j+1) % 3;
1097 // internal edge if this triangle has a lower index than the adjacent
1098 else if (i < t[j]) {
1099 Internal.Bind(in, n[j]);
1100 Internal.Bind(in+1, n[k]);
1106 // Display the edges
1107 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1108 // cout<<"nb nodes = "<<Nodes.Length()<<endl;
1111 Standard_Integer nn;
1112 dis.SetColor(Draw_rouge);
1113 nn = Free.Length() / 2;
1114 for (i = 1; i <= nn; i++) {
1115 dis.Draw(Nodes(Free(2*i-1)).Transformed(tr),
1116 Nodes(Free(2*i)).Transformed(tr));
1121 dis.SetColor(Draw_bleu);
1122 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aIt(Internal);
1123 for (; aIt.More(); aIt.Next()) {
1124 Standard_Integer n1 = aIt.Value();
1125 //alvays pair is put
1127 Standard_Integer n2 = aIt.Value();
1128 dis.Draw(Nodes(n1).Transformed(tr),
1129 Nodes(n2).Transformed(tr));
1134 //=======================================================================
1135 //function : addMeshNormals
1137 //=======================================================================
1138 Standard_Boolean DBRep_DrawableShape::addMeshNormals (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >& theNormals,
1139 const TopoDS_Face& theFace,
1140 const Standard_Real theLength)
1142 TopLoc_Location aLoc;
1143 const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
1144 const Standard_Boolean hasNormals = aTriangulation->HasNormals();
1145 if (aTriangulation.IsNull()
1146 || (!hasNormals && !aTriangulation->HasUVNodes()))
1148 return Standard_False;
1151 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
1152 BRepAdaptor_Surface aSurface (theFace);
1153 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
1155 gp_Pnt aP1 = aNodes (aNodeIter);
1156 if (!aLoc.IsIdentity())
1158 aP1.Transform (aLoc.Transformation());
1164 aNormal = aTriangulation->Normal (aNodeIter);
1168 const gp_Pnt2d& aUVNode = aTriangulation->UVNode (aNodeIter);
1171 aSurface.D1 (aUVNode.X(), aUVNode.Y(), aDummyPnt, aV1, aV2);
1172 aNormal = aV1.Crossed (aV2);
1175 const Standard_Real aNormalLen = aNormal.Magnitude();
1176 if (aNormalLen > 1.e-10)
1178 aNormal.Multiply (theLength / aNormalLen);
1182 aNormal.SetCoord (aNormalLen / 2.0, 0.0, 0.0);
1183 std::cout << "Null normal at node X = " << aP1.X() << ", Y = " << aP1.Y() << ", Z = " << aP1.Z() << "\n";
1186 const gp_Pnt aP2 = aP1.Translated (aNormal);
1187 theNormals.Append (std::pair<gp_Pnt, gp_Pnt> (aP1, aP2));
1189 return Standard_True;
1192 //=======================================================================
1193 //function : addMeshNormals
1195 //=======================================================================
1196 void DBRep_DrawableShape::addMeshNormals (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > & theNormals,
1197 const TopoDS_Shape& theShape,
1198 const Standard_Real theLength)
1200 TopLoc_Location aLoc;
1201 for (TopExp_Explorer aFaceIt(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
1203 const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
1204 NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >* aFaceNormals = theNormals.ChangeSeek(aFace);
1205 if (aFaceNormals == NULL)
1207 aFaceNormals = theNormals.Bound(aFace, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >());
1210 addMeshNormals (*aFaceNormals, aFace, theLength);
1214 //=======================================================================
1215 //function : addSurfaceNormals
1217 //=======================================================================
1218 Standard_Boolean DBRep_DrawableShape::addSurfaceNormals (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >& theNormals,
1219 const TopoDS_Face& theFace,
1220 const Standard_Real theLength,
1221 const Standard_Integer theNbAlongU,
1222 const Standard_Integer theNbAlongV)
1225 TopLoc_Location aLoc;
1226 const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface (theFace, aLoc);
1227 if (aSurface.IsNull())
1229 return Standard_False;
1233 Standard_Real aUmin = 0.0, aVmin = 0.0, aUmax = 0.0, aVmax = 0.0;
1234 BRepTools::UVBounds (theFace, aUmin, aUmax, aVmin, aVmax);
1235 const Standard_Boolean isUseMidU = (theNbAlongU == 1);
1236 const Standard_Boolean isUseMidV = (theNbAlongV == 1);
1237 const Standard_Real aDU = (aUmax - aUmin) / (isUseMidU ? 2 : (theNbAlongU - 1));
1238 const Standard_Real aDV = (aVmax - aVmin) / (isUseMidV ? 2 : (theNbAlongV - 1));
1240 BRepAdaptor_Surface aSurface (theFace);
1241 for (Standard_Integer aUIter = 0; aUIter < theNbAlongU; ++aUIter)
1243 const Standard_Real aU = aUmin + (isUseMidU ? 1 : aUIter) * aDU;
1244 for (Standard_Integer aVIter = 0; aVIter < theNbAlongV; ++aVIter)
1246 const Standard_Real aV = aVmin + (isUseMidV ? 1 : aVIter) * aDV;
1250 aSurface.D1 (aU, aV, aP1, aV1, aV2);
1252 gp_Vec aVec = aV1.Crossed (aV2);
1253 Standard_Real aNormalLen = aVec.Magnitude();
1254 if (aNormalLen > 1.e-10)
1256 aVec.Multiply (theLength / aNormalLen);
1260 aVec.SetCoord (aNormalLen / 2.0, 0.0, 0.0);
1261 std::cout << "Null normal at U = " << aU << ", V = " << aV << "\n";
1264 const gp_Pnt aP2 = aP1.Translated(aVec);
1265 theNormals.Append (std::pair<gp_Pnt, gp_Pnt> (aP1, aP2));
1268 return Standard_True;
1271 //=======================================================================
1272 //function : addSurfaceNormals
1274 //=======================================================================
1275 void DBRep_DrawableShape::addSurfaceNormals (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >& theNormals,
1276 const TopoDS_Shape& theShape,
1277 const Standard_Real theLength,
1278 const Standard_Integer theNbAlongU,
1279 const Standard_Integer theNbAlongV)
1281 for (TopExp_Explorer aFaceIt (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
1283 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
1284 NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >* aFaceNormals = theNormals.ChangeSeek (aFace);
1285 if (aFaceNormals == NULL)
1287 aFaceNormals = theNormals.Bound (aFace, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >());
1289 addSurfaceNormals (*aFaceNormals, aFace, theLength, theNbAlongU, theNbAlongV);