Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-07-07 |
2 | // Created by: Remi LEQUETTE | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
42cf5bc1 | 17 | |
18 | #include <BRep_Curve3D.hxx> | |
7fd59977 | 19 | #include <BRep_CurveOnClosedSurface.hxx> |
42cf5bc1 | 20 | #include <BRep_CurveOnSurface.hxx> |
21 | #include <BRep_CurveRepresentation.hxx> | |
7fd59977 | 22 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
7fd59977 | 23 | #include <BRep_ListIteratorOfListOfPointRepresentation.hxx> |
42cf5bc1 | 24 | #include <BRep_PointRepresentation.hxx> |
7fd59977 | 25 | #include <BRep_Polygon3D.hxx> |
7fd59977 | 26 | #include <BRep_PolygonOnClosedSurface.hxx> |
7fd59977 | 27 | #include <BRep_PolygonOnClosedTriangulation.hxx> |
42cf5bc1 | 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> | |
7fd59977 | 34 | #include <ElSLib.hxx> |
42cf5bc1 | 35 | #include <Geom2d_Curve.hxx> |
36 | #include <Geom2d_TrimmedCurve.hxx> | |
37 | #include <Geom2dAdaptor.hxx> | |
38 | #include <Geom_Curve.hxx> | |
39 | #include <Geom_OffsetSurface.hxx> | |
7fd59977 | 40 | #include <Geom_Plane.hxx> |
41 | #include <Geom_RectangularTrimmedSurface.hxx> | |
42cf5bc1 | 42 | #include <Geom_Surface.hxx> |
7fd59977 | 43 | #include <Geom_TrimmedCurve.hxx> |
7fd59977 | 44 | #include <GeomAdaptor_HCurve.hxx> |
45 | #include <GeomAdaptor_HSurface.hxx> | |
42cf5bc1 | 46 | #include <GeomProjLib.hxx> |
47 | #include <gp_Pnt.hxx> | |
48 | #include <gp_Pnt2d.hxx> | |
49 | #include <NCollection_IncAllocator.hxx> | |
50 | #include <NCollection_Map.hxx> | |
7fd59977 | 51 | #include <Poly_Polygon2D.hxx> |
42cf5bc1 | 52 | #include <Poly_Polygon3D.hxx> |
7fd59977 | 53 | #include <Poly_PolygonOnTriangulation.hxx> |
42cf5bc1 | 54 | #include <Poly_Triangulation.hxx> |
55 | #include <Precision.hxx> | |
56 | #include <ProjLib_ProjectedCurve.hxx> | |
57 | #include <Standard_NoSuchObject.hxx> | |
58 | #include <Standard_NullObject.hxx> | |
59 | #include <TopExp.hxx> | |
60 | #include <TopExp_Explorer.hxx> | |
61 | #include <TopLoc_Location.hxx> | |
62 | #include <TopoDS.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> | |
ab860031 | 70 | #include <TopTools_ShapeMapHasher.hxx> |
92efcf78 | 71 | #include <BRep_GCurve.hxx> |
ab860031 | 72 | |
7fd59977 | 73 | //modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f |
74 | static | |
75 | Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS); | |
76 | //modified by NIZNHY-PKV Fri Oct 17 14:13:33 2008t | |
77 | // | |
78 | //======================================================================= | |
79 | //function : Surface | |
80 | //purpose : Returns the geometric surface of the face. Returns | |
81 | // in <L> the location for the surface. | |
82 | //======================================================================= | |
83 | ||
84 | const Handle(Geom_Surface)& BRep_Tool::Surface(const TopoDS_Face& F, | |
703a6abd | 85 | TopLoc_Location& L) |
7fd59977 | 86 | { |
8447359f | 87 | const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get()); |
7fd59977 | 88 | L = F.Location() * TF->Location(); |
89 | return TF->Surface(); | |
90 | } | |
91 | ||
92 | //======================================================================= | |
93 | //function : Surface | |
94 | //purpose : Returns the geometric surface of the face. It can | |
95 | // be a copy if there is a Location. | |
96 | //======================================================================= | |
97 | ||
98 | Handle(Geom_Surface) BRep_Tool::Surface(const TopoDS_Face& F) | |
99 | { | |
8447359f | 100 | const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get()); |
101 | const Handle(Geom_Surface)& S = TF->Surface(); | |
7fd59977 | 102 | |
103 | if(S.IsNull()) return S; | |
104 | ||
8447359f | 105 | TopLoc_Location L = F.Location() * TF->Location(); |
7fd59977 | 106 | if (!L.IsIdentity()) { |
8447359f | 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); | |
7fd59977 | 110 | } |
111 | return S; | |
112 | } | |
113 | ||
114 | //======================================================================= | |
115 | //function : Triangulation | |
116 | //purpose : Returns the Triangulation of the face. It is a | |
117 | // null handle if there is no triangulation. | |
118 | //======================================================================= | |
119 | ||
8447359f | 120 | const Handle(Poly_Triangulation)& BRep_Tool::Triangulation(const TopoDS_Face& F, |
121 | TopLoc_Location& L) | |
7fd59977 | 122 | { |
123 | L = F.Location(); | |
8447359f | 124 | const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get()); |
125 | return TF->Triangulation(); | |
7fd59977 | 126 | } |
127 | ||
128 | //======================================================================= | |
129 | //function : Tolerance | |
130 | //purpose : Returns the tolerance of the face. | |
131 | //======================================================================= | |
132 | ||
133 | Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F) | |
134 | { | |
8447359f | 135 | const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get()); |
136 | Standard_Real p = TF->Tolerance(); | |
7fd59977 | 137 | Standard_Real pMin = Precision::Confusion(); |
138 | if (p > pMin) return p; | |
139 | else return pMin; | |
140 | } | |
141 | ||
142 | //======================================================================= | |
143 | //function : NaturalRestriction | |
144 | //purpose : Returns the NaturalRestriction flag of the face. | |
145 | //======================================================================= | |
146 | ||
147 | Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F) | |
148 | { | |
8447359f | 149 | const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get()); |
150 | return TF->NaturalRestriction(); | |
7fd59977 | 151 | } |
152 | ||
153 | //======================================================================= | |
154 | //function : Curve | |
155 | //purpose : Returns the 3D curve of the edge. May be a Null | |
156 | // handle. Returns in <L> the location for the curve. | |
157 | // In <First> and <Last> the parameter range. | |
158 | //======================================================================= | |
159 | ||
2b442de5 | 160 | static const Handle(Geom_Curve) nullCurve; |
7fd59977 | 161 | |
162 | const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E, | |
703a6abd O |
163 | TopLoc_Location& L, |
164 | Standard_Real& First, | |
165 | Standard_Real& Last) | |
7fd59977 | 166 | { |
167 | // find the representation | |
8447359f | 168 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
169 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 170 | |
171 | while (itcr.More()) { | |
172 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
173 | if (cr->IsCurve3D()) { | |
8447359f | 174 | const BRep_Curve3D* GC = static_cast<const BRep_Curve3D*>(cr.get()); |
7fd59977 | 175 | L = E.Location() * GC->Location(); |
176 | GC->Range(First,Last); | |
177 | return GC->Curve3D(); | |
178 | } | |
179 | itcr.Next(); | |
180 | } | |
181 | L.Identity(); | |
182 | return nullCurve; | |
183 | } | |
184 | ||
185 | //======================================================================= | |
186 | //function : Curve | |
187 | //purpose : Returns the 3D curve of the edge. May be a Null handle. | |
188 | // In <First> and <Last> the parameter range. | |
189 | // It can be a copy if there is a Location. | |
190 | //======================================================================= | |
191 | ||
192 | Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E, | |
703a6abd O |
193 | Standard_Real& First, |
194 | Standard_Real& Last) | |
7fd59977 | 195 | { |
196 | TopLoc_Location L; | |
8447359f | 197 | const Handle(Geom_Curve)& C = Curve(E,L,First,Last); |
7fd59977 | 198 | if ( !C.IsNull() ) { |
7fd59977 | 199 | if ( !L.IsIdentity() ) { |
8447359f | 200 | Handle(Geom_Geometry) aCopy = C->Transformed(L.Transformation()); |
201 | Geom_Curve* aGC = static_cast<Geom_Curve*>(aCopy.get()); | |
202 | return Handle(Geom_Curve)(aGC); | |
7fd59977 | 203 | } |
204 | } | |
205 | return C; | |
206 | } | |
207 | ||
208 | //======================================================================= | |
209 | //function : IsGeometric | |
210 | //purpose : Returns True if <E> is a 3d curve or a curve on | |
211 | // surface. | |
212 | //======================================================================= | |
213 | ||
214 | Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E) | |
215 | { | |
216 | // find the representation | |
8447359f | 217 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
218 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 219 | |
220 | while (itcr.More()) { | |
221 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
222 | if (cr->IsCurve3D()) { | |
223 | Standard_Real first, last; | |
224 | TopLoc_Location L; | |
225 | const Handle(Geom_Curve)& C = BRep_Tool::Curve(E, L, first, last); | |
226 | if (!C.IsNull()) return Standard_True; | |
227 | } | |
228 | else if (cr->IsCurveOnSurface()) return Standard_True; | |
229 | itcr.Next(); | |
230 | } | |
231 | return Standard_False; | |
232 | } | |
233 | ||
234 | //======================================================================= | |
235 | //function : Polygon3D | |
236 | //purpose : Returns the 3D polygon of the edge. May be a Null | |
237 | // handle. Returns in <L> the location for the polygon. | |
238 | //======================================================================= | |
239 | ||
2b442de5 S |
240 | static const Handle(Poly_Polygon3D) nullPolygon3D; |
241 | ||
7fd59977 | 242 | const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E, |
703a6abd | 243 | TopLoc_Location& L) |
7fd59977 | 244 | { |
245 | // find the representation | |
8447359f | 246 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
247 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 248 | |
249 | while (itcr.More()) { | |
250 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
251 | if (cr->IsPolygon3D()) { | |
8447359f | 252 | const BRep_Polygon3D* GC = static_cast<const BRep_Polygon3D*>(cr.get()); |
7fd59977 | 253 | L = E.Location() * GC->Location(); |
254 | return GC->Polygon3D(); | |
255 | } | |
256 | itcr.Next(); | |
257 | } | |
258 | L.Identity(); | |
259 | return nullPolygon3D; | |
260 | } | |
261 | ||
262 | //======================================================================= | |
263 | //function : CurveOnSurface | |
264 | //purpose : Returns the curve associated to the edge in the | |
265 | // parametric space of the face. Returns a NULL | |
266 | // handle if this curve does not exist. Returns in | |
267 | // <First> and <Last> the parameter range. | |
268 | //======================================================================= | |
269 | ||
270 | Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
271 | const TopoDS_Face& F, |
272 | Standard_Real& First, | |
273 | Standard_Real& Last) | |
7fd59977 | 274 | { |
275 | TopLoc_Location l; | |
276 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l); | |
277 | TopoDS_Edge aLocalEdge = E; | |
278 | if (F.Orientation() == TopAbs_REVERSED) { | |
279 | aLocalEdge.Reverse(); | |
280 | // return CurveOnSurface(E,S,l,First,Last); | |
281 | } | |
282 | // return CurveOnSurface(TopoDS::Edge(E.Reversed()),S,l,First,Last); | |
283 | // else | |
284 | // return CurveOnSurface(E,S,l,First,Last); | |
285 | return CurveOnSurface(aLocalEdge,S,l,First,Last); | |
286 | } | |
287 | ||
288 | //======================================================================= | |
289 | //function : CurveOnSurface | |
290 | //purpose : Returns the curve associated to the edge in the | |
291 | // parametric space of the surface. Returns a NULL | |
292 | // handle if this curve does not exist. Returns in | |
293 | // <First> and <Last> the parameter range. | |
294 | //======================================================================= | |
295 | ||
2b442de5 | 296 | static const Handle(Geom2d_Curve) nullPCurve; |
7fd59977 | 297 | |
298 | Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
299 | const Handle(Geom_Surface)& S, |
300 | const TopLoc_Location& L, | |
301 | Standard_Real& First, | |
302 | Standard_Real& Last) | |
7fd59977 | 303 | { |
304 | TopLoc_Location loc = L.Predivided(E.Location()); | |
305 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
306 | ||
307 | // find the representation | |
8447359f | 308 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
309 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 310 | |
311 | while (itcr.More()) { | |
312 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
313 | if (cr->IsCurveOnSurface(S,loc)) { | |
8447359f | 314 | const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get()); |
7fd59977 | 315 | GC->Range(First,Last); |
316 | if (GC->IsCurveOnClosedSurface() && Eisreversed) | |
703a6abd | 317 | return GC->PCurve2(); |
7fd59977 | 318 | else |
703a6abd | 319 | return GC->PCurve(); |
7fd59977 | 320 | } |
321 | itcr.Next(); | |
322 | } | |
7fd59977 | 323 | |
324 | // for planar surface and 3d curve try a projection | |
325 | // modif 21-05-97 : for RectangularTrimmedSurface, try a projection | |
326 | Handle(Geom_Plane) GP; | |
327 | Handle(Geom_RectangularTrimmedSurface) GRTS; | |
328 | GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
329 | if(!GRTS.IsNull()) | |
330 | GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface()); | |
331 | else | |
332 | GP = Handle(Geom_Plane)::DownCast(S); | |
333 | //fin modif du 21-05-97 | |
334 | ||
bdd1223f | 335 | if (!GP.IsNull()) |
336 | { | |
703a6abd O |
337 | Handle(GeomAdaptor_HCurve) HC; |
338 | Handle(GeomAdaptor_HSurface) HS; | |
339 | ||
340 | HC = new GeomAdaptor_HCurve(); | |
341 | HS = new GeomAdaptor_HSurface(); | |
7fd59977 | 342 | |
bdd1223f | 343 | TopLoc_Location aCurveLocation; |
7fd59977 | 344 | |
0d969553 | 345 | Standard_Real f, l;// for those who call with (u,u). |
bdd1223f | 346 | Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, aCurveLocation, f, l); |
7fd59977 | 347 | |
bdd1223f | 348 | if (C3d.IsNull()) |
349 | { | |
350 | return nullPCurve; | |
351 | } | |
7fd59977 | 352 | |
b7723347 | 353 | aCurveLocation = aCurveLocation.Predivided(L); |
354 | First = f; Last = l; //Range of edge must not be modified | |
7fd59977 | 355 | |
bdd1223f | 356 | if (!aCurveLocation.IsIdentity()) |
357 | { | |
358 | const gp_Trsf& T = aCurveLocation.Transformation(); | |
b7723347 | 359 | Handle(Geom_Geometry) GC3d = C3d->Transformed(T); |
c5f3a425 | 360 | C3d = Handle(Geom_Curve)::DownCast (GC3d); |
b7723347 | 361 | f = C3d->TransformedParameter(f, T); |
362 | l = C3d->TransformedParameter(l, T); | |
7fd59977 | 363 | } |
364 | GeomAdaptor_Surface& GAS = HS->ChangeSurface(); | |
b7723347 | 365 | GAS.Load(GP); |
bdd1223f | 366 | |
7fd59977 | 367 | Handle(Geom_Curve) ProjOnPlane = |
8ac0cf52 | 368 | GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l,Standard_True,Standard_False), |
b7723347 | 369 | GP, |
370 | GP->Position().Direction(), | |
703a6abd | 371 | Standard_True); |
bdd1223f | 372 | |
7fd59977 | 373 | GeomAdaptor_Curve& GAC = HC->ChangeCurve(); |
374 | GAC.Load(ProjOnPlane); | |
375 | ||
376 | ProjLib_ProjectedCurve Proj(HS,HC); | |
377 | Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj); | |
378 | ||
379 | if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) { | |
380 | Handle(Geom2d_TrimmedCurve) TC = | |
c5f3a425 | 381 | Handle(Geom2d_TrimmedCurve)::DownCast (pc); |
7fd59977 | 382 | pc = TC->BasisCurve(); |
383 | } | |
b7723347 | 384 | |
7fd59977 | 385 | return pc; |
386 | } | |
387 | ||
388 | return nullPCurve; | |
389 | } | |
390 | ||
391 | //======================================================================= | |
392 | //function : CurveOnSurface | |
393 | //purpose : | |
394 | //======================================================================= | |
395 | ||
396 | void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
397 | Handle(Geom2d_Curve)& C, |
398 | Handle(Geom_Surface)& S, | |
399 | TopLoc_Location& L, | |
400 | Standard_Real& First, | |
401 | Standard_Real& Last) | |
7fd59977 | 402 | { |
403 | // find the representation | |
8447359f | 404 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
405 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 406 | |
407 | while (itcr.More()) { | |
408 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
409 | if (cr->IsCurveOnSurface()) { | |
8447359f | 410 | const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get()); |
7fd59977 | 411 | C = GC->PCurve(); |
412 | S = GC->Surface(); | |
413 | L = E.Location() * GC->Location(); | |
414 | GC->Range(First,Last); | |
415 | return; | |
416 | } | |
417 | itcr.Next(); | |
418 | } | |
419 | ||
420 | C = Handle(Geom2d_Curve)(); | |
421 | S = Handle(Geom_Surface)(); | |
422 | L = TopLoc_Location(); | |
423 | } | |
424 | ||
425 | //======================================================================= | |
426 | //function : CurveOnSurface | |
427 | //purpose : | |
428 | //======================================================================= | |
429 | ||
430 | void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
431 | Handle(Geom2d_Curve)& C, |
432 | Handle(Geom_Surface)& S, | |
433 | TopLoc_Location& L, | |
434 | Standard_Real& First, | |
435 | Standard_Real& Last, | |
436 | const Standard_Integer Index) | |
7fd59977 | 437 | { |
438 | Standard_Integer i = 0; | |
439 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
440 | ||
441 | // find the representation | |
8447359f | 442 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
443 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 444 | |
445 | while (itcr.More()) { | |
446 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
447 | if (cr->IsCurveOnSurface()) { | |
8447359f | 448 | const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get()); |
7fd59977 | 449 | i++; |
450 | if (i > Index) break; | |
451 | if (i == Index) { | |
703a6abd | 452 | // JMB le 21 Mai 1999 |
0d969553 Y |
453 | // it is done as in the other CurveOnSurface methods, ie. take into account |
454 | // the orientation in case of cut edges (return PCurve2) | |
455 | // otherwise there is a risk to loop curves or to not get the prover one. | |
703a6abd O |
456 | if (GC->IsCurveOnClosedSurface() && Eisreversed) |
457 | C = GC->PCurve2(); | |
458 | else | |
459 | C = GC->PCurve(); | |
460 | S = GC->Surface(); | |
461 | L = E.Location() * GC->Location(); | |
462 | GC->Range(First,Last); | |
463 | return; | |
7fd59977 | 464 | } |
465 | } | |
466 | itcr.Next(); | |
467 | } | |
468 | ||
469 | C = Handle(Geom2d_Curve)(); | |
470 | S = Handle(Geom_Surface)(); | |
471 | L = TopLoc_Location(); | |
472 | } | |
473 | ||
474 | //======================================================================= | |
475 | //function : PolygonOnSurface | |
476 | //purpose : Returns the polygon associated to the edge in the | |
477 | // parametric space of the face. Returns a NULL | |
478 | // handle if this polygon does not exist. | |
479 | //======================================================================= | |
480 | ||
481 | Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E, | |
703a6abd | 482 | const TopoDS_Face& F) |
7fd59977 | 483 | { |
484 | TopLoc_Location l; | |
485 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l); | |
486 | TopoDS_Edge aLocalEdge = E; | |
487 | if (F.Orientation() == TopAbs_REVERSED) { | |
488 | aLocalEdge.Reverse(); | |
489 | // return PolygonOnSurface(E,S,l); | |
490 | } | |
491 | // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l); | |
492 | // else | |
493 | // return PolygonOnSurface(E,S,l); | |
494 | return PolygonOnSurface(aLocalEdge,S,l); | |
495 | } | |
496 | ||
497 | //======================================================================= | |
498 | //function : PolygonOnSurface | |
499 | //purpose : Returns the polygon associated to the edge in the | |
500 | // parametric space of the surface. Returns a NULL | |
501 | // handle if this polygon does not exist. | |
502 | //======================================================================= | |
503 | ||
2b442de5 | 504 | static const Handle(Poly_Polygon2D) nullPolygon2D; |
7fd59977 | 505 | |
8447359f | 506 | Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E, |
507 | const Handle(Geom_Surface)& S, | |
508 | const TopLoc_Location& L) | |
7fd59977 | 509 | { |
510 | TopLoc_Location l = L.Predivided(E.Location()); | |
511 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
512 | ||
513 | // find the representation | |
8447359f | 514 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
515 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 516 | |
517 | while (itcr.More()) { | |
518 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
519 | if (cr->IsPolygonOnSurface(S,l)) { | |
520 | if (cr->IsPolygonOnClosedSurface() && Eisreversed ) | |
703a6abd | 521 | return cr->Polygon2(); |
7fd59977 | 522 | else |
703a6abd | 523 | return cr->Polygon(); |
7fd59977 | 524 | } |
525 | itcr.Next(); | |
526 | } | |
527 | ||
528 | return nullPolygon2D; | |
529 | } | |
530 | ||
531 | //======================================================================= | |
532 | //function : PolygonOnSurface | |
533 | //purpose : | |
534 | //======================================================================= | |
535 | ||
536 | void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
537 | Handle(Poly_Polygon2D)& P, |
538 | Handle(Geom_Surface)& S, | |
539 | TopLoc_Location& L) | |
7fd59977 | 540 | { |
541 | // find the representation | |
8447359f | 542 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
543 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 544 | |
545 | while (itcr.More()) { | |
546 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
547 | if (cr->IsPolygonOnSurface()) { | |
8447359f | 548 | const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get()); |
7fd59977 | 549 | P = PS->Polygon(); |
550 | S = PS->Surface(); | |
551 | L = E.Location() * PS->Location(); | |
552 | return; | |
553 | } | |
554 | itcr.Next(); | |
555 | } | |
556 | ||
557 | L = TopLoc_Location(); | |
558 | P = Handle(Poly_Polygon2D)(); | |
559 | S = Handle(Geom_Surface)(); | |
560 | } | |
561 | ||
562 | //======================================================================= | |
563 | //function : PolygonOnSurface | |
564 | //purpose : | |
565 | //======================================================================= | |
566 | ||
567 | void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E, | |
703a6abd O |
568 | Handle(Poly_Polygon2D)& P, |
569 | Handle(Geom_Surface)& S, | |
570 | TopLoc_Location& L, | |
571 | const Standard_Integer Index) | |
7fd59977 | 572 | { |
573 | Standard_Integer i = 0; | |
574 | ||
575 | // find the representation | |
8447359f | 576 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
577 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 578 | |
579 | while (itcr.More()) { | |
580 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
581 | if (cr->IsPolygonOnSurface()) { | |
8447359f | 582 | const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get()); |
7fd59977 | 583 | i++; |
584 | if (i > Index) break; | |
585 | if (i == Index) { | |
703a6abd O |
586 | P = PS->Polygon(); |
587 | S = PS->Surface(); | |
588 | L = E.Location() * PS->Location(); | |
589 | return; | |
7fd59977 | 590 | } |
591 | } | |
592 | itcr.Next(); | |
593 | } | |
594 | ||
595 | L = TopLoc_Location(); | |
596 | P = Handle(Poly_Polygon2D)(); | |
597 | S = Handle(Geom_Surface)(); | |
598 | } | |
599 | ||
600 | //======================================================================= | |
601 | //function : PolygonOnTriangulation | |
602 | //purpose : Returns the polygon associated to the edge in the | |
603 | // parametric space of the face. Returns a NULL | |
604 | // handle if this polygon does not exist. | |
605 | //======================================================================= | |
606 | ||
2b442de5 | 607 | static const Handle(Poly_PolygonOnTriangulation) nullArray; |
7fd59977 | 608 | |
609 | const Handle(Poly_PolygonOnTriangulation)& | |
610 | BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E, | |
703a6abd O |
611 | const Handle(Poly_Triangulation)& T, |
612 | const TopLoc_Location& L) | |
7fd59977 | 613 | { |
614 | TopLoc_Location l = L.Predivided(E.Location()); | |
615 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
616 | ||
617 | // find the representation | |
8447359f | 618 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
619 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 620 | |
621 | while (itcr.More()) { | |
622 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
623 | if ( cr->IsPolygonOnTriangulation(T,l)) { | |
624 | if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed ) | |
703a6abd | 625 | return cr->PolygonOnTriangulation2(); |
7fd59977 | 626 | else |
703a6abd | 627 | return cr->PolygonOnTriangulation(); |
7fd59977 | 628 | } |
629 | itcr.Next(); | |
630 | } | |
631 | ||
632 | return nullArray; | |
633 | } | |
634 | ||
635 | //======================================================================= | |
636 | //function : PolygonOnTriangulation | |
637 | //purpose : | |
638 | //======================================================================= | |
639 | ||
640 | void | |
641 | BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E, | |
703a6abd O |
642 | Handle(Poly_PolygonOnTriangulation)& P, |
643 | Handle(Poly_Triangulation)& T, | |
644 | TopLoc_Location& L) | |
7fd59977 | 645 | { |
646 | // find the representation | |
8447359f | 647 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
648 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 649 | |
650 | while (itcr.More()) { | |
651 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
652 | if (cr->IsPolygonOnTriangulation()) { | |
8447359f | 653 | const BRep_PolygonOnTriangulation* PT = |
654 | static_cast<const BRep_PolygonOnTriangulation*>(cr.get()); | |
7fd59977 | 655 | P = PT->PolygonOnTriangulation(); |
656 | T = PT->Triangulation(); | |
657 | L = E.Location() * PT->Location(); | |
658 | return; | |
659 | } | |
660 | itcr.Next(); | |
661 | } | |
662 | ||
663 | L = TopLoc_Location(); | |
664 | P = Handle(Poly_PolygonOnTriangulation)(); | |
665 | T = Handle(Poly_Triangulation)(); | |
666 | } | |
667 | ||
668 | //======================================================================= | |
669 | //function : PolygonOnTriangulation | |
670 | //purpose : | |
671 | //======================================================================= | |
672 | ||
673 | void | |
674 | BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E, | |
703a6abd O |
675 | Handle(Poly_PolygonOnTriangulation)& P, |
676 | Handle(Poly_Triangulation)& T, | |
677 | TopLoc_Location& L, | |
678 | const Standard_Integer Index) | |
7fd59977 | 679 | { |
680 | Standard_Integer i = 0; | |
681 | ||
682 | // find the representation | |
8447359f | 683 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
684 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 685 | |
686 | while (itcr.More()) { | |
687 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
688 | if (cr->IsPolygonOnTriangulation()) { | |
8447359f | 689 | const BRep_PolygonOnTriangulation* PT = |
690 | static_cast<const BRep_PolygonOnTriangulation*>(cr.get()); | |
7fd59977 | 691 | i++; |
692 | if (i > Index) break; | |
693 | if (i == Index) { | |
703a6abd O |
694 | T = PT->Triangulation(); |
695 | P = PT->PolygonOnTriangulation(); | |
696 | L = E.Location() * PT->Location(); | |
697 | return; | |
7fd59977 | 698 | } |
699 | } | |
700 | itcr.Next(); | |
701 | } | |
702 | ||
703 | L = TopLoc_Location(); | |
704 | P = Handle(Poly_PolygonOnTriangulation)(); | |
705 | T = Handle(Poly_Triangulation)(); | |
706 | } | |
707 | ||
708 | //======================================================================= | |
709 | //function : IsClosed | |
710 | //purpose : Returns True if <E> has two PCurves in the | |
711 | // parametric space of <F>. i.e. <F> is on a closed | |
712 | // surface and <E> is on the closing curve. | |
713 | //======================================================================= | |
714 | ||
715 | Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E, | |
703a6abd | 716 | const TopoDS_Face& F) |
7fd59977 | 717 | { |
718 | TopLoc_Location l; | |
719 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l); | |
720 | if (IsClosed(E,S,l)) return Standard_True; | |
ff0a70a1 | 721 | const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l); |
722 | return IsClosed(E, T, l); | |
7fd59977 | 723 | } |
724 | ||
725 | //======================================================================= | |
726 | //function : IsClosed | |
727 | //purpose : Returns True if <E> has two PCurves in the | |
728 | // parametric space of <S>. i.e. <S> is a closed | |
729 | // surface and <E> is on the closing curve. | |
730 | //======================================================================= | |
731 | ||
732 | Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E, | |
703a6abd O |
733 | const Handle(Geom_Surface)& S, |
734 | const TopLoc_Location& L) | |
7fd59977 | 735 | { |
736 | //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f | |
737 | if (IsPlane(S)) { | |
738 | return Standard_False; | |
739 | } | |
740 | //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t | |
741 | // | |
742 | TopLoc_Location l = L.Predivided(E.Location()); | |
743 | ||
744 | // find the representation | |
8447359f | 745 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
746 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 747 | |
748 | while (itcr.More()) { | |
749 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
750 | if (cr->IsCurveOnSurface(S,l) && | |
703a6abd | 751 | cr->IsCurveOnClosedSurface()) |
7fd59977 | 752 | return Standard_True; |
753 | itcr.Next(); | |
754 | } | |
755 | return Standard_False; | |
756 | } | |
757 | ||
758 | //======================================================================= | |
759 | //function : IsClosed | |
760 | //purpose : Returns True if <E> has two arrays of indices in | |
761 | // the triangulation <T>. | |
762 | //======================================================================= | |
763 | ||
764 | Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E, | |
ff0a70a1 | 765 | const Handle(Poly_Triangulation)& T, |
766 | const TopLoc_Location& L) | |
7fd59977 | 767 | { |
ff0a70a1 | 768 | TopLoc_Location l = L.Predivided(E.Location()); |
7fd59977 | 769 | |
770 | // find the representation | |
8447359f | 771 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
772 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 773 | |
774 | while (itcr.More()) { | |
775 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
776 | if (cr->IsPolygonOnTriangulation(T,l) && | |
703a6abd | 777 | cr->IsPolygonOnClosedTriangulation()) |
7fd59977 | 778 | return Standard_True; |
779 | itcr.Next(); | |
780 | } | |
781 | return Standard_False; | |
782 | } | |
783 | ||
784 | //======================================================================= | |
785 | //function : Tolerance | |
786 | //purpose : Returns the tolerance for <E>. | |
787 | //======================================================================= | |
788 | ||
789 | Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E) | |
790 | { | |
8447359f | 791 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
792 | Standard_Real p = TE->Tolerance(); | |
7fd59977 | 793 | Standard_Real pMin = Precision::Confusion(); |
794 | if (p > pMin) return p; | |
795 | else return pMin; | |
796 | } | |
797 | ||
798 | //======================================================================= | |
799 | //function : SameParameter | |
800 | //purpose : Returns the SameParameter flag for the edge. | |
801 | //======================================================================= | |
802 | ||
803 | Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E) | |
804 | { | |
8447359f | 805 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
806 | return TE->SameParameter(); | |
7fd59977 | 807 | } |
808 | ||
809 | //======================================================================= | |
810 | //function : SameRange | |
811 | //purpose : Returns the SameRange flag for the edge. | |
812 | //======================================================================= | |
813 | ||
814 | Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E) | |
815 | { | |
8447359f | 816 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
817 | return TE->SameRange(); | |
7fd59977 | 818 | } |
819 | ||
820 | //======================================================================= | |
821 | //function : Degenerated | |
822 | //purpose : Returns True if the edge is degenerated. | |
823 | //======================================================================= | |
824 | ||
825 | Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E) | |
826 | { | |
8447359f | 827 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
828 | return TE->Degenerated(); | |
7fd59977 | 829 | } |
830 | ||
831 | //======================================================================= | |
832 | //function : Range | |
833 | //purpose : | |
834 | //======================================================================= | |
835 | ||
836 | void BRep_Tool::Range(const TopoDS_Edge& E, | |
703a6abd O |
837 | Standard_Real& First, |
838 | Standard_Real& Last) | |
7fd59977 | 839 | { |
840 | // set the range to all the representations | |
8447359f | 841 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
842 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 843 | |
844 | while (itcr.More()) { | |
845 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
846 | if (cr->IsCurve3D()) { | |
8447359f | 847 | const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get()); |
7fd59977 | 848 | if (!CR->Curve3D().IsNull()) { |
703a6abd O |
849 | First = CR->First(); |
850 | Last = CR->Last(); | |
851 | break; | |
7fd59977 | 852 | } |
853 | } | |
854 | else if (cr->IsCurveOnSurface()) { | |
8447359f | 855 | const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get()); |
7fd59977 | 856 | First = CR->First(); |
857 | Last = CR->Last(); | |
858 | break; | |
859 | } | |
860 | itcr.Next(); | |
861 | } | |
862 | } | |
863 | ||
864 | //======================================================================= | |
865 | //function : Range | |
866 | //purpose : | |
867 | //======================================================================= | |
868 | ||
869 | void BRep_Tool::Range(const TopoDS_Edge& E, | |
703a6abd O |
870 | const Handle(Geom_Surface)& S, |
871 | const TopLoc_Location& L, | |
872 | Standard_Real& First, | |
873 | Standard_Real& Last) | |
7fd59977 | 874 | { |
875 | TopLoc_Location l = L.Predivided(E.Location()); | |
876 | ||
877 | // find the representation | |
8447359f | 878 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
879 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 880 | |
881 | while (itcr.More()) { | |
882 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
883 | if (cr->IsCurveOnSurface(S,l)) { | |
8447359f | 884 | const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get()); |
885 | CR->Range(First,Last); | |
7fd59977 | 886 | break; |
887 | } | |
888 | itcr.Next(); | |
889 | } | |
890 | if (!itcr.More()) { | |
891 | Range(E,First,Last); | |
892 | } | |
8447359f | 893 | E.TShape()->Modified(Standard_True); |
7fd59977 | 894 | } |
895 | ||
896 | //======================================================================= | |
897 | //function : Range | |
898 | //purpose : | |
899 | //======================================================================= | |
900 | ||
901 | void BRep_Tool::Range(const TopoDS_Edge& E, | |
703a6abd O |
902 | const TopoDS_Face& F, |
903 | Standard_Real& First, | |
904 | Standard_Real& Last) | |
7fd59977 | 905 | { |
906 | TopLoc_Location L; | |
907 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
908 | Range(E,S,L,First,Last); | |
909 | } | |
910 | ||
911 | //======================================================================= | |
912 | //function : UVPoints | |
913 | //purpose : | |
914 | //======================================================================= | |
915 | ||
916 | void BRep_Tool::UVPoints(const TopoDS_Edge& E, | |
703a6abd O |
917 | const Handle(Geom_Surface)& S, |
918 | const TopLoc_Location& L, | |
919 | gp_Pnt2d& PFirst, | |
920 | gp_Pnt2d& PLast) | |
7fd59977 | 921 | { |
922 | TopLoc_Location l = L.Predivided(E.Location()); | |
923 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
924 | ||
925 | // find the representation | |
8447359f | 926 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
927 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 928 | |
929 | while (itcr.More()) { | |
930 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
931 | if (cr->IsCurveOnSurface(S,l)) { | |
932 | if (cr->IsCurveOnClosedSurface() && Eisreversed) | |
8447359f | 933 | { |
934 | const BRep_CurveOnClosedSurface* CR = | |
935 | static_cast<const BRep_CurveOnClosedSurface*>(cr.get()); | |
936 | CR->UVPoints2(PFirst, PLast); | |
937 | } | |
7fd59977 | 938 | else |
8447359f | 939 | { |
940 | const BRep_CurveOnSurface* CR = | |
941 | static_cast<const BRep_CurveOnSurface*>(cr.get()); | |
942 | CR->UVPoints(PFirst, PLast); | |
943 | } | |
7fd59977 | 944 | return; |
945 | } | |
946 | itcr.Next(); | |
947 | } | |
948 | ||
949 | // for planar surface project the vertices | |
950 | // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices | |
951 | Handle(Geom_Plane) GP; | |
952 | Handle(Geom_RectangularTrimmedSurface) GRTS; | |
953 | GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
954 | if(!GRTS.IsNull()) | |
955 | GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface()); | |
956 | else | |
957 | GP = Handle(Geom_Plane)::DownCast(S); | |
958 | //fin modif du 21-05-97 | |
959 | if (!GP.IsNull()) { | |
960 | // get the two vertices | |
961 | TopoDS_Vertex Vf,Vl; | |
962 | TopExp::Vertices(E,Vf,Vl); | |
963 | ||
964 | TopLoc_Location Linverted = L.Inverted(); | |
965 | Vf.Move(Linverted); | |
966 | Vl.Move(Linverted); | |
967 | Standard_Real u,v; | |
968 | gp_Pln pln = GP->Pln(); | |
969 | ||
970 | u=v=0.; | |
971 | if (!Vf.IsNull()) { | |
972 | gp_Pnt PF = BRep_Tool::Pnt(Vf); | |
973 | ElSLib::Parameters(pln,PF,u,v); | |
974 | } | |
975 | PFirst.SetCoord(u,v); | |
976 | ||
977 | u=v=0.; | |
978 | if (!Vl.IsNull()) { | |
979 | gp_Pnt PL = BRep_Tool::Pnt(Vl); | |
980 | ElSLib::Parameters(pln,PL,u,v); | |
981 | } | |
982 | PLast.SetCoord(u,v); | |
983 | } | |
984 | } | |
985 | ||
986 | //======================================================================= | |
987 | //function : UVPoints | |
988 | //purpose : | |
989 | //======================================================================= | |
990 | ||
991 | void BRep_Tool::UVPoints(const TopoDS_Edge& E, | |
703a6abd O |
992 | const TopoDS_Face& F, |
993 | gp_Pnt2d& PFirst, | |
994 | gp_Pnt2d& PLast) | |
7fd59977 | 995 | { |
996 | TopLoc_Location L; | |
997 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
998 | TopoDS_Edge aLocalEdge = E; | |
999 | if (F.Orientation() == TopAbs_REVERSED) { | |
1000 | aLocalEdge.Reverse(); | |
1001 | // UVPoints(E,S,L,PFirst,PLast); | |
1002 | } | |
1003 | // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast); | |
1004 | // else | |
1005 | // UVPoints(E,S,L,PFirst,PLast); | |
1006 | UVPoints(aLocalEdge,S,L,PFirst,PLast); | |
1007 | } | |
1008 | ||
1009 | //======================================================================= | |
1010 | //function : SetUVPoints | |
1011 | //purpose : | |
1012 | //======================================================================= | |
1013 | ||
1014 | void BRep_Tool::SetUVPoints(const TopoDS_Edge& E, | |
703a6abd O |
1015 | const Handle(Geom_Surface)& S, |
1016 | const TopLoc_Location& L, | |
1017 | const gp_Pnt2d& PFirst, | |
1018 | const gp_Pnt2d& PLast) | |
7fd59977 | 1019 | { |
1020 | TopLoc_Location l = L.Predivided(E.Location()); | |
1021 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); | |
1022 | ||
1023 | // find the representation | |
8447359f | 1024 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
1025 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 1026 | |
1027 | while (itcr.More()) { | |
8447359f | 1028 | Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
7fd59977 | 1029 | if (cr->IsCurveOnSurface(S,l)) { |
1030 | if (cr->IsCurveOnClosedSurface() && Eisreversed) | |
8447359f | 1031 | { |
1032 | BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get()); | |
1033 | CS->SetUVPoints2(PFirst, PLast); | |
1034 | } | |
7fd59977 | 1035 | else |
8447359f | 1036 | { |
1037 | BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get()); | |
1038 | CS->SetUVPoints(PFirst, PLast); | |
1039 | } | |
7fd59977 | 1040 | } |
1041 | itcr.Next(); | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | //======================================================================= | |
1046 | //function : SetUVPoints | |
1047 | //purpose : | |
1048 | //======================================================================= | |
1049 | ||
1050 | void BRep_Tool::SetUVPoints(const TopoDS_Edge& E, | |
703a6abd O |
1051 | const TopoDS_Face& F, |
1052 | const gp_Pnt2d& PFirst, | |
1053 | const gp_Pnt2d& PLast) | |
7fd59977 | 1054 | { |
1055 | TopLoc_Location L; | |
1056 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
1057 | TopoDS_Edge aLocalEdge = E; | |
1058 | if (F.Orientation() == TopAbs_REVERSED) { | |
1059 | aLocalEdge.Reverse(); | |
1060 | // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast); | |
1061 | } | |
1062 | // else | |
1063 | // SetUVPoints(E,S,L,PFirst,PLast); | |
1064 | SetUVPoints(aLocalEdge,S,L,PFirst,PLast); | |
1065 | } | |
1066 | ||
1067 | //======================================================================= | |
1068 | //function : HasContinuity | |
1069 | //purpose : Returns True if the edge is on the surfaces of the | |
1070 | // two faces. | |
1071 | //======================================================================= | |
1072 | ||
1073 | Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E, | |
703a6abd O |
1074 | const TopoDS_Face& F1, |
1075 | const TopoDS_Face& F2) | |
7fd59977 | 1076 | { |
1077 | TopLoc_Location l1,l2; | |
1078 | const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1); | |
1079 | const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2); | |
1080 | return HasContinuity(E,S1,S2,l1,l2); | |
1081 | } | |
1082 | ||
1083 | //======================================================================= | |
1084 | //function : Continuity | |
1085 | //purpose : Returns the continuity. | |
1086 | //======================================================================= | |
1087 | ||
1088 | GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E, | |
703a6abd O |
1089 | const TopoDS_Face& F1, |
1090 | const TopoDS_Face& F2) | |
7fd59977 | 1091 | { |
1092 | TopLoc_Location l1,l2; | |
1093 | const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1); | |
1094 | const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2); | |
1095 | return Continuity(E,S1,S2,l1,l2); | |
1096 | } | |
1097 | ||
1098 | //======================================================================= | |
1099 | //function : HasContinuity | |
1100 | //purpose : Returns True if the edge is on the surfaces. | |
1101 | //======================================================================= | |
1102 | ||
1103 | Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E, | |
703a6abd O |
1104 | const Handle(Geom_Surface)& S1, |
1105 | const Handle(Geom_Surface)& S2, | |
1106 | const TopLoc_Location& L1, | |
1107 | const TopLoc_Location& L2) | |
7fd59977 | 1108 | { |
1109 | const TopLoc_Location& Eloc = E.Location(); | |
1110 | TopLoc_Location l1 = L1.Predivided(Eloc); | |
1111 | TopLoc_Location l2 = L2.Predivided(Eloc); | |
1112 | ||
1113 | // find the representation | |
8447359f | 1114 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
1115 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
7fd59977 | 1116 | |
1117 | while (itcr.More()) { | |
1118 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
1119 | if (cr->IsRegularity(S1,S2,l1,l2)) | |
1120 | return Standard_True; | |
1121 | itcr.Next(); | |
1122 | } | |
1123 | return Standard_False; | |
1124 | } | |
1125 | ||
1126 | //======================================================================= | |
1127 | //function : Continuity | |
1128 | //purpose : Returns the continuity. | |
1129 | //======================================================================= | |
1130 | ||
1131 | GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E, | |
703a6abd O |
1132 | const Handle(Geom_Surface)& S1, |
1133 | const Handle(Geom_Surface)& S2, | |
1134 | const TopLoc_Location& L1, | |
1135 | const TopLoc_Location& L2) | |
7fd59977 | 1136 | { |
1137 | TopLoc_Location l1 = L1.Predivided(E.Location()); | |
1138 | TopLoc_Location l2 = L2.Predivided(E.Location()); | |
1139 | ||
1140 | // find the representation | |
1141 | BRep_ListIteratorOfListOfCurveRepresentation itcr | |
1142 | ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves()); | |
1143 | ||
1144 | while (itcr.More()) { | |
1145 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
1146 | if (cr->IsRegularity(S1,S2,l1,l2)) | |
1147 | return cr->Continuity(); | |
1148 | itcr.Next(); | |
1149 | } | |
1150 | return GeomAbs_C0; | |
1151 | } | |
1152 | ||
bda83605 | 1153 | //======================================================================= |
1154 | //function : HasContinuity | |
1155 | //purpose : Returns True if the edge is on some two surfaces. | |
1156 | //======================================================================= | |
1157 | ||
1158 | Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E) | |
1159 | { | |
8447359f | 1160 | const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get()); |
1161 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
bda83605 | 1162 | |
1163 | for (; itcr.More(); itcr.Next()) | |
1164 | { | |
1165 | const Handle(BRep_CurveRepresentation)& CR = itcr.Value(); | |
1166 | if (CR->IsRegularity()) | |
1167 | return Standard_True; | |
1168 | } | |
1169 | return Standard_False; | |
1170 | } | |
1171 | ||
7fd59977 | 1172 | //======================================================================= |
1173 | //function : Pnt | |
1174 | //purpose : Returns the 3d point. | |
1175 | //======================================================================= | |
1176 | ||
1177 | gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V) | |
1178 | { | |
8447359f | 1179 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); |
1180 | ||
1181 | if (TV == 0) | |
46aed280 | 1182 | { |
1183 | Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt"); | |
1184 | } | |
1185 | ||
8447359f | 1186 | const gp_Pnt& P = TV->Pnt(); |
1187 | if (V.Location().IsIdentity()) | |
1188 | { | |
1189 | return P; | |
1190 | } | |
1191 | ||
1192 | return P.Transformed(V.Location().Transformation()); | |
7fd59977 | 1193 | } |
1194 | ||
1195 | //======================================================================= | |
1196 | //function : Tolerance | |
1197 | //purpose : Returns the tolerance. | |
1198 | //======================================================================= | |
1199 | ||
1200 | Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V) | |
1201 | { | |
8447359f | 1202 | const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get()); |
46aed280 | 1203 | |
8447359f | 1204 | if (aTVert == 0) |
46aed280 | 1205 | { |
1206 | Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt"); | |
1207 | } | |
1208 | ||
1209 | Standard_Real p = aTVert->Tolerance(); | |
7fd59977 | 1210 | Standard_Real pMin = Precision::Confusion(); |
1211 | if (p > pMin) return p; | |
1212 | else return pMin; | |
1213 | } | |
1214 | ||
1215 | //======================================================================= | |
1216 | //function : Parameter | |
1217 | //purpose : Returns the parameter of <V> on <E>. | |
1218 | //======================================================================= | |
1219 | ||
1220 | Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V, | |
8447359f | 1221 | const TopoDS_Edge& E) |
7fd59977 | 1222 | { |
1223 | ||
1224 | // Search the vertex in the edge | |
1225 | ||
1226 | Standard_Boolean rev = Standard_False; | |
1227 | TopoDS_Shape VF; | |
1228 | TopAbs_Orientation orient = TopAbs_INTERNAL; | |
1229 | ||
1230 | TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD)); | |
1231 | ||
1232 | // if the edge has no vertices | |
1233 | // and is degenerated use the vertex orientation | |
1234 | // RLE, june 94 | |
1235 | ||
1236 | if (!itv.More() && Degenerated(E)) { | |
1237 | orient = V.Orientation(); | |
1238 | } | |
1239 | ||
1240 | while (itv.More()) { | |
1241 | const TopoDS_Shape& Vcur = itv.Value(); | |
1242 | if (V.IsSame(Vcur)) { | |
1243 | if (VF.IsNull()) { | |
703a6abd | 1244 | VF = Vcur; |
7fd59977 | 1245 | } |
1246 | else { | |
703a6abd O |
1247 | rev = E.Orientation() == TopAbs_REVERSED; |
1248 | if (Vcur.Orientation() == V.Orientation()) { | |
1249 | VF = Vcur; | |
1250 | } | |
7fd59977 | 1251 | } |
1252 | } | |
1253 | itv.Next(); | |
1254 | } | |
1255 | ||
1256 | if (!VF.IsNull()) orient = VF.Orientation(); | |
1257 | ||
1258 | Standard_Real f,l; | |
1259 | ||
1260 | if (orient == TopAbs_FORWARD) { | |
1261 | BRep_Tool::Range(E,f,l); | |
1262 | return (rev) ? l : f; | |
1263 | } | |
1264 | ||
1265 | else if (orient == TopAbs_REVERSED) { | |
1266 | BRep_Tool::Range(E,f,l); | |
1267 | return (rev) ? f : l; | |
1268 | } | |
1269 | ||
1270 | else { | |
1271 | TopLoc_Location L; | |
1272 | const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l); | |
1273 | L = L.Predivided(V.Location()); | |
1274 | if (!C.IsNull() || Degenerated(E)) { | |
8447359f | 1275 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); |
1276 | BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points()); | |
7fd59977 | 1277 | |
1278 | while (itpr.More()) { | |
703a6abd O |
1279 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
1280 | if (pr->IsPointOnCurve(C,L)) { | |
1281 | Standard_Real p = pr->Parameter(); | |
1282 | Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux | |
1283 | if (!C.IsNull()) { | |
1284 | // Closed curves RLE 16 june 94 | |
1285 | if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p; | |
1286 | if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p; | |
1287 | gp_Pnt Pf = C->Value(f).Transformed(L.Transformation()); | |
1288 | gp_Pnt Pl = C->Value(l).Transformed(L.Transformation()); | |
1289 | Standard_Real tol = BRep_Tool::Tolerance(V); | |
1290 | if (Pf.Distance(Pl) < tol) { | |
1291 | if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) { | |
1292 | if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f; | |
1293 | else res = l;//p = l; | |
1294 | } | |
1295 | } | |
1296 | } | |
1297 | return res;//p; | |
1298 | } | |
1299 | itpr.Next(); | |
7fd59977 | 1300 | } |
1301 | } | |
1302 | else { | |
1303 | // no 3d curve !! | |
1304 | // let us try with the first pcurve | |
1305 | Handle(Geom2d_Curve) PC; | |
1306 | Handle(Geom_Surface) S; | |
1307 | BRep_Tool::CurveOnSurface(E,PC,S,L,f,l); | |
8447359f | 1308 | L = L.Predivided(V.Location()); |
1309 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); | |
1310 | BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points()); | |
7fd59977 | 1311 | |
1312 | while (itpr.More()) { | |
703a6abd O |
1313 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
1314 | if (pr->IsPointOnCurveOnSurface(PC,S,L)) { | |
1315 | Standard_Real p = pr->Parameter(); | |
1316 | // Closed curves RLE 16 june 94 | |
1317 | if (PC->IsClosed()) { | |
1318 | if ((p == PC->FirstParameter()) || | |
1319 | (p == PC->LastParameter())) { | |
1320 | if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter(); | |
1321 | else p = PC->LastParameter(); | |
1322 | } | |
1323 | } | |
1324 | return p; | |
1325 | } | |
1326 | itpr.Next(); | |
7fd59977 | 1327 | } |
1328 | } | |
1329 | } | |
1330 | ||
1331 | Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge"); | |
1332 | return 0; | |
1333 | } | |
1334 | ||
1335 | //======================================================================= | |
1336 | //function : Parameter | |
1337 | //purpose : Returns the parameters of the vertex on the | |
1338 | // pcurve of the edge on the face. | |
1339 | //======================================================================= | |
1340 | ||
1341 | Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V, | |
703a6abd O |
1342 | const TopoDS_Edge& E, |
1343 | const TopoDS_Face& F) | |
7fd59977 | 1344 | { |
1345 | TopLoc_Location L; | |
1346 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
1347 | return BRep_Tool::Parameter(V,E,S,L); | |
1348 | } | |
1349 | ||
1350 | //======================================================================= | |
1351 | //function : Parameter | |
1352 | //purpose : Returns the parameters of the vertex on the | |
1353 | // pcurve of the edge on the surface. | |
1354 | //======================================================================= | |
1355 | ||
1356 | Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V, | |
703a6abd O |
1357 | const TopoDS_Edge& E, |
1358 | const Handle(Geom_Surface)& S, | |
1359 | const TopLoc_Location& L) | |
7fd59977 | 1360 | { |
1361 | // Search the vertex in the edge | |
1362 | ||
1363 | Standard_Boolean rev = Standard_False; | |
1364 | TopoDS_Shape VF; | |
1365 | TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD)); | |
1366 | ||
1367 | while (itv.More()) { | |
1368 | if (V.IsSame(itv.Value())) { | |
1369 | if (VF.IsNull()) VF = itv.Value(); | |
1370 | else { | |
703a6abd O |
1371 | rev = E.Orientation() == TopAbs_REVERSED; |
1372 | if (itv.Value().Orientation() == V.Orientation()) | |
1373 | VF = itv.Value(); | |
7fd59977 | 1374 | } |
1375 | } | |
1376 | itv.Next(); | |
1377 | } | |
1378 | ||
1379 | TopAbs_Orientation orient = TopAbs_INTERNAL; | |
1380 | if (!VF.IsNull()) orient = VF.Orientation(); | |
1381 | ||
1382 | Standard_Real f,l; | |
1383 | ||
1384 | if (orient == TopAbs_FORWARD) { | |
1385 | BRep_Tool::Range(E,S,L,f,l); | |
1386 | return (rev) ? l : f; | |
1387 | } | |
1388 | ||
1389 | else if (orient == TopAbs_REVERSED) { | |
1390 | BRep_Tool::Range(E,S,L,f,l); | |
1391 | return (rev) ? f : l; | |
1392 | } | |
1393 | ||
1394 | else { | |
1395 | Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l); | |
8447359f | 1396 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); |
1397 | BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points()); | |
7fd59977 | 1398 | |
1399 | while (itpr.More()) { | |
1400 | if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L)) | |
1401 | return itpr.Value()->Parameter(); | |
1402 | itpr.Next(); | |
1403 | } | |
1404 | } | |
1405 | ||
1406 | //---------------------------------------------------------- | |
1407 | ||
1408 | TopLoc_Location L1; | |
1409 | const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l); | |
1410 | L1 = L1.Predivided(V.Location()); | |
1411 | if (!C.IsNull() || Degenerated(E)) { | |
8447359f | 1412 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); |
1413 | BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points()); | |
7fd59977 | 1414 | |
1415 | while (itpr.More()) { | |
1416 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); | |
1417 | if (pr->IsPointOnCurve(C,L1)) { | |
703a6abd O |
1418 | Standard_Real p = pr->Parameter(); |
1419 | Standard_Real res = p; | |
1420 | if (!C.IsNull()) { | |
1421 | // Closed curves RLE 16 june 94 | |
1422 | if (Precision::IsNegativeInfinite(f)) return res; | |
1423 | if (Precision::IsPositiveInfinite(l)) return res; | |
1424 | gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation()); | |
1425 | gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation()); | |
1426 | Standard_Real tol = BRep_Tool::Tolerance(V); | |
1427 | if (Pf.Distance(Pl) < tol) { | |
1428 | if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) { | |
1429 | if (V.Orientation() == TopAbs_FORWARD) res = f; | |
1430 | else res = l; | |
1431 | } | |
1432 | } | |
1433 | } | |
1434 | return res; | |
7fd59977 | 1435 | } |
1436 | itpr.Next(); | |
1437 | } | |
1438 | } | |
1439 | ||
1440 | //---------------------------------------------------------- | |
1441 | ||
1442 | Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge"); | |
1443 | return 0; | |
1444 | } | |
1445 | ||
1446 | //======================================================================= | |
1447 | //function : Parameters | |
1448 | //purpose : Returns the parameters of the vertex on the face. | |
1449 | //======================================================================= | |
1450 | ||
1451 | gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V, | |
703a6abd | 1452 | const TopoDS_Face& F) |
7fd59977 | 1453 | { |
1454 | TopLoc_Location L; | |
1455 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
1456 | L = L.Predivided(V.Location()); | |
8447359f | 1457 | const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get()); |
1458 | BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points()); | |
1459 | ||
0d969553 | 1460 | // It is checked if there is PointRepresentation (case non Manifold) |
7fd59977 | 1461 | while (itpr.More()) { |
1462 | if (itpr.Value()->IsPointOnSurface(S,L)) { | |
1463 | return gp_Pnt2d(itpr.Value()->Parameter(), | |
703a6abd | 1464 | itpr.Value()->Parameter2()); |
7fd59977 | 1465 | } |
1466 | itpr.Next(); | |
1467 | } | |
1468 | ||
1469 | TopoDS_Vertex Vf,Vl; | |
1470 | TopoDS_Edge E; | |
0d969553 Y |
1471 | // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000! |
1472 | // even if often there is a way to make more economically than above... | |
7fd59977 | 1473 | TopExp_Explorer exp; |
1474 | for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) { | |
1475 | E = TopoDS::Edge(exp.Current()); | |
1476 | TopExp::Vertices(E, Vf, Vl); | |
1477 | if ((V.IsSame(Vf)) || (V.IsSame(Vl))) { | |
1478 | gp_Pnt2d Pf, Pl; | |
1479 | UVPoints(E, F, Pf, Pl); | |
1480 | if (V.IsSame(Vf)) return Pf; | |
0d969553 | 1481 | else return Pl;//Ambiguity (natural) for degenerated edges. |
7fd59977 | 1482 | } |
1483 | } | |
1484 | Standard_NoSuchObject::Raise("BRep_Tool:: no parameters on surface"); | |
1485 | return gp_Pnt2d(0,0); | |
1486 | } | |
1487 | //======================================================================= | |
1488 | //function : IsClosed | |
ab860031 | 1489 | //purpose : |
7fd59977 | 1490 | //======================================================================= |
ab860031 | 1491 | Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape) |
7fd59977 | 1492 | { |
da72a17c | 1493 | if (theShape.ShapeType() == TopAbs_SHELL) |
ab860031 | 1494 | { |
1495 | NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator); | |
94dea18e | 1496 | TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE); |
1497 | Standard_Boolean hasBound = Standard_False; | |
1498 | for (; exp.More(); exp.Next()) | |
ab860031 | 1499 | { |
7fd59977 | 1500 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); |
ab860031 | 1501 | if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL) |
1502 | continue; | |
94dea18e | 1503 | hasBound = Standard_True; |
ab860031 | 1504 | if (!aMap.Add(E)) |
1505 | aMap.Remove(E); | |
7fd59977 | 1506 | } |
94dea18e | 1507 | return hasBound && aMap.IsEmpty(); |
7fd59977 | 1508 | } |
ab860031 | 1509 | else if (theShape.ShapeType() == TopAbs_WIRE) |
1510 | { | |
1511 | NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator); | |
94dea18e | 1512 | TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX); |
1513 | Standard_Boolean hasBound = Standard_False; | |
1514 | for (; exp.More(); exp.Next()) | |
ab860031 | 1515 | { |
1516 | const TopoDS_Shape& V = exp.Current(); | |
1517 | if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL) | |
1518 | continue; | |
94dea18e | 1519 | hasBound = Standard_True; |
ab860031 | 1520 | if (!aMap.Add(V)) |
1521 | aMap.Remove(V); | |
1522 | } | |
94dea18e | 1523 | return hasBound && aMap.IsEmpty(); |
ab860031 | 1524 | } |
da72a17c | 1525 | else if (theShape.ShapeType() == TopAbs_EDGE) |
1526 | { | |
1527 | TopoDS_Vertex aVFirst, aVLast; | |
1528 | TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast); | |
1529 | return !aVFirst.IsNull() && aVFirst.IsSame(aVLast); | |
1530 | } | |
ab860031 | 1531 | return theShape.Closed(); |
7fd59977 | 1532 | } |
1533 | ||
1534 | //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f | |
1535 | //======================================================================= | |
1536 | //function : IsPlane | |
1537 | //purpose : | |
1538 | //======================================================================= | |
1539 | Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS) | |
1540 | { | |
1541 | Standard_Boolean bRet; | |
1542 | Handle(Geom_Plane) aGP; | |
1543 | Handle(Geom_RectangularTrimmedSurface) aGRTS; | |
1544 | Handle(Geom_OffsetSurface) aGOFS; | |
1545 | // | |
1546 | aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS); | |
1547 | aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS); | |
1548 | // | |
1549 | if(!aGOFS.IsNull()) { | |
1550 | aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface()); | |
1551 | } | |
1552 | else if(!aGRTS.IsNull()) { | |
1553 | aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface()); | |
1554 | } | |
1555 | else { | |
1556 | aGP=Handle(Geom_Plane)::DownCast(aS); | |
1557 | } | |
1558 | // | |
1559 | bRet=!aGP.IsNull(); | |
1560 | // | |
1561 | return bRet; | |
1562 | } | |
ab860031 | 1563 | |
bcd19756 | 1564 | //======================================================================= |
1565 | //function : MaxTolerance | |
1566 | //purpose : | |
1567 | //======================================================================= | |
1568 | Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape, | |
1569 | const TopAbs_ShapeEnum theSubShape) | |
1570 | { | |
1571 | Standard_Real aTol = 0.0; | |
1572 | ||
1573 | // Explorer Shape-Subshape. | |
1574 | TopExp_Explorer anExpSS(theShape, theSubShape); | |
1575 | if (theSubShape == TopAbs_FACE) | |
1576 | { | |
1577 | for( ; anExpSS.More() ; anExpSS.Next() ) | |
1578 | { | |
1579 | const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); | |
1580 | aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape))); | |
1581 | } | |
1582 | } | |
1583 | else if (theSubShape == TopAbs_EDGE) | |
1584 | { | |
1585 | for( ; anExpSS.More() ; anExpSS.Next() ) | |
1586 | { | |
1587 | const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); | |
1588 | aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape))); | |
1589 | } | |
1590 | } | |
1591 | else if (theSubShape == TopAbs_VERTEX) | |
1592 | { | |
1593 | for( ; anExpSS.More() ; anExpSS.Next() ) | |
1594 | { | |
1595 | const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); | |
1596 | aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape))); | |
1597 | } | |
1598 | } | |
1599 | ||
1600 | return aTol; | |
1601 | } |