Commit | Line | Data |
---|---|---|
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 | ||
171d8cd9 P |
51 | //modified by NIZNHY-PKV Thu May 05 09:01:57 2011f |
52 | static | |
53 | Standard_Boolean Validate(const Adaptor3d_Curve&, | |
54 | const Adaptor3d_CurveOnSurface&, | |
55 | const Standard_Real, | |
56 | const Standard_Boolean); | |
57 | static | |
58 | void PrintProblematicPoint(const gp_Pnt&, | |
59 | const Standard_Real, | |
60 | const Standard_Real); | |
61 | ||
62 | static | |
63 | Standard_Real Prec(const Adaptor3d_Curve& aAC3D, | |
64 | const Adaptor3d_CurveOnSurface& aACS); | |
65 | static | |
66 | Standard_Real PrecCurve(const Adaptor3d_Curve& aAC3D); | |
67 | static | |
68 | Standard_Real PrecSurface(const Adaptor3d_CurveOnSurface& aACS); | |
69 | ||
70 | //static Standard_Boolean Validate(const Adaptor3d_Curve&, | |
71 | // const Adaptor3d_Curve&, | |
72 | // const Standard_Real, | |
73 | // const Standard_Boolean); | |
74 | //modified by NIZNHY-PKV Thu May 05 09:02:01 2011t | |
7fd59977 | 75 | |
76 | #define NCONTROL 23 | |
77 | ||
78 | //======================================================================= | |
79 | //function : BRepCheck_Edge | |
80 | //purpose : | |
81 | //======================================================================= | |
82 | ||
83 | BRepCheck_Edge::BRepCheck_Edge(const TopoDS_Edge& E) | |
84 | { | |
85 | Init(E); | |
86 | myGctrl = Standard_True; | |
87 | } | |
88 | ||
89 | //======================================================================= | |
90 | //function : Minimum | |
91 | //purpose : | |
92 | //======================================================================= | |
93 | ||
94 | void BRepCheck_Edge::Minimum() | |
95 | { | |
96 | ||
97 | if (!myMin) { | |
98 | BRepCheck_ListOfStatus thelist; | |
99 | myMap.Bind(myShape, thelist); | |
100 | BRepCheck_ListOfStatus& lst = myMap(myShape); | |
101 | myCref.Nullify(); | |
102 | ||
103 | // Existence et unicite d`une representation 3D | |
104 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); | |
105 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
106 | Standard_Boolean exist = Standard_False; | |
107 | Standard_Boolean unique = Standard_True; | |
108 | // Search for a 3D reference. If no existent one, creates it with the | |
109 | // first encountered CurveOnSurf; if multiple, chooses the first one... | |
110 | ||
111 | Standard_Boolean Degenerated = TE->Degenerated(); | |
112 | Standard_Boolean SameParameter = TE->SameParameter(); | |
113 | Standard_Boolean SameRange = TE->SameRange(); | |
114 | if (!SameRange && SameParameter) { | |
115 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
116 | } | |
117 | // Handle(Geom_Curve) C3d; | |
118 | ||
119 | while (itcr.More()) { | |
120 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
121 | if (cr->IsCurve3D()) { | |
122 | if (!exist) { | |
123 | exist = Standard_True; | |
124 | } | |
125 | else { | |
126 | unique = Standard_False; | |
127 | } | |
128 | if (myCref.IsNull() && !cr->Curve3D().IsNull()) { | |
129 | myCref = cr; | |
130 | } | |
131 | } | |
132 | itcr.Next(); | |
133 | } | |
134 | ||
135 | if (!exist) { | |
136 | BRepCheck::Add(lst,BRepCheck_No3DCurve); | |
137 | // myCref est nulle | |
138 | } | |
139 | else if (!unique) { | |
140 | BRepCheck::Add(lst,BRepCheck_Multiple3DCurve); | |
141 | } | |
142 | ||
143 | if (myCref.IsNull() && !Degenerated) { | |
144 | itcr.Initialize(TE->Curves()); | |
145 | while (itcr.More()) { | |
146 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
147 | if (cr->IsCurveOnSurface()) { | |
148 | myCref = cr; | |
149 | break; | |
150 | } | |
151 | itcr.Next(); | |
152 | } | |
153 | } | |
154 | else if (!myCref.IsNull() && Degenerated){ | |
155 | BRepCheck::Add(lst,BRepCheck_InvalidDegeneratedFlag); | |
156 | } | |
157 | ||
158 | if (!myCref.IsNull()) { | |
159 | const Handle(BRep_GCurve)& GCref = *((Handle(BRep_GCurve)*)&myCref); | |
160 | Standard_Real First,Last; | |
161 | GCref->Range(First,Last); | |
162 | if (Last<=First) { | |
163 | myCref.Nullify(); | |
164 | BRepCheck::Add(lst,BRepCheck_InvalidRange); | |
165 | } | |
166 | else { | |
167 | if (myCref->IsCurve3D()) { | |
168 | // eap 6 Jun 2002 occ332 | |
169 | // better transform C3d instead of transforming Surf upto C3d initial location, | |
170 | // on transformed BSpline surface 'same parameter' may seem wrong | |
171 | TopLoc_Location L = myShape.Location() * myCref->Location(); | |
172 | Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast | |
173 | (myCref->Curve3D()->Transformed | |
174 | (/*myCref->Location()*/L.Transformation())); | |
175 | GeomAdaptor_Curve GAC3d(C3d,First,Last); | |
176 | myHCurve = new GeomAdaptor_HCurve(GAC3d); | |
177 | } | |
178 | else { // curve on surface | |
179 | Handle(Geom_Surface) Sref = myCref->Surface(); | |
180 | Sref = Handle(Geom_Surface)::DownCast | |
181 | (Sref->Transformed(myCref->Location().Transformation())); | |
182 | const Handle(Geom2d_Curve)& PCref = myCref->PCurve(); | |
183 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); | |
184 | Handle(Geom2dAdaptor_HCurve) GHPCref = | |
185 | new Geom2dAdaptor_HCurve(PCref,First,Last); | |
186 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); | |
187 | myHCurve = new Adaptor3d_HCurveOnSurface(ACSref); | |
188 | } | |
189 | } | |
190 | } | |
191 | if (lst.IsEmpty()) { | |
192 | lst.Append(BRepCheck_NoError); | |
193 | } | |
194 | myMin = Standard_True; | |
195 | } | |
196 | } | |
197 | ||
198 | ||
199 | //======================================================================= | |
200 | //function : InContext | |
201 | //purpose : | |
202 | //======================================================================= | |
203 | ||
204 | void BRepCheck_Edge::InContext(const TopoDS_Shape& S) | |
205 | { | |
206 | if (myMap.IsBound(S)) { | |
207 | return; | |
208 | } | |
209 | BRepCheck_ListOfStatus thelist; | |
210 | myMap.Bind(S, thelist); | |
211 | BRepCheck_ListOfStatus& lst = myMap(S); | |
212 | ||
213 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); | |
214 | Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape)); | |
215 | ||
216 | TopAbs_ShapeEnum styp = S.ShapeType(); | |
217 | // for (TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next()) { | |
218 | TopExp_Explorer exp(S,TopAbs_EDGE) ; | |
219 | for ( ; exp.More(); exp.Next()) { | |
220 | if (exp.Current().IsSame(myShape)) { | |
221 | break; | |
222 | } | |
223 | } | |
224 | if (!exp.More()) { | |
225 | BRepCheck::Add(lst,BRepCheck_SubshapeNotInShape); | |
226 | return; | |
227 | } | |
228 | ||
229 | switch (styp) { | |
230 | case TopAbs_FACE: | |
231 | if (!myCref.IsNull()) { | |
232 | ||
233 | Standard_Boolean SameParameter = TE->SameParameter(); | |
234 | Standard_Boolean SameRange = TE->SameRange(); | |
235 | // Modified by skv - Tue Apr 27 11:48:13 2004 Begin | |
236 | if (!SameParameter || !SameRange) { | |
237 | if (!SameParameter) | |
238 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
239 | if (!SameRange) | |
240 | BRepCheck::Add(lst,BRepCheck_InvalidSameRangeFlag); | |
241 | ||
242 | return; | |
243 | } | |
244 | // Modified by skv - Tue Apr 27 11:48:14 2004 End | |
245 | Standard_Real First = myHCurve->FirstParameter(); | |
246 | Standard_Real Last = myHCurve->LastParameter(); | |
247 | ||
248 | Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape()); | |
249 | const TopLoc_Location& Floc = S.Location(); | |
250 | const TopLoc_Location& TFloc = TF->Location(); | |
251 | const Handle(Geom_Surface)& Su = TF->Surface(); | |
252 | TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location()); | |
253 | Standard_Boolean pcurvefound = Standard_False; | |
254 | ||
255 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
256 | while (itcr.More()) { | |
257 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
258 | if (cr != myCref && cr->IsCurveOnSurface(Su,L)) { | |
259 | pcurvefound = Standard_True; | |
260 | const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr); | |
261 | Standard_Real f,l; | |
262 | GC->Range(f,l); | |
263 | // gka OCC | |
264 | // Modified by skv - Tue Apr 27 11:50:35 2004 Begin | |
265 | // if (SameRange && (fabs(f-First) > Precision::PConfusion() || fabs(l-Last)> Precision::PConfusion())) { //f != First || l != Last)) { gka OCC | |
266 | if (fabs(f-First) > Precision::PConfusion() || | |
267 | fabs(l-Last) > Precision::PConfusion()) { | |
268 | BRepCheck::Add(lst,BRepCheck_InvalidSameRangeFlag); | |
269 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
270 | // if (SameParameter) { | |
271 | // BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
272 | // } | |
273 | } | |
274 | // Modified by skv - Tue Apr 27 11:50:37 2004 End | |
275 | if (myGctrl) { | |
276 | Handle(Geom_Surface) Sb = cr->Surface(); | |
277 | Sb = Handle(Geom_Surface)::DownCast | |
278 | // (Su->Transformed(L.Transformation())); | |
279 | (Su->Transformed(/*L*/(Floc * TFloc).Transformation())); | |
280 | Handle(Geom2d_Curve) PC = cr->PCurve(); | |
281 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(Sb); | |
282 | Handle(Geom2dAdaptor_HCurve) GHPC = new Geom2dAdaptor_HCurve(PC,f,l); | |
283 | Adaptor3d_CurveOnSurface ACS(GHPC,GAHS); | |
284 | Standard_Boolean ok = | |
285 | Validate(myHCurve->Curve(),ACS,Tol,SameParameter); | |
286 | if (!ok) { | |
287 | if (cr->IsCurveOnClosedSurface()) { | |
288 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnClosedSurface); | |
289 | } | |
290 | else { | |
291 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnSurface); | |
292 | } | |
293 | // Modified by skv - Tue Apr 27 11:53:00 2004 Begin | |
294 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
295 | // if (SameParameter) { | |
296 | // BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
297 | // } | |
298 | // Modified by skv - Tue Apr 27 11:53:01 2004 End | |
299 | } | |
300 | if (cr->IsCurveOnClosedSurface()) { | |
301 | GHPC->ChangeCurve2d().Load(cr->PCurve2(),f,l); // same bounds | |
302 | ACS.Load(GAHS); // sans doute inutile | |
303 | ACS.Load(GHPC); // meme remarque... | |
304 | ok = Validate(myHCurve->Curve(),ACS,Tol,SameParameter); | |
305 | if (!ok) { | |
306 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnClosedSurface); | |
307 | // Modified by skv - Tue Apr 27 11:53:20 2004 Begin | |
308 | if (SameParameter) { | |
309 | BRepCheck::Add(lst,BRepCheck_InvalidSameParameterFlag); | |
310 | } | |
311 | // Modified by skv - Tue Apr 27 11:53:23 2004 End | |
312 | } | |
313 | } | |
314 | } | |
315 | } | |
316 | itcr.Next(); | |
317 | } | |
318 | ||
319 | if (!pcurvefound) { | |
320 | Handle(Geom_Plane) P; | |
321 | Handle(Standard_Type) dtyp = Su->DynamicType(); | |
322 | if (dtyp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { | |
323 | P = Handle(Geom_Plane)::DownCast | |
324 | (Handle(Geom_RectangularTrimmedSurface):: | |
325 | DownCast(Su)->BasisSurface()); | |
326 | } | |
327 | else { | |
328 | P = Handle(Geom_Plane)::DownCast(Su); | |
329 | } | |
330 | if (P.IsNull()) { // not a plane | |
331 | BRepCheck::Add(lst,BRepCheck_NoCurveOnSurface); | |
332 | } | |
333 | else { // on fait la projection a la volee, comme BRep_Tool | |
334 | // plan en position | |
335 | if (myGctrl) { | |
336 | P = Handle(Geom_Plane):: | |
337 | DownCast(P->Transformed(/*L*/(Floc * TFloc).Transformation()));// eap occ332 | |
338 | //on projette Cref sur ce plan | |
339 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(P); | |
340 | ||
341 | // Dub - Normalement myHCurve est une GeomAdaptor_HCurve | |
342 | GeomAdaptor_Curve& Gac = | |
343 | Handle(GeomAdaptor_HCurve)::DownCast(myHCurve)->ChangeCurve(); | |
344 | Handle(Geom_Curve) C3d = Gac.Curve(); | |
345 | Handle(Geom_Curve) ProjOnPlane = | |
346 | GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,First,Last), | |
347 | P, P->Position().Direction(), | |
348 | Standard_True); | |
349 | Handle(GeomAdaptor_HCurve) aHCurve = | |
350 | new GeomAdaptor_HCurve(ProjOnPlane); | |
351 | ||
352 | ProjLib_ProjectedCurve proj(GAHS,aHCurve); | |
353 | Handle(Geom2d_Curve) PC = Geom2dAdaptor::MakeCurve(proj); | |
354 | Handle(Geom2dAdaptor_HCurve) GHPC = | |
355 | new Geom2dAdaptor_HCurve(PC, | |
356 | myHCurve->FirstParameter(), | |
357 | myHCurve->LastParameter()); | |
358 | ||
359 | Adaptor3d_CurveOnSurface ACS(GHPC,GAHS); | |
360 | ||
361 | Standard_Boolean ok = Validate(myHCurve->Curve(),ACS, | |
362 | Tol,Standard_True); // voir dub... | |
363 | if (!ok) { | |
364 | BRepCheck::Add(lst,BRepCheck_InvalidCurveOnSurface); | |
365 | } | |
366 | } | |
367 | } | |
368 | } | |
369 | } | |
370 | break; | |
371 | case TopAbs_SOLID: | |
372 | { | |
373 | // on verifie que l`edge est bien connectee 2 fois (pas de bord libre) | |
374 | Standard_Integer nbconnection = 0; | |
375 | //TopExp_Explorer exp; | |
376 | for (exp.Init(S,TopAbs_FACE); exp.More(); exp.Next()) { | |
377 | const TopoDS_Face& fac = TopoDS::Face(exp.Current()); | |
378 | TopExp_Explorer exp2; | |
379 | for (exp2.Init(fac,TopAbs_EDGE); exp2.More(); exp2.Next()) { | |
380 | if (exp2.Current().IsSame(myShape)) { | |
381 | nbconnection++; | |
382 | } | |
383 | } | |
384 | } | |
385 | if (nbconnection < 2 && !TE->Degenerated()) { | |
386 | BRepCheck::Add(myMap(S),BRepCheck_FreeEdge); | |
387 | } | |
388 | else if (nbconnection > 2) { | |
389 | BRepCheck::Add(myMap(S),BRepCheck_InvalidMultiConnexity); | |
390 | } | |
391 | else { | |
392 | BRepCheck::Add(myMap(S),BRepCheck_NoError); | |
393 | } | |
394 | } | |
395 | break; | |
396 | default: | |
397 | break; | |
398 | } | |
399 | if (myMap(S).IsEmpty()) { | |
400 | myMap(S).Append(BRepCheck_NoError); | |
401 | } | |
402 | } | |
403 | ||
404 | ||
405 | //======================================================================= | |
406 | //function : Blind | |
407 | //purpose : | |
408 | //======================================================================= | |
409 | ||
410 | void BRepCheck_Edge::Blind() | |
411 | { | |
412 | // Modified by skv - Tue Apr 27 11:36:01 2004 Begin | |
413 | // The body of this function is removed because of its useless. | |
414 | if (!myBlind) { | |
415 | myBlind = Standard_True; | |
416 | } | |
417 | // Modified by skv - Tue Apr 27 11:36:02 2004 End | |
418 | } | |
419 | ||
420 | ||
421 | //======================================================================= | |
422 | //function : GeometricControls | |
423 | //purpose : | |
424 | //======================================================================= | |
425 | ||
426 | void BRepCheck_Edge::GeometricControls(const Standard_Boolean B) | |
427 | { | |
428 | myGctrl = B; | |
429 | } | |
430 | ||
431 | ||
432 | //======================================================================= | |
433 | //function : GeometricControls | |
434 | //purpose : | |
435 | //======================================================================= | |
436 | ||
437 | Standard_Boolean BRepCheck_Edge::GeometricControls() const | |
438 | { | |
439 | return myGctrl; | |
440 | } | |
441 | ||
442 | ||
7fd59977 | 443 | |
444 | ||
445 | //======================================================================= | |
446 | //function : Tolerance | |
447 | //purpose : | |
448 | //======================================================================= | |
449 | ||
450 | Standard_Real BRepCheck_Edge::Tolerance() | |
451 | { | |
452 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); | |
453 | Standard_Integer it, iRep=1, nbRep=(TE->Curves()).Extent(); | |
454 | if (nbRep<=1) { | |
455 | return Precision::Confusion(); | |
456 | } | |
457 | TColStd_Array1OfTransient theRep(1, nbRep*2); | |
458 | Standard_Real First, Last; | |
459 | if (!myHCurve.IsNull()) { | |
460 | First = myHCurve->FirstParameter(); | |
461 | Last= myHCurve->LastParameter(); | |
462 | } | |
463 | else { | |
464 | BRep_Tool::Range(TopoDS::Edge(myShape), First, Last); | |
465 | } | |
466 | ||
467 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
468 | for (; itcr.More(); itcr.Next()) { | |
469 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); | |
470 | if (cr->IsCurve3D() && !TE->Degenerated()) { | |
471 | //// modified by jgv, 20.03.03 //// | |
472 | TopLoc_Location Loc = myShape.Location() * cr->Location(); | |
473 | Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast | |
474 | (cr->Curve3D()->Transformed( Loc.Transformation() )); | |
475 | /////////////////////////////////// | |
476 | GeomAdaptor_Curve GAC3d(C3d,First,Last); | |
477 | it=iRep; | |
478 | if (iRep>1) { | |
479 | theRep(iRep)=theRep(1); | |
480 | it=1; | |
481 | } | |
482 | theRep(it) = new GeomAdaptor_HCurve(GAC3d); | |
483 | iRep++; | |
484 | } | |
485 | else if (cr->IsCurveOnSurface()) { | |
486 | { | |
487 | Handle(Geom_Surface) Sref = cr->Surface(); | |
488 | //// modified by jgv, 20.03.03 //// | |
489 | TopLoc_Location Loc = myShape.Location() * cr->Location(); | |
490 | Sref = Handle(Geom_Surface)::DownCast | |
491 | (Sref->Transformed( Loc.Transformation() )); | |
492 | /////////////////////////////////// | |
493 | const Handle(Geom2d_Curve)& PCref = cr->PCurve(); | |
494 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); | |
495 | Handle(Geom2dAdaptor_HCurve) GHPCref = | |
496 | new Geom2dAdaptor_HCurve(PCref,First,Last); | |
497 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); | |
498 | theRep(iRep) = new Adaptor3d_HCurveOnSurface(ACSref); | |
499 | iRep++; | |
500 | } | |
501 | if (cr->IsCurveOnClosedSurface()) { | |
502 | Handle(Geom_Surface) Sref = cr->Surface(); | |
503 | Sref = Handle(Geom_Surface)::DownCast | |
504 | (Sref->Transformed(cr->Location().Transformation())); | |
505 | const Handle(Geom2d_Curve)& PCref = cr->PCurve2(); | |
506 | Handle(GeomAdaptor_HSurface) GAHSref = new GeomAdaptor_HSurface(Sref); | |
507 | Handle(Geom2dAdaptor_HCurve) GHPCref = | |
508 | new Geom2dAdaptor_HCurve(PCref,First,Last); | |
509 | Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref); | |
510 | theRep(iRep) = new Adaptor3d_HCurveOnSurface(ACSref); | |
511 | iRep++; | |
512 | nbRep++; | |
513 | } | |
514 | } | |
515 | else { | |
516 | nbRep--; | |
517 | } | |
518 | } | |
519 | ||
520 | Standard_Real dist2, tol2, tolCal=0., prm; | |
521 | gp_Pnt center, othP; | |
522 | Standard_Integer i, imax; | |
523 | for (i= 0; i< NCONTROL; i++) { | |
524 | prm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); | |
525 | tol2=dist2=0.; | |
526 | center=(*(Handle(Adaptor3d_HCurve)*)&theRep(1))->Value(prm); | |
527 | for (iRep=2; iRep<=nbRep; iRep++) { | |
528 | othP=(*(Handle(Adaptor3d_HCurve)*)&theRep(iRep))->Value(prm); | |
529 | dist2=center.SquareDistance(othP); | |
530 | if (dist2>tolCal) tolCal=dist2; | |
531 | } | |
532 | if (tol2>tolCal) { | |
533 | tolCal=tol2; | |
534 | imax=i; | |
535 | } | |
536 | } | |
537 | // On prend 5% de marge car au dessus on crontrole severement | |
538 | return sqrt(tolCal)*1.05; | |
539 | } | |
171d8cd9 P |
540 | |
541 | //======================================================================= | |
542 | //function : Validate | |
543 | //purpose : | |
544 | //======================================================================= | |
545 | Standard_Boolean Validate(const Adaptor3d_Curve& CRef, | |
546 | const Adaptor3d_CurveOnSurface& Other, | |
547 | const Standard_Real Tol, | |
548 | const Standard_Boolean SameParameter) | |
549 | { | |
550 | Standard_Boolean Status, proj; | |
551 | Standard_Real aPC, First, Last, Error; | |
552 | gp_Pnt problematic_point ; | |
553 | // | |
554 | Status = Standard_True; | |
555 | Error = 0.; | |
556 | First = CRef.FirstParameter(); | |
557 | Last = CRef.LastParameter(); | |
558 | // | |
559 | aPC=Precision::PConfusion(); | |
560 | proj = (!SameParameter || | |
561 | fabs(Other.FirstParameter()-First) > aPC || | |
562 | fabs( Other.LastParameter()-Last) > aPC); | |
563 | if (!proj) { | |
564 | Standard_Integer i; | |
6e6cd5d9 | 565 | Standard_Real Tol2, prm, dD; |
171d8cd9 P |
566 | gp_Pnt pref, pother; |
567 | //modified by NIZNHY-PKV Thu May 05 09:06:41 2011f | |
568 | //OCC22428 | |
569 | dD=Prec(CRef, Other);//3.e-15; | |
570 | Tol2=Tol+dD; | |
571 | Tol2=Tol2*Tol2; | |
572 | //Tol2=Tol*Tol; | |
573 | //modified by NIZNHY-PKV Thu May 05 09:06:47 2011t | |
574 | ||
575 | for (i = 0; i< NCONTROL; ++i) { | |
576 | prm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); | |
577 | pref = CRef.Value(prm); | |
578 | pother = Other.Value(prm); | |
579 | if (pref.SquareDistance(pother) > Tol2) { | |
580 | problematic_point = pref ; | |
581 | Status = Standard_False; | |
582 | Error = pref.Distance(pother); | |
583 | PrintProblematicPoint(problematic_point, Error, Tol); | |
584 | return Status; | |
585 | //goto FINISH ; | |
586 | } | |
587 | } | |
588 | } | |
589 | else { | |
590 | Extrema_LocateExtPC refd,otherd; | |
591 | Standard_Real OFirst = Other.FirstParameter(); | |
592 | Standard_Real OLast = Other.LastParameter(); | |
593 | gp_Pnt pd = CRef.Value(First); | |
594 | gp_Pnt pdo = Other.Value(OFirst); | |
595 | Standard_Real distt = pd.SquareDistance(pdo); | |
596 | if (distt > Tol*Tol) { | |
597 | problematic_point = pd ; | |
598 | Status = Standard_False ; | |
599 | Error = Sqrt(distt); | |
600 | PrintProblematicPoint(problematic_point, Error, Tol); | |
601 | return Status; | |
602 | //goto FINISH ; | |
603 | } | |
604 | pd = CRef.Value(Last); | |
605 | pdo = Other.Value(OLast); | |
606 | distt = pd.SquareDistance(pdo); | |
607 | if (distt > Tol*Tol) { | |
608 | problematic_point = pd ; | |
609 | Status = Standard_False ; | |
610 | Error = Sqrt(distt); | |
611 | PrintProblematicPoint(problematic_point, Error, Tol); | |
612 | return Status; | |
613 | //goto FINISH ; | |
614 | } | |
615 | ||
616 | refd.Initialize(CRef,First,Last,CRef.Resolution(Tol)); | |
617 | otherd.Initialize(Other,OFirst,OLast,Other.Resolution(Tol)); | |
618 | for (Standard_Integer i = 2; i< NCONTROL-1; i++) { | |
619 | Standard_Real rprm = ((NCONTROL-1-i)*First + i*Last)/(NCONTROL-1); | |
620 | gp_Pnt pref = CRef.Value(rprm); | |
621 | Standard_Real oprm = ((NCONTROL-1-i)*OFirst + i*OLast)/(NCONTROL-1); | |
622 | gp_Pnt pother = Other.Value(oprm); | |
623 | refd.Perform(pother,rprm); | |
624 | if (!refd.IsDone() || refd.SquareDistance() > Tol * Tol) { | |
625 | problematic_point = pref ; | |
626 | Status = Standard_False ; | |
627 | if (refd.IsDone()) { | |
628 | Error = sqrt (refd.SquareDistance()); | |
629 | } | |
630 | else { | |
631 | Error = RealLast(); | |
632 | } | |
633 | PrintProblematicPoint(problematic_point, Error, Tol); | |
634 | return Status; | |
635 | //goto FINISH ; | |
636 | } | |
637 | otherd.Perform(pref,oprm); | |
638 | if (!otherd.IsDone() || otherd.SquareDistance() > Tol * Tol) { | |
639 | problematic_point = pref ; | |
640 | Status = Standard_False ; | |
641 | if (otherd.IsDone()) { | |
642 | Error = sqrt (otherd.SquareDistance()); | |
643 | } | |
644 | else { | |
645 | Error = RealLast(); | |
646 | } | |
647 | PrintProblematicPoint(problematic_point, Error, Tol); | |
648 | return Status; | |
649 | //goto FINISH ; | |
650 | } | |
651 | } | |
652 | } | |
653 | //FINISH : | |
654 | /* | |
655 | #ifdef DEB | |
656 | if (! Status) { | |
657 | cout << " **** probleme de SameParameter au point :" << endl; | |
658 | cout << " " << problematic_point.Coord(1) << " " | |
659 | << problematic_point.Coord(2) << " " | |
660 | << problematic_point.Coord(3) << endl ; | |
661 | cout << " Erreur detectee :" << Error << " Tolerance :" << Tol << endl; | |
662 | } | |
663 | #endif | |
664 | */ | |
665 | ||
666 | return Status ; | |
667 | ||
668 | } | |
669 | //======================================================================= | |
670 | //function : Prec | |
671 | //purpose : | |
672 | //======================================================================= | |
673 | Standard_Real Prec(const Adaptor3d_Curve& aAC3D, | |
674 | const Adaptor3d_CurveOnSurface& aACS) | |
675 | { | |
676 | Standard_Real aXEmax, aXC, aXS; | |
677 | // | |
678 | aXC=PrecCurve(aAC3D); | |
679 | aXS=PrecSurface(aACS); | |
680 | aXEmax=(aXC>aXS) ? aXC: aXS; | |
681 | return aXEmax; | |
682 | } | |
683 | //======================================================================= | |
684 | //function : PrecCurve | |
685 | //purpose : | |
686 | //======================================================================= | |
687 | Standard_Real PrecCurve(const Adaptor3d_Curve& aAC3D) | |
688 | { | |
689 | Standard_Real aXEmax; | |
690 | GeomAbs_CurveType aCT; | |
691 | // | |
692 | aXEmax=RealEpsilon(); | |
693 | // | |
694 | aCT=aAC3D.GetType(); | |
695 | if (aCT==GeomAbs_Ellipse) { | |
696 | Standard_Integer i; | |
697 | Standard_Real aX[5], aXE; | |
698 | // | |
699 | gp_Elips aEL3D=aAC3D.Ellipse(); | |
700 | aEL3D.Location().Coord(aX[0], aX[1], aX[2]); | |
701 | aX[3]=aEL3D.MajorRadius(); | |
702 | aX[4]=aEL3D.MinorRadius(); | |
703 | aXEmax=-1.; | |
704 | for (i=0; i<5; ++i) { | |
705 | if (aX[i]<0.) { | |
706 | aX[i]=-aX[i]; | |
707 | } | |
708 | aXE=Epsilon(aX[i]); | |
709 | if (aXE>aXEmax) { | |
710 | aXEmax=aXE; | |
711 | } | |
712 | } | |
713 | }//if (aCT=GeomAbs_Ellipse) { | |
714 | // | |
715 | return aXEmax; | |
716 | } | |
717 | //======================================================================= | |
718 | //function : PrecSurface | |
719 | //purpose : | |
720 | //======================================================================= | |
721 | Standard_Real PrecSurface(const Adaptor3d_CurveOnSurface& aACS) | |
722 | { | |
723 | Standard_Real aXEmax; | |
724 | GeomAbs_SurfaceType aST; | |
725 | // | |
726 | aXEmax=RealEpsilon(); | |
727 | // | |
728 | const Handle(Adaptor3d_HSurface)& aAHS=aACS.GetSurface(); | |
729 | aST=aAHS->GetType(); | |
730 | if (aST==GeomAbs_Cone) { | |
731 | gp_Cone aCone=aAHS->Cone(); | |
732 | Standard_Integer i; | |
733 | Standard_Real aX[4], aXE; | |
734 | // | |
735 | aCone.Location().Coord(aX[0], aX[1], aX[2]); | |
736 | aX[3]=aCone.RefRadius(); | |
737 | aXEmax=-1.; | |
738 | for (i=0; i<4; ++i) { | |
739 | if (aX[i]<0.) { | |
740 | aX[i]=-aX[i]; | |
741 | } | |
742 | aXE=Epsilon(aX[i]); | |
743 | if (aXE>aXEmax) { | |
744 | aXEmax=aXE; | |
745 | } | |
746 | } | |
747 | }//if (aST==GeomAbs_Cone) { | |
748 | return aXEmax; | |
749 | } | |
750 | //======================================================================= | |
751 | //function : PrintProblematicPoint | |
752 | //purpose : | |
753 | //======================================================================= | |
754 | #ifdef DEB | |
755 | void PrintProblematicPoint(const gp_Pnt& problematic_point, | |
756 | const Standard_Real Error, | |
757 | const Standard_Real Tol) | |
758 | { | |
759 | cout << " **** probleme de SameParameter au point :" << endl; | |
760 | cout << " " << problematic_point.Coord(1) << " " | |
761 | << problematic_point.Coord(2) << " " << problematic_point.Coord(3) << endl ; | |
762 | cout << " Erreur detectee :" << Error << " Tolerance :" << Tol << endl; | |
763 | } | |
764 | #else | |
765 | void PrintProblematicPoint(const gp_Pnt&, | |
766 | const Standard_Real, | |
767 | const Standard_Real) | |
768 | { | |
769 | } | |
770 | #endif |