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