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 <F> has a surface.
212 //=======================================================================
213 Standard_Boolean BRep_Tool::IsGeometric (const TopoDS_Face& F)
215 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
216 const Handle(Geom_Surface)& S = TF->Surface();
220 //=======================================================================
221 //function : IsGeometric
222 //purpose : Returns True if <E> is a 3d curve or a curve on
224 //=======================================================================
226 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
228 // find the representation
229 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
230 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
232 while (itcr.More()) {
233 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
234 if (cr->IsCurve3D()) {
235 Handle(BRep_Curve3D) GC (Handle(BRep_Curve3D)::DownCast (cr));
236 if (! GC.IsNull() && ! GC->Curve3D().IsNull())
237 return Standard_True;
239 else if (cr->IsCurveOnSurface()) return Standard_True;
242 return Standard_False;
245 //=======================================================================
246 //function : Polygon3D
247 //purpose : Returns the 3D polygon of the edge. May be a Null
248 // handle. Returns in <L> the location for the polygon.
249 //=======================================================================
251 static const Handle(Poly_Polygon3D) nullPolygon3D;
253 const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
256 // find the representation
257 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
258 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
260 while (itcr.More()) {
261 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
262 if (cr->IsPolygon3D()) {
263 const BRep_Polygon3D* GC = static_cast<const BRep_Polygon3D*>(cr.get());
264 L = E.Location() * GC->Location();
265 return GC->Polygon3D();
270 return nullPolygon3D;
273 //=======================================================================
274 //function : CurveOnSurface
275 //purpose : Returns the curve associated to the edge in the
276 // parametric space of the face. Returns a NULL
277 // handle if this curve does not exist. Returns in
278 // <First> and <Last> the parameter range.
279 //=======================================================================
281 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
282 const TopoDS_Face& F,
283 Standard_Real& First,
285 Standard_Boolean* theIsStored)
288 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
289 TopoDS_Edge aLocalEdge = E;
290 if (F.Orientation() == TopAbs_REVERSED) {
291 aLocalEdge.Reverse();
293 return CurveOnSurface(aLocalEdge, S, l, First, Last, theIsStored);
296 //=======================================================================
297 //function : CurveOnSurface
298 //purpose : Returns the curve associated to the edge in the
299 // parametric space of the surface. Returns a NULL
300 // handle if this curve does not exist. Returns in
301 // <First> and <Last> the parameter range.
302 //=======================================================================
304 static const Handle(Geom2d_Curve) nullPCurve;
306 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
307 const Handle(Geom_Surface)& S,
308 const TopLoc_Location& L,
309 Standard_Real& First,
311 Standard_Boolean* theIsStored)
313 TopLoc_Location loc = L.Predivided(E.Location());
314 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
316 *theIsStored = Standard_True;
318 // find the representation
319 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
320 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
322 while (itcr.More()) {
323 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
324 if (cr->IsCurveOnSurface(S,loc)) {
325 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
326 GC->Range(First,Last);
327 if (GC->IsCurveOnClosedSurface() && Eisreversed)
328 return GC->PCurve2();
335 // Curve is not found. Try projection on plane
337 *theIsStored = Standard_False;
338 return CurveOnPlane(E, S, L, First, Last);
341 //=======================================================================
342 //function : CurveOnPlane
343 //purpose : For planar surface returns projection of the edge on the plane
344 //=======================================================================
345 Handle(Geom2d_Curve) BRep_Tool::CurveOnPlane(const TopoDS_Edge& E,
346 const Handle(Geom_Surface)& S,
347 const TopLoc_Location& L,
348 Standard_Real& First,
353 // Check if the surface is planar
354 Handle(Geom_Plane) GP;
355 Handle(Geom_RectangularTrimmedSurface) GRTS;
356 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
358 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
360 GP = Handle(Geom_Plane)::DownCast(S);
366 // Check existence of 3d curve in edge
368 TopLoc_Location aCurveLocation;
369 Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, aCurveLocation, f, l);
375 aCurveLocation = aCurveLocation.Predivided(L);
378 // Transform curve and update parameters in account of scale factor
379 if (!aCurveLocation.IsIdentity())
381 const gp_Trsf& aTrsf = aCurveLocation.Transformation();
382 C3D = Handle(Geom_Curve)::DownCast(C3D->Transformed(aTrsf));
383 f = C3D->TransformedParameter(f, aTrsf);
384 l = C3D->TransformedParameter(l, aTrsf);
387 // Perform projection
388 Handle(Geom_Curve) ProjOnPlane =
389 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3D, f, l, Standard_True, Standard_False),
391 GP->Position().Direction(),
394 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(GP);
395 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(ProjOnPlane);
397 ProjLib_ProjectedCurve Proj(HS, HC);
398 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
400 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
401 Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(pc);
402 pc = TC->BasisCurve();
408 //=======================================================================
409 //function : CurveOnSurface
411 //=======================================================================
413 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
414 Handle(Geom2d_Curve)& C,
415 Handle(Geom_Surface)& S,
417 Standard_Real& First,
420 // find the representation
421 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
422 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
424 while (itcr.More()) {
425 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
426 if (cr->IsCurveOnSurface()) {
427 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
430 L = E.Location() * GC->Location();
431 GC->Range(First,Last);
443 //=======================================================================
444 //function : CurveOnSurface
446 //=======================================================================
448 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
449 Handle(Geom2d_Curve)& C,
450 Handle(Geom_Surface)& S,
452 Standard_Real& First,
454 const Standard_Integer Index)
459 Standard_Integer i = 0;
460 // find the representation
461 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
462 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
463 for (; itcr.More(); itcr.Next())
465 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
466 if (cr->IsCurveOnSurface())
468 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
470 // Compare index taking into account the fact that for the curves on
471 // closed surfaces there are two PCurves
474 else if (GC->IsCurveOnClosedSurface() && (++i == Index))
480 L = E.Location() * GC->Location();
481 GC->Range(First, Last);
492 //=======================================================================
493 //function : PolygonOnSurface
494 //purpose : Returns the polygon associated to the edge in the
495 // parametric space of the face. Returns a NULL
496 // handle if this polygon does not exist.
497 //=======================================================================
499 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
500 const TopoDS_Face& F)
503 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
504 TopoDS_Edge aLocalEdge = E;
505 if (F.Orientation() == TopAbs_REVERSED) {
506 aLocalEdge.Reverse();
507 // return PolygonOnSurface(E,S,l);
509 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
511 // return PolygonOnSurface(E,S,l);
512 return PolygonOnSurface(aLocalEdge,S,l);
515 //=======================================================================
516 //function : PolygonOnSurface
517 //purpose : Returns the polygon associated to the edge in the
518 // parametric space of the surface. Returns a NULL
519 // handle if this polygon does not exist.
520 //=======================================================================
522 static const Handle(Poly_Polygon2D) nullPolygon2D;
524 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
525 const Handle(Geom_Surface)& S,
526 const TopLoc_Location& L)
528 TopLoc_Location l = L.Predivided(E.Location());
529 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
531 // find the representation
532 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
533 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
535 while (itcr.More()) {
536 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
537 if (cr->IsPolygonOnSurface(S,l)) {
538 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
539 return cr->Polygon2();
541 return cr->Polygon();
546 return nullPolygon2D;
549 //=======================================================================
550 //function : PolygonOnSurface
552 //=======================================================================
554 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
555 Handle(Poly_Polygon2D)& P,
556 Handle(Geom_Surface)& S,
559 // find the representation
560 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
561 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
563 while (itcr.More()) {
564 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
565 if (cr->IsPolygonOnSurface()) {
566 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
569 L = E.Location() * PS->Location();
580 //=======================================================================
581 //function : PolygonOnSurface
583 //=======================================================================
585 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
586 Handle(Poly_Polygon2D)& P,
587 Handle(Geom_Surface)& S,
589 const Standard_Integer Index)
591 Standard_Integer i = 0;
593 // find the representation
594 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
595 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
597 while (itcr.More()) {
598 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
599 if (cr->IsPolygonOnSurface()) {
600 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
602 if (i > Index) break;
606 L = E.Location() * PS->Location();
618 //=======================================================================
619 //function : PolygonOnTriangulation
620 //purpose : Returns the polygon associated to the edge in the
621 // parametric space of the face. Returns a NULL
622 // handle if this polygon does not exist.
623 //=======================================================================
625 static const Handle(Poly_PolygonOnTriangulation) nullArray;
627 const Handle(Poly_PolygonOnTriangulation)&
628 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
629 const Handle(Poly_Triangulation)& T,
630 const TopLoc_Location& L)
632 TopLoc_Location l = L.Predivided(E.Location());
633 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
635 // find the representation
636 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
637 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
639 while (itcr.More()) {
640 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
641 if ( cr->IsPolygonOnTriangulation(T,l)) {
642 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
643 return cr->PolygonOnTriangulation2();
645 return cr->PolygonOnTriangulation();
653 //=======================================================================
654 //function : PolygonOnTriangulation
656 //=======================================================================
659 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
660 Handle(Poly_PolygonOnTriangulation)& P,
661 Handle(Poly_Triangulation)& T,
664 // find the representation
665 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
666 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
668 while (itcr.More()) {
669 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
670 if (cr->IsPolygonOnTriangulation()) {
671 const BRep_PolygonOnTriangulation* PT =
672 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
673 P = PT->PolygonOnTriangulation();
674 T = PT->Triangulation();
675 L = E.Location() * PT->Location();
686 //=======================================================================
687 //function : PolygonOnTriangulation
689 //=======================================================================
692 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
693 Handle(Poly_PolygonOnTriangulation)& P,
694 Handle(Poly_Triangulation)& T,
696 const Standard_Integer Index)
698 Standard_Integer i = 0;
700 // find the representation
701 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
702 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
704 while (itcr.More()) {
705 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
706 if (cr->IsPolygonOnTriangulation()) {
707 const BRep_PolygonOnTriangulation* PT =
708 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
710 if (i > Index) break;
712 T = PT->Triangulation();
713 P = PT->PolygonOnTriangulation();
714 L = E.Location() * PT->Location();
726 //=======================================================================
727 //function : IsClosed
728 //purpose : Returns True if <E> has two PCurves in the
729 // parametric space of <F>. i.e. <F> is on a closed
730 // surface and <E> is on the closing curve.
731 //=======================================================================
733 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
734 const TopoDS_Face& F)
737 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
738 if (IsClosed(E,S,l)) return Standard_True;
739 const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l);
740 return IsClosed(E, T, l);
743 //=======================================================================
744 //function : IsClosed
745 //purpose : Returns True if <E> has two PCurves in the
746 // parametric space of <S>. i.e. <S> is a closed
747 // surface and <E> is on the closing curve.
748 //=======================================================================
750 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
751 const Handle(Geom_Surface)& S,
752 const TopLoc_Location& L)
754 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
756 return Standard_False;
758 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
760 TopLoc_Location l = L.Predivided(E.Location());
762 // find the representation
763 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
764 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
766 while (itcr.More()) {
767 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
768 if (cr->IsCurveOnSurface(S,l) &&
769 cr->IsCurveOnClosedSurface())
770 return Standard_True;
773 return Standard_False;
776 //=======================================================================
777 //function : IsClosed
778 //purpose : Returns True if <E> has two arrays of indices in
779 // the triangulation <T>.
780 //=======================================================================
782 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
783 const Handle(Poly_Triangulation)& T,
784 const TopLoc_Location& L)
786 TopLoc_Location l = L.Predivided(E.Location());
788 // find the representation
789 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
790 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
792 while (itcr.More()) {
793 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
794 if (cr->IsPolygonOnTriangulation(T,l) &&
795 cr->IsPolygonOnClosedTriangulation())
796 return Standard_True;
799 return Standard_False;
802 //=======================================================================
803 //function : Tolerance
804 //purpose : Returns the tolerance for <E>.
805 //=======================================================================
807 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
809 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
810 Standard_Real p = TE->Tolerance();
811 Standard_Real pMin = Precision::Confusion();
812 if (p > pMin) return p;
816 //=======================================================================
817 //function : SameParameter
818 //purpose : Returns the SameParameter flag for the edge.
819 //=======================================================================
821 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
823 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
824 return TE->SameParameter();
827 //=======================================================================
828 //function : SameRange
829 //purpose : Returns the SameRange flag for the edge.
830 //=======================================================================
832 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
834 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
835 return TE->SameRange();
838 //=======================================================================
839 //function : Degenerated
840 //purpose : Returns True if the edge is degenerated.
841 //=======================================================================
843 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
845 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
846 return TE->Degenerated();
849 //=======================================================================
852 //=======================================================================
854 void BRep_Tool::Range(const TopoDS_Edge& E,
855 Standard_Real& First,
858 // set the range to all the representations
859 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
860 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
862 while (itcr.More()) {
863 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
864 if (cr->IsCurve3D()) {
865 const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get());
866 if (!CR->Curve3D().IsNull()) {
872 else if (cr->IsCurveOnSurface()) {
873 const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get());
883 //=======================================================================
886 //=======================================================================
888 void BRep_Tool::Range(const TopoDS_Edge& E,
889 const Handle(Geom_Surface)& S,
890 const TopLoc_Location& L,
891 Standard_Real& First,
894 TopLoc_Location l = L.Predivided(E.Location());
896 // find the representation
897 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
898 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
900 while (itcr.More()) {
901 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
902 if (cr->IsCurveOnSurface(S,l)) {
903 const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get());
904 CR->Range(First,Last);
912 E.TShape()->Modified(Standard_True);
915 //=======================================================================
918 //=======================================================================
920 void BRep_Tool::Range(const TopoDS_Edge& E,
921 const TopoDS_Face& F,
922 Standard_Real& First,
926 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
927 Range(E,S,L,First,Last);
930 //=======================================================================
931 //function : UVPoints
933 //=======================================================================
935 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
936 const Handle(Geom_Surface)& S,
937 const TopLoc_Location& L,
941 TopLoc_Location l = L.Predivided(E.Location());
942 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
944 // find the representation
945 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
946 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
948 while (itcr.More()) {
949 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
950 if (cr->IsCurveOnSurface(S,l)) {
951 if (cr->IsCurveOnClosedSurface() && Eisreversed)
953 const BRep_CurveOnClosedSurface* CR =
954 static_cast<const BRep_CurveOnClosedSurface*>(cr.get());
955 CR->UVPoints2(PFirst, PLast);
959 const BRep_CurveOnSurface* CR =
960 static_cast<const BRep_CurveOnSurface*>(cr.get());
961 CR->UVPoints(PFirst, PLast);
968 // for planar surface project the vertices
969 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
970 Handle(Geom_Plane) GP;
971 Handle(Geom_RectangularTrimmedSurface) GRTS;
972 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
974 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
976 GP = Handle(Geom_Plane)::DownCast(S);
977 //fin modif du 21-05-97
979 // get the two vertices
981 TopExp::Vertices(E,Vf,Vl);
983 TopLoc_Location Linverted = L.Inverted();
987 gp_Pln pln = GP->Pln();
991 gp_Pnt PF = BRep_Tool::Pnt(Vf);
992 ElSLib::Parameters(pln,PF,u,v);
994 PFirst.SetCoord(u,v);
998 gp_Pnt PL = BRep_Tool::Pnt(Vl);
999 ElSLib::Parameters(pln,PL,u,v);
1001 PLast.SetCoord(u,v);
1005 PFirst.SetCoord (0., 0.);
1006 PLast.SetCoord (0., 0.);
1010 //=======================================================================
1011 //function : UVPoints
1013 //=======================================================================
1015 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
1016 const TopoDS_Face& F,
1021 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1022 TopoDS_Edge aLocalEdge = E;
1023 if (F.Orientation() == TopAbs_REVERSED) {
1024 aLocalEdge.Reverse();
1025 // UVPoints(E,S,L,PFirst,PLast);
1027 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1029 // UVPoints(E,S,L,PFirst,PLast);
1030 UVPoints(aLocalEdge,S,L,PFirst,PLast);
1033 //=======================================================================
1034 //function : SetUVPoints
1036 //=======================================================================
1038 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1039 const Handle(Geom_Surface)& S,
1040 const TopLoc_Location& L,
1041 const gp_Pnt2d& PFirst,
1042 const gp_Pnt2d& PLast)
1044 TopLoc_Location l = L.Predivided(E.Location());
1045 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
1047 // find the representation
1048 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1049 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1051 while (itcr.More()) {
1052 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1053 if (cr->IsCurveOnSurface(S,l)) {
1054 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1056 BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get());
1057 CS->SetUVPoints2(PFirst, PLast);
1061 BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get());
1062 CS->SetUVPoints(PFirst, PLast);
1069 //=======================================================================
1070 //function : SetUVPoints
1072 //=======================================================================
1074 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1075 const TopoDS_Face& F,
1076 const gp_Pnt2d& PFirst,
1077 const gp_Pnt2d& PLast)
1080 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1081 TopoDS_Edge aLocalEdge = E;
1082 if (F.Orientation() == TopAbs_REVERSED) {
1083 aLocalEdge.Reverse();
1084 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1087 // SetUVPoints(E,S,L,PFirst,PLast);
1088 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1091 //=======================================================================
1092 //function : HasContinuity
1093 //purpose : Returns True if the edge is on the surfaces of the
1095 //=======================================================================
1097 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1098 const TopoDS_Face& F1,
1099 const TopoDS_Face& F2)
1101 TopLoc_Location l1,l2;
1102 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1103 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1104 return HasContinuity(E,S1,S2,l1,l2);
1107 //=======================================================================
1108 //function : Continuity
1109 //purpose : Returns the continuity.
1110 //=======================================================================
1112 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1113 const TopoDS_Face& F1,
1114 const TopoDS_Face& F2)
1116 TopLoc_Location l1,l2;
1117 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1118 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1119 return Continuity(E,S1,S2,l1,l2);
1122 //=======================================================================
1123 //function : HasContinuity
1124 //purpose : Returns True if the edge is on the surfaces.
1125 //=======================================================================
1127 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1128 const Handle(Geom_Surface)& S1,
1129 const Handle(Geom_Surface)& S2,
1130 const TopLoc_Location& L1,
1131 const TopLoc_Location& L2)
1133 const TopLoc_Location& Eloc = E.Location();
1134 TopLoc_Location l1 = L1.Predivided(Eloc);
1135 TopLoc_Location l2 = L2.Predivided(Eloc);
1137 // find the representation
1138 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1139 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1141 while (itcr.More()) {
1142 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1143 if (cr->IsRegularity(S1,S2,l1,l2))
1144 return Standard_True;
1147 return Standard_False;
1150 //=======================================================================
1151 //function : Continuity
1152 //purpose : Returns the continuity.
1153 //=======================================================================
1155 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1156 const Handle(Geom_Surface)& S1,
1157 const Handle(Geom_Surface)& S2,
1158 const TopLoc_Location& L1,
1159 const TopLoc_Location& L2)
1161 TopLoc_Location l1 = L1.Predivided(E.Location());
1162 TopLoc_Location l2 = L2.Predivided(E.Location());
1164 // find the representation
1165 BRep_ListIteratorOfListOfCurveRepresentation itcr
1166 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1168 while (itcr.More()) {
1169 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1170 if (cr->IsRegularity(S1,S2,l1,l2))
1171 return cr->Continuity();
1177 //=======================================================================
1178 //function : HasContinuity
1179 //purpose : Returns True if the edge is on some two surfaces.
1180 //=======================================================================
1182 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1184 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1185 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1187 for (; itcr.More(); itcr.Next())
1189 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1190 if (CR->IsRegularity())
1191 return Standard_True;
1193 return Standard_False;
1196 //=======================================================================
1197 //function : MaxContinuity
1199 //=======================================================================
1200 GeomAbs_Shape BRep_Tool::MaxContinuity (const TopoDS_Edge& theEdge)
1202 GeomAbs_Shape aMaxCont = GeomAbs_C0;
1203 for (BRep_ListIteratorOfListOfCurveRepresentation aReprIter ((*((Handle(BRep_TEdge)*)&theEdge.TShape()))->ChangeCurves());
1204 aReprIter.More(); aReprIter.Next())
1206 const Handle(BRep_CurveRepresentation)& aRepr = aReprIter.Value();
1207 if (aRepr->IsRegularity())
1209 const GeomAbs_Shape aCont = aRepr->Continuity();
1210 if ((Standard_Integer )aCont > (Standard_Integer )aMaxCont)
1219 //=======================================================================
1221 //purpose : Returns the 3d point.
1222 //=======================================================================
1224 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1226 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1230 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1233 const gp_Pnt& P = TV->Pnt();
1234 if (V.Location().IsIdentity())
1239 return P.Transformed(V.Location().Transformation());
1242 //=======================================================================
1243 //function : Tolerance
1244 //purpose : Returns the tolerance.
1245 //=======================================================================
1247 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1249 const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get());
1253 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1256 Standard_Real p = aTVert->Tolerance();
1257 Standard_Real pMin = Precision::Confusion();
1258 if (p > pMin) return p;
1262 //=======================================================================
1263 //function : Parameter
1264 //purpose : Returns the parameter of <V> on <E>.
1265 //=======================================================================
1267 Standard_Boolean BRep_Tool::Parameter (const TopoDS_Vertex& theV,
1268 const TopoDS_Edge& theE,
1269 Standard_Real& theParam)
1271 // Search the vertex in the edge
1273 Standard_Boolean rev = Standard_False;
1275 TopAbs_Orientation orient = TopAbs_INTERNAL;
1277 TopoDS_Iterator itv(theE.Oriented(TopAbs_FORWARD));
1279 // if the edge has no vertices
1280 // and is degenerated use the vertex orientation
1283 if (!itv.More() && BRep_Tool::Degenerated(theE)) {
1284 orient = theV.Orientation();
1287 while (itv.More()) {
1288 const TopoDS_Shape& Vcur = itv.Value();
1289 if (theV.IsSame(Vcur)) {
1294 rev = theE.Orientation() == TopAbs_REVERSED;
1295 if (Vcur.Orientation() == theV.Orientation()) {
1303 if (!VF.IsNull()) orient = VF.Orientation();
1307 if (orient == TopAbs_FORWARD) {
1308 BRep_Tool::Range(theE, f, l);
1309 theParam = (rev) ? l : f;
1310 return Standard_True;
1313 else if (orient == TopAbs_REVERSED) {
1314 BRep_Tool::Range(theE, f, l);
1315 theParam = (rev) ? f : l;
1316 return Standard_True;
1321 const Handle(Geom_Curve)& C = BRep_Tool::Curve(theE, L, f, l);
1322 L = L.Predivided(theV.Location());
1323 if (!C.IsNull() || BRep_Tool::Degenerated(theE)) {
1324 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(theV.TShape().get());
1325 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1327 while (itpr.More()) {
1328 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1329 if (pr->IsPointOnCurve(C, L)) {
1330 Standard_Real p = pr->Parameter();
1331 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1333 // Closed curves RLE 16 june 94
1334 if (Precision::IsNegativeInfinite(f))
1336 theParam = pr->Parameter();//p;
1337 return Standard_True;
1339 if (Precision::IsPositiveInfinite(l))
1341 theParam = pr->Parameter();//p;
1342 return Standard_True;
1344 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1345 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1346 Standard_Real tol = BRep_Tool::Tolerance(theV);
1347 if (Pf.Distance(Pl) < tol) {
1348 if (Pf.Distance(BRep_Tool::Pnt(theV)) < tol) {
1349 if (theV.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1350 else res = l;//p = l;
1355 return Standard_True;
1362 // let us try with the first pcurve
1363 Handle(Geom2d_Curve) PC;
1364 Handle(Geom_Surface) S;
1365 BRep_Tool::CurveOnSurface(theE, PC, S, L, f, l);
1366 L = L.Predivided(theV.Location());
1367 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(theV.TShape().get());
1368 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1370 while (itpr.More()) {
1371 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1372 if (pr->IsPointOnCurveOnSurface(PC, S, L)) {
1373 Standard_Real p = pr->Parameter();
1374 // Closed curves RLE 16 june 94
1375 if (PC->IsClosed()) {
1376 if ((p == PC->FirstParameter()) ||
1377 (p == PC->LastParameter())) {
1378 if (theV.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1379 else p = PC->LastParameter();
1383 return Standard_True;
1390 return Standard_False;
1393 //=======================================================================
1394 //function : Parameter
1395 //purpose : Returns the parameter of <V> on <E>.
1396 //=======================================================================
1398 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1399 const TopoDS_Edge& E)
1402 if (Parameter(V, E, p)) return p;
1403 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1406 //=======================================================================
1407 //function : Parameter
1408 //purpose : Returns the parameters of the vertex on the
1409 // pcurve of the edge on the face.
1410 //=======================================================================
1412 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1413 const TopoDS_Edge& E,
1414 const TopoDS_Face& F)
1417 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1418 return BRep_Tool::Parameter(V,E,S,L);
1421 //=======================================================================
1422 //function : Parameter
1423 //purpose : Returns the parameters of the vertex on the
1424 // pcurve of the edge on the surface.
1425 //=======================================================================
1427 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1428 const TopoDS_Edge& E,
1429 const Handle(Geom_Surface)& S,
1430 const TopLoc_Location& L)
1432 // Search the vertex in the edge
1434 Standard_Boolean rev = Standard_False;
1436 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1438 while (itv.More()) {
1439 if (V.IsSame(itv.Value())) {
1440 if (VF.IsNull()) VF = itv.Value();
1442 rev = E.Orientation() == TopAbs_REVERSED;
1443 if (itv.Value().Orientation() == V.Orientation())
1450 TopAbs_Orientation orient = TopAbs_INTERNAL;
1451 if (!VF.IsNull()) orient = VF.Orientation();
1455 if (orient == TopAbs_FORWARD) {
1456 BRep_Tool::Range(E,S,L,f,l);
1457 return (rev) ? l : f;
1460 else if (orient == TopAbs_REVERSED) {
1461 BRep_Tool::Range(E,S,L,f,l);
1462 return (rev) ? f : l;
1466 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1467 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1468 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1470 while (itpr.More()) {
1471 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1472 return itpr.Value()->Parameter();
1477 //----------------------------------------------------------
1480 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1481 L1 = L1.Predivided(V.Location());
1482 if (!C.IsNull() || Degenerated(E)) {
1483 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1484 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1486 while (itpr.More()) {
1487 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1488 if (pr->IsPointOnCurve(C,L1)) {
1489 Standard_Real p = pr->Parameter();
1490 Standard_Real res = p;
1492 // Closed curves RLE 16 june 94
1493 if (Precision::IsNegativeInfinite(f)) return res;
1494 if (Precision::IsPositiveInfinite(l)) return res;
1495 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1496 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1497 Standard_Real tol = BRep_Tool::Tolerance(V);
1498 if (Pf.Distance(Pl) < tol) {
1499 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1500 if (V.Orientation() == TopAbs_FORWARD) res = f;
1511 //----------------------------------------------------------
1513 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1516 //=======================================================================
1517 //function : Parameters
1518 //purpose : Returns the parameters of the vertex on the face.
1519 //=======================================================================
1521 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1522 const TopoDS_Face& F)
1525 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1526 L = L.Predivided(V.Location());
1527 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1528 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1530 // It is checked if there is PointRepresentation (case non Manifold)
1531 while (itpr.More()) {
1532 if (itpr.Value()->IsPointOnSurface(S,L)) {
1533 return gp_Pnt2d(itpr.Value()->Parameter(),
1534 itpr.Value()->Parameter2());
1539 TopoDS_Vertex Vf,Vl;
1541 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1542 // even if often there is a way to make more economically than above...
1543 TopExp_Explorer exp;
1544 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1545 E = TopoDS::Edge(exp.Current());
1546 TopExp::Vertices(E, Vf, Vl);
1547 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1549 UVPoints(E, F, Pf, Pl);
1550 if (V.IsSame(Vf)) return Pf;
1551 else return Pl;//Ambiguity (natural) for degenerated edges.
1554 throw Standard_NoSuchObject("BRep_Tool:: no parameters on surface");
1556 //=======================================================================
1557 //function : IsClosed
1559 //=======================================================================
1560 Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape)
1562 if (theShape.ShapeType() == TopAbs_SHELL)
1564 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1565 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1566 Standard_Boolean hasBound = Standard_False;
1567 for (; exp.More(); exp.Next())
1569 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1570 if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL)
1572 hasBound = Standard_True;
1576 return hasBound && aMap.IsEmpty();
1578 else if (theShape.ShapeType() == TopAbs_WIRE)
1580 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1581 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX);
1582 Standard_Boolean hasBound = Standard_False;
1583 for (; exp.More(); exp.Next())
1585 const TopoDS_Shape& V = exp.Current();
1586 if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL)
1588 hasBound = Standard_True;
1592 return hasBound && aMap.IsEmpty();
1594 else if (theShape.ShapeType() == TopAbs_EDGE)
1596 TopoDS_Vertex aVFirst, aVLast;
1597 TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast);
1598 return !aVFirst.IsNull() && aVFirst.IsSame(aVLast);
1600 return theShape.Closed();
1603 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1604 //=======================================================================
1605 //function : IsPlane
1607 //=======================================================================
1608 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1610 Standard_Boolean bRet;
1611 Handle(Geom_Plane) aGP;
1612 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1613 Handle(Geom_OffsetSurface) aGOFS;
1615 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1616 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1618 if(!aGOFS.IsNull()) {
1619 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1621 else if(!aGRTS.IsNull()) {
1622 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1625 aGP=Handle(Geom_Plane)::DownCast(aS);
1633 //=======================================================================
1634 //function : MaxTolerance
1636 //=======================================================================
1637 Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape,
1638 const TopAbs_ShapeEnum theSubShape)
1640 Standard_Real aTol = 0.0;
1642 // Explorer Shape-Subshape.
1643 TopExp_Explorer anExpSS(theShape, theSubShape);
1644 if (theSubShape == TopAbs_FACE)
1646 for( ; anExpSS.More() ; anExpSS.Next() )
1648 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1649 aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape)));
1652 else if (theSubShape == TopAbs_EDGE)
1654 for( ; anExpSS.More() ; anExpSS.Next() )
1656 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1657 aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape)));
1660 else if (theSubShape == TopAbs_VERTEX)
1662 for( ; anExpSS.More() ; anExpSS.Next() )
1664 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1665 aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape)));