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();
186 //=======================================================================
188 //purpose : Returns the 3D curve of the edge. May be a Null handle.
189 // In <First> and <Last> the parameter range.
190 // It can be a copy if there is a Location.
191 //=======================================================================
193 Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
194 Standard_Real& First,
198 const Handle(Geom_Curve)& C = Curve(E,L,First,Last);
200 if ( !L.IsIdentity() ) {
201 Handle(Geom_Geometry) aCopy = C->Transformed(L.Transformation());
202 Geom_Curve* aGC = static_cast<Geom_Curve*>(aCopy.get());
203 return Handle(Geom_Curve)(aGC);
209 //=======================================================================
210 //function : IsGeometric
211 //purpose : Returns True if <E> is a 3d curve or a curve on
213 //=======================================================================
215 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
217 // find the representation
218 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
219 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
221 while (itcr.More()) {
222 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
223 if (cr->IsCurve3D()) {
224 Handle(BRep_Curve3D) GC (Handle(BRep_Curve3D)::DownCast (cr));
225 if (! GC.IsNull() && ! GC->Curve3D().IsNull())
226 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 // Curve is not found. Try projection on plane
325 return CurveOnPlane(E, S, L, First, Last);
328 //=======================================================================
329 //function : CurveOnPlane
330 //purpose : For planar surface returns projection of the edge on the plane
331 //=======================================================================
332 Handle(Geom2d_Curve) BRep_Tool::CurveOnPlane(const TopoDS_Edge& E,
333 const Handle(Geom_Surface)& S,
334 const TopLoc_Location& L,
335 Standard_Real& First,
340 // Check if the surface is planar
341 Handle(Geom_Plane) GP;
342 Handle(Geom_RectangularTrimmedSurface) GRTS;
343 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
345 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
347 GP = Handle(Geom_Plane)::DownCast(S);
353 // Check existence of 3d curve in edge
355 TopLoc_Location aCurveLocation;
356 Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, aCurveLocation, f, l);
362 aCurveLocation = aCurveLocation.Predivided(L);
365 // Transform curve and update parameters in account of scale factor
366 if (!aCurveLocation.IsIdentity())
368 const gp_Trsf& aTrsf = aCurveLocation.Transformation();
369 C3D = Handle(Geom_Curve)::DownCast(C3D->Transformed(aTrsf));
370 f = C3D->TransformedParameter(f, aTrsf);
371 l = C3D->TransformedParameter(l, aTrsf);
374 // Perform projection
375 Handle(Geom_Curve) ProjOnPlane =
376 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3D, f, l, Standard_True, Standard_False),
378 GP->Position().Direction(),
381 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(GP);
382 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(ProjOnPlane);
384 ProjLib_ProjectedCurve Proj(HS, HC);
385 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
387 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
388 Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(pc);
389 pc = TC->BasisCurve();
395 //=======================================================================
396 //function : CurveOnSurface
398 //=======================================================================
400 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
401 Handle(Geom2d_Curve)& C,
402 Handle(Geom_Surface)& S,
404 Standard_Real& First,
407 // find the representation
408 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
409 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
411 while (itcr.More()) {
412 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
413 if (cr->IsCurveOnSurface()) {
414 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
417 L = E.Location() * GC->Location();
418 GC->Range(First,Last);
430 //=======================================================================
431 //function : CurveOnSurface
433 //=======================================================================
435 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
436 Handle(Geom2d_Curve)& C,
437 Handle(Geom_Surface)& S,
439 Standard_Real& First,
441 const Standard_Integer Index)
446 Standard_Integer i = 0;
447 // find the representation
448 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
449 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
450 for (; itcr.More(); itcr.Next())
452 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
453 if (cr->IsCurveOnSurface())
455 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
457 // Compare index taking into account the fact that for the curves on
458 // closed surfaces there are two PCurves
461 else if (GC->IsCurveOnClosedSurface() && (++i == Index))
467 L = E.Location() * GC->Location();
468 GC->Range(First, Last);
479 //=======================================================================
480 //function : PolygonOnSurface
481 //purpose : Returns the polygon associated to the edge in the
482 // parametric space of the face. Returns a NULL
483 // handle if this polygon does not exist.
484 //=======================================================================
486 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
487 const TopoDS_Face& F)
490 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
491 TopoDS_Edge aLocalEdge = E;
492 if (F.Orientation() == TopAbs_REVERSED) {
493 aLocalEdge.Reverse();
494 // return PolygonOnSurface(E,S,l);
496 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
498 // return PolygonOnSurface(E,S,l);
499 return PolygonOnSurface(aLocalEdge,S,l);
502 //=======================================================================
503 //function : PolygonOnSurface
504 //purpose : Returns the polygon associated to the edge in the
505 // parametric space of the surface. Returns a NULL
506 // handle if this polygon does not exist.
507 //=======================================================================
509 static const Handle(Poly_Polygon2D) nullPolygon2D;
511 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
512 const Handle(Geom_Surface)& S,
513 const TopLoc_Location& L)
515 TopLoc_Location l = L.Predivided(E.Location());
516 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
518 // find the representation
519 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
520 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
522 while (itcr.More()) {
523 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
524 if (cr->IsPolygonOnSurface(S,l)) {
525 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
526 return cr->Polygon2();
528 return cr->Polygon();
533 return nullPolygon2D;
536 //=======================================================================
537 //function : PolygonOnSurface
539 //=======================================================================
541 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
542 Handle(Poly_Polygon2D)& P,
543 Handle(Geom_Surface)& S,
546 // find the representation
547 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
548 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
550 while (itcr.More()) {
551 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
552 if (cr->IsPolygonOnSurface()) {
553 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
556 L = E.Location() * PS->Location();
567 //=======================================================================
568 //function : PolygonOnSurface
570 //=======================================================================
572 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
573 Handle(Poly_Polygon2D)& P,
574 Handle(Geom_Surface)& S,
576 const Standard_Integer Index)
578 Standard_Integer i = 0;
580 // find the representation
581 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
582 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
584 while (itcr.More()) {
585 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
586 if (cr->IsPolygonOnSurface()) {
587 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
589 if (i > Index) break;
593 L = E.Location() * PS->Location();
605 //=======================================================================
606 //function : PolygonOnTriangulation
607 //purpose : Returns the polygon associated to the edge in the
608 // parametric space of the face. Returns a NULL
609 // handle if this polygon does not exist.
610 //=======================================================================
612 static const Handle(Poly_PolygonOnTriangulation) nullArray;
614 const Handle(Poly_PolygonOnTriangulation)&
615 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
616 const Handle(Poly_Triangulation)& T,
617 const TopLoc_Location& L)
619 TopLoc_Location l = L.Predivided(E.Location());
620 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
622 // find the representation
623 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
624 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
626 while (itcr.More()) {
627 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
628 if ( cr->IsPolygonOnTriangulation(T,l)) {
629 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
630 return cr->PolygonOnTriangulation2();
632 return cr->PolygonOnTriangulation();
640 //=======================================================================
641 //function : PolygonOnTriangulation
643 //=======================================================================
646 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
647 Handle(Poly_PolygonOnTriangulation)& P,
648 Handle(Poly_Triangulation)& T,
651 // find the representation
652 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
653 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
655 while (itcr.More()) {
656 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
657 if (cr->IsPolygonOnTriangulation()) {
658 const BRep_PolygonOnTriangulation* PT =
659 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
660 P = PT->PolygonOnTriangulation();
661 T = PT->Triangulation();
662 L = E.Location() * PT->Location();
673 //=======================================================================
674 //function : PolygonOnTriangulation
676 //=======================================================================
679 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
680 Handle(Poly_PolygonOnTriangulation)& P,
681 Handle(Poly_Triangulation)& T,
683 const Standard_Integer Index)
685 Standard_Integer i = 0;
687 // find the representation
688 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
689 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
691 while (itcr.More()) {
692 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
693 if (cr->IsPolygonOnTriangulation()) {
694 const BRep_PolygonOnTriangulation* PT =
695 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
697 if (i > Index) break;
699 T = PT->Triangulation();
700 P = PT->PolygonOnTriangulation();
701 L = E.Location() * PT->Location();
713 //=======================================================================
714 //function : IsClosed
715 //purpose : Returns True if <E> has two PCurves in the
716 // parametric space of <F>. i.e. <F> is on a closed
717 // surface and <E> is on the closing curve.
718 //=======================================================================
720 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
721 const TopoDS_Face& F)
724 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
725 if (IsClosed(E,S,l)) return Standard_True;
726 const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l);
727 return IsClosed(E, T, l);
730 //=======================================================================
731 //function : IsClosed
732 //purpose : Returns True if <E> has two PCurves in the
733 // parametric space of <S>. i.e. <S> is a closed
734 // surface and <E> is on the closing curve.
735 //=======================================================================
737 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
738 const Handle(Geom_Surface)& S,
739 const TopLoc_Location& L)
741 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
743 return Standard_False;
745 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
747 TopLoc_Location l = L.Predivided(E.Location());
749 // find the representation
750 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
751 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
753 while (itcr.More()) {
754 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
755 if (cr->IsCurveOnSurface(S,l) &&
756 cr->IsCurveOnClosedSurface())
757 return Standard_True;
760 return Standard_False;
763 //=======================================================================
764 //function : IsClosed
765 //purpose : Returns True if <E> has two arrays of indices in
766 // the triangulation <T>.
767 //=======================================================================
769 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
770 const Handle(Poly_Triangulation)& T,
771 const TopLoc_Location& L)
773 TopLoc_Location l = L.Predivided(E.Location());
775 // find the representation
776 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
777 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
779 while (itcr.More()) {
780 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
781 if (cr->IsPolygonOnTriangulation(T,l) &&
782 cr->IsPolygonOnClosedTriangulation())
783 return Standard_True;
786 return Standard_False;
789 //=======================================================================
790 //function : Tolerance
791 //purpose : Returns the tolerance for <E>.
792 //=======================================================================
794 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
796 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
797 Standard_Real p = TE->Tolerance();
798 Standard_Real pMin = Precision::Confusion();
799 if (p > pMin) return p;
803 //=======================================================================
804 //function : SameParameter
805 //purpose : Returns the SameParameter flag for the edge.
806 //=======================================================================
808 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
810 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
811 return TE->SameParameter();
814 //=======================================================================
815 //function : SameRange
816 //purpose : Returns the SameRange flag for the edge.
817 //=======================================================================
819 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
821 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
822 return TE->SameRange();
825 //=======================================================================
826 //function : Degenerated
827 //purpose : Returns True if the edge is degenerated.
828 //=======================================================================
830 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
832 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
833 return TE->Degenerated();
836 //=======================================================================
839 //=======================================================================
841 void BRep_Tool::Range(const TopoDS_Edge& E,
842 Standard_Real& First,
845 // set the range to all the representations
846 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
847 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
849 while (itcr.More()) {
850 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
851 if (cr->IsCurve3D()) {
852 const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get());
853 if (!CR->Curve3D().IsNull()) {
859 else if (cr->IsCurveOnSurface()) {
860 const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get());
870 //=======================================================================
873 //=======================================================================
875 void BRep_Tool::Range(const TopoDS_Edge& E,
876 const Handle(Geom_Surface)& S,
877 const TopLoc_Location& L,
878 Standard_Real& First,
881 TopLoc_Location l = L.Predivided(E.Location());
883 // find the representation
884 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
885 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
887 while (itcr.More()) {
888 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
889 if (cr->IsCurveOnSurface(S,l)) {
890 const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get());
891 CR->Range(First,Last);
899 E.TShape()->Modified(Standard_True);
902 //=======================================================================
905 //=======================================================================
907 void BRep_Tool::Range(const TopoDS_Edge& E,
908 const TopoDS_Face& F,
909 Standard_Real& First,
913 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
914 Range(E,S,L,First,Last);
917 //=======================================================================
918 //function : UVPoints
920 //=======================================================================
922 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
923 const Handle(Geom_Surface)& S,
924 const TopLoc_Location& L,
928 TopLoc_Location l = L.Predivided(E.Location());
929 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
931 // find the representation
932 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
933 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
935 while (itcr.More()) {
936 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
937 if (cr->IsCurveOnSurface(S,l)) {
938 if (cr->IsCurveOnClosedSurface() && Eisreversed)
940 const BRep_CurveOnClosedSurface* CR =
941 static_cast<const BRep_CurveOnClosedSurface*>(cr.get());
942 CR->UVPoints2(PFirst, PLast);
946 const BRep_CurveOnSurface* CR =
947 static_cast<const BRep_CurveOnSurface*>(cr.get());
948 CR->UVPoints(PFirst, PLast);
955 // for planar surface project the vertices
956 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
957 Handle(Geom_Plane) GP;
958 Handle(Geom_RectangularTrimmedSurface) GRTS;
959 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
961 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
963 GP = Handle(Geom_Plane)::DownCast(S);
964 //fin modif du 21-05-97
966 // get the two vertices
968 TopExp::Vertices(E,Vf,Vl);
970 TopLoc_Location Linverted = L.Inverted();
974 gp_Pln pln = GP->Pln();
978 gp_Pnt PF = BRep_Tool::Pnt(Vf);
979 ElSLib::Parameters(pln,PF,u,v);
981 PFirst.SetCoord(u,v);
985 gp_Pnt PL = BRep_Tool::Pnt(Vl);
986 ElSLib::Parameters(pln,PL,u,v);
992 PFirst.SetCoord (0., 0.);
993 PLast.SetCoord (0., 0.);
997 //=======================================================================
998 //function : UVPoints
1000 //=======================================================================
1002 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
1003 const TopoDS_Face& F,
1008 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1009 TopoDS_Edge aLocalEdge = E;
1010 if (F.Orientation() == TopAbs_REVERSED) {
1011 aLocalEdge.Reverse();
1012 // UVPoints(E,S,L,PFirst,PLast);
1014 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1016 // UVPoints(E,S,L,PFirst,PLast);
1017 UVPoints(aLocalEdge,S,L,PFirst,PLast);
1020 //=======================================================================
1021 //function : SetUVPoints
1023 //=======================================================================
1025 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1026 const Handle(Geom_Surface)& S,
1027 const TopLoc_Location& L,
1028 const gp_Pnt2d& PFirst,
1029 const gp_Pnt2d& PLast)
1031 TopLoc_Location l = L.Predivided(E.Location());
1032 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
1034 // find the representation
1035 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1036 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1038 while (itcr.More()) {
1039 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1040 if (cr->IsCurveOnSurface(S,l)) {
1041 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1043 BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get());
1044 CS->SetUVPoints2(PFirst, PLast);
1048 BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get());
1049 CS->SetUVPoints(PFirst, PLast);
1056 //=======================================================================
1057 //function : SetUVPoints
1059 //=======================================================================
1061 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1062 const TopoDS_Face& F,
1063 const gp_Pnt2d& PFirst,
1064 const gp_Pnt2d& PLast)
1067 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1068 TopoDS_Edge aLocalEdge = E;
1069 if (F.Orientation() == TopAbs_REVERSED) {
1070 aLocalEdge.Reverse();
1071 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1074 // SetUVPoints(E,S,L,PFirst,PLast);
1075 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1078 //=======================================================================
1079 //function : HasContinuity
1080 //purpose : Returns True if the edge is on the surfaces of the
1082 //=======================================================================
1084 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1085 const TopoDS_Face& F1,
1086 const TopoDS_Face& F2)
1088 TopLoc_Location l1,l2;
1089 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1090 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1091 return HasContinuity(E,S1,S2,l1,l2);
1094 //=======================================================================
1095 //function : Continuity
1096 //purpose : Returns the continuity.
1097 //=======================================================================
1099 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1100 const TopoDS_Face& F1,
1101 const TopoDS_Face& F2)
1103 TopLoc_Location l1,l2;
1104 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1105 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1106 return Continuity(E,S1,S2,l1,l2);
1109 //=======================================================================
1110 //function : HasContinuity
1111 //purpose : Returns True if the edge is on the surfaces.
1112 //=======================================================================
1114 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1115 const Handle(Geom_Surface)& S1,
1116 const Handle(Geom_Surface)& S2,
1117 const TopLoc_Location& L1,
1118 const TopLoc_Location& L2)
1120 const TopLoc_Location& Eloc = E.Location();
1121 TopLoc_Location l1 = L1.Predivided(Eloc);
1122 TopLoc_Location l2 = L2.Predivided(Eloc);
1124 // find the representation
1125 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1126 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1128 while (itcr.More()) {
1129 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1130 if (cr->IsRegularity(S1,S2,l1,l2))
1131 return Standard_True;
1134 return Standard_False;
1137 //=======================================================================
1138 //function : Continuity
1139 //purpose : Returns the continuity.
1140 //=======================================================================
1142 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1143 const Handle(Geom_Surface)& S1,
1144 const Handle(Geom_Surface)& S2,
1145 const TopLoc_Location& L1,
1146 const TopLoc_Location& L2)
1148 TopLoc_Location l1 = L1.Predivided(E.Location());
1149 TopLoc_Location l2 = L2.Predivided(E.Location());
1151 // find the representation
1152 BRep_ListIteratorOfListOfCurveRepresentation itcr
1153 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1155 while (itcr.More()) {
1156 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1157 if (cr->IsRegularity(S1,S2,l1,l2))
1158 return cr->Continuity();
1164 //=======================================================================
1165 //function : HasContinuity
1166 //purpose : Returns True if the edge is on some two surfaces.
1167 //=======================================================================
1169 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1171 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1172 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1174 for (; itcr.More(); itcr.Next())
1176 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1177 if (CR->IsRegularity())
1178 return Standard_True;
1180 return Standard_False;
1183 //=======================================================================
1185 //purpose : Returns the 3d point.
1186 //=======================================================================
1188 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1190 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1194 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1197 const gp_Pnt& P = TV->Pnt();
1198 if (V.Location().IsIdentity())
1203 return P.Transformed(V.Location().Transformation());
1206 //=======================================================================
1207 //function : Tolerance
1208 //purpose : Returns the tolerance.
1209 //=======================================================================
1211 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1213 const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get());
1217 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1220 Standard_Real p = aTVert->Tolerance();
1221 Standard_Real pMin = Precision::Confusion();
1222 if (p > pMin) return p;
1226 //=======================================================================
1227 //function : Parameter
1228 //purpose : Returns the parameter of <V> on <E>.
1229 //=======================================================================
1231 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1232 const TopoDS_Edge& E)
1235 // Search the vertex in the edge
1237 Standard_Boolean rev = Standard_False;
1239 TopAbs_Orientation orient = TopAbs_INTERNAL;
1241 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1243 // if the edge has no vertices
1244 // and is degenerated use the vertex orientation
1247 if (!itv.More() && Degenerated(E)) {
1248 orient = V.Orientation();
1251 while (itv.More()) {
1252 const TopoDS_Shape& Vcur = itv.Value();
1253 if (V.IsSame(Vcur)) {
1258 rev = E.Orientation() == TopAbs_REVERSED;
1259 if (Vcur.Orientation() == V.Orientation()) {
1267 if (!VF.IsNull()) orient = VF.Orientation();
1271 if (orient == TopAbs_FORWARD) {
1272 BRep_Tool::Range(E,f,l);
1273 return (rev) ? l : f;
1276 else if (orient == TopAbs_REVERSED) {
1277 BRep_Tool::Range(E,f,l);
1278 return (rev) ? f : l;
1283 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
1284 L = L.Predivided(V.Location());
1285 if (!C.IsNull() || Degenerated(E)) {
1286 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1287 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1289 while (itpr.More()) {
1290 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1291 if (pr->IsPointOnCurve(C,L)) {
1292 Standard_Real p = pr->Parameter();
1293 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1295 // Closed curves RLE 16 june 94
1296 if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p;
1297 if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p;
1298 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1299 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1300 Standard_Real tol = BRep_Tool::Tolerance(V);
1301 if (Pf.Distance(Pl) < tol) {
1302 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1303 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1304 else res = l;//p = l;
1315 // let us try with the first pcurve
1316 Handle(Geom2d_Curve) PC;
1317 Handle(Geom_Surface) S;
1318 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
1319 L = L.Predivided(V.Location());
1320 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1321 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1323 while (itpr.More()) {
1324 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1325 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
1326 Standard_Real p = pr->Parameter();
1327 // Closed curves RLE 16 june 94
1328 if (PC->IsClosed()) {
1329 if ((p == PC->FirstParameter()) ||
1330 (p == PC->LastParameter())) {
1331 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1332 else p = PC->LastParameter();
1342 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1345 //=======================================================================
1346 //function : Parameter
1347 //purpose : Returns the parameters of the vertex on the
1348 // pcurve of the edge on the face.
1349 //=======================================================================
1351 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1352 const TopoDS_Edge& E,
1353 const TopoDS_Face& F)
1356 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1357 return BRep_Tool::Parameter(V,E,S,L);
1360 //=======================================================================
1361 //function : Parameter
1362 //purpose : Returns the parameters of the vertex on the
1363 // pcurve of the edge on the surface.
1364 //=======================================================================
1366 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1367 const TopoDS_Edge& E,
1368 const Handle(Geom_Surface)& S,
1369 const TopLoc_Location& L)
1371 // Search the vertex in the edge
1373 Standard_Boolean rev = Standard_False;
1375 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1377 while (itv.More()) {
1378 if (V.IsSame(itv.Value())) {
1379 if (VF.IsNull()) VF = itv.Value();
1381 rev = E.Orientation() == TopAbs_REVERSED;
1382 if (itv.Value().Orientation() == V.Orientation())
1389 TopAbs_Orientation orient = TopAbs_INTERNAL;
1390 if (!VF.IsNull()) orient = VF.Orientation();
1394 if (orient == TopAbs_FORWARD) {
1395 BRep_Tool::Range(E,S,L,f,l);
1396 return (rev) ? l : f;
1399 else if (orient == TopAbs_REVERSED) {
1400 BRep_Tool::Range(E,S,L,f,l);
1401 return (rev) ? f : l;
1405 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1406 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1407 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1409 while (itpr.More()) {
1410 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1411 return itpr.Value()->Parameter();
1416 //----------------------------------------------------------
1419 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1420 L1 = L1.Predivided(V.Location());
1421 if (!C.IsNull() || Degenerated(E)) {
1422 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1423 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1425 while (itpr.More()) {
1426 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1427 if (pr->IsPointOnCurve(C,L1)) {
1428 Standard_Real p = pr->Parameter();
1429 Standard_Real res = p;
1431 // Closed curves RLE 16 june 94
1432 if (Precision::IsNegativeInfinite(f)) return res;
1433 if (Precision::IsPositiveInfinite(l)) return res;
1434 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1435 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1436 Standard_Real tol = BRep_Tool::Tolerance(V);
1437 if (Pf.Distance(Pl) < tol) {
1438 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1439 if (V.Orientation() == TopAbs_FORWARD) res = f;
1450 //----------------------------------------------------------
1452 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1455 //=======================================================================
1456 //function : Parameters
1457 //purpose : Returns the parameters of the vertex on the face.
1458 //=======================================================================
1460 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1461 const TopoDS_Face& F)
1464 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1465 L = L.Predivided(V.Location());
1466 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1467 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1469 // It is checked if there is PointRepresentation (case non Manifold)
1470 while (itpr.More()) {
1471 if (itpr.Value()->IsPointOnSurface(S,L)) {
1472 return gp_Pnt2d(itpr.Value()->Parameter(),
1473 itpr.Value()->Parameter2());
1478 TopoDS_Vertex Vf,Vl;
1480 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1481 // even if often there is a way to make more economically than above...
1482 TopExp_Explorer exp;
1483 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1484 E = TopoDS::Edge(exp.Current());
1485 TopExp::Vertices(E, Vf, Vl);
1486 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1488 UVPoints(E, F, Pf, Pl);
1489 if (V.IsSame(Vf)) return Pf;
1490 else return Pl;//Ambiguity (natural) for degenerated edges.
1493 throw Standard_NoSuchObject("BRep_Tool:: no parameters on surface");
1495 //=======================================================================
1496 //function : IsClosed
1498 //=======================================================================
1499 Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape)
1501 if (theShape.ShapeType() == TopAbs_SHELL)
1503 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1504 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1505 Standard_Boolean hasBound = Standard_False;
1506 for (; exp.More(); exp.Next())
1508 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1509 if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL)
1511 hasBound = Standard_True;
1515 return hasBound && aMap.IsEmpty();
1517 else if (theShape.ShapeType() == TopAbs_WIRE)
1519 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1520 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX);
1521 Standard_Boolean hasBound = Standard_False;
1522 for (; exp.More(); exp.Next())
1524 const TopoDS_Shape& V = exp.Current();
1525 if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL)
1527 hasBound = Standard_True;
1531 return hasBound && aMap.IsEmpty();
1533 else if (theShape.ShapeType() == TopAbs_EDGE)
1535 TopoDS_Vertex aVFirst, aVLast;
1536 TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast);
1537 return !aVFirst.IsNull() && aVFirst.IsSame(aVLast);
1539 return theShape.Closed();
1542 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1543 //=======================================================================
1544 //function : IsPlane
1546 //=======================================================================
1547 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1549 Standard_Boolean bRet;
1550 Handle(Geom_Plane) aGP;
1551 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1552 Handle(Geom_OffsetSurface) aGOFS;
1554 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1555 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1557 if(!aGOFS.IsNull()) {
1558 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1560 else if(!aGRTS.IsNull()) {
1561 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1564 aGP=Handle(Geom_Plane)::DownCast(aS);
1572 //=======================================================================
1573 //function : MaxTolerance
1575 //=======================================================================
1576 Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape,
1577 const TopAbs_ShapeEnum theSubShape)
1579 Standard_Real aTol = 0.0;
1581 // Explorer Shape-Subshape.
1582 TopExp_Explorer anExpSS(theShape, theSubShape);
1583 if (theSubShape == TopAbs_FACE)
1585 for( ; anExpSS.More() ; anExpSS.Next() )
1587 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1588 aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape)));
1591 else if (theSubShape == TopAbs_EDGE)
1593 for( ; anExpSS.More() ; anExpSS.Next() )
1595 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1596 aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape)));
1599 else if (theSubShape == TopAbs_VERTEX)
1601 for( ; anExpSS.More() ; anExpSS.Next() )
1603 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1604 aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape)));