1 // Created on: 1993-07-07
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-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 <BRep_Curve3D.hxx>
19 #include <BRep_CurveOnClosedSurface.hxx>
20 #include <BRep_CurveOnSurface.hxx>
21 #include <BRep_CurveRepresentation.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
24 #include <BRep_PointRepresentation.hxx>
25 #include <BRep_Polygon3D.hxx>
26 #include <BRep_PolygonOnClosedSurface.hxx>
27 #include <BRep_PolygonOnClosedTriangulation.hxx>
28 #include <BRep_PolygonOnSurface.hxx>
29 #include <BRep_PolygonOnTriangulation.hxx>
30 #include <BRep_TEdge.hxx>
31 #include <BRep_TFace.hxx>
32 #include <BRep_Tool.hxx>
33 #include <BRep_TVertex.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <Geom2d_TrimmedCurve.hxx>
37 #include <Geom2dAdaptor.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_OffsetSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_RectangularTrimmedSurface.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom_TrimmedCurve.hxx>
44 #include <GeomAdaptor_HCurve.hxx>
45 #include <GeomAdaptor_HSurface.hxx>
46 #include <GeomProjLib.hxx>
48 #include <gp_Pnt2d.hxx>
49 #include <NCollection_IncAllocator.hxx>
50 #include <NCollection_Map.hxx>
51 #include <Poly_Polygon2D.hxx>
52 #include <Poly_Polygon3D.hxx>
53 #include <Poly_PolygonOnTriangulation.hxx>
54 #include <Poly_Triangulation.hxx>
55 #include <Precision.hxx>
56 #include <ProjLib_ProjectedCurve.hxx>
57 #include <Standard_NoSuchObject.hxx>
58 #include <Standard_NullObject.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopLoc_Location.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Iterator.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Vertex.hxx>
68 #include <TopoDS_Wire.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <TopTools_ShapeMapHasher.hxx>
71 #include <BRep_GCurve.hxx>
73 //modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f
75 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS);
76 //modified by NIZNHY-PKV Fri Oct 17 14:13:33 2008t
78 //=======================================================================
80 //purpose : Returns the geometric surface of the face. Returns
81 // in <L> the location for the surface.
82 //=======================================================================
84 const Handle(Geom_Surface)& BRep_Tool::Surface(const TopoDS_Face& F,
87 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
88 L = F.Location() * TF->Location();
92 //=======================================================================
94 //purpose : Returns the geometric surface of the face. It can
95 // be a copy if there is a Location.
96 //=======================================================================
98 Handle(Geom_Surface) BRep_Tool::Surface(const TopoDS_Face& F)
100 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
101 const Handle(Geom_Surface)& S = TF->Surface();
103 if(S.IsNull()) return S;
105 TopLoc_Location L = F.Location() * TF->Location();
106 if (!L.IsIdentity()) {
107 Handle(Geom_Geometry) aCopy = S->Transformed(L.Transformation());
108 Geom_Surface* aGS = static_cast<Geom_Surface*>(aCopy.get());
109 return Handle(Geom_Surface)(aGS);
114 //=======================================================================
115 //function : Triangulation
116 //purpose : Returns the Triangulation of the face. It is a
117 // null handle if there is no triangulation.
118 //=======================================================================
120 const Handle(Poly_Triangulation)& BRep_Tool::Triangulation(const TopoDS_Face& F,
124 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
125 return TF->Triangulation();
128 //=======================================================================
129 //function : Tolerance
130 //purpose : Returns the tolerance of the face.
131 //=======================================================================
133 Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F)
135 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
136 Standard_Real p = TF->Tolerance();
137 Standard_Real pMin = Precision::Confusion();
138 if (p > pMin) return p;
142 //=======================================================================
143 //function : NaturalRestriction
144 //purpose : Returns the NaturalRestriction flag of the face.
145 //=======================================================================
147 Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F)
149 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
150 return TF->NaturalRestriction();
153 //=======================================================================
155 //purpose : Returns the 3D curve of the edge. May be a Null
156 // handle. Returns in <L> the location for the curve.
157 // In <First> and <Last> the parameter range.
158 //=======================================================================
160 static const Handle(Geom_Curve) nullCurve;
162 const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E,
164 Standard_Real& First,
167 // find the representation
168 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
169 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
171 while (itcr.More()) {
172 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
173 if (cr->IsCurve3D()) {
174 const BRep_Curve3D* GC = static_cast<const BRep_Curve3D*>(cr.get());
175 L = E.Location() * GC->Location();
176 GC->Range(First,Last);
177 return GC->Curve3D();
185 //=======================================================================
187 //purpose : Returns the 3D curve of the edge. May be a Null handle.
188 // In <First> and <Last> the parameter range.
189 // It can be a copy if there is a Location.
190 //=======================================================================
192 Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
193 Standard_Real& First,
197 const Handle(Geom_Curve)& C = Curve(E,L,First,Last);
199 if ( !L.IsIdentity() ) {
200 Handle(Geom_Geometry) aCopy = C->Transformed(L.Transformation());
201 Geom_Curve* aGC = static_cast<Geom_Curve*>(aCopy.get());
202 return Handle(Geom_Curve)(aGC);
208 //=======================================================================
209 //function : IsGeometric
210 //purpose : Returns True if <E> is a 3d curve or a curve on
212 //=======================================================================
214 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
216 // find the representation
217 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
218 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
220 while (itcr.More()) {
221 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
222 if (cr->IsCurve3D()) {
223 Standard_Real first, last;
225 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E, L, first, last);
226 if (!C.IsNull()) return Standard_True;
228 else if (cr->IsCurveOnSurface()) return Standard_True;
231 return Standard_False;
234 //=======================================================================
235 //function : Polygon3D
236 //purpose : Returns the 3D polygon of the edge. May be a Null
237 // handle. Returns in <L> the location for the polygon.
238 //=======================================================================
240 static const Handle(Poly_Polygon3D) nullPolygon3D;
242 const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
245 // find the representation
246 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
247 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
249 while (itcr.More()) {
250 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
251 if (cr->IsPolygon3D()) {
252 const BRep_Polygon3D* GC = static_cast<const BRep_Polygon3D*>(cr.get());
253 L = E.Location() * GC->Location();
254 return GC->Polygon3D();
259 return nullPolygon3D;
262 //=======================================================================
263 //function : CurveOnSurface
264 //purpose : Returns the curve associated to the edge in the
265 // parametric space of the face. Returns a NULL
266 // handle if this curve does not exist. Returns in
267 // <First> and <Last> the parameter range.
268 //=======================================================================
270 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
271 const TopoDS_Face& F,
272 Standard_Real& First,
276 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
277 TopoDS_Edge aLocalEdge = E;
278 if (F.Orientation() == TopAbs_REVERSED) {
279 aLocalEdge.Reverse();
280 // return CurveOnSurface(E,S,l,First,Last);
282 // return CurveOnSurface(TopoDS::Edge(E.Reversed()),S,l,First,Last);
284 // return CurveOnSurface(E,S,l,First,Last);
285 return CurveOnSurface(aLocalEdge,S,l,First,Last);
288 //=======================================================================
289 //function : CurveOnSurface
290 //purpose : Returns the curve associated to the edge in the
291 // parametric space of the surface. Returns a NULL
292 // handle if this curve does not exist. Returns in
293 // <First> and <Last> the parameter range.
294 //=======================================================================
296 static const Handle(Geom2d_Curve) nullPCurve;
298 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
299 const Handle(Geom_Surface)& S,
300 const TopLoc_Location& L,
301 Standard_Real& First,
304 TopLoc_Location loc = L.Predivided(E.Location());
305 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
307 // find the representation
308 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
309 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
311 while (itcr.More()) {
312 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
313 if (cr->IsCurveOnSurface(S,loc)) {
314 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
315 GC->Range(First,Last);
316 if (GC->IsCurveOnClosedSurface() && Eisreversed)
317 return GC->PCurve2();
324 // for planar surface and 3d curve try a projection
325 // modif 21-05-97 : for RectangularTrimmedSurface, try a projection
326 Handle(Geom_Plane) GP;
327 Handle(Geom_RectangularTrimmedSurface) GRTS;
328 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
330 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
332 GP = Handle(Geom_Plane)::DownCast(S);
333 //fin modif du 21-05-97
337 Handle(GeomAdaptor_HCurve) HC;
338 Handle(GeomAdaptor_HSurface) HS;
340 HC = new GeomAdaptor_HCurve();
341 HS = new GeomAdaptor_HSurface();
343 TopLoc_Location aCurveLocation;
345 Standard_Real f, l;// for those who call with (u,u).
346 Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, aCurveLocation, f, l);
353 aCurveLocation = aCurveLocation.Predivided(L);
354 First = f; Last = l; //Range of edge must not be modified
356 if (!aCurveLocation.IsIdentity())
358 const gp_Trsf& T = aCurveLocation.Transformation();
359 Handle(Geom_Geometry) GC3d = C3d->Transformed(T);
360 C3d = Handle(Geom_Curve)::DownCast (GC3d);
361 f = C3d->TransformedParameter(f, T);
362 l = C3d->TransformedParameter(l, T);
364 GeomAdaptor_Surface& GAS = HS->ChangeSurface();
367 Handle(Geom_Curve) ProjOnPlane =
368 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l,Standard_True,Standard_False),
370 GP->Position().Direction(),
373 GeomAdaptor_Curve& GAC = HC->ChangeCurve();
374 GAC.Load(ProjOnPlane);
376 ProjLib_ProjectedCurve Proj(HS,HC);
377 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
379 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
380 Handle(Geom2d_TrimmedCurve) TC =
381 Handle(Geom2d_TrimmedCurve)::DownCast (pc);
382 pc = TC->BasisCurve();
391 //=======================================================================
392 //function : CurveOnSurface
394 //=======================================================================
396 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
397 Handle(Geom2d_Curve)& C,
398 Handle(Geom_Surface)& S,
400 Standard_Real& First,
403 // find the representation
404 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
405 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
407 while (itcr.More()) {
408 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
409 if (cr->IsCurveOnSurface()) {
410 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
413 L = E.Location() * GC->Location();
414 GC->Range(First,Last);
420 C = Handle(Geom2d_Curve)();
421 S = Handle(Geom_Surface)();
422 L = TopLoc_Location();
425 //=======================================================================
426 //function : CurveOnSurface
428 //=======================================================================
430 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
431 Handle(Geom2d_Curve)& C,
432 Handle(Geom_Surface)& S,
434 Standard_Real& First,
436 const Standard_Integer Index)
438 Standard_Integer i = 0;
439 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
441 // find the representation
442 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
443 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
445 while (itcr.More()) {
446 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
447 if (cr->IsCurveOnSurface()) {
448 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
450 if (i > Index) break;
452 // JMB le 21 Mai 1999
453 // it is done as in the other CurveOnSurface methods, ie. take into account
454 // the orientation in case of cut edges (return PCurve2)
455 // otherwise there is a risk to loop curves or to not get the prover one.
456 if (GC->IsCurveOnClosedSurface() && Eisreversed)
461 L = E.Location() * GC->Location();
462 GC->Range(First,Last);
469 C = Handle(Geom2d_Curve)();
470 S = Handle(Geom_Surface)();
471 L = TopLoc_Location();
474 //=======================================================================
475 //function : PolygonOnSurface
476 //purpose : Returns the polygon associated to the edge in the
477 // parametric space of the face. Returns a NULL
478 // handle if this polygon does not exist.
479 //=======================================================================
481 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
482 const TopoDS_Face& F)
485 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
486 TopoDS_Edge aLocalEdge = E;
487 if (F.Orientation() == TopAbs_REVERSED) {
488 aLocalEdge.Reverse();
489 // return PolygonOnSurface(E,S,l);
491 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
493 // return PolygonOnSurface(E,S,l);
494 return PolygonOnSurface(aLocalEdge,S,l);
497 //=======================================================================
498 //function : PolygonOnSurface
499 //purpose : Returns the polygon associated to the edge in the
500 // parametric space of the surface. Returns a NULL
501 // handle if this polygon does not exist.
502 //=======================================================================
504 static const Handle(Poly_Polygon2D) nullPolygon2D;
506 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
507 const Handle(Geom_Surface)& S,
508 const TopLoc_Location& L)
510 TopLoc_Location l = L.Predivided(E.Location());
511 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
513 // find the representation
514 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
515 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
517 while (itcr.More()) {
518 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
519 if (cr->IsPolygonOnSurface(S,l)) {
520 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
521 return cr->Polygon2();
523 return cr->Polygon();
528 return nullPolygon2D;
531 //=======================================================================
532 //function : PolygonOnSurface
534 //=======================================================================
536 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
537 Handle(Poly_Polygon2D)& P,
538 Handle(Geom_Surface)& S,
541 // find the representation
542 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
543 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
545 while (itcr.More()) {
546 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
547 if (cr->IsPolygonOnSurface()) {
548 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
551 L = E.Location() * PS->Location();
557 L = TopLoc_Location();
558 P = Handle(Poly_Polygon2D)();
559 S = Handle(Geom_Surface)();
562 //=======================================================================
563 //function : PolygonOnSurface
565 //=======================================================================
567 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
568 Handle(Poly_Polygon2D)& P,
569 Handle(Geom_Surface)& S,
571 const Standard_Integer Index)
573 Standard_Integer i = 0;
575 // find the representation
576 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
577 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
579 while (itcr.More()) {
580 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
581 if (cr->IsPolygonOnSurface()) {
582 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
584 if (i > Index) break;
588 L = E.Location() * PS->Location();
595 L = TopLoc_Location();
596 P = Handle(Poly_Polygon2D)();
597 S = Handle(Geom_Surface)();
600 //=======================================================================
601 //function : PolygonOnTriangulation
602 //purpose : Returns the polygon associated to the edge in the
603 // parametric space of the face. Returns a NULL
604 // handle if this polygon does not exist.
605 //=======================================================================
607 static const Handle(Poly_PolygonOnTriangulation) nullArray;
609 const Handle(Poly_PolygonOnTriangulation)&
610 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
611 const Handle(Poly_Triangulation)& T,
612 const TopLoc_Location& L)
614 TopLoc_Location l = L.Predivided(E.Location());
615 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
617 // find the representation
618 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
619 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
621 while (itcr.More()) {
622 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
623 if ( cr->IsPolygonOnTriangulation(T,l)) {
624 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
625 return cr->PolygonOnTriangulation2();
627 return cr->PolygonOnTriangulation();
635 //=======================================================================
636 //function : PolygonOnTriangulation
638 //=======================================================================
641 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
642 Handle(Poly_PolygonOnTriangulation)& P,
643 Handle(Poly_Triangulation)& T,
646 // find the representation
647 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
648 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
650 while (itcr.More()) {
651 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
652 if (cr->IsPolygonOnTriangulation()) {
653 const BRep_PolygonOnTriangulation* PT =
654 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
655 P = PT->PolygonOnTriangulation();
656 T = PT->Triangulation();
657 L = E.Location() * PT->Location();
663 L = TopLoc_Location();
664 P = Handle(Poly_PolygonOnTriangulation)();
665 T = Handle(Poly_Triangulation)();
668 //=======================================================================
669 //function : PolygonOnTriangulation
671 //=======================================================================
674 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
675 Handle(Poly_PolygonOnTriangulation)& P,
676 Handle(Poly_Triangulation)& T,
678 const Standard_Integer Index)
680 Standard_Integer i = 0;
682 // find the representation
683 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
684 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
686 while (itcr.More()) {
687 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
688 if (cr->IsPolygonOnTriangulation()) {
689 const BRep_PolygonOnTriangulation* PT =
690 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
692 if (i > Index) break;
694 T = PT->Triangulation();
695 P = PT->PolygonOnTriangulation();
696 L = E.Location() * PT->Location();
703 L = TopLoc_Location();
704 P = Handle(Poly_PolygonOnTriangulation)();
705 T = Handle(Poly_Triangulation)();
708 //=======================================================================
709 //function : IsClosed
710 //purpose : Returns True if <E> has two PCurves in the
711 // parametric space of <F>. i.e. <F> is on a closed
712 // surface and <E> is on the closing curve.
713 //=======================================================================
715 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
716 const TopoDS_Face& F)
719 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
720 if (IsClosed(E,S,l)) return Standard_True;
721 const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l);
722 return IsClosed(E, T, l);
725 //=======================================================================
726 //function : IsClosed
727 //purpose : Returns True if <E> has two PCurves in the
728 // parametric space of <S>. i.e. <S> is a closed
729 // surface and <E> is on the closing curve.
730 //=======================================================================
732 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
733 const Handle(Geom_Surface)& S,
734 const TopLoc_Location& L)
736 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
738 return Standard_False;
740 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
742 TopLoc_Location l = L.Predivided(E.Location());
744 // find the representation
745 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
746 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
748 while (itcr.More()) {
749 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
750 if (cr->IsCurveOnSurface(S,l) &&
751 cr->IsCurveOnClosedSurface())
752 return Standard_True;
755 return Standard_False;
758 //=======================================================================
759 //function : IsClosed
760 //purpose : Returns True if <E> has two arrays of indices in
761 // the triangulation <T>.
762 //=======================================================================
764 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
765 const Handle(Poly_Triangulation)& T,
766 const TopLoc_Location& L)
768 TopLoc_Location l = L.Predivided(E.Location());
770 // find the representation
771 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
772 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
774 while (itcr.More()) {
775 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
776 if (cr->IsPolygonOnTriangulation(T,l) &&
777 cr->IsPolygonOnClosedTriangulation())
778 return Standard_True;
781 return Standard_False;
784 //=======================================================================
785 //function : Tolerance
786 //purpose : Returns the tolerance for <E>.
787 //=======================================================================
789 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
791 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
792 Standard_Real p = TE->Tolerance();
793 Standard_Real pMin = Precision::Confusion();
794 if (p > pMin) return p;
798 //=======================================================================
799 //function : SameParameter
800 //purpose : Returns the SameParameter flag for the edge.
801 //=======================================================================
803 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
805 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
806 return TE->SameParameter();
809 //=======================================================================
810 //function : SameRange
811 //purpose : Returns the SameRange flag for the edge.
812 //=======================================================================
814 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
816 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
817 return TE->SameRange();
820 //=======================================================================
821 //function : Degenerated
822 //purpose : Returns True if the edge is degenerated.
823 //=======================================================================
825 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
827 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
828 return TE->Degenerated();
831 //=======================================================================
834 //=======================================================================
836 void BRep_Tool::Range(const TopoDS_Edge& E,
837 Standard_Real& First,
840 // set the range to all the representations
841 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
842 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
844 while (itcr.More()) {
845 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
846 if (cr->IsCurve3D()) {
847 const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get());
848 if (!CR->Curve3D().IsNull()) {
854 else if (cr->IsCurveOnSurface()) {
855 const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get());
864 //=======================================================================
867 //=======================================================================
869 void BRep_Tool::Range(const TopoDS_Edge& E,
870 const Handle(Geom_Surface)& S,
871 const TopLoc_Location& L,
872 Standard_Real& First,
875 TopLoc_Location l = L.Predivided(E.Location());
877 // find the representation
878 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
879 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
881 while (itcr.More()) {
882 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
883 if (cr->IsCurveOnSurface(S,l)) {
884 const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get());
885 CR->Range(First,Last);
893 E.TShape()->Modified(Standard_True);
896 //=======================================================================
899 //=======================================================================
901 void BRep_Tool::Range(const TopoDS_Edge& E,
902 const TopoDS_Face& F,
903 Standard_Real& First,
907 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
908 Range(E,S,L,First,Last);
911 //=======================================================================
912 //function : UVPoints
914 //=======================================================================
916 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
917 const Handle(Geom_Surface)& S,
918 const TopLoc_Location& L,
922 TopLoc_Location l = L.Predivided(E.Location());
923 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
925 // find the representation
926 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
927 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
929 while (itcr.More()) {
930 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
931 if (cr->IsCurveOnSurface(S,l)) {
932 if (cr->IsCurveOnClosedSurface() && Eisreversed)
934 const BRep_CurveOnClosedSurface* CR =
935 static_cast<const BRep_CurveOnClosedSurface*>(cr.get());
936 CR->UVPoints2(PFirst, PLast);
940 const BRep_CurveOnSurface* CR =
941 static_cast<const BRep_CurveOnSurface*>(cr.get());
942 CR->UVPoints(PFirst, PLast);
949 // for planar surface project the vertices
950 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
951 Handle(Geom_Plane) GP;
952 Handle(Geom_RectangularTrimmedSurface) GRTS;
953 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
955 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
957 GP = Handle(Geom_Plane)::DownCast(S);
958 //fin modif du 21-05-97
960 // get the two vertices
962 TopExp::Vertices(E,Vf,Vl);
964 TopLoc_Location Linverted = L.Inverted();
968 gp_Pln pln = GP->Pln();
972 gp_Pnt PF = BRep_Tool::Pnt(Vf);
973 ElSLib::Parameters(pln,PF,u,v);
975 PFirst.SetCoord(u,v);
979 gp_Pnt PL = BRep_Tool::Pnt(Vl);
980 ElSLib::Parameters(pln,PL,u,v);
986 //=======================================================================
987 //function : UVPoints
989 //=======================================================================
991 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
992 const TopoDS_Face& F,
997 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
998 TopoDS_Edge aLocalEdge = E;
999 if (F.Orientation() == TopAbs_REVERSED) {
1000 aLocalEdge.Reverse();
1001 // UVPoints(E,S,L,PFirst,PLast);
1003 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1005 // UVPoints(E,S,L,PFirst,PLast);
1006 UVPoints(aLocalEdge,S,L,PFirst,PLast);
1009 //=======================================================================
1010 //function : SetUVPoints
1012 //=======================================================================
1014 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1015 const Handle(Geom_Surface)& S,
1016 const TopLoc_Location& L,
1017 const gp_Pnt2d& PFirst,
1018 const gp_Pnt2d& PLast)
1020 TopLoc_Location l = L.Predivided(E.Location());
1021 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
1023 // find the representation
1024 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1025 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1027 while (itcr.More()) {
1028 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1029 if (cr->IsCurveOnSurface(S,l)) {
1030 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1032 BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get());
1033 CS->SetUVPoints2(PFirst, PLast);
1037 BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get());
1038 CS->SetUVPoints(PFirst, PLast);
1045 //=======================================================================
1046 //function : SetUVPoints
1048 //=======================================================================
1050 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1051 const TopoDS_Face& F,
1052 const gp_Pnt2d& PFirst,
1053 const gp_Pnt2d& PLast)
1056 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1057 TopoDS_Edge aLocalEdge = E;
1058 if (F.Orientation() == TopAbs_REVERSED) {
1059 aLocalEdge.Reverse();
1060 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1063 // SetUVPoints(E,S,L,PFirst,PLast);
1064 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1067 //=======================================================================
1068 //function : HasContinuity
1069 //purpose : Returns True if the edge is on the surfaces of the
1071 //=======================================================================
1073 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1074 const TopoDS_Face& F1,
1075 const TopoDS_Face& F2)
1077 TopLoc_Location l1,l2;
1078 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1079 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1080 return HasContinuity(E,S1,S2,l1,l2);
1083 //=======================================================================
1084 //function : Continuity
1085 //purpose : Returns the continuity.
1086 //=======================================================================
1088 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1089 const TopoDS_Face& F1,
1090 const TopoDS_Face& F2)
1092 TopLoc_Location l1,l2;
1093 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1094 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1095 return Continuity(E,S1,S2,l1,l2);
1098 //=======================================================================
1099 //function : HasContinuity
1100 //purpose : Returns True if the edge is on the surfaces.
1101 //=======================================================================
1103 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1104 const Handle(Geom_Surface)& S1,
1105 const Handle(Geom_Surface)& S2,
1106 const TopLoc_Location& L1,
1107 const TopLoc_Location& L2)
1109 const TopLoc_Location& Eloc = E.Location();
1110 TopLoc_Location l1 = L1.Predivided(Eloc);
1111 TopLoc_Location l2 = L2.Predivided(Eloc);
1113 // find the representation
1114 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1115 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1117 while (itcr.More()) {
1118 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1119 if (cr->IsRegularity(S1,S2,l1,l2))
1120 return Standard_True;
1123 return Standard_False;
1126 //=======================================================================
1127 //function : Continuity
1128 //purpose : Returns the continuity.
1129 //=======================================================================
1131 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1132 const Handle(Geom_Surface)& S1,
1133 const Handle(Geom_Surface)& S2,
1134 const TopLoc_Location& L1,
1135 const TopLoc_Location& L2)
1137 TopLoc_Location l1 = L1.Predivided(E.Location());
1138 TopLoc_Location l2 = L2.Predivided(E.Location());
1140 // find the representation
1141 BRep_ListIteratorOfListOfCurveRepresentation itcr
1142 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1144 while (itcr.More()) {
1145 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1146 if (cr->IsRegularity(S1,S2,l1,l2))
1147 return cr->Continuity();
1153 //=======================================================================
1154 //function : HasContinuity
1155 //purpose : Returns True if the edge is on some two surfaces.
1156 //=======================================================================
1158 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1160 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1161 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1163 for (; itcr.More(); itcr.Next())
1165 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1166 if (CR->IsRegularity())
1167 return Standard_True;
1169 return Standard_False;
1172 //=======================================================================
1174 //purpose : Returns the 3d point.
1175 //=======================================================================
1177 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1179 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1183 Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1186 const gp_Pnt& P = TV->Pnt();
1187 if (V.Location().IsIdentity())
1192 return P.Transformed(V.Location().Transformation());
1195 //=======================================================================
1196 //function : Tolerance
1197 //purpose : Returns the tolerance.
1198 //=======================================================================
1200 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1202 const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get());
1206 Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1209 Standard_Real p = aTVert->Tolerance();
1210 Standard_Real pMin = Precision::Confusion();
1211 if (p > pMin) return p;
1215 //=======================================================================
1216 //function : Parameter
1217 //purpose : Returns the parameter of <V> on <E>.
1218 //=======================================================================
1220 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1221 const TopoDS_Edge& E)
1224 // Search the vertex in the edge
1226 Standard_Boolean rev = Standard_False;
1228 TopAbs_Orientation orient = TopAbs_INTERNAL;
1230 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1232 // if the edge has no vertices
1233 // and is degenerated use the vertex orientation
1236 if (!itv.More() && Degenerated(E)) {
1237 orient = V.Orientation();
1240 while (itv.More()) {
1241 const TopoDS_Shape& Vcur = itv.Value();
1242 if (V.IsSame(Vcur)) {
1247 rev = E.Orientation() == TopAbs_REVERSED;
1248 if (Vcur.Orientation() == V.Orientation()) {
1256 if (!VF.IsNull()) orient = VF.Orientation();
1260 if (orient == TopAbs_FORWARD) {
1261 BRep_Tool::Range(E,f,l);
1262 return (rev) ? l : f;
1265 else if (orient == TopAbs_REVERSED) {
1266 BRep_Tool::Range(E,f,l);
1267 return (rev) ? f : l;
1272 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
1273 L = L.Predivided(V.Location());
1274 if (!C.IsNull() || Degenerated(E)) {
1275 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1276 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1278 while (itpr.More()) {
1279 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1280 if (pr->IsPointOnCurve(C,L)) {
1281 Standard_Real p = pr->Parameter();
1282 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1284 // Closed curves RLE 16 june 94
1285 if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p;
1286 if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p;
1287 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1288 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1289 Standard_Real tol = BRep_Tool::Tolerance(V);
1290 if (Pf.Distance(Pl) < tol) {
1291 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1292 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1293 else res = l;//p = l;
1304 // let us try with the first pcurve
1305 Handle(Geom2d_Curve) PC;
1306 Handle(Geom_Surface) S;
1307 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
1308 L = L.Predivided(V.Location());
1309 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1310 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1312 while (itpr.More()) {
1313 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1314 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
1315 Standard_Real p = pr->Parameter();
1316 // Closed curves RLE 16 june 94
1317 if (PC->IsClosed()) {
1318 if ((p == PC->FirstParameter()) ||
1319 (p == PC->LastParameter())) {
1320 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1321 else p = PC->LastParameter();
1331 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1335 //=======================================================================
1336 //function : Parameter
1337 //purpose : Returns the parameters of the vertex on the
1338 // pcurve of the edge on the face.
1339 //=======================================================================
1341 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1342 const TopoDS_Edge& E,
1343 const TopoDS_Face& F)
1346 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1347 return BRep_Tool::Parameter(V,E,S,L);
1350 //=======================================================================
1351 //function : Parameter
1352 //purpose : Returns the parameters of the vertex on the
1353 // pcurve of the edge on the surface.
1354 //=======================================================================
1356 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1357 const TopoDS_Edge& E,
1358 const Handle(Geom_Surface)& S,
1359 const TopLoc_Location& L)
1361 // Search the vertex in the edge
1363 Standard_Boolean rev = Standard_False;
1365 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1367 while (itv.More()) {
1368 if (V.IsSame(itv.Value())) {
1369 if (VF.IsNull()) VF = itv.Value();
1371 rev = E.Orientation() == TopAbs_REVERSED;
1372 if (itv.Value().Orientation() == V.Orientation())
1379 TopAbs_Orientation orient = TopAbs_INTERNAL;
1380 if (!VF.IsNull()) orient = VF.Orientation();
1384 if (orient == TopAbs_FORWARD) {
1385 BRep_Tool::Range(E,S,L,f,l);
1386 return (rev) ? l : f;
1389 else if (orient == TopAbs_REVERSED) {
1390 BRep_Tool::Range(E,S,L,f,l);
1391 return (rev) ? f : l;
1395 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1396 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1397 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1399 while (itpr.More()) {
1400 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1401 return itpr.Value()->Parameter();
1406 //----------------------------------------------------------
1409 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1410 L1 = L1.Predivided(V.Location());
1411 if (!C.IsNull() || Degenerated(E)) {
1412 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1413 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1415 while (itpr.More()) {
1416 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1417 if (pr->IsPointOnCurve(C,L1)) {
1418 Standard_Real p = pr->Parameter();
1419 Standard_Real res = p;
1421 // Closed curves RLE 16 june 94
1422 if (Precision::IsNegativeInfinite(f)) return res;
1423 if (Precision::IsPositiveInfinite(l)) return res;
1424 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1425 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1426 Standard_Real tol = BRep_Tool::Tolerance(V);
1427 if (Pf.Distance(Pl) < tol) {
1428 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1429 if (V.Orientation() == TopAbs_FORWARD) res = f;
1440 //----------------------------------------------------------
1442 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1446 //=======================================================================
1447 //function : Parameters
1448 //purpose : Returns the parameters of the vertex on the face.
1449 //=======================================================================
1451 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1452 const TopoDS_Face& F)
1455 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1456 L = L.Predivided(V.Location());
1457 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1458 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1460 // It is checked if there is PointRepresentation (case non Manifold)
1461 while (itpr.More()) {
1462 if (itpr.Value()->IsPointOnSurface(S,L)) {
1463 return gp_Pnt2d(itpr.Value()->Parameter(),
1464 itpr.Value()->Parameter2());
1469 TopoDS_Vertex Vf,Vl;
1471 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1472 // even if often there is a way to make more economically than above...
1473 TopExp_Explorer exp;
1474 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1475 E = TopoDS::Edge(exp.Current());
1476 TopExp::Vertices(E, Vf, Vl);
1477 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1479 UVPoints(E, F, Pf, Pl);
1480 if (V.IsSame(Vf)) return Pf;
1481 else return Pl;//Ambiguity (natural) for degenerated edges.
1484 Standard_NoSuchObject::Raise("BRep_Tool:: no parameters on surface");
1485 return gp_Pnt2d(0,0);
1487 //=======================================================================
1488 //function : IsClosed
1490 //=======================================================================
1491 Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape)
1493 if (theShape.ShapeType() == TopAbs_SHELL)
1495 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1496 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1497 Standard_Boolean hasBound = Standard_False;
1498 for (; exp.More(); exp.Next())
1500 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1501 if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL)
1503 hasBound = Standard_True;
1507 return hasBound && aMap.IsEmpty();
1509 else if (theShape.ShapeType() == TopAbs_WIRE)
1511 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1512 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX);
1513 Standard_Boolean hasBound = Standard_False;
1514 for (; exp.More(); exp.Next())
1516 const TopoDS_Shape& V = exp.Current();
1517 if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL)
1519 hasBound = Standard_True;
1523 return hasBound && aMap.IsEmpty();
1525 else if (theShape.ShapeType() == TopAbs_EDGE)
1527 TopoDS_Vertex aVFirst, aVLast;
1528 TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast);
1529 return !aVFirst.IsNull() && aVFirst.IsSame(aVLast);
1531 return theShape.Closed();
1534 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1535 //=======================================================================
1536 //function : IsPlane
1538 //=======================================================================
1539 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1541 Standard_Boolean bRet;
1542 Handle(Geom_Plane) aGP;
1543 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1544 Handle(Geom_OffsetSurface) aGOFS;
1546 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1547 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1549 if(!aGOFS.IsNull()) {
1550 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1552 else if(!aGRTS.IsNull()) {
1553 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1556 aGP=Handle(Geom_Plane)::DownCast(aS);
1564 //=======================================================================
1565 //function : MaxTolerance
1567 //=======================================================================
1568 Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape,
1569 const TopAbs_ShapeEnum theSubShape)
1571 Standard_Real aTol = 0.0;
1573 // Explorer Shape-Subshape.
1574 TopExp_Explorer anExpSS(theShape, theSubShape);
1575 if (theSubShape == TopAbs_FACE)
1577 for( ; anExpSS.More() ; anExpSS.Next() )
1579 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1580 aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape)));
1583 else if (theSubShape == TopAbs_EDGE)
1585 for( ; anExpSS.More() ; anExpSS.Next() )
1587 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1588 aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape)));
1591 else if (theSubShape == TopAbs_VERTEX)
1593 for( ; anExpSS.More() ; anExpSS.Next() )
1595 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1596 aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape)));