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