7fd59977 |
1 | // File: BRepCheck_Edge.cxx |
2 | // Created: Mon Dec 11 13:42:44 1995 |
3 | // Author: Jacques GOUSSARD |
4 | // <jag@bravox> |
5 | |
6 | |
7 | #include <BRepCheck_Edge.ixx> |
8 | #include <TColStd_Array1OfTransient.hxx> |
9 | |
10 | #include <BRepCheck_ListOfStatus.hxx> |
11 | #include <BRepCheck_ListIteratorOfListOfStatus.hxx> |
12 | |
13 | #include <BRep_TEdge.hxx> |
14 | #include <BRep_TFace.hxx> |
15 | |
16 | #include <BRep_CurveRepresentation.hxx> |
17 | #include <BRep_ListOfCurveRepresentation.hxx> |
18 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
19 | #include <BRep_GCurve.hxx> |
20 | #include <BRep_CurveOnSurface.hxx> |
21 | |
22 | #include <BRep_Tool.hxx> |
23 | |
24 | #include <TopExp_Explorer.hxx> |
25 | |
26 | #include <Geom_Surface.hxx> |
27 | #include <Geom_RectangularTrimmedSurface.hxx> |
28 | #include <Geom_Plane.hxx> |
29 | #include <Geom_TrimmedCurve.hxx> |
30 | #include <Geom2d_Curve.hxx> |
31 | |
32 | #include <Geom2dAdaptor_HCurve.hxx> |
33 | #include <GeomAdaptor_Curve.hxx> |
34 | #include <GeomAdaptor_HCurve.hxx> |
35 | #include <GeomAdaptor_HSurface.hxx> |
36 | #include <Adaptor3d_CurveOnSurface.hxx> |
37 | #include <Adaptor3d_HCurveOnSurface.hxx> |
38 | |
39 | #include <ProjLib_ProjectedCurve.hxx> |
40 | #include <GeomProjLib.hxx> |
41 | #include <Extrema_LocateExtPC.hxx> |
42 | |
43 | #include <BRepCheck.hxx> |
44 | #include <Geom2dAdaptor.hxx> |
45 | #include <TopoDS.hxx> |
46 | #include <TopAbs_ShapeEnum.hxx> |
47 | #include <TopoDS_Face.hxx> |
48 | #include <Precision.hxx> |
49 | |
50 | |
51 | static Standard_Boolean Validate(const Adaptor3d_Curve&, |
52 | const Adaptor3d_Curve&, |
53 | const Standard_Real, |
54 | const Standard_Boolean); |
55 | |
56 | |
57 | #define NCONTROL 23 |
58 | |
59 | //======================================================================= |
60 | //function : BRepCheck_Edge |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | BRepCheck_Edge::BRepCheck_Edge(const TopoDS_Edge& E) |
65 | { |
66 | Init(E); |
67 | myGctrl = Standard_True; |
68 | } |
69 | |
70 | //======================================================================= |
71 | //function : Minimum |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | void BRepCheck_Edge::Minimum() |
76 | { |
77 | |
78 | if (!myMin) { |
79 | BRepCheck_ListOfStatus thelist; |
80 | myMap.Bind(myShape, thelist); |
81 | BRepCheck_ListOfStatus& lst = myMap(myShape); |
82 | myCref.Nullify(); |
83 | |
84 | // Existence et unicite d`une representation 3D |
85 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); |
86 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); |
87 | Standard_Boolean exist = Standard_False; |
88 | Standard_Boolean unique = Standard_True; |
89 | // Search for a 3D reference. If no existent one, creates it with the |
90 | // first encountered CurveOnSurf; if multiple, chooses the first one... |
91 | |
92 | Standard_Boolean Degenerated = TE->Degenerated(); |
93 | Standard_Boolean SameParameter = TE->SameParameter(); |
94 | Standard_Boolean SameRange = TE->SameRange(); |
95 | if (!SameRange && SameParameter) { |
96 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
97 | } |
98 | // Handle(Geom_Curve) C3d; |
99 | |
100 | while (itcr.More()) { |
101 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
102 | if (cr->IsCurve3D()) { |
103 | if (!exist) { |
104 | exist = Standard_True; |
105 | } |
106 | else { |
107 | unique = Standard_False; |
108 | } |
109 | if (myCref.IsNull() && !cr->Curve3D().IsNull()) { |
110 | myCref = cr; |
111 | } |
112 | } |
113 | itcr.Next(); |
114 | } |
115 | |
116 | if (!exist) { |
117 | BRepCheck::Add(lst,BRepCheck_No3DCurve); |
118 | // myCref est nulle |
119 | } |
120 | else if (!unique) { |
121 | BRepCheck::Add(lst,BRepCheck_Multiple3DCurve); |
122 | } |
123 | |
124 | if (myCref.IsNull() && !Degenerated) { |
125 | itcr.Initialize(TE->Curves()); |
126 | while (itcr.More()) { |
127 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
128 | if (cr->IsCurveOnSurface()) { |
129 | myCref = cr; |
130 | break; |
131 | } |
132 | itcr.Next(); |
133 | } |
134 | } |
135 | else if (!myCref.IsNull() && Degenerated){ |
136 | BRepCheck::Add(lst,BRepCheck_InvalidDegeneratedFlag); |
137 | } |
138 | |
139 | if (!myCref.IsNull()) { |
140 | const Handle(BRep_GCurve)& GCref = *((Handle(BRep_GCurve)*)&myCref); |
141 | Standard_Real First,Last; |
142 | GCref->Range(First,Last); |
143 | if (Last<=First) { |
144 | myCref.Nullify(); |
145 | BRepCheck::Add(lst,BRepCheck_InvalidRange); |
146 | } |
147 | else { |
148 | if (myCref->IsCurve3D()) { |
149 | // eap 6 Jun 2002 occ332 |
150 | // better transform C3d instead of transforming Surf upto C3d initial location, |
151 | // on transformed BSpline surface 'same parameter' may seem wrong |
152 | TopLoc_Location L = myShape.Location() * myCref->Location(); |
153 | Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast |
154 | (myCref->Curve3D()->Transformed |
155 | (/*myCref->Location()*/L.Transformation())); |
156 | GeomAdaptor_Curve GAC3d(C3d,First,Last); |
157 | myHCurve = new GeomAdaptor_HCurve(GAC3d); |
158 | } |
159 | else { // curve on surface |
160 | Handle(Geom_Surface) Sref = myCref->Surface(); |
161 | Sref = Handle(Geom_Surface)::DownCast |
162 | (Sref->Transformed(myCref->Location().Transformation())); |
163 | const Handle(Geom2d_Curve)& PCref = myCref->PCurve(); |
164 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); |
165 | Handle(Geom2dAdaptor_HCurve) GHPCref = |
166 | new Geom2dAdaptor_HCurve(PCref,First,Last); |
167 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); |
168 | myHCurve = new Adaptor3d_HCurveOnSurface(ACSref); |
169 | } |
170 | } |
171 | } |
172 | if (lst.IsEmpty()) { |
173 | lst.Append(BRepCheck_NoError); |
174 | } |
175 | myMin = Standard_True; |
176 | } |
177 | } |
178 | |
179 | |
180 | //======================================================================= |
181 | //function : InContext |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | void BRepCheck_Edge::InContext(const TopoDS_Shape& S) |
186 | { |
187 | if (myMap.IsBound(S)) { |
188 | return; |
189 | } |
190 | BRepCheck_ListOfStatus thelist; |
191 | myMap.Bind(S, thelist); |
192 | BRepCheck_ListOfStatus& lst = myMap(S); |
193 | |
194 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); |
195 | Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape)); |
196 | |
197 | TopAbs_ShapeEnum styp = S.ShapeType(); |
198 | // for (TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next()) { |
199 | TopExp_Explorer exp(S,TopAbs_EDGE) ; |
200 | for ( ; exp.More(); exp.Next()) { |
201 | if (exp.Current().IsSame(myShape)) { |
202 | break; |
203 | } |
204 | } |
205 | if (!exp.More()) { |
206 | BRepCheck::Add(lst,BRepCheck_SubshapeNotInShape); |
207 | return; |
208 | } |
209 | |
210 | switch (styp) { |
211 | case TopAbs_FACE: |
212 | if (!myCref.IsNull()) { |
213 | |
214 | Standard_Boolean SameParameter = TE->SameParameter(); |
215 | Standard_Boolean SameRange = TE->SameRange(); |
216 | // Modified by skv - Tue Apr 27 11:48:13 2004 Begin |
217 | if (!SameParameter || !SameRange) { |
218 | if (!SameParameter) |
219 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
220 | if (!SameRange) |
221 | BRepCheck::Add(lst,BRepCheck_InvalidSameRangeFlag); |
222 | |
223 | return; |
224 | } |
225 | // Modified by skv - Tue Apr 27 11:48:14 2004 End |
226 | Standard_Real First = myHCurve->FirstParameter(); |
227 | Standard_Real Last = myHCurve->LastParameter(); |
228 | |
229 | Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape()); |
230 | const TopLoc_Location& Floc = S.Location(); |
231 | const TopLoc_Location& TFloc = TF->Location(); |
232 | const Handle(Geom_Surface)& Su = TF->Surface(); |
233 | TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location()); |
234 | Standard_Boolean pcurvefound = Standard_False; |
235 | |
236 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); |
237 | while (itcr.More()) { |
238 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
239 | if (cr != myCref && cr->IsCurveOnSurface(Su,L)) { |
240 | pcurvefound = Standard_True; |
241 | const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr); |
242 | Standard_Real f,l; |
243 | GC->Range(f,l); |
244 | // gka OCC |
245 | // Modified by skv - Tue Apr 27 11:50:35 2004 Begin |
246 | // if (SameRange && (fabs(f-First) > Precision::PConfusion() || fabs(l-Last)> Precision::PConfusion())) { //f != First || l != Last)) { gka OCC |
247 | if (fabs(f-First) > Precision::PConfusion() || |
248 | fabs(l-Last) > Precision::PConfusion()) { |
249 | BRepCheck::Add(lst,BRepCheck_InvalidSameRangeFlag); |
250 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
251 | // if (SameParameter) { |
252 | // BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
253 | // } |
254 | } |
255 | // Modified by skv - Tue Apr 27 11:50:37 2004 End |
256 | if (myGctrl) { |
257 | Handle(Geom_Surface) Sb = cr->Surface(); |
258 | Sb = Handle(Geom_Surface)::DownCast |
259 | // (Su->Transformed(L.Transformation())); |
260 | (Su->Transformed(/*L*/(Floc * TFloc).Transformation())); |
261 | Handle(Geom2d_Curve) PC = cr->PCurve(); |
262 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(Sb); |
263 | Handle(Geom2dAdaptor_HCurve) GHPC = new Geom2dAdaptor_HCurve(PC,f,l); |
264 | Adaptor3d_CurveOnSurface ACS(GHPC,GAHS); |
265 | Standard_Boolean ok = |
266 | Validate(myHCurve->Curve(),ACS,Tol,SameParameter); |
267 | if (!ok) { |
268 | if (cr->IsCurveOnClosedSurface()) { |
269 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnClosedSurface); |
270 | } |
271 | else { |
272 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnSurface); |
273 | } |
274 | // Modified by skv - Tue Apr 27 11:53:00 2004 Begin |
275 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
276 | // if (SameParameter) { |
277 | // BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
278 | // } |
279 | // Modified by skv - Tue Apr 27 11:53:01 2004 End |
280 | } |
281 | if (cr->IsCurveOnClosedSurface()) { |
282 | GHPC->ChangeCurve2d().Load(cr->PCurve2(),f,l); // same bounds |
283 | ACS.Load(GAHS); // sans doute inutile |
284 | ACS.Load(GHPC); // meme remarque... |
285 | ok = Validate(myHCurve->Curve(),ACS,Tol,SameParameter); |
286 | if (!ok) { |
287 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnClosedSurface); |
288 | // Modified by skv - Tue Apr 27 11:53:20 2004 Begin |
289 | if (SameParameter) { |
290 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); |
291 | } |
292 | // Modified by skv - Tue Apr 27 11:53:23 2004 End |
293 | } |
294 | } |
295 | } |
296 | } |
297 | itcr.Next(); |
298 | } |
299 | |
300 | if (!pcurvefound) { |
301 | Handle(Geom_Plane) P; |
302 | Handle(Standard_Type) dtyp = Su->DynamicType(); |
303 | if (dtyp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
304 | P = Handle(Geom_Plane)::DownCast |
305 | (Handle(Geom_RectangularTrimmedSurface):: |
306 | DownCast(Su)->BasisSurface()); |
307 | } |
308 | else { |
309 | P = Handle(Geom_Plane)::DownCast(Su); |
310 | } |
311 | if (P.IsNull()) { // not a plane |
312 | BRepCheck::Add(lst,BRepCheck_NoCurveOnSurface); |
313 | } |
314 | else { // on fait la projection a la volee, comme BRep_Tool |
315 | // plan en position |
316 | if (myGctrl) { |
317 | P = Handle(Geom_Plane):: |
318 | DownCast(P->Transformed(/*L*/(Floc * TFloc).Transformation()));// eap occ332 |
319 | //on projette Cref sur ce plan |
320 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(P); |
321 | |
322 | // Dub - Normalement myHCurve est une GeomAdaptor_HCurve |
323 | GeomAdaptor_Curve& Gac = |
324 | Handle(GeomAdaptor_HCurve)::DownCast(myHCurve)->ChangeCurve(); |
325 | Handle(Geom_Curve) C3d = Gac.Curve(); |
326 | Handle(Geom_Curve) ProjOnPlane = |
327 | GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,First,Last), |
328 | P, P->Position().Direction(), |
329 | Standard_True); |
330 | Handle(GeomAdaptor_HCurve) aHCurve = |
331 | new GeomAdaptor_HCurve(ProjOnPlane); |
332 | |
333 | ProjLib_ProjectedCurve proj(GAHS,aHCurve); |
334 | Handle(Geom2d_Curve) PC = Geom2dAdaptor::MakeCurve(proj); |
335 | Handle(Geom2dAdaptor_HCurve) GHPC = |
336 | new Geom2dAdaptor_HCurve(PC, |
337 | myHCurve->FirstParameter(), |
338 | myHCurve->LastParameter()); |
339 | |
340 | Adaptor3d_CurveOnSurface ACS(GHPC,GAHS); |
341 | |
342 | Standard_Boolean ok = Validate(myHCurve->Curve(),ACS, |
343 | Tol,Standard_True); // voir dub... |
344 | if (!ok) { |
345 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnSurface); |
346 | } |
347 | } |
348 | } |
349 | } |
350 | } |
351 | break; |
352 | case TopAbs_SOLID: |
353 | { |
354 | // on verifie que l`edge est bien connectee 2 fois (pas de bord libre) |
355 | Standard_Integer nbconnection = 0; |
356 | //TopExp_Explorer exp; |
357 | for (exp.Init(S,TopAbs_FACE); exp.More(); exp.Next()) { |
358 | const TopoDS_Face& fac = TopoDS::Face(exp.Current()); |
359 | TopExp_Explorer exp2; |
360 | for (exp2.Init(fac,TopAbs_EDGE); exp2.More(); exp2.Next()) { |
361 | if (exp2.Current().IsSame(myShape)) { |
362 | nbconnection++; |
363 | } |
364 | } |
365 | } |
366 | if (nbconnection < 2 && !TE->Degenerated()) { |
367 | BRepCheck::Add(myMap(S),BRepCheck_FreeEdge); |
368 | } |
369 | else if (nbconnection > 2) { |
370 | BRepCheck::Add(myMap(S),BRepCheck_InvalidMultiConnexity); |
371 | } |
372 | else { |
373 | BRepCheck::Add(myMap(S),BRepCheck_NoError); |
374 | } |
375 | } |
376 | break; |
377 | default: |
378 | break; |
379 | } |
380 | if (myMap(S).IsEmpty()) { |
381 | myMap(S).Append(BRepCheck_NoError); |
382 | } |
383 | } |
384 | |
385 | |
386 | //======================================================================= |
387 | //function : Blind |
388 | //purpose : |
389 | //======================================================================= |
390 | |
391 | void BRepCheck_Edge::Blind() |
392 | { |
393 | // Modified by skv - Tue Apr 27 11:36:01 2004 Begin |
394 | // The body of this function is removed because of its useless. |
395 | if (!myBlind) { |
396 | myBlind = Standard_True; |
397 | } |
398 | // Modified by skv - Tue Apr 27 11:36:02 2004 End |
399 | } |
400 | |
401 | |
402 | //======================================================================= |
403 | //function : GeometricControls |
404 | //purpose : |
405 | //======================================================================= |
406 | |
407 | void BRepCheck_Edge::GeometricControls(const Standard_Boolean B) |
408 | { |
409 | myGctrl = B; |
410 | } |
411 | |
412 | |
413 | //======================================================================= |
414 | //function : GeometricControls |
415 | //purpose : |
416 | //======================================================================= |
417 | |
418 | Standard_Boolean BRepCheck_Edge::GeometricControls() const |
419 | { |
420 | return myGctrl; |
421 | } |
422 | |
423 | |
424 | //======================================================================= |
425 | //function : Validate |
426 | //purpose : |
427 | //======================================================================= |
428 | |
429 | static Standard_Boolean Validate(const Adaptor3d_Curve& CRef, |
430 | const Adaptor3d_Curve& Other, |
431 | const Standard_Real Tol, |
432 | const Standard_Boolean SameParameter) |
433 | { |
434 | Standard_Boolean Status = Standard_True; |
435 | gp_Pnt problematic_point ; |
436 | Standard_Real First = CRef.FirstParameter(); |
437 | Standard_Real Last = CRef.LastParameter(); |
438 | //gka OCC |
439 | Standard_Boolean proj = (!SameParameter || |
440 | fabs(Other.FirstParameter()-First) > Precision::PConfusion() || |
441 | fabs( Other.LastParameter()-Last) > Precision::PConfusion());//First != Other.FirstParameter() ||Last != Other.LastParameter()); gka OCC |
442 | |
443 | Standard_Real Error = 0; |
444 | |
445 | if (!proj) { |
446 | Standard_Real Tol2 = Tol*Tol; |
447 | for (Standard_Integer i = 0; i< NCONTROL; i++) { |
448 | Standard_Real prm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); |
449 | gp_Pnt pref = CRef.Value(prm); |
450 | gp_Pnt pother = Other.Value(prm); |
451 | if (pref.SquareDistance(pother) > Tol2) { |
452 | problematic_point = pref ; |
453 | Status = Standard_False; |
454 | Error = pref.Distance(pother); |
455 | goto FINISH ; |
456 | } |
457 | } |
458 | } |
459 | else { |
460 | Extrema_LocateExtPC refd,otherd; |
461 | Standard_Real OFirst = Other.FirstParameter(); |
462 | Standard_Real OLast = Other.LastParameter(); |
463 | gp_Pnt pd = CRef.Value(First); |
464 | gp_Pnt pdo = Other.Value(OFirst); |
465 | Standard_Real distt = pd.SquareDistance(pdo); |
466 | if (distt > Tol*Tol) { |
467 | problematic_point = pd ; |
468 | Status = Standard_False ; |
469 | Error = Sqrt(distt); |
470 | goto FINISH ; |
471 | } |
472 | pd = CRef.Value(Last); |
473 | pdo = Other.Value(OLast); |
474 | distt = pd.SquareDistance(pdo); |
475 | if (distt > Tol*Tol) { |
476 | problematic_point = pd ; |
477 | Status = Standard_False ; |
478 | Error = Sqrt(distt); |
479 | goto FINISH ; |
480 | } |
481 | |
482 | refd.Initialize(CRef,First,Last,CRef.Resolution(Tol)); |
483 | otherd.Initialize(Other,OFirst,OLast,Other.Resolution(Tol)); |
484 | for (Standard_Integer i = 2; i< NCONTROL-1; i++) { |
485 | Standard_Real rprm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); |
486 | gp_Pnt pref = CRef.Value(rprm); |
487 | Standard_Real oprm = ((NCONTROL-1-i)*OFirst + i*OLast)/(NCONTROL-1); |
488 | gp_Pnt pother = Other.Value(oprm); |
489 | refd.Perform(pother,rprm); |
490 | if (!refd.IsDone() || refd.SquareDistance() > Tol * Tol) { |
491 | problematic_point = pref ; |
492 | Status = Standard_False ; |
493 | if (refd.IsDone()) { |
494 | Error = sqrt (refd.SquareDistance()); |
495 | } |
496 | else { |
497 | Error = RealLast(); |
498 | } |
499 | goto FINISH ; |
500 | } |
501 | otherd.Perform(pref,oprm); |
502 | if (!otherd.IsDone() || otherd.SquareDistance() > Tol * Tol) { |
503 | problematic_point = pref ; |
504 | Status = Standard_False ; |
505 | if (otherd.IsDone()) { |
506 | Error = sqrt (otherd.SquareDistance()); |
507 | } |
508 | else { |
509 | Error = RealLast(); |
510 | } |
511 | goto FINISH ; |
512 | } |
513 | } |
514 | } |
515 | FINISH : |
516 | |
517 | #ifdef DEB |
518 | if (! Status) { |
519 | cout << " **** probleme de SameParameter au point :" << endl; |
520 | cout << " " << problematic_point.Coord(1) << " " |
521 | << problematic_point.Coord(2) << " " |
522 | << problematic_point.Coord(3) << endl ; |
523 | cout << " Erreur detectee :" << Error << " Tolerance :" << Tol << endl; |
524 | } |
525 | #endif |
526 | |
527 | |
528 | return Status ; |
529 | |
530 | } |
531 | |
532 | |
533 | //======================================================================= |
534 | //function : Tolerance |
535 | //purpose : |
536 | //======================================================================= |
537 | |
538 | Standard_Real BRepCheck_Edge::Tolerance() |
539 | { |
540 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); |
541 | Standard_Integer it, iRep=1, nbRep=(TE->Curves()).Extent(); |
542 | if (nbRep<=1) { |
543 | return Precision::Confusion(); |
544 | } |
545 | TColStd_Array1OfTransient theRep(1, nbRep*2); |
546 | Standard_Real First, Last; |
547 | if (!myHCurve.IsNull()) { |
548 | First = myHCurve->FirstParameter(); |
549 | Last= myHCurve->LastParameter(); |
550 | } |
551 | else { |
552 | BRep_Tool::Range(TopoDS::Edge(myShape), First, Last); |
553 | } |
554 | |
555 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); |
556 | for (; itcr.More(); itcr.Next()) { |
557 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
558 | if (cr->IsCurve3D() && !TE->Degenerated()) { |
559 | //// modified by jgv, 20.03.03 //// |
560 | TopLoc_Location Loc = myShape.Location() * cr->Location(); |
561 | Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast |
562 | (cr->Curve3D()->Transformed( Loc.Transformation() )); |
563 | /////////////////////////////////// |
564 | GeomAdaptor_Curve GAC3d(C3d,First,Last); |
565 | it=iRep; |
566 | if (iRep>1) { |
567 | theRep(iRep)=theRep(1); |
568 | it=1; |
569 | } |
570 | theRep(it) = new GeomAdaptor_HCurve(GAC3d); |
571 | iRep++; |
572 | } |
573 | else if (cr->IsCurveOnSurface()) { |
574 | { |
575 | Handle(Geom_Surface) Sref = cr->Surface(); |
576 | //// modified by jgv, 20.03.03 //// |
577 | TopLoc_Location Loc = myShape.Location() * cr->Location(); |
578 | Sref = Handle(Geom_Surface)::DownCast |
579 | (Sref->Transformed( Loc.Transformation() )); |
580 | /////////////////////////////////// |
581 | const Handle(Geom2d_Curve)& PCref = cr->PCurve(); |
582 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); |
583 | Handle(Geom2dAdaptor_HCurve) GHPCref = |
584 | new Geom2dAdaptor_HCurve(PCref,First,Last); |
585 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); |
586 | theRep(iRep) = new Adaptor3d_HCurveOnSurface(ACSref); |
587 | iRep++; |
588 | } |
589 | if (cr->IsCurveOnClosedSurface()) { |
590 | Handle(Geom_Surface) Sref = cr->Surface(); |
591 | Sref = Handle(Geom_Surface)::DownCast |
592 | (Sref->Transformed(cr->Location().Transformation())); |
593 | const Handle(Geom2d_Curve)& PCref = cr->PCurve2(); |
594 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); |
595 | Handle(Geom2dAdaptor_HCurve) GHPCref = |
596 | new Geom2dAdaptor_HCurve(PCref,First,Last); |
597 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); |
598 | theRep(iRep) = new Adaptor3d_HCurveOnSurface(ACSref); |
599 | iRep++; |
600 | nbRep++; |
601 | } |
602 | } |
603 | else { |
604 | nbRep--; |
605 | } |
606 | } |
607 | |
608 | Standard_Real dist2, tol2, tolCal=0., prm; |
609 | gp_Pnt center, othP; |
610 | Standard_Integer i, imax; |
611 | for (i= 0; i< NCONTROL; i++) { |
612 | prm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); |
613 | tol2=dist2=0.; |
614 | center=(*(Handle(Adaptor3d_HCurve)*)&theRep(1))->Value(prm); |
615 | for (iRep=2; iRep<=nbRep; iRep++) { |
616 | othP=(*(Handle(Adaptor3d_HCurve)*)&theRep(iRep))->Value(prm); |
617 | dist2=center.SquareDistance(othP); |
618 | if (dist2>tolCal) tolCal=dist2; |
619 | } |
620 | if (tol2>tolCal) { |
621 | tolCal=tol2; |
622 | imax=i; |
623 | } |
624 | } |
625 | // On prend 5% de marge car au dessus on crontrole severement |
626 | return sqrt(tolCal)*1.05; |
627 | } |