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_Curve.hxx>
45 #include <GeomAdaptor_Surface.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
117 //=======================================================================
118 const Handle(Poly_Triangulation)& BRep_Tool::Triangulation (const TopoDS_Face& theFace,
119 TopLoc_Location& theLocation,
120 const Poly_MeshPurpose theMeshPurpose)
122 theLocation = theFace.Location();
123 const BRep_TFace* aTFace = static_cast<const BRep_TFace*>(theFace.TShape().get());
124 return aTFace->Triangulation (theMeshPurpose);
127 //=======================================================================
128 //function : Triangulations
130 //=======================================================================
131 const Poly_ListOfTriangulation& BRep_Tool::Triangulations (const TopoDS_Face& theFace,
132 TopLoc_Location& theLocation)
134 theLocation = theFace.Location();
135 const BRep_TFace* aTFace = static_cast<const BRep_TFace*>(theFace.TShape().get());
136 return aTFace->Triangulations();
139 //=======================================================================
140 //function : Tolerance
141 //purpose : Returns the tolerance of the face.
142 //=======================================================================
144 Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F)
146 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
147 Standard_Real p = TF->Tolerance();
148 Standard_Real pMin = Precision::Confusion();
149 if (p > pMin) return p;
153 //=======================================================================
154 //function : NaturalRestriction
155 //purpose : Returns the NaturalRestriction flag of the face.
156 //=======================================================================
158 Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F)
160 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
161 return TF->NaturalRestriction();
164 //=======================================================================
166 //purpose : Returns the 3D curve of the edge. May be a Null
167 // handle. Returns in <L> the location for the curve.
168 // In <First> and <Last> the parameter range.
169 //=======================================================================
171 static const Handle(Geom_Curve) nullCurve;
173 const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E,
175 Standard_Real& First,
178 // find the representation
179 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
180 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
182 while (itcr.More()) {
183 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
184 if (cr->IsCurve3D()) {
185 const BRep_Curve3D* GC = static_cast<const BRep_Curve3D*>(cr.get());
186 L = E.Location() * GC->Location();
187 GC->Range(First,Last);
188 return GC->Curve3D();
197 //=======================================================================
199 //purpose : Returns the 3D curve of the edge. May be a Null handle.
200 // In <First> and <Last> the parameter range.
201 // It can be a copy if there is a Location.
202 //=======================================================================
204 Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
205 Standard_Real& First,
209 const Handle(Geom_Curve)& C = Curve(E,L,First,Last);
211 if ( !L.IsIdentity() ) {
212 Handle(Geom_Geometry) aCopy = C->Transformed(L.Transformation());
213 Geom_Curve* aGC = static_cast<Geom_Curve*>(aCopy.get());
214 return Handle(Geom_Curve)(aGC);
220 //=======================================================================
221 //function : IsGeometric
222 //purpose : Returns True if <F> has a surface.
223 //=======================================================================
224 Standard_Boolean BRep_Tool::IsGeometric (const TopoDS_Face& F)
226 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
227 const Handle(Geom_Surface)& S = TF->Surface();
231 //=======================================================================
232 //function : IsGeometric
233 //purpose : Returns True if <E> is a 3d curve or a curve on
235 //=======================================================================
237 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
239 // find the representation
240 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
241 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
243 while (itcr.More()) {
244 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
245 if (cr->IsCurve3D()) {
246 Handle(BRep_Curve3D) GC (Handle(BRep_Curve3D)::DownCast (cr));
247 if (! GC.IsNull() && ! GC->Curve3D().IsNull())
248 return Standard_True;
250 else if (cr->IsCurveOnSurface()) return Standard_True;
253 return Standard_False;
256 //=======================================================================
257 //function : Polygon3D
258 //purpose : Returns the 3D polygon of the edge. May be a Null
259 // handle. Returns in <L> the location for the polygon.
260 //=======================================================================
262 static const Handle(Poly_Polygon3D) nullPolygon3D;
264 const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
267 // find the representation
268 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
269 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
271 while (itcr.More()) {
272 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
273 if (cr->IsPolygon3D()) {
274 const BRep_Polygon3D* GC = static_cast<const BRep_Polygon3D*>(cr.get());
275 L = E.Location() * GC->Location();
276 return GC->Polygon3D();
281 return nullPolygon3D;
284 //=======================================================================
285 //function : CurveOnSurface
286 //purpose : Returns the curve associated to the edge in the
287 // parametric space of the face. Returns a NULL
288 // handle if this curve does not exist. Returns in
289 // <First> and <Last> the parameter range.
290 //=======================================================================
292 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
293 const TopoDS_Face& F,
294 Standard_Real& First,
296 Standard_Boolean* theIsStored)
299 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
300 TopoDS_Edge aLocalEdge = E;
301 if (F.Orientation() == TopAbs_REVERSED) {
302 aLocalEdge.Reverse();
304 return CurveOnSurface(aLocalEdge, S, l, First, Last, theIsStored);
307 //=======================================================================
308 //function : CurveOnSurface
309 //purpose : Returns the curve associated to the edge in the
310 // parametric space of the surface. Returns a NULL
311 // handle if this curve does not exist. Returns in
312 // <First> and <Last> the parameter range.
313 //=======================================================================
315 static const Handle(Geom2d_Curve) nullPCurve;
317 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
318 const Handle(Geom_Surface)& S,
319 const TopLoc_Location& L,
320 Standard_Real& First,
322 Standard_Boolean* theIsStored)
324 TopLoc_Location loc = L.Predivided(E.Location());
325 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
327 *theIsStored = Standard_True;
329 // find the representation
330 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
331 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
333 while (itcr.More()) {
334 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
335 if (cr->IsCurveOnSurface(S,loc)) {
336 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
337 GC->Range(First,Last);
338 if (GC->IsCurveOnClosedSurface() && Eisreversed)
339 return GC->PCurve2();
346 // Curve is not found. Try projection on plane
348 *theIsStored = Standard_False;
349 return CurveOnPlane(E, S, L, First, Last);
352 //=======================================================================
353 //function : CurveOnPlane
354 //purpose : For planar surface returns projection of the edge on the plane
355 //=======================================================================
356 Handle(Geom2d_Curve) BRep_Tool::CurveOnPlane(const TopoDS_Edge& E,
357 const Handle(Geom_Surface)& S,
358 const TopLoc_Location& L,
359 Standard_Real& First,
364 // Check if the surface is planar
365 Handle(Geom_Plane) GP;
366 Handle(Geom_RectangularTrimmedSurface) GRTS;
367 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
369 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
371 GP = Handle(Geom_Plane)::DownCast(S);
377 // Check existence of 3d curve in edge
379 TopLoc_Location aCurveLocation;
380 Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, aCurveLocation, f, l);
386 aCurveLocation = aCurveLocation.Predivided(L);
389 // Transform curve and update parameters in account of scale factor
390 if (!aCurveLocation.IsIdentity())
392 const gp_Trsf& aTrsf = aCurveLocation.Transformation();
393 C3D = Handle(Geom_Curve)::DownCast(C3D->Transformed(aTrsf));
394 f = C3D->TransformedParameter(f, aTrsf);
395 l = C3D->TransformedParameter(l, aTrsf);
398 // Perform projection
399 Handle(Geom_Curve) ProjOnPlane =
400 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3D, f, l, Standard_True, Standard_False),
402 GP->Position().Direction(),
405 Handle(GeomAdaptor_Surface) HS = new GeomAdaptor_Surface(GP);
406 Handle(GeomAdaptor_Curve) HC = new GeomAdaptor_Curve(ProjOnPlane);
408 ProjLib_ProjectedCurve Proj(HS, HC);
409 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
411 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
412 Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(pc);
413 pc = TC->BasisCurve();
419 //=======================================================================
420 //function : CurveOnSurface
422 //=======================================================================
424 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
425 Handle(Geom2d_Curve)& C,
426 Handle(Geom_Surface)& S,
428 Standard_Real& First,
431 // find the representation
432 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
433 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
435 while (itcr.More()) {
436 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
437 if (cr->IsCurveOnSurface()) {
438 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
441 L = E.Location() * GC->Location();
442 GC->Range(First,Last);
454 //=======================================================================
455 //function : CurveOnSurface
457 //=======================================================================
459 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
460 Handle(Geom2d_Curve)& C,
461 Handle(Geom_Surface)& S,
463 Standard_Real& First,
465 const Standard_Integer Index)
470 Standard_Integer i = 0;
471 // find the representation
472 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
473 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
474 for (; itcr.More(); itcr.Next())
476 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
477 if (cr->IsCurveOnSurface())
479 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
481 // Compare index taking into account the fact that for the curves on
482 // closed surfaces there are two PCurves
485 else if (GC->IsCurveOnClosedSurface() && (++i == Index))
491 L = E.Location() * GC->Location();
492 GC->Range(First, Last);
503 //=======================================================================
504 //function : PolygonOnSurface
505 //purpose : Returns the polygon associated to the edge in the
506 // parametric space of the face. Returns a NULL
507 // handle if this polygon does not exist.
508 //=======================================================================
510 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
511 const TopoDS_Face& F)
514 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
515 TopoDS_Edge aLocalEdge = E;
516 if (F.Orientation() == TopAbs_REVERSED) {
517 aLocalEdge.Reverse();
518 // return PolygonOnSurface(E,S,l);
520 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
522 // return PolygonOnSurface(E,S,l);
523 return PolygonOnSurface(aLocalEdge,S,l);
526 //=======================================================================
527 //function : PolygonOnSurface
528 //purpose : Returns the polygon associated to the edge in the
529 // parametric space of the surface. Returns a NULL
530 // handle if this polygon does not exist.
531 //=======================================================================
533 static const Handle(Poly_Polygon2D) nullPolygon2D;
535 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
536 const Handle(Geom_Surface)& S,
537 const TopLoc_Location& L)
539 TopLoc_Location l = L.Predivided(E.Location());
540 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
542 // find the representation
543 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
544 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
546 while (itcr.More()) {
547 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
548 if (cr->IsPolygonOnSurface(S,l)) {
549 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
550 return cr->Polygon2();
552 return cr->Polygon();
557 return nullPolygon2D;
560 //=======================================================================
561 //function : PolygonOnSurface
563 //=======================================================================
565 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
566 Handle(Poly_Polygon2D)& P,
567 Handle(Geom_Surface)& S,
570 // find the representation
571 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
572 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
574 while (itcr.More()) {
575 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
576 if (cr->IsPolygonOnSurface()) {
577 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
580 L = E.Location() * PS->Location();
591 //=======================================================================
592 //function : PolygonOnSurface
594 //=======================================================================
596 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
597 Handle(Poly_Polygon2D)& P,
598 Handle(Geom_Surface)& S,
600 const Standard_Integer Index)
602 Standard_Integer i = 0;
604 // find the representation
605 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
606 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
608 while (itcr.More()) {
609 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
610 if (cr->IsPolygonOnSurface()) {
611 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
613 if (i > Index) break;
617 L = E.Location() * PS->Location();
629 //=======================================================================
630 //function : PolygonOnTriangulation
631 //purpose : Returns the polygon associated to the edge in the
632 // parametric space of the face. Returns a NULL
633 // handle if this polygon does not exist.
634 //=======================================================================
636 static const Handle(Poly_PolygonOnTriangulation) nullArray;
638 const Handle(Poly_PolygonOnTriangulation)&
639 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
640 const Handle(Poly_Triangulation)& T,
641 const TopLoc_Location& L)
643 TopLoc_Location l = L.Predivided(E.Location());
644 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
646 // find the representation
647 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
648 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
650 while (itcr.More()) {
651 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
652 if ( cr->IsPolygonOnTriangulation(T,l)) {
653 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
654 return cr->PolygonOnTriangulation2();
656 return cr->PolygonOnTriangulation();
664 //=======================================================================
665 //function : PolygonOnTriangulation
667 //=======================================================================
670 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
671 Handle(Poly_PolygonOnTriangulation)& P,
672 Handle(Poly_Triangulation)& T,
675 // find the representation
676 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
677 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
679 while (itcr.More()) {
680 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
681 if (cr->IsPolygonOnTriangulation()) {
682 const BRep_PolygonOnTriangulation* PT =
683 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
684 P = PT->PolygonOnTriangulation();
685 T = PT->Triangulation();
686 L = E.Location() * PT->Location();
697 //=======================================================================
698 //function : PolygonOnTriangulation
700 //=======================================================================
703 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
704 Handle(Poly_PolygonOnTriangulation)& P,
705 Handle(Poly_Triangulation)& T,
707 const Standard_Integer Index)
709 Standard_Integer i = 0;
711 // find the representation
712 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
713 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
715 while (itcr.More()) {
716 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
717 if (cr->IsPolygonOnTriangulation()) {
718 const BRep_PolygonOnTriangulation* PT =
719 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
721 if (i > Index) break;
723 T = PT->Triangulation();
724 P = PT->PolygonOnTriangulation();
725 L = E.Location() * PT->Location();
737 //=======================================================================
738 //function : IsClosed
739 //purpose : Returns True if <E> has two PCurves in the
740 // parametric space of <F>. i.e. <F> is on a closed
741 // surface and <E> is on the closing curve.
742 //=======================================================================
744 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
745 const TopoDS_Face& F)
748 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
749 if (IsClosed(E,S,l)) return Standard_True;
750 const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l);
751 return IsClosed(E, T, l);
754 //=======================================================================
755 //function : IsClosed
756 //purpose : Returns True if <E> has two PCurves in the
757 // parametric space of <S>. i.e. <S> is a closed
758 // surface and <E> is on the closing curve.
759 //=======================================================================
761 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
762 const Handle(Geom_Surface)& S,
763 const TopLoc_Location& L)
765 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
767 return Standard_False;
769 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
771 TopLoc_Location l = L.Predivided(E.Location());
773 // find the representation
774 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
775 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
777 while (itcr.More()) {
778 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
779 if (cr->IsCurveOnSurface(S,l) &&
780 cr->IsCurveOnClosedSurface())
781 return Standard_True;
784 return Standard_False;
787 //=======================================================================
788 //function : IsClosed
789 //purpose : Returns True if <E> has two arrays of indices in
790 // the triangulation <T>.
791 //=======================================================================
793 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
794 const Handle(Poly_Triangulation)& T,
795 const TopLoc_Location& L)
797 TopLoc_Location l = L.Predivided(E.Location());
799 // find the representation
800 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
801 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
803 while (itcr.More()) {
804 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
805 if (cr->IsPolygonOnTriangulation(T,l) &&
806 cr->IsPolygonOnClosedTriangulation())
807 return Standard_True;
810 return Standard_False;
813 //=======================================================================
814 //function : Tolerance
815 //purpose : Returns the tolerance for <E>.
816 //=======================================================================
818 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
820 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
821 Standard_Real p = TE->Tolerance();
822 Standard_Real pMin = Precision::Confusion();
823 if (p > pMin) return p;
827 //=======================================================================
828 //function : SameParameter
829 //purpose : Returns the SameParameter flag for the edge.
830 //=======================================================================
832 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
834 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
835 return TE->SameParameter();
838 //=======================================================================
839 //function : SameRange
840 //purpose : Returns the SameRange flag for the edge.
841 //=======================================================================
843 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
845 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
846 return TE->SameRange();
849 //=======================================================================
850 //function : Degenerated
851 //purpose : Returns True if the edge is degenerated.
852 //=======================================================================
854 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
856 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
857 return TE->Degenerated();
860 //=======================================================================
863 //=======================================================================
865 void BRep_Tool::Range(const TopoDS_Edge& E,
866 Standard_Real& First,
869 // set the range to all the representations
870 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
871 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
873 while (itcr.More()) {
874 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
875 if (cr->IsCurve3D()) {
876 const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get());
877 if (!CR->Curve3D().IsNull()) {
883 else if (cr->IsCurveOnSurface()) {
884 const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get());
894 //=======================================================================
897 //=======================================================================
899 void BRep_Tool::Range(const TopoDS_Edge& E,
900 const Handle(Geom_Surface)& S,
901 const TopLoc_Location& L,
902 Standard_Real& First,
905 TopLoc_Location l = L.Predivided(E.Location());
907 // find the representation
908 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
909 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
911 while (itcr.More()) {
912 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
913 if (cr->IsCurveOnSurface(S,l)) {
914 const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get());
915 CR->Range(First,Last);
923 E.TShape()->Modified(Standard_True);
926 //=======================================================================
929 //=======================================================================
931 void BRep_Tool::Range(const TopoDS_Edge& E,
932 const TopoDS_Face& F,
933 Standard_Real& First,
937 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
938 Range(E,S,L,First,Last);
941 //=======================================================================
942 //function : UVPoints
944 //=======================================================================
946 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
947 const Handle(Geom_Surface)& S,
948 const TopLoc_Location& L,
952 TopLoc_Location l = L.Predivided(E.Location());
953 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
955 // find the representation
956 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
957 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
959 while (itcr.More()) {
960 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
961 if (cr->IsCurveOnSurface(S,l)) {
962 if (cr->IsCurveOnClosedSurface() && Eisreversed)
964 const BRep_CurveOnClosedSurface* CR =
965 static_cast<const BRep_CurveOnClosedSurface*>(cr.get());
966 CR->UVPoints2(PFirst, PLast);
970 const BRep_CurveOnSurface* CR =
971 static_cast<const BRep_CurveOnSurface*>(cr.get());
972 CR->UVPoints(PFirst, PLast);
979 // for planar surface project the vertices
980 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
981 Handle(Geom_Plane) GP;
982 Handle(Geom_RectangularTrimmedSurface) GRTS;
983 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
985 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
987 GP = Handle(Geom_Plane)::DownCast(S);
988 //fin modif du 21-05-97
990 // get the two vertices
992 TopExp::Vertices(E,Vf,Vl);
994 TopLoc_Location Linverted = L.Inverted();
998 gp_Pln pln = GP->Pln();
1002 gp_Pnt PF = BRep_Tool::Pnt(Vf);
1003 ElSLib::Parameters(pln,PF,u,v);
1005 PFirst.SetCoord(u,v);
1009 gp_Pnt PL = BRep_Tool::Pnt(Vl);
1010 ElSLib::Parameters(pln,PL,u,v);
1012 PLast.SetCoord(u,v);
1016 PFirst.SetCoord (0., 0.);
1017 PLast.SetCoord (0., 0.);
1021 //=======================================================================
1022 //function : UVPoints
1024 //=======================================================================
1026 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
1027 const TopoDS_Face& F,
1032 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1033 TopoDS_Edge aLocalEdge = E;
1034 if (F.Orientation() == TopAbs_REVERSED) {
1035 aLocalEdge.Reverse();
1036 // UVPoints(E,S,L,PFirst,PLast);
1038 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1040 // UVPoints(E,S,L,PFirst,PLast);
1041 UVPoints(aLocalEdge,S,L,PFirst,PLast);
1044 //=======================================================================
1045 //function : SetUVPoints
1047 //=======================================================================
1049 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1050 const Handle(Geom_Surface)& S,
1051 const TopLoc_Location& L,
1052 const gp_Pnt2d& PFirst,
1053 const gp_Pnt2d& PLast)
1055 TopLoc_Location l = L.Predivided(E.Location());
1056 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
1058 // find the representation
1059 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1060 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1062 while (itcr.More()) {
1063 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1064 if (cr->IsCurveOnSurface(S,l)) {
1065 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1067 BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get());
1068 CS->SetUVPoints2(PFirst, PLast);
1072 BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get());
1073 CS->SetUVPoints(PFirst, PLast);
1080 //=======================================================================
1081 //function : SetUVPoints
1083 //=======================================================================
1085 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1086 const TopoDS_Face& F,
1087 const gp_Pnt2d& PFirst,
1088 const gp_Pnt2d& PLast)
1091 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1092 TopoDS_Edge aLocalEdge = E;
1093 if (F.Orientation() == TopAbs_REVERSED) {
1094 aLocalEdge.Reverse();
1095 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1098 // SetUVPoints(E,S,L,PFirst,PLast);
1099 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1102 //=======================================================================
1103 //function : HasContinuity
1104 //purpose : Returns True if the edge is on the surfaces of the
1106 //=======================================================================
1108 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1109 const TopoDS_Face& F1,
1110 const TopoDS_Face& F2)
1112 TopLoc_Location l1,l2;
1113 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1114 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1115 return HasContinuity(E,S1,S2,l1,l2);
1118 //=======================================================================
1119 //function : Continuity
1120 //purpose : Returns the continuity.
1121 //=======================================================================
1123 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1124 const TopoDS_Face& F1,
1125 const TopoDS_Face& F2)
1127 TopLoc_Location l1,l2;
1128 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1129 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1130 return Continuity(E,S1,S2,l1,l2);
1133 //=======================================================================
1134 //function : HasContinuity
1135 //purpose : Returns True if the edge is on the surfaces.
1136 //=======================================================================
1138 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1139 const Handle(Geom_Surface)& S1,
1140 const Handle(Geom_Surface)& S2,
1141 const TopLoc_Location& L1,
1142 const TopLoc_Location& L2)
1144 const TopLoc_Location& Eloc = E.Location();
1145 TopLoc_Location l1 = L1.Predivided(Eloc);
1146 TopLoc_Location l2 = L2.Predivided(Eloc);
1148 // find the representation
1149 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1150 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1152 while (itcr.More()) {
1153 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1154 if (cr->IsRegularity(S1,S2,l1,l2))
1155 return Standard_True;
1158 return Standard_False;
1161 //=======================================================================
1162 //function : Continuity
1163 //purpose : Returns the continuity.
1164 //=======================================================================
1166 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1167 const Handle(Geom_Surface)& S1,
1168 const Handle(Geom_Surface)& S2,
1169 const TopLoc_Location& L1,
1170 const TopLoc_Location& L2)
1172 TopLoc_Location l1 = L1.Predivided(E.Location());
1173 TopLoc_Location l2 = L2.Predivided(E.Location());
1175 // find the representation
1176 BRep_ListIteratorOfListOfCurveRepresentation itcr
1177 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1179 while (itcr.More()) {
1180 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1181 if (cr->IsRegularity(S1,S2,l1,l2))
1182 return cr->Continuity();
1188 //=======================================================================
1189 //function : HasContinuity
1190 //purpose : Returns True if the edge is on some two surfaces.
1191 //=======================================================================
1193 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1195 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1196 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1198 for (; itcr.More(); itcr.Next())
1200 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1201 if (CR->IsRegularity())
1202 return Standard_True;
1204 return Standard_False;
1207 //=======================================================================
1208 //function : MaxContinuity
1210 //=======================================================================
1211 GeomAbs_Shape BRep_Tool::MaxContinuity (const TopoDS_Edge& theEdge)
1213 GeomAbs_Shape aMaxCont = GeomAbs_C0;
1214 for (BRep_ListIteratorOfListOfCurveRepresentation aReprIter ((*((Handle(BRep_TEdge)*)&theEdge.TShape()))->ChangeCurves());
1215 aReprIter.More(); aReprIter.Next())
1217 const Handle(BRep_CurveRepresentation)& aRepr = aReprIter.Value();
1218 if (aRepr->IsRegularity())
1220 const GeomAbs_Shape aCont = aRepr->Continuity();
1221 if ((Standard_Integer )aCont > (Standard_Integer )aMaxCont)
1230 //=======================================================================
1232 //purpose : Returns the 3d point.
1233 //=======================================================================
1235 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1237 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1241 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1244 const gp_Pnt& P = TV->Pnt();
1245 if (V.Location().IsIdentity())
1250 return P.Transformed(V.Location().Transformation());
1253 //=======================================================================
1254 //function : Tolerance
1255 //purpose : Returns the tolerance.
1256 //=======================================================================
1258 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1260 const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get());
1264 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1267 Standard_Real p = aTVert->Tolerance();
1268 Standard_Real pMin = Precision::Confusion();
1269 if (p > pMin) return p;
1273 //=======================================================================
1274 //function : Parameter
1275 //purpose : Returns the parameter of <V> on <E>.
1276 //=======================================================================
1278 Standard_Boolean BRep_Tool::Parameter (const TopoDS_Vertex& theV,
1279 const TopoDS_Edge& theE,
1280 Standard_Real& theParam)
1282 // Search the vertex in the edge
1284 Standard_Boolean rev = Standard_False;
1286 TopAbs_Orientation orient = TopAbs_INTERNAL;
1288 TopoDS_Iterator itv(theE.Oriented(TopAbs_FORWARD));
1290 // if the edge has no vertices
1291 // and is degenerated use the vertex orientation
1294 if (!itv.More() && BRep_Tool::Degenerated(theE)) {
1295 orient = theV.Orientation();
1298 while (itv.More()) {
1299 const TopoDS_Shape& Vcur = itv.Value();
1300 if (theV.IsSame(Vcur)) {
1305 rev = theE.Orientation() == TopAbs_REVERSED;
1306 if (Vcur.Orientation() == theV.Orientation()) {
1314 if (!VF.IsNull()) orient = VF.Orientation();
1318 if (orient == TopAbs_FORWARD) {
1319 BRep_Tool::Range(theE, f, l);
1320 theParam = (rev) ? l : f;
1321 return Standard_True;
1324 else if (orient == TopAbs_REVERSED) {
1325 BRep_Tool::Range(theE, f, l);
1326 theParam = (rev) ? f : l;
1327 return Standard_True;
1332 const Handle(Geom_Curve)& C = BRep_Tool::Curve(theE, L, f, l);
1333 L = L.Predivided(theV.Location());
1334 if (!C.IsNull() || BRep_Tool::Degenerated(theE)) {
1335 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(theV.TShape().get());
1336 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1338 while (itpr.More()) {
1339 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1340 if (pr->IsPointOnCurve(C, L)) {
1341 Standard_Real p = pr->Parameter();
1342 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1344 // Closed curves RLE 16 june 94
1345 if (Precision::IsNegativeInfinite(f))
1347 theParam = pr->Parameter();//p;
1348 return Standard_True;
1350 if (Precision::IsPositiveInfinite(l))
1352 theParam = pr->Parameter();//p;
1353 return Standard_True;
1355 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1356 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1357 Standard_Real tol = BRep_Tool::Tolerance(theV);
1358 if (Pf.Distance(Pl) < tol) {
1359 if (Pf.Distance(BRep_Tool::Pnt(theV)) < tol) {
1360 if (theV.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1361 else res = l;//p = l;
1366 return Standard_True;
1373 // let us try with the first pcurve
1374 Handle(Geom2d_Curve) PC;
1375 Handle(Geom_Surface) S;
1376 BRep_Tool::CurveOnSurface(theE, PC, S, L, f, l);
1377 L = L.Predivided(theV.Location());
1378 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(theV.TShape().get());
1379 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1381 while (itpr.More()) {
1382 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1383 if (pr->IsPointOnCurveOnSurface(PC, S, L)) {
1384 Standard_Real p = pr->Parameter();
1385 // Closed curves RLE 16 june 94
1386 if (PC->IsClosed()) {
1387 if ((p == PC->FirstParameter()) ||
1388 (p == PC->LastParameter())) {
1389 if (theV.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1390 else p = PC->LastParameter();
1394 return Standard_True;
1401 return Standard_False;
1404 //=======================================================================
1405 //function : Parameter
1406 //purpose : Returns the parameter of <V> on <E>.
1407 //=======================================================================
1409 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1410 const TopoDS_Edge& E)
1413 if (Parameter(V, E, p)) return p;
1414 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1417 //=======================================================================
1418 //function : Parameter
1419 //purpose : Returns the parameters of the vertex on the
1420 // pcurve of the edge on the face.
1421 //=======================================================================
1423 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1424 const TopoDS_Edge& E,
1425 const TopoDS_Face& F)
1428 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1429 return BRep_Tool::Parameter(V,E,S,L);
1432 //=======================================================================
1433 //function : Parameter
1434 //purpose : Returns the parameters of the vertex on the
1435 // pcurve of the edge on the surface.
1436 //=======================================================================
1438 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1439 const TopoDS_Edge& E,
1440 const Handle(Geom_Surface)& S,
1441 const TopLoc_Location& L)
1443 // Search the vertex in the edge
1445 Standard_Boolean rev = Standard_False;
1447 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1449 while (itv.More()) {
1450 if (V.IsSame(itv.Value())) {
1451 if (VF.IsNull()) VF = itv.Value();
1453 rev = E.Orientation() == TopAbs_REVERSED;
1454 if (itv.Value().Orientation() == V.Orientation())
1461 TopAbs_Orientation orient = TopAbs_INTERNAL;
1462 if (!VF.IsNull()) orient = VF.Orientation();
1466 if (orient == TopAbs_FORWARD) {
1467 BRep_Tool::Range(E,S,L,f,l);
1468 return (rev) ? l : f;
1471 else if (orient == TopAbs_REVERSED) {
1472 BRep_Tool::Range(E,S,L,f,l);
1473 return (rev) ? f : l;
1477 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1478 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1479 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1481 while (itpr.More()) {
1482 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1483 return itpr.Value()->Parameter();
1488 //----------------------------------------------------------
1491 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1492 L1 = L1.Predivided(V.Location());
1493 if (!C.IsNull() || Degenerated(E)) {
1494 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1495 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1497 while (itpr.More()) {
1498 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1499 if (pr->IsPointOnCurve(C,L1)) {
1500 Standard_Real p = pr->Parameter();
1501 Standard_Real res = p;
1503 // Closed curves RLE 16 june 94
1504 if (Precision::IsNegativeInfinite(f)) return res;
1505 if (Precision::IsPositiveInfinite(l)) return res;
1506 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1507 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1508 Standard_Real tol = BRep_Tool::Tolerance(V);
1509 if (Pf.Distance(Pl) < tol) {
1510 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1511 if (V.Orientation() == TopAbs_FORWARD) res = f;
1522 //----------------------------------------------------------
1524 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1527 //=======================================================================
1528 //function : Parameters
1529 //purpose : Returns the parameters of the vertex on the face.
1530 //=======================================================================
1532 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1533 const TopoDS_Face& F)
1536 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1537 L = L.Predivided(V.Location());
1538 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1539 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1541 // It is checked if there is PointRepresentation (case non Manifold)
1542 while (itpr.More()) {
1543 if (itpr.Value()->IsPointOnSurface(S,L)) {
1544 return gp_Pnt2d(itpr.Value()->Parameter(),
1545 itpr.Value()->Parameter2());
1550 TopoDS_Vertex Vf,Vl;
1552 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1553 // even if often there is a way to make more economically than above...
1554 TopExp_Explorer exp;
1555 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1556 E = TopoDS::Edge(exp.Current());
1557 TopExp::Vertices(E, Vf, Vl);
1558 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1560 UVPoints(E, F, Pf, Pl);
1561 if (V.IsSame(Vf)) return Pf;
1562 else return Pl;//Ambiguity (natural) for degenerated edges.
1565 throw Standard_NoSuchObject("BRep_Tool:: no parameters on surface");
1567 //=======================================================================
1568 //function : IsClosed
1570 //=======================================================================
1571 Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape)
1573 if (theShape.ShapeType() == TopAbs_SHELL)
1575 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1576 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1577 Standard_Boolean hasBound = Standard_False;
1578 for (; exp.More(); exp.Next())
1580 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1581 if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL)
1583 hasBound = Standard_True;
1587 return hasBound && aMap.IsEmpty();
1589 else if (theShape.ShapeType() == TopAbs_WIRE)
1591 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1592 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX);
1593 Standard_Boolean hasBound = Standard_False;
1594 for (; exp.More(); exp.Next())
1596 const TopoDS_Shape& V = exp.Current();
1597 if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL)
1599 hasBound = Standard_True;
1603 return hasBound && aMap.IsEmpty();
1605 else if (theShape.ShapeType() == TopAbs_EDGE)
1607 TopoDS_Vertex aVFirst, aVLast;
1608 TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast);
1609 return !aVFirst.IsNull() && aVFirst.IsSame(aVLast);
1611 return theShape.Closed();
1614 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1615 //=======================================================================
1616 //function : IsPlane
1618 //=======================================================================
1619 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1621 Standard_Boolean bRet;
1622 Handle(Geom_Plane) aGP;
1623 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1624 Handle(Geom_OffsetSurface) aGOFS;
1626 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1627 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1629 if(!aGOFS.IsNull()) {
1630 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1632 else if(!aGRTS.IsNull()) {
1633 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1636 aGP=Handle(Geom_Plane)::DownCast(aS);
1644 //=======================================================================
1645 //function : MaxTolerance
1647 //=======================================================================
1648 Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape,
1649 const TopAbs_ShapeEnum theSubShape)
1651 Standard_Real aTol = 0.0;
1653 // Explorer Shape-Subshape.
1654 TopExp_Explorer anExpSS(theShape, theSubShape);
1655 if (theSubShape == TopAbs_FACE)
1657 for( ; anExpSS.More() ; anExpSS.Next() )
1659 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1660 aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape)));
1663 else if (theSubShape == TopAbs_EDGE)
1665 for( ; anExpSS.More() ; anExpSS.Next() )
1667 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1668 aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape)));
1671 else if (theSubShape == TopAbs_VERTEX)
1673 for( ; anExpSS.More() ; anExpSS.Next() )
1675 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1676 aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape)));