1 // Created on: 1993-07-07
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BRep_Tool.ixx>
23 #include <BRep_TFace.hxx>
24 #include <BRep_TEdge.hxx>
25 #include <BRep_TVertex.hxx>
26 #include <BRep_CurveRepresentation.hxx>
27 #include <BRep_CurveOnSurface.hxx>
28 #include <BRep_CurveOnClosedSurface.hxx>
29 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
30 #include <BRep_PointRepresentation.hxx>
31 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
32 #include <BRep_Curve3D.hxx>
33 #include <BRep_Polygon3D.hxx>
34 #include <BRep_PolygonOnSurface.hxx>
35 #include <BRep_PolygonOnClosedSurface.hxx>
36 #include <BRep_PolygonOnTriangulation.hxx>
37 #include <BRep_PolygonOnClosedTriangulation.hxx>
39 #include <TopoDS_Iterator.hxx>
40 #include <TopExp_Explorer.hxx>
42 #include <TopTools_MapOfShape.hxx>
44 #include <Geom_Plane.hxx>
45 #include <Geom_RectangularTrimmedSurface.hxx>
46 #include <Geom_OffsetSurface.hxx>
47 #include <Geom_TrimmedCurve.hxx>
48 #include <Geom2d_TrimmedCurve.hxx>
49 #include <ProjLib_ProjectedCurve.hxx>
50 #include <GeomProjLib.hxx>
51 #include <Geom2dAdaptor.hxx>
52 #include <GeomAdaptor_HCurve.hxx>
53 #include <GeomAdaptor_HSurface.hxx>
54 #include <Precision.hxx>
55 #include <Poly_Triangulation.hxx>
56 #include <Poly_Polygon3D.hxx>
57 #include <Poly_Polygon2D.hxx>
58 #include <Poly_PolygonOnTriangulation.hxx>
60 //modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f
62 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS);
63 //modified by NIZNHY-PKV Fri Oct 17 14:13:33 2008t
65 //=======================================================================
67 //purpose : Returns the geometric surface of the face. Returns
68 // in <L> the location for the surface.
69 //=======================================================================
71 const Handle(Geom_Surface)& BRep_Tool::Surface(const TopoDS_Face& F,
74 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
75 L = F.Location() * TF->Location();
79 //=======================================================================
81 //purpose : Returns the geometric surface of the face. It can
82 // be a copy if there is a Location.
83 //=======================================================================
85 Handle(Geom_Surface) BRep_Tool::Surface(const TopoDS_Face& F)
87 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
88 TopLoc_Location L = F.Location() * TF->Location();
89 Handle(Geom_Surface) S = TF->Surface();
91 if(S.IsNull()) return S;
93 Handle(Geom_Geometry) S1;
94 if (!L.IsIdentity()) {
96 S = *((Handle(Geom_Surface)*)&S1);
97 S->Transform(L.Transformation());
102 //=======================================================================
103 //function : Triangulation
104 //purpose : Returns the Triangulation of the face. It is a
105 // null handle if there is no triangulation.
106 //=======================================================================
108 const Handle(Poly_Triangulation)&
109 BRep_Tool::Triangulation(const TopoDS_Face& F,
113 return (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation();
116 //=======================================================================
117 //function : Tolerance
118 //purpose : Returns the tolerance of the face.
119 //=======================================================================
121 Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F)
123 Standard_Real p = (*((Handle(BRep_TFace)*)&F.TShape()))->Tolerance();
124 Standard_Real pMin = Precision::Confusion();
125 if (p > pMin) return p;
129 //=======================================================================
130 //function : NaturalRestriction
131 //purpose : Returns the NaturalRestriction flag of the face.
132 //=======================================================================
134 Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F)
136 return (*((Handle(BRep_TFace)*) &F.TShape()))->NaturalRestriction();
139 //=======================================================================
141 //purpose : Returns the 3D curve of the edge. May be a Null
142 // handle. Returns in <L> the location for the curve.
143 // In <First> and <Last> the parameter range.
144 //=======================================================================
146 static const Handle(Geom_Curve) nullCurve;
148 const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E,
150 Standard_Real& First,
153 // find the representation
154 BRep_ListIteratorOfListOfCurveRepresentation itcr
155 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
157 while (itcr.More()) {
158 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
159 if (cr->IsCurve3D()) {
160 const Handle(BRep_Curve3D)& GC = *((Handle(BRep_Curve3D)*)&cr);
161 L = E.Location() * GC->Location();
162 GC->Range(First,Last);
163 return GC->Curve3D();
171 //=======================================================================
173 //purpose : Returns the 3D curve of the edge. May be a Null handle.
174 // In <First> and <Last> the parameter range.
175 // It can be a copy if there is a Location.
176 //=======================================================================
178 Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
179 Standard_Real& First,
183 Handle(Geom_Curve) C = Curve(E,L,First,Last);
185 Handle(Geom_Geometry) C1;
186 if ( !L.IsIdentity() ) {
188 C = *((Handle(Geom_Curve)*)&C1);
189 C->Transform(L.Transformation());
195 //=======================================================================
196 //function : IsGeometric
197 //purpose : Returns True if <E> is a 3d curve or a curve on
199 //=======================================================================
201 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
203 // find the representation
204 BRep_ListIteratorOfListOfCurveRepresentation itcr
205 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
207 while (itcr.More()) {
208 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
209 if (cr->IsCurve3D()) {
210 Standard_Real first, last;
212 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E, L, first, last);
213 if (!C.IsNull()) return Standard_True;
215 else if (cr->IsCurveOnSurface()) return Standard_True;
218 return Standard_False;
221 //=======================================================================
222 //function : Polygon3D
223 //purpose : Returns the 3D polygon of the edge. May be a Null
224 // handle. Returns in <L> the location for the polygon.
225 //=======================================================================
227 static const Handle(Poly_Polygon3D) nullPolygon3D;
229 const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
232 // find the representation
233 BRep_ListIteratorOfListOfCurveRepresentation itcr
234 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
236 while (itcr.More()) {
237 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
238 if (cr->IsPolygon3D()) {
239 const Handle(BRep_Polygon3D)& GC = *((Handle(BRep_Polygon3D)*)&cr);
240 L = E.Location() * GC->Location();
241 return GC->Polygon3D();
246 return nullPolygon3D;
249 //=======================================================================
250 //function : CurveOnSurface
251 //purpose : Returns the curve associated to the edge in the
252 // parametric space of the face. Returns a NULL
253 // handle if this curve does not exist. Returns in
254 // <First> and <Last> the parameter range.
255 //=======================================================================
257 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
258 const TopoDS_Face& F,
259 Standard_Real& First,
263 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
264 TopoDS_Edge aLocalEdge = E;
265 if (F.Orientation() == TopAbs_REVERSED) {
266 aLocalEdge.Reverse();
267 // return CurveOnSurface(E,S,l,First,Last);
269 // return CurveOnSurface(TopoDS::Edge(E.Reversed()),S,l,First,Last);
271 // return CurveOnSurface(E,S,l,First,Last);
272 return CurveOnSurface(aLocalEdge,S,l,First,Last);
275 //=======================================================================
276 //function : CurveOnSurface
277 //purpose : Returns the curve associated to the edge in the
278 // parametric space of the surface. Returns a NULL
279 // handle if this curve does not exist. Returns in
280 // <First> and <Last> the parameter range.
281 //=======================================================================
283 static const Handle(Geom2d_Curve) nullPCurve;
285 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
286 const Handle(Geom_Surface)& S,
287 const TopLoc_Location& L,
288 Standard_Real& First,
291 TopLoc_Location loc = L.Predivided(E.Location());
292 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
294 // find the representation
295 BRep_ListIteratorOfListOfCurveRepresentation itcr
296 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
298 while (itcr.More()) {
299 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
300 if (cr->IsCurveOnSurface(S,loc)) {
301 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
302 GC->Range(First,Last);
303 if (GC->IsCurveOnClosedSurface() && Eisreversed)
304 return GC->PCurve2();
311 // for planar surface and 3d curve try a projection
312 // modif 21-05-97 : for RectangularTrimmedSurface, try a projection
313 Handle(Geom_Plane) GP;
314 Handle(Geom_RectangularTrimmedSurface) GRTS;
315 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
317 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
319 GP = Handle(Geom_Plane)::DownCast(S);
320 //fin modif du 21-05-97
324 Handle(GeomAdaptor_HCurve) HC;
325 Handle(GeomAdaptor_HSurface) HS;
327 HC = new GeomAdaptor_HCurve();
328 HS = new GeomAdaptor_HSurface();
332 Standard_Real f, l;// for those who call with (u,u).
333 Handle(Geom_Curve) C3d =
334 BRep_Tool::Curve(E,/*LC,*/f,l); // transforming plane instead of curve
335 // we can loose scale factor of Curve transformation (eap 13 May 2002)
337 LC = L/*.Predivided(LC)*/;
339 if (C3d.IsNull()) return nullPCurve;
341 Handle(Geom_Plane) Plane = GP;
342 if (!LC.IsIdentity()) {
343 const gp_Trsf& T = LC.Transformation();
344 Handle(Geom_Geometry) GPT = GP->Transformed(T);
345 Plane = *((Handle(Geom_Plane)*)&GPT);
347 GeomAdaptor_Surface& GAS = HS->ChangeSurface();
350 Handle(Geom_Curve) ProjOnPlane =
351 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l),
353 Plane->Position().Direction(),
356 GeomAdaptor_Curve& GAC = HC->ChangeCurve();
357 GAC.Load(ProjOnPlane);
359 ProjLib_ProjectedCurve Proj(HS,HC);
360 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
362 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
363 Handle(Geom2d_TrimmedCurve) TC =
364 (*((Handle(Geom2d_TrimmedCurve)*)&pc));
365 pc = TC->BasisCurve();
374 //=======================================================================
375 //function : CurveOnSurface
377 //=======================================================================
379 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
380 Handle(Geom2d_Curve)& C,
381 Handle(Geom_Surface)& S,
383 Standard_Real& First,
386 // find the representation
387 BRep_ListIteratorOfListOfCurveRepresentation itcr
388 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
390 while (itcr.More()) {
391 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
392 if (cr->IsCurveOnSurface()) {
393 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
396 L = E.Location() * GC->Location();
397 GC->Range(First,Last);
403 C = Handle(Geom2d_Curve)();
404 S = Handle(Geom_Surface)();
405 L = TopLoc_Location();
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,
419 const Standard_Integer Index)
421 Standard_Integer i = 0;
422 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
424 // find the representation
425 BRep_ListIteratorOfListOfCurveRepresentation itcr
426 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
428 while (itcr.More()) {
429 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
430 if (cr->IsCurveOnSurface()) {
431 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
433 if (i > Index) break;
435 // JMB le 21 Mai 1999
436 // it is done as in the other CurveOnSurface methods, ie. take into account
437 // the orientation in case of cut edges (return PCurve2)
438 // otherwise there is a risk to loop curves or to not get the prover one.
439 if (GC->IsCurveOnClosedSurface() && Eisreversed)
444 L = E.Location() * GC->Location();
445 GC->Range(First,Last);
452 C = Handle(Geom2d_Curve)();
453 S = Handle(Geom_Surface)();
454 L = TopLoc_Location();
457 //=======================================================================
458 //function : PolygonOnSurface
459 //purpose : Returns the polygon associated to the edge in the
460 // parametric space of the face. Returns a NULL
461 // handle if this polygon does not exist.
462 //=======================================================================
464 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
465 const TopoDS_Face& F)
468 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
469 TopoDS_Edge aLocalEdge = E;
470 if (F.Orientation() == TopAbs_REVERSED) {
471 aLocalEdge.Reverse();
472 // return PolygonOnSurface(E,S,l);
474 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
476 // return PolygonOnSurface(E,S,l);
477 return PolygonOnSurface(aLocalEdge,S,l);
480 //=======================================================================
481 //function : PolygonOnSurface
482 //purpose : Returns the polygon associated to the edge in the
483 // parametric space of the surface. Returns a NULL
484 // handle if this polygon does not exist.
485 //=======================================================================
487 static const Handle(Poly_Polygon2D) nullPolygon2D;
489 Handle(Poly_Polygon2D)
490 BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
491 const Handle(Geom_Surface)& S,
492 const TopLoc_Location& L)
494 TopLoc_Location l = L.Predivided(E.Location());
495 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
497 // find the representation
498 BRep_ListIteratorOfListOfCurveRepresentation itcr
499 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
501 while (itcr.More()) {
502 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
503 if (cr->IsPolygonOnSurface(S,l)) {
504 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
505 return cr->Polygon2();
507 return cr->Polygon();
512 return nullPolygon2D;
515 //=======================================================================
516 //function : PolygonOnSurface
518 //=======================================================================
520 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
521 Handle(Poly_Polygon2D)& P,
522 Handle(Geom_Surface)& S,
525 // find the representation
526 BRep_ListIteratorOfListOfCurveRepresentation itcr
527 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
529 while (itcr.More()) {
530 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
531 if (cr->IsPolygonOnSurface()) {
532 const Handle(BRep_PolygonOnSurface)& PS =
533 *((Handle(BRep_PolygonOnSurface)*)&cr);
536 L = E.Location() * PS->Location();
542 L = TopLoc_Location();
543 P = Handle(Poly_Polygon2D)();
544 S = Handle(Geom_Surface)();
547 //=======================================================================
548 //function : PolygonOnSurface
550 //=======================================================================
552 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
553 Handle(Poly_Polygon2D)& P,
554 Handle(Geom_Surface)& S,
556 const Standard_Integer Index)
558 Standard_Integer i = 0;
560 // find the representation
561 BRep_ListIteratorOfListOfCurveRepresentation itcr
562 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
564 while (itcr.More()) {
565 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
566 if (cr->IsPolygonOnSurface()) {
567 const Handle(BRep_PolygonOnSurface)& PS =
568 *((Handle(BRep_PolygonOnSurface)*)&cr);
570 if (i > Index) break;
574 L = E.Location() * PS->Location();
581 L = TopLoc_Location();
582 P = Handle(Poly_Polygon2D)();
583 S = Handle(Geom_Surface)();
586 //=======================================================================
587 //function : PolygonOnTriangulation
588 //purpose : Returns the polygon associated to the edge in the
589 // parametric space of the face. Returns a NULL
590 // handle if this polygon does not exist.
591 //=======================================================================
593 static const Handle(Poly_PolygonOnTriangulation) nullArray;
595 const Handle(Poly_PolygonOnTriangulation)&
596 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
597 const Handle(Poly_Triangulation)& T,
598 const TopLoc_Location& L)
600 TopLoc_Location l = L.Predivided(E.Location());
601 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
603 // find the representation
604 BRep_ListIteratorOfListOfCurveRepresentation itcr
605 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
607 while (itcr.More()) {
608 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
609 if ( cr->IsPolygonOnTriangulation(T,l)) {
610 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
611 return cr->PolygonOnTriangulation2();
613 return cr->PolygonOnTriangulation();
621 //=======================================================================
622 //function : PolygonOnTriangulation
624 //=======================================================================
627 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
628 Handle(Poly_PolygonOnTriangulation)& P,
629 Handle(Poly_Triangulation)& T,
632 // find the representation
633 BRep_ListIteratorOfListOfCurveRepresentation itcr
634 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
636 while (itcr.More()) {
637 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
638 if (cr->IsPolygonOnTriangulation()) {
639 const Handle(BRep_PolygonOnTriangulation)& PT =
640 *((Handle(BRep_PolygonOnTriangulation)*)&cr);
641 P = PT->PolygonOnTriangulation();
642 T = PT->Triangulation();
643 L = E.Location() * PT->Location();
649 L = TopLoc_Location();
650 P = Handle(Poly_PolygonOnTriangulation)();
651 T = Handle(Poly_Triangulation)();
654 //=======================================================================
655 //function : PolygonOnTriangulation
657 //=======================================================================
660 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
661 Handle(Poly_PolygonOnTriangulation)& P,
662 Handle(Poly_Triangulation)& T,
664 const Standard_Integer Index)
666 Standard_Integer i = 0;
668 // find the representation
669 BRep_ListIteratorOfListOfCurveRepresentation itcr
670 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
672 while (itcr.More()) {
673 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
674 if (cr->IsPolygonOnTriangulation()) {
675 const Handle(BRep_PolygonOnTriangulation)& PT =
676 *((Handle(BRep_PolygonOnTriangulation)*)&cr);
678 if (i > Index) break;
680 T = PT->Triangulation();
681 P = PT->PolygonOnTriangulation();
682 L = E.Location() * PT->Location();
689 L = TopLoc_Location();
690 P = Handle(Poly_PolygonOnTriangulation)();
691 T = Handle(Poly_Triangulation)();
694 //=======================================================================
695 //function : IsClosed
696 //purpose : Returns True if <E> has two PCurves in the
697 // parametric space of <F>. i.e. <F> is on a closed
698 // surface and <E> is on the closing curve.
699 //=======================================================================
701 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
702 const TopoDS_Face& F)
705 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
706 if (IsClosed(E,S,l)) return Standard_True;
707 return IsClosed(E, BRep_Tool::Triangulation(F,l));
710 //=======================================================================
711 //function : IsClosed
712 //purpose : Returns True if <E> has two PCurves in the
713 // parametric space of <S>. i.e. <S> is a closed
714 // surface and <E> is on the closing curve.
715 //=======================================================================
717 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
718 const Handle(Geom_Surface)& S,
719 const TopLoc_Location& L)
721 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
723 return Standard_False;
725 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
727 TopLoc_Location l = L.Predivided(E.Location());
729 // find the representation
730 BRep_ListIteratorOfListOfCurveRepresentation itcr
731 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
733 while (itcr.More()) {
734 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
735 if (cr->IsCurveOnSurface(S,l) &&
736 cr->IsCurveOnClosedSurface())
737 return Standard_True;
740 return Standard_False;
743 //=======================================================================
744 //function : IsClosed
745 //purpose : Returns True if <E> has two arrays of indices in
746 // the triangulation <T>.
747 //=======================================================================
749 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
750 const Handle(Poly_Triangulation)& T)
752 TopLoc_Location l = E.Location();
754 // find the representation
755 BRep_ListIteratorOfListOfCurveRepresentation itcr
756 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
758 while (itcr.More()) {
759 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
760 if (cr->IsPolygonOnTriangulation(T,l) &&
761 cr->IsPolygonOnClosedTriangulation())
762 return Standard_True;
765 return Standard_False;
768 //=======================================================================
769 //function : Tolerance
770 //purpose : Returns the tolerance for <E>.
771 //=======================================================================
773 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
775 Standard_Real p = (*((Handle(BRep_TEdge)*)&E.TShape()))->Tolerance();
776 Standard_Real pMin = Precision::Confusion();
777 if (p > pMin) return p;
781 //=======================================================================
782 //function : SameParameter
783 //purpose : Returns the SameParameter flag for the edge.
784 //=======================================================================
786 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
788 return (*((Handle(BRep_TEdge)*)&E.TShape()))->SameParameter();
791 //=======================================================================
792 //function : SameRange
793 //purpose : Returns the SameRange flag for the edge.
794 //=======================================================================
796 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
798 return (*((Handle(BRep_TEdge)*)&E.TShape()))->SameRange();
801 //=======================================================================
802 //function : Degenerated
803 //purpose : Returns True if the edge is degenerated.
804 //=======================================================================
806 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
808 return (*((Handle(BRep_TEdge)*)&E.TShape()))->Degenerated();
811 //=======================================================================
814 //=======================================================================
816 void BRep_Tool::Range(const TopoDS_Edge& E,
817 Standard_Real& First,
820 // set the range to all the representations
821 BRep_ListIteratorOfListOfCurveRepresentation itcr
822 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
824 while (itcr.More()) {
825 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
826 if (cr->IsCurve3D()) {
827 const Handle(BRep_Curve3D)& CR = *((Handle(BRep_Curve3D)*)&cr);
828 if (!CR->Curve3D().IsNull()) {
834 else if (cr->IsCurveOnSurface()) {
835 const Handle(BRep_GCurve)& CR = *((Handle(BRep_GCurve)*)&cr);
844 //=======================================================================
847 //=======================================================================
849 void BRep_Tool::Range(const TopoDS_Edge& E,
850 const Handle(Geom_Surface)& S,
851 const TopLoc_Location& L,
852 Standard_Real& First,
855 TopLoc_Location l = L.Predivided(E.Location());
857 // find the representation
858 BRep_ListIteratorOfListOfCurveRepresentation itcr
859 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
861 while (itcr.More()) {
862 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
863 if (cr->IsCurveOnSurface(S,l)) {
864 (*((Handle(BRep_GCurve)*)&cr))->Range(First,Last);
872 (*((Handle(BRep_TEdge)*)&E.TShape()))->Modified(Standard_True);
875 //=======================================================================
878 //=======================================================================
880 void BRep_Tool::Range(const TopoDS_Edge& E,
881 const TopoDS_Face& F,
882 Standard_Real& First,
886 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
887 Range(E,S,L,First,Last);
890 //=======================================================================
891 //function : UVPoints
893 //=======================================================================
895 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
896 const Handle(Geom_Surface)& S,
897 const TopLoc_Location& L,
901 TopLoc_Location l = L.Predivided(E.Location());
902 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
904 // find the representation
905 BRep_ListIteratorOfListOfCurveRepresentation itcr
906 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
908 while (itcr.More()) {
909 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
910 if (cr->IsCurveOnSurface(S,l)) {
911 if (cr->IsCurveOnClosedSurface() && Eisreversed)
912 (*((Handle(BRep_CurveOnClosedSurface)*)&cr))->UVPoints2(PFirst,PLast);
914 (*((Handle(BRep_CurveOnSurface)*)&cr))->UVPoints(PFirst,PLast);
920 // for planar surface project the vertices
921 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
922 Handle(Geom_Plane) GP;
923 Handle(Geom_RectangularTrimmedSurface) GRTS;
924 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
926 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
928 GP = Handle(Geom_Plane)::DownCast(S);
929 //fin modif du 21-05-97
931 // get the two vertices
933 TopExp::Vertices(E,Vf,Vl);
935 TopLoc_Location Linverted = L.Inverted();
939 gp_Pln pln = GP->Pln();
943 gp_Pnt PF = BRep_Tool::Pnt(Vf);
944 ElSLib::Parameters(pln,PF,u,v);
946 PFirst.SetCoord(u,v);
950 gp_Pnt PL = BRep_Tool::Pnt(Vl);
951 ElSLib::Parameters(pln,PL,u,v);
957 //=======================================================================
958 //function : UVPoints
960 //=======================================================================
962 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
963 const TopoDS_Face& F,
968 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
969 TopoDS_Edge aLocalEdge = E;
970 if (F.Orientation() == TopAbs_REVERSED) {
971 aLocalEdge.Reverse();
972 // UVPoints(E,S,L,PFirst,PLast);
974 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
976 // UVPoints(E,S,L,PFirst,PLast);
977 UVPoints(aLocalEdge,S,L,PFirst,PLast);
980 //=======================================================================
981 //function : SetUVPoints
983 //=======================================================================
985 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
986 const Handle(Geom_Surface)& S,
987 const TopLoc_Location& L,
988 const gp_Pnt2d& PFirst,
989 const gp_Pnt2d& PLast)
991 TopLoc_Location l = L.Predivided(E.Location());
992 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
994 // find the representation
995 BRep_ListIteratorOfListOfCurveRepresentation itcr
996 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
998 while (itcr.More()) {
999 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1000 if (cr->IsCurveOnSurface(S,l)) {
1001 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1002 (*((Handle(BRep_CurveOnClosedSurface)*) &cr))->
1003 SetUVPoints2(PFirst,PLast);
1005 (*((Handle(BRep_CurveOnSurface)*) &cr))->
1006 SetUVPoints(PFirst,PLast);
1012 //=======================================================================
1013 //function : SetUVPoints
1015 //=======================================================================
1017 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1018 const TopoDS_Face& F,
1019 const gp_Pnt2d& PFirst,
1020 const gp_Pnt2d& PLast)
1023 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1024 TopoDS_Edge aLocalEdge = E;
1025 if (F.Orientation() == TopAbs_REVERSED) {
1026 aLocalEdge.Reverse();
1027 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1030 // SetUVPoints(E,S,L,PFirst,PLast);
1031 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1034 //=======================================================================
1035 //function : HasContinuity
1036 //purpose : Returns True if the edge is on the surfaces of the
1038 //=======================================================================
1040 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1041 const TopoDS_Face& F1,
1042 const TopoDS_Face& F2)
1044 TopLoc_Location l1,l2;
1045 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1046 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1047 return HasContinuity(E,S1,S2,l1,l2);
1050 //=======================================================================
1051 //function : Continuity
1052 //purpose : Returns the continuity.
1053 //=======================================================================
1055 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1056 const TopoDS_Face& F1,
1057 const TopoDS_Face& F2)
1059 TopLoc_Location l1,l2;
1060 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1061 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1062 return Continuity(E,S1,S2,l1,l2);
1065 //=======================================================================
1066 //function : HasContinuity
1067 //purpose : Returns True if the edge is on the surfaces.
1068 //=======================================================================
1070 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1071 const Handle(Geom_Surface)& S1,
1072 const Handle(Geom_Surface)& S2,
1073 const TopLoc_Location& L1,
1074 const TopLoc_Location& L2)
1076 const TopLoc_Location& Eloc = E.Location();
1077 TopLoc_Location l1 = L1.Predivided(Eloc);
1078 TopLoc_Location l2 = L2.Predivided(Eloc);
1080 // find the representation
1081 BRep_ListIteratorOfListOfCurveRepresentation itcr
1082 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1084 while (itcr.More()) {
1085 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1086 if (cr->IsRegularity(S1,S2,l1,l2))
1087 return Standard_True;
1090 return Standard_False;
1093 //=======================================================================
1094 //function : Continuity
1095 //purpose : Returns the continuity.
1096 //=======================================================================
1098 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1099 const Handle(Geom_Surface)& S1,
1100 const Handle(Geom_Surface)& S2,
1101 const TopLoc_Location& L1,
1102 const TopLoc_Location& L2)
1104 TopLoc_Location l1 = L1.Predivided(E.Location());
1105 TopLoc_Location l2 = L2.Predivided(E.Location());
1107 // find the representation
1108 BRep_ListIteratorOfListOfCurveRepresentation itcr
1109 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1111 while (itcr.More()) {
1112 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1113 if (cr->IsRegularity(S1,S2,l1,l2))
1114 return cr->Continuity();
1120 //=======================================================================
1121 //function : HasContinuity
1122 //purpose : Returns True if the edge is on some two surfaces.
1123 //=======================================================================
1125 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1127 BRep_ListIteratorOfListOfCurveRepresentation itcr
1128 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
1130 for (; itcr.More(); itcr.Next())
1132 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1133 if (CR->IsRegularity())
1134 return Standard_True;
1136 return Standard_False;
1139 //=======================================================================
1141 //purpose : Returns the 3d point.
1142 //=======================================================================
1144 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1146 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1147 gp_Pnt P = TV->Pnt();
1148 P.Transform(V.Location().Transformation());
1152 //=======================================================================
1153 //function : Tolerance
1154 //purpose : Returns the tolerance.
1155 //=======================================================================
1157 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1159 Standard_Real p = (*((Handle(BRep_TVertex)*)&V.TShape()))->Tolerance();
1160 Standard_Real pMin = Precision::Confusion();
1161 if (p > pMin) return p;
1165 //=======================================================================
1166 //function : Parameter
1167 //purpose : Returns the parameter of <V> on <E>.
1168 //=======================================================================
1170 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1171 const TopoDS_Edge& E)
1174 // Search the vertex in the edge
1176 Standard_Boolean rev = Standard_False;
1178 TopAbs_Orientation orient = TopAbs_INTERNAL;
1180 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1182 // if the edge has no vertices
1183 // and is degenerated use the vertex orientation
1186 if (!itv.More() && Degenerated(E)) {
1187 orient = V.Orientation();
1190 while (itv.More()) {
1191 const TopoDS_Shape& Vcur = itv.Value();
1192 if (V.IsSame(Vcur)) {
1197 rev = E.Orientation() == TopAbs_REVERSED;
1198 if (Vcur.Orientation() == V.Orientation()) {
1206 if (!VF.IsNull()) orient = VF.Orientation();
1210 if (orient == TopAbs_FORWARD) {
1211 BRep_Tool::Range(E,f,l);
1212 return (rev) ? l : f;
1215 else if (orient == TopAbs_REVERSED) {
1216 BRep_Tool::Range(E,f,l);
1217 return (rev) ? f : l;
1222 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
1223 L = L.Predivided(V.Location());
1224 if (!C.IsNull() || Degenerated(E)) {
1225 BRep_ListIteratorOfListOfPointRepresentation itpr
1226 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1228 while (itpr.More()) {
1229 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1230 if (pr->IsPointOnCurve(C,L)) {
1231 Standard_Real p = pr->Parameter();
1232 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1234 // Closed curves RLE 16 june 94
1235 if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p;
1236 if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p;
1237 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1238 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1239 Standard_Real tol = BRep_Tool::Tolerance(V);
1240 if (Pf.Distance(Pl) < tol) {
1241 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1242 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1243 else res = l;//p = l;
1254 // let us try with the first pcurve
1255 Handle(Geom2d_Curve) PC;
1256 Handle(Geom_Surface) S;
1257 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
1258 L = L.Predivided(V.Location());
1259 BRep_ListIteratorOfListOfPointRepresentation itpr
1260 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1262 while (itpr.More()) {
1263 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1264 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
1265 Standard_Real p = pr->Parameter();
1266 // Closed curves RLE 16 june 94
1267 if (PC->IsClosed()) {
1268 if ((p == PC->FirstParameter()) ||
1269 (p == PC->LastParameter())) {
1270 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1271 else p = PC->LastParameter();
1281 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1285 //=======================================================================
1286 //function : Parameter
1287 //purpose : Returns the parameters of the vertex on the
1288 // pcurve of the edge on the face.
1289 //=======================================================================
1291 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1292 const TopoDS_Edge& E,
1293 const TopoDS_Face& F)
1296 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1297 return BRep_Tool::Parameter(V,E,S,L);
1300 //=======================================================================
1301 //function : Parameter
1302 //purpose : Returns the parameters of the vertex on the
1303 // pcurve of the edge on the surface.
1304 //=======================================================================
1306 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1307 const TopoDS_Edge& E,
1308 const Handle(Geom_Surface)& S,
1309 const TopLoc_Location& L)
1311 // Search the vertex in the edge
1313 Standard_Boolean rev = Standard_False;
1315 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1317 while (itv.More()) {
1318 if (V.IsSame(itv.Value())) {
1319 if (VF.IsNull()) VF = itv.Value();
1321 rev = E.Orientation() == TopAbs_REVERSED;
1322 if (itv.Value().Orientation() == V.Orientation())
1329 TopAbs_Orientation orient = TopAbs_INTERNAL;
1330 if (!VF.IsNull()) orient = VF.Orientation();
1334 if (orient == TopAbs_FORWARD) {
1335 BRep_Tool::Range(E,S,L,f,l);
1336 return (rev) ? l : f;
1339 else if (orient == TopAbs_REVERSED) {
1340 BRep_Tool::Range(E,S,L,f,l);
1341 return (rev) ? f : l;
1345 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1346 BRep_ListIteratorOfListOfPointRepresentation itpr
1347 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1349 while (itpr.More()) {
1350 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1351 return itpr.Value()->Parameter();
1356 //----------------------------------------------------------
1359 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1360 L1 = L1.Predivided(V.Location());
1361 if (!C.IsNull() || Degenerated(E)) {
1362 BRep_ListIteratorOfListOfPointRepresentation itpr
1363 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1365 while (itpr.More()) {
1366 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1367 if (pr->IsPointOnCurve(C,L1)) {
1368 Standard_Real p = pr->Parameter();
1369 Standard_Real res = p;
1371 // Closed curves RLE 16 june 94
1372 if (Precision::IsNegativeInfinite(f)) return res;
1373 if (Precision::IsPositiveInfinite(l)) return res;
1374 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1375 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1376 Standard_Real tol = BRep_Tool::Tolerance(V);
1377 if (Pf.Distance(Pl) < tol) {
1378 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1379 if (V.Orientation() == TopAbs_FORWARD) res = f;
1390 //----------------------------------------------------------
1392 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1396 //=======================================================================
1397 //function : Parameters
1398 //purpose : Returns the parameters of the vertex on the face.
1399 //=======================================================================
1401 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1402 const TopoDS_Face& F)
1405 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1406 L = L.Predivided(V.Location());
1407 BRep_ListIteratorOfListOfPointRepresentation itpr
1408 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1409 // It is checked if there is PointRepresentation (case non Manifold)
1411 while (itpr.More()) {
1412 if (itpr.Value()->IsPointOnSurface(S,L)) {
1413 return gp_Pnt2d(itpr.Value()->Parameter(),
1414 itpr.Value()->Parameter2());
1419 TopoDS_Vertex Vf,Vl;
1421 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1422 // even if often there is a way to make more economically than above...
1423 TopExp_Explorer exp;
1424 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1425 E = TopoDS::Edge(exp.Current());
1426 TopExp::Vertices(E, Vf, Vl);
1427 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1429 UVPoints(E, F, Pf, Pl);
1430 if (V.IsSame(Vf)) return Pf;
1431 else return Pl;//Ambiguity (natural) for degenerated edges.
1434 Standard_NoSuchObject::Raise("BRep_Tool:: no parameters on surface");
1435 return gp_Pnt2d(0,0);
1437 //=======================================================================
1438 //function : IsClosed
1439 //purpose : Returns <True> if S if flaged Closed, if S is a
1440 // Solid,Shell or Compound returns <True> is S has no free boundaries.
1441 //=======================================================================
1442 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Shape& S)
1444 if (S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_SOLID ||
1445 S.ShapeType() == TopAbs_COMPOUND) {
1446 TopTools_MapOfShape M;
1447 TopExp_Explorer exp;
1448 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
1449 // for (TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next()) {
1450 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1451 if (BRep_Tool::Degenerated(E)) continue;
1452 if (!M.Add(E)) M.Remove(E);
1454 if ( M.IsEmpty()) return 1;
1456 return (S.Closed());
1459 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1460 //=======================================================================
1461 //function : IsPlane
1463 //=======================================================================
1464 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1466 Standard_Boolean bRet;
1467 Handle(Geom_Plane) aGP;
1468 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1469 Handle(Geom_OffsetSurface) aGOFS;
1471 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1472 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1474 if(!aGOFS.IsNull()) {
1475 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1477 else if(!aGRTS.IsNull()) {
1478 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1481 aGP=Handle(Geom_Plane)::DownCast(aS);