Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-12-15 |
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 | // |
973c2be1 | 8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
10 | // by the Free Software Foundation, with special exception defined in the file | |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
17 | //pmn 26/09/97 Add parameters of approximation in BuildCurve3d | |
7fd59977 | 18 | // Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 |
19 | ||
20 | #include <BRepLib.ixx> | |
21 | #include <BRepAdaptor_Surface.hxx> | |
22 | #include <BRepAdaptor_HSurface.hxx> | |
23 | #include <BRepAdaptor_HCurve2d.hxx> | |
24 | #include <BRep_Tool.hxx> | |
25 | #include <BRep_Builder.hxx> | |
26 | #include <Geom_Surface.hxx> | |
27 | #include <Geom_RectangularTrimmedSurface.hxx> | |
28 | #include <Geom_Plane.hxx> | |
29 | #include <Geom_Curve.hxx> | |
30 | #include <Geom_BSplineCurve.hxx> | |
31 | #include <Geom_TrimmedCurve.hxx> | |
32 | #include <Geom2d_Curve.hxx> | |
33 | #include <Geom2d_TrimmedCurve.hxx> | |
34 | #include <Geom2d_BSplineCurve.hxx> | |
35 | #include <GeomLib.hxx> | |
36 | #include <TopExp_Explorer.hxx> | |
37 | #include <TopoDS.hxx> | |
38 | #include <TopoDS_Edge.hxx> | |
39 | #include <TopoDS_Face.hxx> | |
40 | #include <TopoDS_Vertex.hxx> | |
41 | #include <TopTools_MapOfShape.hxx> | |
42 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> | |
43 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
44 | #include <TopExp.hxx> | |
45 | #include <gp.hxx> | |
46 | #include <gp_Ax2.hxx> | |
47 | #include <gp_Pln.hxx> | |
48 | #include <Standard_Real.hxx> | |
49 | #include <Precision.hxx> | |
50 | #include <BRep_GCurve.hxx> | |
51 | #include <BRep_TEdge.hxx> | |
52 | #include <BRep_TFace.hxx> | |
53 | #include <AppParCurves_MultiCurve.hxx> | |
54 | #include <AppParCurves_MultiBSpCurve.hxx> | |
55 | #include <BRep_ListOfCurveRepresentation.hxx> | |
56 | #include <BRep_CurveRepresentation.hxx> | |
57 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> | |
58 | #include <BRep_TVertex.hxx> | |
41194117 | 59 | #include <AdvApprox_ApproxAFunction.hxx> |
7fd59977 | 60 | #include <Approx_SameParameter.hxx> |
61 | #include <TColgp_Array1OfPnt.hxx> | |
62 | #include <TColgp_Array1OfPnt2d.hxx> | |
63 | #include <TColStd_Array1OfReal.hxx> | |
7fd59977 | 64 | #include <TColStd_MapOfTransient.hxx> |
65 | #include <GeomAdaptor_Curve.hxx> | |
66 | #include <GeomAdaptor_HCurve.hxx> | |
67 | #include <GeomAdaptor_Surface.hxx> | |
68 | #include <GeomAdaptor_HSurface.hxx> | |
69 | #include <Geom2dAdaptor_Curve.hxx> | |
70 | #include <Geom2dAdaptor_HCurve.hxx> | |
71 | #include <Geom2dAdaptor.hxx> | |
72 | #include <Geom2dConvert.hxx> | |
73 | #include <GCPnts_QuasiUniformDeflection.hxx> | |
74 | #include <BSplCLib.hxx> | |
75 | #include <ElSLib.hxx> | |
76 | #include <Adaptor3d_CurveOnSurface.hxx> | |
77 | #include <Extrema_LocateExtPC.hxx> | |
78 | #include <ProjLib_ProjectedCurve.hxx> | |
79 | #include <BRepClass3d_SolidClassifier.hxx> | |
80 | #include <Bnd_Box.hxx> | |
81 | #include <BRepBndLib.hxx> | |
82 | #include <Approx_CurvilinearParameter.hxx> | |
83 | #include <Geom_BSplineSurface.hxx> | |
84 | ||
7fd59977 | 85 | |
41194117 | 86 | // TODO - not thread-safe static variables |
7fd59977 | 87 | static Standard_Real thePrecision = Precision::Confusion(); |
88 | static Handle(Geom_Plane) thePlane; | |
89 | ||
90 | //======================================================================= | |
91 | //function : Precision | |
92 | //purpose : | |
93 | //======================================================================= | |
94 | ||
95 | void BRepLib::Precision(const Standard_Real P) | |
96 | { | |
97 | thePrecision = P; | |
98 | } | |
99 | ||
100 | //======================================================================= | |
101 | //function : Precision | |
102 | //purpose : | |
103 | //======================================================================= | |
104 | ||
105 | Standard_Real BRepLib::Precision() | |
106 | { | |
107 | return thePrecision; | |
108 | } | |
109 | ||
110 | //======================================================================= | |
111 | //function : Plane | |
112 | //purpose : | |
113 | //======================================================================= | |
114 | ||
115 | void BRepLib::Plane(const Handle(Geom_Plane)& P) | |
116 | { | |
117 | thePlane = P; | |
118 | } | |
119 | ||
120 | ||
121 | //======================================================================= | |
122 | //function : Plane | |
123 | //purpose : | |
124 | //======================================================================= | |
125 | ||
126 | const Handle(Geom_Plane)& BRepLib::Plane() | |
127 | { | |
128 | if (thePlane.IsNull()) thePlane = new Geom_Plane(gp::XOY()); | |
129 | return thePlane; | |
130 | } | |
131 | //======================================================================= | |
132 | //function : CheckSameRange | |
133 | //purpose : | |
134 | //======================================================================= | |
135 | ||
136 | Standard_Boolean BRepLib::CheckSameRange(const TopoDS_Edge& AnEdge, | |
137 | const Standard_Real Tolerance) | |
138 | { | |
139 | Standard_Boolean IsSameRange = Standard_True, | |
140 | first_time_in = Standard_True ; | |
141 | ||
142 | BRep_ListIteratorOfListOfCurveRepresentation an_Iterator | |
143 | ((*((Handle(BRep_TEdge)*)&AnEdge.TShape()))->ChangeCurves()); | |
144 | ||
145 | Standard_Real first, last; | |
7fd59977 | 146 | Standard_Real current_first =0., current_last =0. ; |
7fd59977 | 147 | Handle(BRep_GCurve) geometric_representation_ptr ; |
148 | ||
149 | while (IsSameRange && an_Iterator.More()) { | |
150 | geometric_representation_ptr = | |
151 | Handle(BRep_GCurve)::DownCast(an_Iterator.Value()); | |
152 | if (!geometric_representation_ptr.IsNull()) { | |
153 | ||
154 | first = geometric_representation_ptr->First(); | |
155 | last = geometric_representation_ptr->Last(); | |
156 | if (first_time_in ) { | |
157 | current_first = first ; | |
158 | current_last = last ; | |
159 | first_time_in = Standard_False ; | |
160 | } | |
161 | else { | |
162 | IsSameRange = (Abs(current_first - first) <= Tolerance) | |
163 | && (Abs(current_last -last) <= Tolerance ) ; | |
164 | } | |
165 | } | |
166 | an_Iterator.Next() ; | |
167 | } | |
168 | return IsSameRange ; | |
169 | } | |
170 | ||
171 | //======================================================================= | |
172 | //function : SameRange | |
173 | //purpose : | |
174 | //======================================================================= | |
175 | ||
176 | void BRepLib::SameRange(const TopoDS_Edge& AnEdge, | |
177 | const Standard_Real Tolerance) | |
178 | { | |
179 | BRep_ListIteratorOfListOfCurveRepresentation an_Iterator | |
180 | ((*((Handle(BRep_TEdge)*)&AnEdge.TShape()))->ChangeCurves()); | |
181 | ||
182 | Handle(Geom2d_Curve) Curve2dPtr, Curve2dPtr2, NewCurve2dPtr, NewCurve2dPtr2; | |
183 | TopLoc_Location LocalLoc ; | |
184 | ||
185 | Standard_Boolean first_time_in = Standard_True, | |
186 | has_curve, | |
187 | has_closed_curve ; | |
188 | Handle(BRep_GCurve) geometric_representation_ptr ; | |
189 | Standard_Real first, | |
190 | current_first, | |
191 | last, | |
192 | current_last ; | |
193 | ||
194 | const Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, | |
195 | LocalLoc, | |
196 | current_first, | |
197 | current_last); | |
198 | if (!C.IsNull()) { | |
199 | first_time_in = Standard_False ; | |
200 | } | |
201 | ||
202 | while (an_Iterator.More()) { | |
203 | geometric_representation_ptr = | |
204 | Handle(BRep_GCurve)::DownCast(an_Iterator.Value()); | |
205 | if (! geometric_representation_ptr.IsNull()) { | |
206 | has_closed_curve = | |
207 | has_curve = Standard_False ; | |
208 | first = geometric_representation_ptr->First(); | |
209 | last = geometric_representation_ptr->Last(); | |
210 | if (geometric_representation_ptr->IsCurveOnSurface()) { | |
211 | Curve2dPtr = geometric_representation_ptr->PCurve() ; | |
212 | has_curve = Standard_True ; | |
213 | } | |
214 | if (geometric_representation_ptr->IsCurveOnClosedSurface()) { | |
215 | Curve2dPtr2 = geometric_representation_ptr->PCurve2() ; | |
216 | has_closed_curve = Standard_True ; | |
217 | } | |
218 | if (has_curve || has_closed_curve) { | |
219 | if (first_time_in) { | |
220 | current_first = first ; | |
221 | current_last = last ; | |
222 | first_time_in = Standard_False ; | |
223 | } | |
224 | ||
225 | if (Abs(first - current_first) > Precision::Confusion() || | |
226 | Abs(last - current_last) > Precision::Confusion() ) | |
227 | { | |
228 | if (has_curve) | |
229 | { | |
230 | GeomLib::SameRange(Tolerance, | |
231 | Curve2dPtr, | |
232 | geometric_representation_ptr->First(), | |
233 | geometric_representation_ptr->Last(), | |
234 | current_first, | |
235 | current_last, | |
236 | NewCurve2dPtr); | |
237 | geometric_representation_ptr->PCurve(NewCurve2dPtr) ; | |
238 | } | |
239 | if (has_closed_curve) | |
240 | { | |
241 | GeomLib::SameRange(Tolerance, | |
242 | Curve2dPtr2, | |
243 | geometric_representation_ptr->First(), | |
244 | geometric_representation_ptr->Last(), | |
245 | current_first, | |
246 | current_last, | |
247 | NewCurve2dPtr2); | |
248 | geometric_representation_ptr->PCurve2(NewCurve2dPtr2) ; | |
249 | } | |
250 | } | |
251 | } | |
252 | } | |
253 | an_Iterator.Next() ; | |
254 | } | |
255 | BRep_Builder B; | |
256 | B.Range(TopoDS::Edge(AnEdge), | |
257 | current_first, | |
258 | current_last) ; | |
259 | ||
260 | B.SameRange(AnEdge, | |
261 | Standard_True) ; | |
262 | } | |
263 | ||
264 | //======================================================================= | |
265 | //function : EvaluateMaxSegment | |
266 | //purpose : return MaxSegment to pass in approximation, if MaxSegment==0 provided | |
267 | //======================================================================= | |
268 | ||
269 | static Standard_Integer evaluateMaxSegment(const Standard_Integer aMaxSegment, | |
270 | const Adaptor3d_CurveOnSurface& aCurveOnSurface) | |
271 | { | |
272 | if (aMaxSegment != 0) return aMaxSegment; | |
273 | ||
274 | Handle(Adaptor3d_HSurface) aSurf = aCurveOnSurface.GetSurface(); | |
275 | Handle(Adaptor2d_HCurve2d) aCurv2d = aCurveOnSurface.GetCurve(); | |
276 | ||
277 | Standard_Real aNbSKnots = 0, aNbC2dKnots = 0; | |
278 | ||
279 | if (aSurf->GetType() == GeomAbs_BSplineSurface) { | |
280 | Handle(Geom_BSplineSurface) aBSpline = aSurf->BSpline(); | |
281 | aNbSKnots = Max(aBSpline->NbUKnots(), aBSpline->NbVKnots()); | |
282 | } | |
283 | if (aCurv2d->GetType() == GeomAbs_BSplineCurve) { | |
284 | aNbC2dKnots = aCurv2d->NbKnots(); | |
285 | } | |
286 | Standard_Integer aReturn = (Standard_Integer) ( 30 + Max(aNbSKnots, aNbC2dKnots) ) ; | |
287 | return aReturn; | |
288 | } | |
289 | ||
290 | //======================================================================= | |
291 | //function : BuildCurve3d | |
292 | //purpose : | |
293 | //======================================================================= | |
294 | ||
295 | Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, | |
296 | const Standard_Real Tolerance, | |
297 | const GeomAbs_Shape Continuity, | |
298 | const Standard_Integer MaxDegree, | |
299 | const Standard_Integer MaxSegment) | |
300 | { | |
301 | Standard_Integer //ErrorCode, | |
302 | // ReturnCode = 0, | |
303 | ii, | |
304 | // num_knots, | |
305 | jj; | |
306 | ||
307 | TopLoc_Location LocalLoc,L[2],LC; | |
308 | Standard_Real f,l,fc,lc, first[2], last[2], | |
309 | tolerance, | |
310 | max_deviation, | |
311 | average_deviation ; | |
312 | Handle(Geom2d_Curve) Curve2dPtr, Curve2dArray[2] ; | |
313 | Handle(Geom_Surface) SurfacePtr, SurfaceArray[2] ; | |
314 | ||
315 | Standard_Integer not_done ; | |
316 | // if the edge has a 3d curve returns true | |
317 | ||
318 | ||
319 | const Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge,LocalLoc,f,l); | |
320 | if (!C.IsNull()) | |
321 | return Standard_True; | |
322 | // | |
323 | // this should not exists but UpdateEdge makes funny things | |
324 | // if the edge is not same range | |
325 | // | |
326 | if (! CheckSameRange(AnEdge, | |
327 | Precision::Confusion())) { | |
328 | SameRange(AnEdge, | |
329 | Tolerance) ; | |
330 | } | |
331 | ||
332 | ||
333 | ||
334 | // search a curve on a plane | |
335 | Handle(Geom_Surface) S; | |
336 | Handle(Geom2d_Curve) PC; | |
337 | Standard_Integer i = 0; | |
338 | Handle(Geom_Plane) P; | |
339 | not_done = 1 ; | |
340 | ||
341 | while (not_done) { | |
342 | i++; | |
343 | BRep_Tool::CurveOnSurface(AnEdge,PC,S,LocalLoc,f,l,i); | |
344 | Handle(Geom_RectangularTrimmedSurface) RT = | |
345 | Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
346 | if ( RT.IsNull()) { | |
347 | P = Handle(Geom_Plane)::DownCast(S); | |
348 | } | |
349 | else { | |
350 | P = Handle(Geom_Plane)::DownCast(RT->BasisSurface()); | |
351 | } | |
352 | not_done = ! (S.IsNull() || !P.IsNull()) ; | |
353 | } | |
354 | if (! P.IsNull()) { | |
355 | // compute the 3d curve | |
356 | gp_Ax2 axes = P->Position().Ax2(); | |
357 | Handle(Geom_Curve) C3d = GeomLib::To3d(axes,PC); | |
dfc06d1f A |
358 | if (C3d.IsNull()) |
359 | return Standard_False; | |
7fd59977 | 360 | // update the edge |
361 | Standard_Real First, Last; | |
362 | ||
363 | BRep_Builder B; | |
364 | Standard_Boolean is_closed ; | |
365 | is_closed = AnEdge.Closed() ; | |
366 | ||
367 | B.UpdateEdge(AnEdge,C3d,LocalLoc,0.0e0); | |
368 | BRep_Tool::Range(AnEdge, S, LC, First, Last); | |
0d969553 | 369 | B.Range(AnEdge, First, Last); //Do not forget 3D range.(PRO6412) |
7fd59977 | 370 | TopoDS_Edge E = AnEdge ; |
371 | E.Closed(is_closed) ; | |
372 | ||
373 | } | |
374 | else { | |
375 | // | |
376 | // compute the 3d curve using existing surface | |
377 | // | |
378 | fc = f ; | |
379 | lc = l ; | |
380 | if (!BRep_Tool::Degenerated(AnEdge)) { | |
381 | jj = 0 ; | |
382 | for (ii = 0 ; ii < 3 ; ii++ ) { | |
383 | BRep_Tool::CurveOnSurface(TopoDS::Edge(AnEdge), | |
384 | Curve2dPtr, | |
385 | SurfacePtr, | |
386 | LocalLoc, | |
387 | fc, | |
388 | lc, | |
389 | ii) ; | |
390 | ||
391 | if (!Curve2dPtr.IsNull() && jj < 2){ | |
392 | Curve2dArray[jj] = Curve2dPtr ; | |
393 | SurfaceArray[jj] = SurfacePtr ; | |
394 | L[jj] = LocalLoc ; | |
395 | first[jj] = fc ; | |
396 | last[jj] = lc ; | |
397 | jj += 1 ; | |
398 | } | |
399 | } | |
400 | f = first[0] ; | |
401 | l = last[0] ; | |
402 | Curve2dPtr = Curve2dArray[0] ; | |
403 | SurfacePtr = SurfaceArray[0] ; | |
404 | ||
405 | Geom2dAdaptor_Curve AnAdaptor3dCurve2d (Curve2dPtr, f, l) ; | |
406 | GeomAdaptor_Surface AnAdaptor3dSurface (SurfacePtr) ; | |
407 | Handle(Geom2dAdaptor_HCurve) AnAdaptor3dCurve2dPtr = | |
408 | new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; | |
409 | Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr = | |
410 | new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; | |
411 | Adaptor3d_CurveOnSurface CurveOnSurface( AnAdaptor3dCurve2dPtr, | |
412 | AnAdaptor3dSurfacePtr) ; | |
413 | ||
414 | Handle(Geom_Curve) NewCurvePtr ; | |
415 | ||
416 | GeomLib::BuildCurve3d(Tolerance, | |
417 | CurveOnSurface, | |
418 | f, | |
419 | l, | |
420 | NewCurvePtr, | |
421 | max_deviation, | |
422 | average_deviation, | |
423 | Continuity, | |
424 | MaxDegree, | |
425 | evaluateMaxSegment(MaxSegment,CurveOnSurface)) ; | |
426 | BRep_Builder B; | |
427 | tolerance = BRep_Tool::Tolerance(AnEdge) ; | |
428 | //Patch | |
429 | //max_deviation = Max(tolerance, max_deviation) ; | |
430 | max_deviation = Max( tolerance, Tolerance ); | |
dfc06d1f A |
431 | if (NewCurvePtr.IsNull()) |
432 | return Standard_False; | |
7fd59977 | 433 | Standard_Boolean is_closed ; |
434 | is_closed = AnEdge.Closed() ; | |
435 | B.UpdateEdge(TopoDS::Edge(AnEdge), | |
436 | NewCurvePtr, | |
437 | L[0], | |
438 | max_deviation) ; | |
439 | TopoDS_Edge E = AnEdge ; | |
440 | E.Closed(is_closed) ; | |
441 | if (jj == 1 ) { | |
442 | // | |
443 | // if there is only one curve on surface attached to the edge | |
444 | // than it can be qualified sameparameter | |
445 | // | |
446 | B.SameParameter(TopoDS::Edge(AnEdge), | |
447 | Standard_True) ; | |
448 | } | |
449 | } | |
450 | else { | |
451 | return Standard_False ; | |
452 | } | |
453 | ||
454 | } | |
455 | return Standard_True; | |
456 | } | |
457 | //======================================================================= | |
458 | //function : BuildCurves3d | |
459 | //purpose : | |
460 | //======================================================================= | |
461 | ||
462 | Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S) | |
463 | ||
464 | { | |
465 | return BRepLib::BuildCurves3d(S, | |
466 | 1.0e-5) ; | |
467 | } | |
468 | ||
469 | //======================================================================= | |
470 | //function : BuildCurves3d | |
471 | //purpose : | |
472 | //======================================================================= | |
473 | ||
474 | Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S, | |
475 | const Standard_Real Tolerance, | |
476 | const GeomAbs_Shape Continuity, | |
477 | const Standard_Integer MaxDegree, | |
478 | const Standard_Integer MaxSegment) | |
479 | { | |
480 | Standard_Boolean boolean_value, | |
481 | ok = Standard_True; | |
482 | TopTools_MapOfShape a_counter ; | |
483 | TopExp_Explorer ex(S,TopAbs_EDGE); | |
484 | ||
485 | while (ex.More()) { | |
486 | if (a_counter.Add(ex.Current())) { | |
487 | boolean_value = | |
488 | BuildCurve3d(TopoDS::Edge(ex.Current()), | |
489 | Tolerance, Continuity, | |
490 | MaxDegree, MaxSegment); | |
491 | ok = ok && boolean_value ; | |
492 | } | |
493 | ex.Next(); | |
494 | } | |
495 | return ok; | |
496 | } | |
497 | //======================================================================= | |
498 | //function : UpdateEdgeTolerance | |
499 | //purpose : | |
500 | //======================================================================= | |
501 | ||
502 | Standard_Boolean BRepLib::UpdateEdgeTol(const TopoDS_Edge& AnEdge, | |
503 | const Standard_Real MinToleranceRequested, | |
504 | const Standard_Real MaxToleranceToCheck) | |
505 | { | |
506 | ||
507 | Standard_Integer curve_on_surface_index, | |
508 | curve_index, | |
509 | not_done, | |
510 | has_closed_curve, | |
511 | has_curve, | |
512 | jj, | |
513 | ii, | |
514 | geom_reference_curve_flag = 0, | |
515 | max_sampling_points = 90, | |
516 | min_sampling_points = 30 ; | |
517 | ||
518 | Standard_Real factor = 100.0e0, | |
519 | // sampling_array[2], | |
520 | safe_factor = 1.4e0, | |
521 | current_last, | |
522 | current_first, | |
523 | max_distance, | |
524 | coded_edge_tolerance, | |
525 | edge_tolerance = 0.0e0 ; | |
526 | Handle(TColStd_HArray1OfReal) parameters_ptr ; | |
527 | Handle(BRep_GCurve) geometric_representation_ptr ; | |
528 | ||
529 | if (BRep_Tool::Degenerated(AnEdge)) return Standard_False ; | |
530 | coded_edge_tolerance = BRep_Tool::Tolerance(AnEdge) ; | |
531 | if (coded_edge_tolerance > MaxToleranceToCheck) return Standard_False ; | |
532 | ||
533 | const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&AnEdge.TShape()); | |
534 | BRep_ListOfCurveRepresentation& list_curve_rep = TE->ChangeCurves() ; | |
535 | BRep_ListIteratorOfListOfCurveRepresentation an_iterator(list_curve_rep), | |
536 | second_iterator(list_curve_rep) ; | |
537 | Handle(Geom2d_Curve) curve2d_ptr, new_curve2d_ptr; | |
538 | Handle(Geom_Surface) surface_ptr ; | |
539 | TopLoc_Location local_location ; | |
540 | GCPnts_QuasiUniformDeflection a_sampler ; | |
541 | GeomAdaptor_Curve geom_reference_curve ; | |
542 | Adaptor3d_CurveOnSurface curve_on_surface_reference ; | |
543 | Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, | |
544 | local_location, | |
545 | current_first, | |
546 | current_last); | |
547 | curve_on_surface_index = -1 ; | |
548 | if (!C.IsNull()) { | |
549 | if (! local_location.IsIdentity()) { | |
550 | C = Handle(Geom_Curve):: | |
551 | DownCast(C-> Transformed(local_location.Transformation()) ) ; | |
552 | } | |
553 | geom_reference_curve.Load(C) ; | |
554 | geom_reference_curve_flag = 1 ; | |
555 | a_sampler.Initialize(geom_reference_curve, | |
556 | MinToleranceRequested * factor, | |
557 | current_first, | |
558 | current_last) ; | |
559 | } | |
560 | else { | |
561 | not_done = 1 ; | |
562 | curve_on_surface_index = 0 ; | |
563 | ||
564 | while (not_done && an_iterator.More()) { | |
565 | geometric_representation_ptr = | |
566 | Handle(BRep_GCurve)::DownCast(second_iterator.Value()); | |
567 | if (!geometric_representation_ptr.IsNull() | |
568 | && geometric_representation_ptr->IsCurveOnSurface()) { | |
569 | curve2d_ptr = geometric_representation_ptr->PCurve() ; | |
570 | local_location = geometric_representation_ptr->Location() ; | |
571 | current_first = geometric_representation_ptr->First(); | |
572 | //first = geometric_representation_ptr->First(); | |
573 | current_last = geometric_representation_ptr->Last(); | |
574 | // must be inverted | |
575 | // | |
576 | if (! local_location.IsIdentity() ) { | |
577 | surface_ptr = Handle(Geom_Surface):: | |
578 | DownCast( geometric_representation_ptr->Surface()-> | |
579 | Transformed(local_location.Transformation()) ) ; | |
580 | } | |
581 | else { | |
582 | surface_ptr = | |
583 | geometric_representation_ptr->Surface() ; | |
584 | } | |
585 | not_done = 0 ; | |
586 | } | |
587 | curve_on_surface_index += 1 ; | |
588 | } | |
589 | Geom2dAdaptor_Curve AnAdaptor3dCurve2d (curve2d_ptr) ; | |
590 | GeomAdaptor_Surface AnAdaptor3dSurface (surface_ptr) ; | |
591 | Handle(Geom2dAdaptor_HCurve) AnAdaptor3dCurve2dPtr = | |
592 | new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; | |
593 | Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr = | |
594 | new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; | |
595 | curve_on_surface_reference.Load( AnAdaptor3dCurve2dPtr) ; | |
596 | curve_on_surface_reference.Load( AnAdaptor3dSurfacePtr) ; | |
597 | a_sampler.Initialize(curve_on_surface_reference, | |
598 | MinToleranceRequested * factor, | |
599 | current_first, | |
600 | current_last) ; | |
601 | } | |
602 | TColStd_Array1OfReal sampling_parameters(1,a_sampler.NbPoints()) ; | |
603 | for (ii = 1 ; ii <= a_sampler.NbPoints() ; ii++) { | |
604 | sampling_parameters(ii) = a_sampler.Parameter(ii) ; | |
605 | } | |
606 | if (a_sampler.NbPoints() < min_sampling_points) { | |
607 | GeomLib::DensifyArray1OfReal(min_sampling_points, | |
608 | sampling_parameters, | |
609 | parameters_ptr) ; | |
610 | } | |
611 | else if (a_sampler.NbPoints() > max_sampling_points) { | |
612 | GeomLib::RemovePointsFromArray(max_sampling_points, | |
613 | sampling_parameters, | |
614 | parameters_ptr) ; | |
615 | } | |
616 | else { | |
617 | jj = 1 ; | |
618 | parameters_ptr = | |
619 | new TColStd_HArray1OfReal(1,sampling_parameters.Length()) ; | |
620 | for (ii = sampling_parameters.Lower() ; ii <= sampling_parameters.Upper() ; ii++) { | |
621 | parameters_ptr->ChangeArray1()(jj) = | |
622 | sampling_parameters(ii) ; | |
623 | jj +=1 ; | |
624 | } | |
625 | } | |
626 | ||
627 | curve_index = 0 ; | |
628 | ||
629 | while (second_iterator.More()) { | |
630 | geometric_representation_ptr = | |
631 | Handle(BRep_GCurve)::DownCast(second_iterator.Value()); | |
632 | if (! geometric_representation_ptr.IsNull() && | |
633 | curve_index != curve_on_surface_index) { | |
634 | has_closed_curve = | |
635 | has_curve = Standard_False ; | |
636 | // first = geometric_representation_ptr->First(); | |
637 | // last = geometric_representation_ptr->Last(); | |
638 | local_location = geometric_representation_ptr->Location() ; | |
639 | if (geometric_representation_ptr->IsCurveOnSurface()) { | |
640 | curve2d_ptr = geometric_representation_ptr->PCurve() ; | |
641 | has_curve = Standard_True ; | |
642 | } | |
643 | if (geometric_representation_ptr->IsCurveOnClosedSurface()) { | |
644 | curve2d_ptr = geometric_representation_ptr->PCurve2() ; | |
645 | has_closed_curve = Standard_True ; | |
646 | } | |
647 | ||
648 | if (has_curve || | |
649 | has_closed_curve) { | |
650 | if (! local_location.IsIdentity() ) { | |
651 | surface_ptr = Handle(Geom_Surface):: | |
652 | DownCast( geometric_representation_ptr->Surface()-> | |
653 | Transformed(local_location.Transformation()) ) ; | |
654 | } | |
655 | else { | |
656 | surface_ptr = | |
657 | geometric_representation_ptr->Surface() ; | |
658 | } | |
659 | Geom2dAdaptor_Curve an_adaptor_curve2d (curve2d_ptr) ; | |
660 | GeomAdaptor_Surface an_adaptor_surface(surface_ptr) ; | |
661 | Handle(Geom2dAdaptor_HCurve) an_adaptor_curve2d_ptr = | |
662 | new Geom2dAdaptor_HCurve(an_adaptor_curve2d) ; | |
663 | Handle(GeomAdaptor_HSurface) an_adaptor_surface_ptr = | |
664 | new GeomAdaptor_HSurface (an_adaptor_surface) ; | |
665 | Adaptor3d_CurveOnSurface a_curve_on_surface(an_adaptor_curve2d_ptr, | |
666 | an_adaptor_surface_ptr) ; | |
667 | ||
668 | if (BRep_Tool::SameParameter(AnEdge)) { | |
669 | ||
670 | GeomLib::EvalMaxParametricDistance(a_curve_on_surface, | |
671 | geom_reference_curve, | |
672 | MinToleranceRequested, | |
673 | parameters_ptr->Array1(), | |
674 | max_distance) ; | |
675 | } | |
676 | else if (geom_reference_curve_flag) { | |
677 | GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, | |
678 | geom_reference_curve, | |
679 | MinToleranceRequested, | |
680 | parameters_ptr->Array1(), | |
681 | max_distance) ; | |
682 | } | |
683 | else { | |
684 | ||
685 | GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, | |
686 | curve_on_surface_reference, | |
687 | MinToleranceRequested, | |
688 | parameters_ptr->Array1(), | |
689 | max_distance) ; | |
690 | } | |
691 | max_distance *= safe_factor ; | |
692 | edge_tolerance = Max(max_distance, edge_tolerance) ; | |
693 | } | |
694 | ||
695 | ||
696 | } | |
697 | curve_index += 1 ; | |
698 | second_iterator.Next() ; | |
699 | } | |
700 | ||
701 | TE->Tolerance(edge_tolerance); | |
702 | return Standard_True ; | |
703 | ||
704 | } | |
705 | //======================================================================= | |
706 | //function : UpdateEdgeTolerance | |
707 | //purpose : | |
708 | //======================================================================= | |
709 | ||
710 | Standard_Boolean BRepLib::UpdateEdgeTolerance(const TopoDS_Shape& S, | |
711 | const Standard_Real MinToleranceRequested, | |
712 | const Standard_Real MaxToleranceToCheck) | |
713 | { | |
714 | TopExp_Explorer ex(S,TopAbs_EDGE); | |
715 | TopTools_MapOfShape a_counter ; | |
716 | ||
717 | Standard_Boolean return_status = Standard_False, | |
718 | local_flag ; | |
719 | ||
720 | while (ex.More()) { | |
721 | if (a_counter.Add(ex.Current())) { | |
722 | local_flag = | |
723 | BRepLib::UpdateEdgeTol(TopoDS::Edge(ex.Current()), | |
724 | MinToleranceRequested, | |
725 | MaxToleranceToCheck) ; | |
726 | if (local_flag && ! return_status) { | |
727 | return_status = Standard_True ; | |
728 | } | |
729 | } | |
730 | ex.Next(); | |
731 | } | |
732 | return return_status ; | |
733 | } | |
734 | ||
735 | //======================================================================= | |
736 | //function : SetEdgeTol | |
737 | //purpose : | |
738 | //======================================================================= | |
739 | ||
740 | static void SetEdgeTol(const TopoDS_Edge& E, | |
741 | const TopoDS_Face& F) | |
742 | { | |
743 | TopLoc_Location L; | |
744 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); | |
745 | TopLoc_Location l = L.Predivided(E.Location()); | |
746 | ||
747 | const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape()); | |
748 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->ChangeCurves()); | |
749 | ||
750 | while (itcr.More()) { | |
751 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
752 | if(cr->IsCurveOnSurface(S,l)) return; | |
753 | itcr.Next(); | |
754 | } | |
755 | ||
756 | Handle(Geom_Plane) GP; | |
757 | Handle(Geom_RectangularTrimmedSurface) GRTS; | |
758 | GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
759 | if(!GRTS.IsNull()) | |
760 | GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface()); | |
761 | else | |
762 | GP = Handle(Geom_Plane)::DownCast(S); | |
763 | ||
41194117 K |
764 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(); |
765 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); | |
7fd59977 | 766 | |
767 | TopLoc_Location LC; | |
768 | Standard_Real First, Last; | |
769 | GeomAdaptor_Curve& GAC = HC->ChangeCurve(); | |
770 | GAC.Load(BRep_Tool::Curve(E,LC,First,Last)); | |
771 | LC = L.Predivided(LC); | |
772 | ||
773 | if (!LC.IsIdentity()) { | |
774 | GP = Handle(Geom_Plane)::DownCast( | |
775 | GP->Transformed(LC.Transformation())); | |
776 | } | |
777 | GeomAdaptor_Surface& GAS = HS->ChangeSurface(); | |
778 | GAS.Load(GP); | |
779 | ||
780 | ProjLib_ProjectedCurve Proj(HS,HC); | |
781 | Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj); | |
782 | ||
783 | gp_Pln pln = GAS.Plane(); | |
784 | Standard_Real d2 = 0.; | |
785 | Standard_Integer nn = 23; | |
786 | Standard_Real unsurnn = 1./nn; | |
787 | for(Standard_Integer i = 0; i <= nn; i++){ | |
788 | Standard_Real t = unsurnn*i; | |
789 | Standard_Real u = First*(1.-t) + Last*t; | |
790 | gp_Pnt Pc3d = HC->Value(u); | |
791 | gp_Pnt2d p2d = pc->Value(u); | |
792 | gp_Pnt Pcons = ElSLib::Value(p2d.X(),p2d.Y(),pln); | |
793 | Standard_Real temp = Pc3d.SquareDistance(Pcons); | |
794 | if(temp > d2) d2 = temp; | |
795 | } | |
796 | d2 = 1.5*sqrt(d2); | |
797 | TE->UpdateTolerance(d2); | |
798 | } | |
799 | ||
800 | //======================================================================= | |
801 | //function : SameParameter | |
802 | //purpose : | |
803 | //======================================================================= | |
804 | void BRepLib::SameParameter(const TopoDS_Shape& S, | |
805 | const Standard_Real Tolerance, | |
806 | const Standard_Boolean forced) | |
807 | { | |
808 | TopExp_Explorer ex(S,TopAbs_EDGE); | |
809 | TopTools_MapOfShape Done; | |
810 | BRep_Builder brB; | |
811 | ||
812 | while (ex.More()) { | |
813 | if (Done.Add(ex.Current())) { | |
814 | if (forced) { | |
815 | brB.SameRange(TopoDS::Edge(ex.Current()), Standard_False); | |
816 | brB.SameParameter(TopoDS::Edge(ex.Current()), Standard_False); | |
817 | } | |
818 | BRepLib::SameParameter(TopoDS::Edge(ex.Current()),Tolerance); | |
819 | } | |
820 | ex.Next(); | |
821 | } | |
822 | ||
823 | Done.Clear(); | |
824 | BRepAdaptor_Surface BS; | |
825 | for(ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()){ | |
826 | const TopoDS_Face& curface = TopoDS::Face(ex.Current()); | |
827 | if(!Done.Add(curface)) continue; | |
828 | BS.Initialize(curface); | |
829 | if(BS.GetType() != GeomAbs_Plane) continue; | |
830 | TopExp_Explorer ex2; | |
831 | for(ex2.Init(curface,TopAbs_EDGE); ex2.More(); ex2.Next()){ | |
832 | const TopoDS_Edge& E = TopoDS::Edge(ex2.Current()); | |
833 | SetEdgeTol(E,curface); | |
834 | } | |
835 | } | |
836 | BRepLib::UpdateTolerances(S); | |
837 | } | |
838 | ||
0d969553 | 839 | //================================================================ |
7fd59977 | 840 | //function : SameParameter |
0d969553 Y |
841 | //WARNING : New spec DUB LBO 9/9/97. |
842 | // Recode in the edge the best tolerance found, | |
843 | // for vertex extremities it is required to find something else | |
844 | //================================================================ | |
7fd59977 | 845 | static Standard_Boolean EvalTol(const Handle(Geom2d_Curve)& pc, |
846 | const Handle(Geom_Surface)& s, | |
847 | const GeomAdaptor_Curve& gac, | |
848 | const Standard_Real tol, | |
849 | Standard_Real& tolbail) | |
850 | { | |
851 | Standard_Integer ok = 0; | |
852 | Standard_Real f = gac.FirstParameter(); | |
853 | Standard_Real l = gac.LastParameter(); | |
854 | Extrema_LocateExtPC Projector; | |
855 | Projector.Initialize(gac,f,l,tol); | |
856 | Standard_Real u,v; | |
857 | gp_Pnt p; | |
858 | tolbail = tol; | |
859 | for(Standard_Integer i = 1; i <= 5; i++){ | |
860 | Standard_Real t = i/6.; | |
861 | t = (1.-t) * f + t * l; | |
862 | pc->Value(t).Coord(u,v); | |
863 | p = s->Value(u,v); | |
864 | Projector.Perform(p,t); | |
865 | if (Projector.IsDone()) { | |
866 | Standard_Real dist2 = Projector.SquareDistance(); | |
867 | if(dist2 > tolbail * tolbail) tolbail = sqrt (dist2); | |
868 | ok++; | |
869 | } | |
870 | } | |
871 | return (ok > 2); | |
872 | } | |
873 | ||
874 | static Standard_Real ComputeTol(const Handle(Adaptor3d_HCurve)& c3d, | |
875 | const Handle(Adaptor2d_HCurve2d)& c2d, | |
876 | const Handle(Adaptor3d_HSurface)& surf, | |
877 | const Standard_Integer nbp) | |
878 | ||
879 | { | |
880 | ||
881 | TColStd_Array1OfReal dist(1,nbp+10); | |
882 | dist.Init(-1.); | |
883 | ||
884 | ||
885 | Adaptor3d_CurveOnSurface cons(c2d,surf); | |
886 | Standard_Real d2 = 0.; | |
887 | Standard_Integer nn = nbp; | |
888 | Standard_Real unsurnn = 1./nn; | |
889 | Standard_Real first = c3d->FirstParameter(); | |
890 | Standard_Real last = c3d->LastParameter(); | |
891 | Standard_Integer i = 0; | |
892 | for(i = 0; i <= nn; i++){ | |
893 | Standard_Real t = unsurnn*i; | |
894 | Standard_Real u = first*(1.-t) + last*t; | |
895 | gp_Pnt Pc3d = c3d->Value(u); | |
896 | gp_Pnt Pcons = cons.Value(u); | |
897 | if (Precision::IsInfinite(Pcons.X()) || | |
898 | Precision::IsInfinite(Pcons.Y()) || | |
899 | Precision::IsInfinite(Pcons.Z())) { | |
900 | d2=Precision::Infinite(); | |
901 | break; | |
902 | } | |
903 | Standard_Real temp = Pc3d.SquareDistance(Pcons); | |
904 | ||
905 | ||
906 | dist(i+1) = temp; | |
907 | ||
908 | ||
909 | if(temp > d2) d2 = temp; | |
910 | } | |
911 | ||
912 | ||
913 | Standard_Boolean ana = Standard_False; | |
914 | Standard_Real D2 = 0; | |
915 | Standard_Integer N1 = 0; | |
916 | Standard_Integer N2 = 0; | |
917 | Standard_Integer N3 = 0; | |
918 | ||
919 | for( i = 1; i<= nbp+10; i++) | |
920 | if( dist(i) > 0 ) { | |
921 | if( dist(i) < 1.0 ) N1++; | |
922 | else N2++; | |
923 | } | |
924 | ||
925 | if( N1 > N2 && N2 != 0 ) N3 = 100*N2/(N1+N2); | |
926 | if( N3 < 10 && N3 != 0 ) { | |
927 | ana = Standard_True; | |
928 | for( i = 1; i<= nbp+10; i++) | |
929 | if( dist(i) > 0 && dist(i) < 1.0 ) | |
930 | if( dist(i) > D2 ) D2 = dist(i); | |
931 | } | |
932 | ||
933 | //d2 = 1.5*sqrt(d2); | |
934 | d2 = (!ana) ? 1.5*sqrt(d2) : 1.5*sqrt(D2); | |
935 | if(d2<1.e-7) d2 = 1.e-7; | |
936 | ||
937 | return d2; | |
938 | } | |
939 | ||
940 | ||
941 | ||
942 | void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, | |
943 | const Standard_Real Tolerance) | |
944 | { | |
945 | if (BRep_Tool::SameParameter(AnEdge)) return; | |
946 | ||
947 | const Standard_Integer NCONTROL = 22; | |
948 | ||
41194117 K |
949 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(); |
950 | Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve(); | |
951 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); | |
7fd59977 | 952 | GeomAdaptor_Curve& GAC = HC->ChangeCurve(); |
953 | Geom2dAdaptor_Curve& GAC2d = HC2d->ChangeCurve2d(); | |
954 | GeomAdaptor_Surface& GAS = HS->ChangeSurface(); | |
7fd59977 | 955 | Standard_Real f3d =0.,l3d =0.; |
7fd59977 | 956 | TopLoc_Location L3d; |
957 | Handle(Geom_Curve) C3d; | |
958 | ||
959 | const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &AnEdge.TShape()); | |
960 | BRep_ListOfCurveRepresentation& CList = TE->ChangeCurves(); | |
961 | BRep_ListIteratorOfListOfCurveRepresentation It(CList); | |
962 | ||
963 | Standard_Boolean NotDone = Standard_True; | |
964 | ||
965 | while (NotDone && It.More()) { | |
966 | Handle(BRep_GCurve) GCurve = Handle(BRep_GCurve)::DownCast(It.Value()); | |
967 | if (!GCurve.IsNull() && GCurve->IsCurve3D()) { | |
968 | C3d = GCurve->Curve3D() ; | |
969 | f3d = GCurve->First(); | |
970 | l3d = GCurve->Last(); | |
971 | L3d = GCurve->Location() ; | |
972 | NotDone = Standard_False; | |
973 | } | |
974 | It.Next() ; | |
975 | } | |
976 | ||
977 | if(C3d.IsNull()) return; | |
978 | ||
979 | // modified by NIZHNY-OCC486 Tue Aug 27 17:15:13 2002 : | |
980 | Standard_Boolean m_TrimmedPeriodical = Standard_False; | |
981 | Handle(Standard_Type) TheType = C3d->DynamicType(); | |
982 | if( TheType == STANDARD_TYPE(Geom_TrimmedCurve)) | |
983 | { | |
984 | const Handle(Geom_Curve)& gtC = (*((Handle(Geom_TrimmedCurve)*)&C3d))->BasisCurve(); | |
985 | m_TrimmedPeriodical = gtC->IsPeriodic(); | |
986 | } | |
987 | // modified by NIZHNY-OCC486 Tue Aug 27 17:15:17 2002 . | |
988 | ||
989 | BRep_Builder B; | |
990 | if(!C3d->IsPeriodic()) { | |
991 | Standard_Real Udeb = C3d->FirstParameter(); | |
992 | Standard_Real Ufin = C3d->LastParameter(); | |
993 | // modified by NIZHNY-OCC486 Tue Aug 27 17:17:14 2002 : | |
994 | //if (Udeb > f3d) f3d = Udeb; | |
995 | //if (l3d > Ufin) l3d = Ufin; | |
996 | if(!m_TrimmedPeriodical) | |
997 | { | |
998 | if (Udeb > f3d) f3d = Udeb; | |
999 | if (l3d > Ufin) l3d = Ufin; | |
1000 | } | |
1001 | // modified by NIZHNY-OCC486 Tue Aug 27 17:17:55 2002 . | |
1002 | } | |
1003 | if(!L3d.IsIdentity()){ | |
1004 | C3d = Handle(Geom_Curve)::DownCast(C3d->Transformed(L3d.Transformation())); | |
1005 | } | |
1006 | GAC.Load(C3d,f3d,l3d); | |
1007 | ||
1008 | Standard_Boolean IsSameP = 1; | |
1009 | Standard_Real maxdist = 0.; | |
1010 | ||
1011 | // Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin | |
1012 | Standard_Real anEdgeTol = BRep_Tool::Tolerance(AnEdge); | |
1013 | // Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End | |
1014 | Standard_Boolean SameRange = BRep_Tool::SameRange(AnEdge); | |
1015 | Standard_Boolean YaPCu = Standard_False; | |
1016 | It.Initialize(CList); | |
1017 | ||
1018 | while (It.More()) { | |
1019 | Standard_Boolean isANA = Standard_False; | |
1020 | Standard_Boolean isBSP = Standard_False; | |
1021 | Handle(BRep_GCurve) GCurve = Handle(BRep_GCurve)::DownCast(It.Value()); | |
1022 | Handle(Geom2d_Curve) PC[2]; | |
1023 | Handle(Geom_Surface) S; | |
1024 | if (!GCurve.IsNull() && GCurve->IsCurveOnSurface()) { | |
1025 | YaPCu = Standard_True; | |
1026 | PC[0] = GCurve->PCurve(); | |
1027 | TopLoc_Location PCLoc = GCurve->Location(); | |
1028 | S = GCurve->Surface(); | |
1029 | if (!PCLoc.IsIdentity() ) { | |
1030 | S = Handle(Geom_Surface)::DownCast(S->Transformed(PCLoc.Transformation())); | |
1031 | } | |
1032 | GAS.Load(S); | |
1033 | if (GCurve->IsCurveOnClosedSurface()) { | |
1034 | PC[1] = GCurve->PCurve2(); | |
1035 | } | |
1036 | ||
1037 | // Eval tol2d to compute SameRange | |
973f1c39 | 1038 | Standard_Real UResol = Max(GAS.UResolution(Tolerance), Precision::PConfusion()); |
1039 | Standard_Real VResol = Max(GAS.VResolution(Tolerance), Precision::PConfusion()); | |
7fd59977 | 1040 | Standard_Real Tol2d = Min(UResol, VResol); |
1041 | for(Standard_Integer i = 0; i < 2; i++){ | |
1042 | Handle(Geom2d_Curve) curPC = PC[i]; | |
1043 | Standard_Boolean updatepc = 0; | |
1044 | if(curPC.IsNull()) break; | |
1045 | if(!SameRange){ | |
1046 | GeomLib::SameRange(Tol2d, | |
1047 | PC[i],GCurve->First(),GCurve->Last(), | |
1048 | f3d,l3d,curPC); | |
1049 | ||
1050 | updatepc = (curPC != PC[i]); | |
1051 | ||
1052 | } | |
1053 | Standard_Boolean goodpc = 1; | |
1054 | GAC2d.Load(curPC,f3d,l3d); | |
1055 | ||
1056 | Standard_Real error = ComputeTol(HC, HC2d, HS, NCONTROL); | |
1057 | ||
1058 | if(GAC2d.GetType() == GeomAbs_BSplineCurve && | |
1059 | GAC2d.Continuity() == GeomAbs_C0) { | |
1060 | Handle(Geom2d_BSplineCurve) bs2d = GAC2d.BSpline(); | |
1061 | Handle(Geom2d_BSplineCurve) bs2dsov = bs2d; | |
1062 | Standard_Real fC0 = bs2d->FirstParameter(), lC0 = bs2d->LastParameter(); | |
1063 | Standard_Boolean repar = Standard_True; | |
1064 | gp_Pnt2d OriginPoint; | |
1065 | bs2d->D0(fC0, OriginPoint); | |
1066 | Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d, Tol2d); | |
1067 | isBSP = Standard_True; | |
1068 | ||
1069 | if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 | |
1070 | gp_Pnt2d NewOriginPoint; | |
1071 | bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); | |
1072 | if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || | |
1073 | Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { | |
1074 | ||
1075 | TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); | |
1076 | bs2d->Knots(Knotbs2d); | |
1077 | ||
1078 | for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { | |
1079 | bs2d->D0(Knotbs2d(Index), NewOriginPoint); | |
1080 | if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || | |
1081 | Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; | |
1082 | ||
1083 | bs2d->SetOrigin(Index); | |
1084 | break; | |
1085 | } | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if(bs2d->Continuity() == GeomAbs_C0) { | |
1090 | Standard_Real tolbail; | |
1091 | if(EvalTol(curPC,S,GAC,Tolerance,tolbail)){ | |
1092 | bs2d = bs2dsov; | |
1093 | Standard_Real UResbail = GAS.UResolution(tolbail); | |
1094 | Standard_Real VResbail = GAS.VResolution(tolbail); | |
1095 | Standard_Real Tol2dbail = Min(UResbail,VResbail); | |
1096 | bs2d->D0(bs2d->FirstParameter(), OriginPoint); | |
1097 | ||
1098 | Standard_Integer nbp = bs2d->NbPoles(); | |
1099 | TColgp_Array1OfPnt2d poles(1,nbp); | |
1100 | bs2d->Poles(poles); | |
1101 | gp_Pnt2d p = poles(1), p1; | |
1102 | Standard_Real d = Precision::Infinite(); | |
1103 | for(Standard_Integer ip = 2; ip <= nbp; ip++) { | |
1104 | p1 = poles(ip); | |
1105 | d = Min(d,p.SquareDistance(p1)); | |
1106 | p = p1; | |
1107 | } | |
1108 | d = sqrt(d)*.1; | |
1109 | ||
1110 | Tol2dbail = Max(Min(Tol2dbail,d),Tol2d); | |
1111 | ||
1112 | Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d,Tol2dbail); | |
1113 | ||
1114 | if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 | |
1115 | gp_Pnt2d NewOriginPoint; | |
1116 | bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); | |
1117 | if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || | |
1118 | Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { | |
1119 | ||
1120 | TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); | |
1121 | bs2d->Knots(Knotbs2d); | |
1122 | ||
1123 | for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { | |
1124 | bs2d->D0(Knotbs2d(Index), NewOriginPoint); | |
1125 | if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || | |
1126 | Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; | |
1127 | ||
1128 | bs2d->SetOrigin(Index); | |
1129 | break; | |
1130 | } | |
1131 | } | |
1132 | } | |
1133 | ||
1134 | ||
1135 | if(bs2d->Continuity() == GeomAbs_C0) { | |
1136 | goodpc = 1; | |
1137 | bs2d = bs2dsov; | |
1138 | repar = Standard_False; | |
1139 | } | |
1140 | } | |
1141 | else goodpc = 0; | |
1142 | } | |
1143 | ||
1144 | if(goodpc){ | |
1145 | if(repar) { | |
1146 | Standard_Integer NbKnots = bs2d->NbKnots(); | |
1147 | TColStd_Array1OfReal Knots(1,NbKnots); | |
1148 | bs2d->Knots(Knots); | |
1149 | // BSplCLib::Reparametrize(f3d,l3d,Knots); | |
1150 | BSplCLib::Reparametrize(fC0,lC0,Knots); | |
1151 | bs2d->SetKnots(Knots); | |
1152 | GAC2d.Load(bs2d,f3d,l3d); | |
1153 | curPC = bs2d; | |
1154 | Standard_Boolean updatepcsov = updatepc; | |
1155 | updatepc = Standard_True; | |
1156 | ||
1157 | Standard_Real error1 = ComputeTol(HC, HC2d, HS, NCONTROL); | |
1158 | if(error1 > error) { | |
1159 | bs2d = bs2dsov; | |
1160 | GAC2d.Load(bs2d,f3d,l3d); | |
1161 | curPC = bs2d; | |
1162 | updatepc = updatepcsov; | |
1163 | isANA = Standard_True; | |
1164 | } | |
1165 | else { | |
1166 | error = error1; | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | //check, if new BSpline "good" or not --------- IFV, Jan of 2000 | |
1171 | GeomAbs_Shape cont = bs2d->Continuity(); | |
1172 | Standard_Boolean IsBad = Standard_False; | |
1173 | ||
1174 | if(cont > GeomAbs_C0 && error > Max(1.e-3,Tolerance)) { | |
1175 | Standard_Integer NbKnots = bs2d->NbKnots(); | |
1176 | TColStd_Array1OfReal Knots(1,NbKnots); | |
1177 | bs2d->Knots(Knots); | |
1178 | Standard_Real critratio = 10.; | |
1179 | Standard_Real dtprev = Knots(2) - Knots(1), dtratio = 1.; | |
1180 | Standard_Real dtmin = dtprev; | |
1181 | Standard_Real dtcur; | |
1182 | for(Standard_Integer j = 2; j < NbKnots; j++) { | |
1183 | dtcur = Knots(j+1) - Knots(j); | |
1184 | dtmin = Min(dtmin, dtcur); | |
1185 | ||
1186 | if(IsBad) continue; | |
1187 | ||
1188 | if(dtcur > dtprev) dtratio = dtcur/dtprev; | |
1189 | else dtratio = dtprev/dtcur; | |
1190 | if(dtratio > critratio) {IsBad = Standard_True;} | |
1191 | dtprev = dtcur; | |
1192 | ||
1193 | } | |
1194 | if(IsBad) { | |
1195 | // To avoid failures in Approx_CurvilinearParameter | |
1196 | bs2d->Resolution(Max(1.e-3,Tolerance), dtcur); | |
1197 | if(dtmin < dtcur) IsBad = Standard_False; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | ||
1202 | if(IsBad ) { //if BSpline "bad", try to reparametrize it | |
1203 | // by its curve length | |
1204 | ||
1205 | // GeomAbs_Shape cont = bs2d->Continuity(); | |
1206 | if(cont > GeomAbs_C2) cont = GeomAbs_C2; | |
1207 | Standard_Integer maxdeg = bs2d->Degree(); | |
1208 | if(maxdeg == 1) maxdeg = 14; | |
1209 | Approx_CurvilinearParameter AppCurPar(HC2d, HS, Max(1.e-3,Tolerance), | |
1210 | cont, maxdeg, 10); | |
1211 | if(AppCurPar.IsDone() || AppCurPar.HasResult()) { | |
1212 | bs2d = AppCurPar.Curve2d1(); | |
1213 | GAC2d.Load(bs2d,f3d,l3d); | |
1214 | curPC = bs2d; | |
1215 | ||
1216 | if(Abs(bs2d->FirstParameter() - fC0) > Tol2d || | |
1217 | Abs(bs2d->LastParameter() - lC0) > Tol2d ) { | |
1218 | Standard_Integer NbKnots = bs2d->NbKnots(); | |
1219 | TColStd_Array1OfReal Knots(1,NbKnots); | |
1220 | bs2d->Knots(Knots); | |
1221 | // BSplCLib::Reparametrize(f3d,l3d,Knots); | |
1222 | BSplCLib::Reparametrize(fC0,lC0,Knots); | |
1223 | bs2d->SetKnots(Knots); | |
1224 | GAC2d.Load(bs2d,f3d,l3d); | |
1225 | curPC = bs2d; | |
1226 | ||
1227 | } | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | ||
1232 | } | |
1233 | } | |
1234 | ||
1235 | ||
1236 | if(goodpc){ | |
1237 | // Approx_SameParameter SameP(HC,HC2d,HS,Tolerance); | |
1238 | Standard_Real aTol = (isANA && isBSP) ? 1.e-7 : Tolerance; | |
1239 | Approx_SameParameter SameP(HC,HC2d,HS,aTol); | |
1240 | ||
1241 | if (SameP.IsSameParameter()) { | |
1242 | maxdist = Max(maxdist,SameP.TolReached()); | |
1243 | if(updatepc){ | |
1244 | if (i == 0) GCurve->PCurve(curPC); | |
1245 | else GCurve->PCurve2(curPC); | |
1246 | } | |
1247 | } | |
1248 | else if (SameP.IsDone()) { | |
1249 | Standard_Real tolreached = SameP.TolReached(); | |
1250 | if(tolreached < error) { | |
1251 | curPC = SameP.Curve2d(); | |
1252 | updatepc = Standard_True; | |
1253 | maxdist = Max(maxdist,tolreached); | |
1254 | } | |
1255 | else { | |
1256 | maxdist = Max(maxdist, error); | |
1257 | } | |
1258 | if(updatepc){ | |
1259 | if (i == 0) GCurve->PCurve(curPC); | |
1260 | else GCurve->PCurve2(curPC); | |
1261 | } | |
1262 | } | |
1263 | else IsSameP = 0; | |
1264 | ||
1265 | } | |
1266 | else IsSameP = 0; | |
1267 | ||
1268 | // Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin | |
1269 | if (!IsSameP) { | |
1270 | if (anEdgeTol > error) { | |
1271 | maxdist = Max(maxdist, anEdgeTol); | |
1272 | IsSameP = Standard_True; | |
1273 | } | |
1274 | } | |
1275 | // Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End | |
1276 | } | |
1277 | } | |
1278 | It.Next() ; | |
1279 | } | |
1280 | B.Range(AnEdge,f3d,l3d); | |
1281 | B.SameRange(AnEdge,Standard_True); | |
1282 | if ( IsSameP) { | |
0d969553 Y |
1283 | // Reduce eventually the tolerance of the edge, as |
1284 | // all its representations are processed (except for some associated | |
1285 | // to planes and not stored in the edge !) | |
1286 | // The same cannot be done with vertices that cannot be enlarged | |
1287 | // or left as is. | |
7fd59977 | 1288 | if (YaPCu) { |
0d969553 | 1289 | // Avoid setting too small tolerances. |
7fd59977 | 1290 | maxdist = Max(maxdist,Precision::Confusion()); |
1291 | TopoDS_Vertex V1,V2; | |
1292 | TopExp::Vertices(AnEdge,V1,V2); | |
1293 | if (!V1.IsNull()) | |
1294 | B.UpdateVertex(V1,maxdist); | |
1295 | if (!V2.IsNull()) | |
1296 | B.UpdateVertex(V2,maxdist); | |
1297 | TE->Modified(Standard_True); | |
1298 | TE->Tolerance(maxdist); | |
1299 | } | |
1300 | B.SameParameter(AnEdge,Standard_True); | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | //======================================================================= | |
1305 | //function : UpdateTolerances | |
1306 | //purpose : | |
1307 | //======================================================================= | |
1308 | void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, | |
1309 | const Standard_Boolean verifyTolerance) | |
1310 | { | |
1311 | ||
0d969553 Y |
1312 | // Harmonize tolerances |
1313 | // with rule Tolerance(VERTEX)>=Tolerance(EDGE)>=Tolerance(FACE) | |
7fd59977 | 1314 | BRep_Builder B; |
1315 | Standard_Real tol=0; | |
1316 | if (verifyTolerance) { | |
0d969553 | 1317 | // Set tolerance to its minimum value |
7fd59977 | 1318 | Handle(Geom_Surface) S; |
1319 | TopLoc_Location l; | |
1320 | TopExp_Explorer ex; | |
1321 | Bnd_Box aB; | |
1322 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dMax; | |
1323 | for (ex.Init(aShape, TopAbs_FACE); ex.More(); ex.Next()) { | |
1324 | const TopoDS_Face& curf=TopoDS::Face(ex.Current()); | |
1325 | S = BRep_Tool::Surface(curf, l); | |
1326 | if (!S.IsNull()) { | |
1327 | aB.SetVoid(); | |
1328 | BRepBndLib::Add(curf,aB); | |
1329 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { | |
1330 | S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); | |
1331 | } | |
1332 | GeomAdaptor_Surface AS(S); | |
1333 | switch (AS.GetType()) { | |
1334 | case GeomAbs_Plane: | |
1335 | case GeomAbs_Cylinder: | |
1336 | case GeomAbs_Cone: | |
1337 | { | |
1338 | tol=Precision::Confusion(); | |
1339 | break; | |
1340 | } | |
1341 | case GeomAbs_Sphere: | |
1342 | case GeomAbs_Torus: | |
1343 | { | |
1344 | tol=Precision::Confusion()*2; | |
1345 | break; | |
1346 | } | |
1347 | default: | |
1348 | tol=Precision::Confusion()*4; | |
1349 | } | |
1350 | if (!aB.IsWhole()) { | |
1351 | aB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); | |
1352 | dMax=1.; | |
1353 | if (!aB.IsOpenXmin() && !aB.IsOpenXmax()) dMax=aXmax-aXmin; | |
1354 | if (!aB.IsOpenYmin() && !aB.IsOpenYmax()) aYmin=aYmax-aYmin; | |
1355 | if (!aB.IsOpenZmin() && !aB.IsOpenZmax()) aZmin=aZmax-aZmin; | |
1356 | if (aYmin>dMax) dMax=aYmin; | |
1357 | if (aZmin>dMax) dMax=aZmin; | |
1358 | tol=tol*dMax; | |
0d969553 | 1359 | // Do not process tolerances > 1. |
7fd59977 | 1360 | if (tol>1.) tol=0.99; |
1361 | } | |
1362 | const Handle(BRep_TFace)& Tf = *((Handle(BRep_TFace)*)&curf.TShape()); | |
1363 | Tf->Tolerance(tol); | |
1364 | } | |
1365 | } | |
1366 | } | |
1367 | ||
0d969553 | 1368 | //Process edges |
7fd59977 | 1369 | TopTools_IndexedDataMapOfShapeListOfShape parents; |
1370 | TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, parents); | |
1371 | TopTools_ListIteratorOfListOfShape lConx; | |
1372 | Standard_Integer iCur; | |
1373 | for (iCur=1; iCur<=parents.Extent(); iCur++) { | |
1374 | tol=0; | |
1375 | for (lConx.Initialize(parents(iCur)); lConx.More(); lConx.Next()) { | |
1376 | tol=Max(tol, BRep_Tool::Tolerance(TopoDS::Face(lConx.Value()))); | |
1377 | } | |
0d969553 Y |
1378 | // Update can only increase tolerance, so if the edge has a greater |
1379 | // tolerance than its faces it is not concerned | |
7fd59977 | 1380 | B.UpdateEdge(TopoDS::Edge(parents.FindKey(iCur)), tol); |
1381 | } | |
1382 | ||
0d969553 | 1383 | //Vertices are processed |
7fd59977 | 1384 | parents.Clear(); |
1385 | TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, parents); | |
1386 | TColStd_MapOfTransient Initialized; | |
1387 | TopTools_MapOfShape Done; | |
1388 | Standard_Integer nbV = parents.Extent(); | |
1389 | for (iCur=1; iCur<=nbV; iCur++) { | |
1390 | tol=0; | |
1391 | Done.Clear(); | |
1392 | const TopoDS_Vertex& V = TopoDS::Vertex(parents.FindKey(iCur)); | |
1393 | Bnd_Box box; | |
1394 | box.Add(BRep_Tool::Pnt(V)); | |
1395 | gp_Pnt p3d; | |
1396 | for (lConx.Initialize(parents(iCur)); lConx.More(); lConx.Next()) { | |
1397 | const TopoDS_Edge& E = TopoDS::Edge(lConx.Value()); | |
1398 | if(!Done.Add(E)) continue; | |
1399 | tol=Max(tol, BRep_Tool::Tolerance(E)); | |
1400 | if(!BRep_Tool::SameRange(E)) continue; | |
1401 | Standard_Real par = BRep_Tool::Parameter(V,E); | |
1402 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape()); | |
1403 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
1404 | const TopLoc_Location& Eloc = E.Location(); | |
1405 | while (itcr.More()) { | |
0d969553 | 1406 | // For each CurveRepresentation, check the provided parameter |
7fd59977 | 1407 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
1408 | const TopLoc_Location& loc = cr->Location(); | |
1409 | TopLoc_Location L = (Eloc * loc); | |
1410 | if (cr->IsCurve3D()) { | |
1411 | const Handle(Geom_Curve)& C = cr->Curve3D(); | |
0d969553 | 1412 | if (!C.IsNull()) { // edge non degenerated |
7fd59977 | 1413 | p3d = C->Value(par); |
1414 | p3d.Transform(L.Transformation()); | |
1415 | box.Add(p3d); | |
1416 | } | |
1417 | } | |
1418 | else if (cr->IsCurveOnSurface()) { | |
1419 | const Handle(Geom_Surface)& Su = cr->Surface(); | |
1420 | const Handle(Geom2d_Curve)& PC = cr->PCurve(); | |
1421 | Handle(Geom2d_Curve) PC2; | |
1422 | if (cr->IsCurveOnClosedSurface()) { | |
1423 | PC2 = cr->PCurve2(); | |
1424 | } | |
1425 | gp_Pnt2d p2d = PC->Value(par); | |
1426 | p3d = Su->Value(p2d.X(),p2d.Y()); | |
1427 | p3d.Transform(L.Transformation()); | |
1428 | box.Add(p3d); | |
1429 | if (!PC2.IsNull()) { | |
1430 | p2d = PC2->Value(par); | |
1431 | p3d = Su->Value(p2d.X(),p2d.Y()); | |
1432 | p3d.Transform(L.Transformation()); | |
1433 | box.Add(p3d); | |
1434 | } | |
1435 | } | |
1436 | itcr.Next(); | |
1437 | } | |
1438 | } | |
1439 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; | |
1440 | box.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); | |
1441 | aXmax -= aXmin; aYmax -= aYmin; aZmax -= aZmin; | |
1442 | tol = Max(tol,sqrt(aXmax*aXmax+aYmax*aYmax+aZmax*aZmax)); | |
1443 | tol += 2.*Epsilon(tol); | |
1444 | if (verifyTolerance) { | |
0d969553 Y |
1445 | // ASet minimum value of the tolerance |
1446 | // Attention to sharing of the vertex by other shapes | |
7fd59977 | 1447 | const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*)&V.TShape()); |
1448 | if (Initialized.Add(TV)) | |
1449 | TV->Tolerance(tol); | |
1450 | else | |
1451 | B.UpdateVertex(V, tol); | |
1452 | } | |
1453 | else { | |
0d969553 Y |
1454 | // Update can only increase tolerance, so if the edge has a greater |
1455 | // tolerance than its faces it is not concerned | |
7fd59977 | 1456 | B.UpdateVertex(V, tol); |
1457 | } | |
1458 | } | |
1459 | } | |
1460 | ||
1461 | //======================================================================= | |
1462 | //function : OrientClosedSolid | |
1463 | //purpose : | |
1464 | //======================================================================= | |
1465 | Standard_Boolean BRepLib::OrientClosedSolid(TopoDS_Solid& solid) | |
1466 | { | |
0d969553 | 1467 | // Set material inside the solid |
7fd59977 | 1468 | BRepClass3d_SolidClassifier where(solid); |
1469 | where.PerformInfinitePoint(Precision::Confusion()); | |
1470 | if (where.State()==TopAbs_IN) { | |
1471 | solid.Reverse(); | |
1472 | } | |
1473 | else if (where.State()==TopAbs_ON || where.State()==TopAbs_UNKNOWN) | |
1474 | return Standard_False; | |
1475 | ||
1476 | return Standard_True; | |
1477 | } | |
1478 | ||
1479 | //======================================================================= | |
1480 | //function : tgtfaces | |
0d969553 Y |
1481 | //purpose : check the angle at the border between two squares. |
1482 | // Two shares should have a shared front edge. | |
7fd59977 | 1483 | //======================================================================= |
1484 | ||
1485 | static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed, | |
1486 | const TopoDS_Face& F1, | |
1487 | const TopoDS_Face& F2, | |
1488 | const Standard_Real ta, | |
1489 | const Standard_Boolean couture) | |
1490 | { | |
1491 | Standard_Real u; | |
1492 | TopoDS_Edge E = Ed; | |
1493 | BRepAdaptor_Surface aBAS1(F1,Standard_False); | |
1494 | BRepAdaptor_Surface aBAS2(F2,Standard_False); | |
1495 | Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(aBAS1); | |
1496 | Handle(BRepAdaptor_HSurface) HS2; | |
1497 | if(couture) HS2 = HS1; | |
1498 | else HS2 = new BRepAdaptor_HSurface(aBAS2); | |
1499 | ||
1500 | E.Orientation(TopAbs_FORWARD); | |
1501 | Handle(BRepAdaptor_HCurve2d) HC2d1 = new BRepAdaptor_HCurve2d(); | |
1502 | HC2d1->ChangeCurve2d().Initialize(E,F1); | |
1503 | if(couture) E.Orientation(TopAbs_REVERSED); | |
1504 | Handle(BRepAdaptor_HCurve2d) HC2d2 = new BRepAdaptor_HCurve2d(); | |
1505 | HC2d2->ChangeCurve2d().Initialize(E,F2); | |
1506 | Adaptor3d_CurveOnSurface C1(HC2d1,HS1); | |
1507 | Adaptor3d_CurveOnSurface C2(HC2d2,HS2); | |
1508 | ||
1509 | Standard_Boolean rev1 = (F1.Orientation() == TopAbs_REVERSED); | |
1510 | Standard_Boolean rev2 = (F2.Orientation() == TopAbs_REVERSED); | |
c6541a0c | 1511 | Standard_Real f,l,eps, angmax = -M_PI; |
7fd59977 | 1512 | Standard_Real ang =0.; |
7fd59977 | 1513 | BRep_Tool::Range(E,f,l); |
1514 | Extrema_LocateExtPC ext; | |
1515 | Standard_Boolean IsInitialized = Standard_False; | |
1516 | ||
1517 | eps = (l - f)/100.; | |
0d969553 Y |
1518 | f += eps; // to avoid calculations on |
1519 | l -= eps; // points of pointed squares. | |
7fd59977 | 1520 | gp_Pnt2d p; |
1521 | gp_Pnt pp1,pp2;//,PP; | |
1522 | gp_Vec du,dv; | |
1523 | gp_Vec d1,d2; | |
1524 | Standard_Real uu, vv, norm; | |
1525 | ||
1526 | Standard_Integer i; | |
1527 | Standard_Boolean Nok; | |
1528 | for(i = 0; (i<= 20) && (angmax<=ta) ; i++){ | |
0d969553 | 1529 | // First suppose that this is sameParameter |
7fd59977 | 1530 | Nok = Standard_True; |
1531 | u = f + (l-f)*i/20; | |
1532 | HC2d1->D0(u,p); | |
1533 | HS1->D1(p.X(),p.Y(),pp1,du,dv); | |
1534 | d1 = (du.Crossed(dv)); | |
1535 | norm = d1.Magnitude(); | |
1536 | if (norm > 1.e-12) d1 /= norm; | |
1537 | else Nok=Standard_False; | |
1538 | if(rev1) d1.Reverse(); | |
1539 | ||
1540 | HC2d2->D0(u,p); | |
1541 | HS2->D1(p.X(), p.Y(), pp2, du, dv); | |
1542 | d2 = (du.Crossed(dv)); | |
1543 | norm = d2.Magnitude(); | |
1544 | if (norm> 1.e-12) d2 /= norm; | |
1545 | else Nok=Standard_False; | |
1546 | if(rev2) d2.Reverse(); | |
1547 | if (Nok) ang = d1.Angle(d2); | |
1548 | ||
0d969553 | 1549 | if (Nok &&(ang > ta)) { // Refine by projection |
7fd59977 | 1550 | if (! IsInitialized ) { |
1551 | ext.Initialize(C2,f,l,Precision::PConfusion()); | |
1552 | IsInitialized = Standard_True; | |
1553 | } | |
1554 | ext.Perform(pp1,u); | |
1555 | if(ext.IsDone() && ext.IsMin()){ | |
1556 | Extrema_POnCurv poc = ext.Point(); | |
1557 | Standard_Real v = poc.Parameter(); | |
1558 | ||
1559 | HC2d2->D0(v,p); | |
1560 | p.Coord(uu,vv); | |
1561 | HS2->D1(p.X(), p.Y(), pp2, du, dv); | |
1562 | d2 = (du.Crossed(dv)); | |
1563 | norm = d2.Magnitude(); | |
1564 | if (norm> 1.e-12) d2 /= norm; | |
1565 | else Nok = Standard_False; | |
1566 | if(rev2) d2.Reverse(); | |
1567 | if (Nok) ang = d1.Angle(d2); | |
1568 | } | |
1569 | } | |
1570 | if(ang >= angmax) angmax = ang; | |
1571 | } | |
1572 | ||
1573 | return (angmax<=ta); | |
1574 | ||
1575 | } | |
1576 | ||
1577 | ||
1578 | //======================================================================= | |
1579 | // function : EncodeRegularity | |
0d969553 Y |
1580 | // purpose : code the regularities on all edges of the shape, boundary of |
1581 | // two faces that do not have it. | |
7fd59977 | 1582 | //======================================================================= |
1583 | ||
1584 | void BRepLib::EncodeRegularity(const TopoDS_Shape& S, | |
1585 | const Standard_Real TolAng) | |
1586 | { | |
1587 | BRep_Builder B; | |
1588 | TopTools_IndexedDataMapOfShapeListOfShape M; | |
1589 | TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,M); | |
1590 | TopTools_ListIteratorOfListOfShape It; | |
1591 | TopExp_Explorer Ex; | |
1592 | TopoDS_Face F1,F2; | |
1593 | Standard_Boolean found, couture; | |
1594 | for(Standard_Integer i = 1; i <= M.Extent(); i++){ | |
1595 | TopoDS_Edge E = TopoDS::Edge(M.FindKey(i)); | |
1596 | found = Standard_False; couture = Standard_False; | |
1597 | F1.Nullify(); | |
1598 | for(It.Initialize(M.FindFromIndex(i));It.More() && !found;It.Next()){ | |
1599 | if(F1.IsNull()) { F1 = TopoDS::Face(It.Value()); } | |
1600 | else { | |
1601 | if(!F1.IsSame(TopoDS::Face(It.Value()))){ | |
1602 | found = Standard_True; | |
1603 | F2 = TopoDS::Face(It.Value()); | |
1604 | } | |
1605 | } | |
1606 | } | |
0d969553 | 1607 | if (!found && !F1.IsNull()){//is it a sewing edge? |
7fd59977 | 1608 | TopAbs_Orientation orE = E.Orientation(); |
1609 | TopoDS_Edge curE; | |
1610 | for(Ex.Init(F1,TopAbs_EDGE);Ex.More() && !found;Ex.Next()){ | |
1611 | curE= TopoDS::Edge(Ex.Current()); | |
1612 | if(E.IsSame(curE) && orE != curE.Orientation()) { | |
1613 | found = Standard_True; | |
1614 | couture = Standard_True; | |
1615 | F2 = F1; | |
1616 | } | |
1617 | } | |
1618 | } | |
1619 | if(found){ | |
1620 | if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){ | |
041bfce9 | 1621 | |
1622 | try { | |
1623 | if(tgtfaces(E, F1, F2, TolAng, couture)){ | |
1624 | B.Continuity(E,F1,F2,GeomAbs_G1); | |
1625 | } | |
1626 | } | |
1627 | catch(Standard_Failure) | |
1628 | { | |
1629 | } | |
7fd59977 | 1630 | } |
1631 | } | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | //======================================================================= | |
1636 | // function : EncodeRegularity | |
0d969553 | 1637 | // purpose : code the regularity between 2 faces on an edge |
7fd59977 | 1638 | //======================================================================= |
1639 | ||
1640 | void BRepLib::EncodeRegularity(TopoDS_Edge& E, | |
1641 | const TopoDS_Face& F1, | |
1642 | const TopoDS_Face& F2, | |
1643 | const Standard_Real TolAng) | |
1644 | { | |
1645 | BRep_Builder B; | |
1646 | if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){ | |
041bfce9 | 1647 | try { |
1648 | if( tgtfaces(E, F1, F2, TolAng, F1.IsEqual(F2))) { | |
1649 | B.Continuity(E,F1,F2,GeomAbs_G1); | |
1650 | } | |
1651 | } | |
1652 | catch(Standard_Failure) | |
1653 | { | |
1654 | } | |
7fd59977 | 1655 | } |
1656 | } | |
1657 | ||
1658 | //======================================================================= | |
1659 | //function : SortFaces | |
1660 | //purpose : | |
1661 | //======================================================================= | |
1662 | ||
1663 | void BRepLib::SortFaces (const TopoDS_Shape& Sh, | |
1664 | TopTools_ListOfShape& LF) | |
1665 | { | |
1666 | LF.Clear(); | |
1667 | TopTools_ListOfShape LTri,LPlan,LCyl,LCon,LSphere,LTor,LOther; | |
1668 | TopExp_Explorer exp(Sh,TopAbs_FACE); | |
1669 | TopLoc_Location l; | |
1670 | Handle(Geom_Surface) S; | |
1671 | ||
1672 | for (; exp.More(); exp.Next()) { | |
1673 | const TopoDS_Face& F = TopoDS::Face(exp.Current()); | |
1674 | S = BRep_Tool::Surface(F, l); | |
1675 | if (!S.IsNull()) { | |
1676 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { | |
1677 | S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); | |
1678 | } | |
1679 | GeomAdaptor_Surface AS(S); | |
1680 | switch (AS.GetType()) { | |
1681 | case GeomAbs_Plane: | |
1682 | { | |
1683 | LPlan.Append(F); | |
1684 | break; | |
1685 | } | |
1686 | case GeomAbs_Cylinder: | |
1687 | { | |
1688 | LCyl.Append(F); | |
1689 | break; | |
1690 | } | |
1691 | case GeomAbs_Cone: | |
1692 | { | |
1693 | LCon.Append(F); | |
1694 | break; | |
1695 | } | |
1696 | case GeomAbs_Sphere: | |
1697 | { | |
1698 | LSphere.Append(F); | |
1699 | break; | |
1700 | } | |
1701 | case GeomAbs_Torus: | |
1702 | { | |
1703 | LTor.Append(F); | |
1704 | break; | |
1705 | } | |
1706 | default: | |
1707 | LOther.Append(F); | |
1708 | } | |
1709 | } | |
1710 | else LTri.Append(F); | |
1711 | } | |
1712 | LF.Append(LPlan); LF.Append(LCyl ); LF.Append(LCon); LF.Append(LSphere); | |
1713 | LF.Append(LTor ); LF.Append(LOther); LF.Append(LTri); | |
1714 | } | |
1715 | ||
1716 | //======================================================================= | |
1717 | //function : ReverseSortFaces | |
1718 | //purpose : | |
1719 | //======================================================================= | |
1720 | ||
1721 | void BRepLib::ReverseSortFaces (const TopoDS_Shape& Sh, | |
1722 | TopTools_ListOfShape& LF) | |
1723 | { | |
1724 | LF.Clear(); | |
1725 | TopTools_ListOfShape LTri,LPlan,LCyl,LCon,LSphere,LTor,LOther; | |
1726 | TopExp_Explorer exp(Sh,TopAbs_FACE); | |
1727 | TopLoc_Location l; | |
1728 | Handle(Geom_Surface) S; | |
1729 | ||
1730 | for (; exp.More(); exp.Next()) { | |
1731 | const TopoDS_Face& F = TopoDS::Face(exp.Current()); | |
1732 | S = BRep_Tool::Surface(F, l); | |
1733 | if (!S.IsNull()) { | |
1734 | if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { | |
1735 | S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); | |
1736 | } | |
1737 | GeomAdaptor_Surface AS(S); | |
1738 | switch (AS.GetType()) { | |
1739 | case GeomAbs_Plane: | |
1740 | { | |
1741 | LPlan.Append(F); | |
1742 | break; | |
1743 | } | |
1744 | case GeomAbs_Cylinder: | |
1745 | { | |
1746 | LCyl.Append(F); | |
1747 | break; | |
1748 | } | |
1749 | case GeomAbs_Cone: | |
1750 | { | |
1751 | LCon.Append(F); | |
1752 | break; | |
1753 | } | |
1754 | case GeomAbs_Sphere: | |
1755 | { | |
1756 | LSphere.Append(F); | |
1757 | break; | |
1758 | } | |
1759 | case GeomAbs_Torus: | |
1760 | { | |
1761 | LTor.Append(F); | |
1762 | break; | |
1763 | } | |
1764 | default: | |
1765 | LOther.Append(F); | |
1766 | } | |
1767 | } | |
1768 | else LTri.Append(F); | |
1769 | } | |
1770 | LF.Append(LTri); LF.Append(LOther); LF.Append(LTor ); LF.Append(LSphere); | |
1771 | LF.Append(LCon); LF.Append(LCyl ); LF.Append(LPlan); | |
1772 | ||
1773 | } | |
1774 | ||
1775 |