Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: ShapeAnalysis_Wire.cxx |
2 | // Created: Thu Jan 20 14:46:55 2000 | |
3 | // Author: data exchange team | |
4 | // <det@nnov> | |
5 | ||
6 | //:pdn 11.12.98: FixDegenerated improved | |
7 | //:pdn 05.01.99: renaming method CheckLittle to CheckSmall | |
8 | //:l0 abv 10.01.99: CATIA01 #1727: fix intersecting edges always if edge is lacking | |
9 | //:n2 abv 22.01.99: ma-test5.igs: IGES read (pref3d): remove degen edge with no pcurve | |
10 | //:o4 abv 17.02.99: r0301_db.stp #53082: adding parameter isClosed to CheckOrder | |
11 | // rln 03.03.99 S4135: using updated ShapeAnalysis_Surface for checking of singularities | |
12 | //:p9 abv 11.03.99: PRO7226 #489490: fix :i9 moved to allow fixing a set of degenerated edges | |
13 | //#77 rln 11.03.99: S4135: using singularity which has minimum gap between singular point and input 3D point | |
14 | //#84 rln 18.03.99: inserting degenerated edge between ends of pcurves | |
15 | //pdn 12.03.99 S4135 check degenerated applies minimal tolerance first. | |
16 | //pdn 16.03.99 S4135 adding check of non adjacent edjes. | |
17 | //#83 rln 19.03.99: processing segments in intersection as in BRepCheck | |
18 | //%15 pdn 15.03.99 checking of small area wire added | |
19 | //#2 smh 26.03.99 S4163 Zero divide | |
20 | //#4 szv S4163 optimizing | |
21 | //:r6 abv 08.04.99: protect FixIE against working out of curve range | |
22 | //:s1 abv 22.04.99: PRO7226 #489490: ensure fixing of degenerated edge | |
23 | //#9 smh 14.12.99 BUC60615 Using tolerance of verteces during checking degenerated edge. | |
24 | ||
25 | #include <ShapeAnalysis_Wire.ixx> | |
26 | ||
27 | #include <Precision.hxx> | |
28 | ||
29 | #include <Geom_Curve.hxx> | |
30 | #include <Geom2d_Curve.hxx> | |
31 | #include <GeomAdaptor_HSurface.hxx> | |
32 | #include <Geom2dAdaptor_Curve.hxx> | |
33 | #include <Geom2dInt_GInter.hxx> | |
34 | #include <IntRes2d_Domain.hxx> | |
35 | #include <IntRes2d_Transition.hxx> | |
36 | #include <IntRes2d_IntersectionPoint.hxx> | |
37 | #include <IntRes2d_IntersectionSegment.hxx> | |
38 | ||
39 | #include <TopoDS_Edge.hxx> | |
40 | #include <TopoDS_Vertex.hxx> | |
41 | #include <BRep_Builder.hxx> | |
42 | #include <BRep_Tool.hxx> | |
43 | #include <BRepTools.hxx> | |
44 | ||
45 | #include <ShapeExtend.hxx> | |
46 | #include <ShapeAnalysis.hxx> | |
47 | #include <ShapeAnalysis_Curve.hxx> | |
48 | #include <ShapeAnalysis_Edge.hxx> | |
49 | ||
50 | #include <TopoDS.hxx> | |
51 | #include <Precision.hxx> | |
52 | #include <TColgp_Array1OfPnt.hxx> | |
53 | #include <TColStd_Array1OfReal.hxx> | |
54 | #include <Bnd_Array1OfBox2d.hxx> | |
55 | #include <BndLib_Add2dCurve.hxx> | |
56 | #include <Bnd_Box2d.hxx> | |
57 | ||
58 | //szvsh addition | |
59 | #include <Geom2dAdaptor_HCurve.hxx> | |
60 | #include <Adaptor3d_CurveOnSurface.hxx> | |
61 | #include <TColgp_SequenceOfPnt.hxx> | |
62 | #include <ShapeAnalysis_Surface.hxx> | |
63 | #include <TopoDS_Wire.hxx> | |
64 | #include <ShapeAnalysis.hxx> | |
65 | #include <Geom_Plane.hxx> | |
66 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> | |
67 | #include <TopoDS_Iterator.hxx> | |
68 | #include <TopTools_DataMapOfShapeListOfShape.hxx> | |
69 | #include <TopTools_ListOfShape.hxx> | |
70 | #include <TopTools_IndexedMapOfShape.hxx> | |
71 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
72 | #include <TopExp.hxx> | |
73 | ||
74 | //======================================================================= | |
75 | //function : ShapeAnalysis_Wire | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | ShapeAnalysis_Wire::ShapeAnalysis_Wire() | |
80 | { | |
81 | ClearStatuses(); | |
82 | myPrecision = ::Precision::Confusion(); | |
83 | } | |
84 | ||
85 | //======================================================================= | |
86 | //function : ShapeAnalysis_Wire | |
87 | //purpose : | |
88 | //======================================================================= | |
89 | ||
90 | ShapeAnalysis_Wire::ShapeAnalysis_Wire (const TopoDS_Wire& wire, | |
91 | const TopoDS_Face& face, | |
92 | const Standard_Real precision) | |
93 | { | |
94 | Init (wire, face, precision); | |
95 | } | |
96 | ||
97 | //======================================================================= | |
98 | //function : ShapeAnalysis_Wire | |
99 | //purpose : | |
100 | //======================================================================= | |
101 | ||
102 | ShapeAnalysis_Wire::ShapeAnalysis_Wire (const Handle(ShapeExtend_WireData)& sbwd, | |
103 | const TopoDS_Face& face, | |
104 | const Standard_Real precision) | |
105 | { | |
106 | Init (sbwd, face, precision); | |
107 | } | |
108 | ||
109 | //======================================================================= | |
110 | //function : Init | |
111 | //purpose : | |
112 | //======================================================================= | |
113 | ||
114 | void ShapeAnalysis_Wire::Init (const TopoDS_Wire& wire, | |
115 | const TopoDS_Face& face, const Standard_Real precision) | |
116 | { | |
117 | Init (new ShapeExtend_WireData (wire), face, precision); | |
118 | } | |
119 | ||
120 | //======================================================================= | |
121 | //function : Init | |
122 | //purpose : | |
123 | //======================================================================= | |
124 | ||
125 | void ShapeAnalysis_Wire::Init (const Handle(ShapeExtend_WireData)& sbwd, | |
126 | const TopoDS_Face& face, const Standard_Real precision) | |
127 | { | |
128 | Load (sbwd); | |
129 | SetFace (face); | |
130 | SetPrecision (precision); | |
131 | } | |
132 | ||
133 | //======================================================================= | |
134 | //function : Load | |
135 | //purpose : | |
136 | //======================================================================= | |
137 | ||
138 | void ShapeAnalysis_Wire::Load (const TopoDS_Wire& wire) | |
139 | { | |
140 | ClearStatuses(); | |
141 | myWire = new ShapeExtend_WireData (wire); | |
142 | } | |
143 | ||
144 | //======================================================================= | |
145 | //function : Load | |
146 | //purpose : | |
147 | //======================================================================= | |
148 | ||
149 | void ShapeAnalysis_Wire::Load (const Handle(ShapeExtend_WireData)& sbwd) | |
150 | { | |
151 | ClearStatuses(); | |
152 | myWire = sbwd; | |
153 | } | |
154 | ||
155 | //======================================================================= | |
156 | //function : SetFace | |
157 | //purpose : | |
158 | //======================================================================= | |
159 | ||
160 | void ShapeAnalysis_Wire::SetFace(const TopoDS_Face& face) | |
161 | { | |
162 | myFace = face; | |
163 | if(!face.IsNull()) | |
164 | mySurf = new ShapeAnalysis_Surface ( BRep_Tool::Surface ( myFace ) ); | |
165 | } | |
166 | ||
167 | //======================================================================= | |
168 | //function : SetSurface | |
169 | //purpose : | |
170 | //======================================================================= | |
171 | ||
172 | void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface) | |
173 | { | |
174 | SetSurface ( surface, TopLoc_Location() ); | |
175 | } | |
176 | ||
177 | //======================================================================= | |
178 | //function : SetSurface | |
179 | //purpose : | |
180 | //======================================================================= | |
181 | ||
182 | void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface, | |
183 | const TopLoc_Location& location) | |
184 | { | |
185 | BRep_Builder B; | |
186 | TopoDS_Face face; | |
187 | B.MakeFace ( face, surface, location, ::Precision::Confusion() ); | |
188 | SetFace ( face ); | |
189 | } | |
190 | ||
191 | //======================================================================= | |
192 | //function : SetPrecision | |
193 | //purpose : | |
194 | //======================================================================= | |
195 | ||
196 | void ShapeAnalysis_Wire::SetPrecision(const Standard_Real precision) | |
197 | { | |
198 | myPrecision = precision; | |
199 | } | |
200 | ||
201 | //======================================================================= | |
202 | //function : ClearStatuses | |
203 | //purpose : | |
204 | //======================================================================= | |
205 | ||
206 | void ShapeAnalysis_Wire::ClearStatuses() | |
207 | { | |
208 | myStatusOrder = myStatusConnected = | |
209 | myStatusEdgeCurves = myStatusDegenerated = | |
210 | myStatusClosed = myStatusLacking = | |
211 | myStatusSelfIntersection = myStatusSmall = | |
212 | myStatusGaps3d = myStatusGaps2d = | |
213 | myStatusCurveGaps = myStatusLoop = myStatus = 0; | |
214 | ||
215 | myMin3d = myMin2d = myMax3d = myMax2d = 0.; | |
216 | } | |
217 | ||
218 | //======================================================================= | |
219 | //function : Perform | |
220 | //purpose : | |
221 | //======================================================================= | |
222 | ||
223 | Standard_Boolean ShapeAnalysis_Wire::Perform() | |
224 | { | |
225 | Standard_Boolean result = Standard_False; | |
226 | result |= CheckOrder(); | |
227 | result |= CheckSmall(); | |
228 | result |= CheckConnected(); | |
229 | result |= CheckEdgeCurves(); | |
230 | result |= CheckDegenerated(); | |
231 | result |= CheckSelfIntersection(); | |
232 | result |= CheckLacking(); | |
233 | result |= CheckClosed(); | |
234 | return result; | |
235 | } | |
236 | ||
237 | //======================================================================= | |
238 | //function : CheckOrder | |
239 | //purpose : | |
240 | //======================================================================= | |
241 | ||
242 | Standard_Boolean ShapeAnalysis_Wire::CheckOrder (const Standard_Boolean isClosed, | |
243 | const Standard_Boolean mode3d) | |
244 | { | |
245 | ShapeAnalysis_WireOrder sawo; | |
246 | CheckOrder (sawo, isClosed, mode3d); | |
247 | myStatusOrder = myStatus; | |
248 | return StatusOrder (ShapeExtend_DONE); | |
249 | } | |
250 | ||
251 | //======================================================================= | |
252 | //function : CheckSmall | |
253 | //purpose : | |
254 | //======================================================================= | |
255 | ||
256 | Standard_Boolean ShapeAnalysis_Wire::CheckSmall(const Standard_Real precsmall) | |
257 | { | |
258 | for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) { | |
259 | CheckSmall (i, precsmall); | |
260 | myStatusSmall |= myStatus; | |
261 | } | |
262 | return StatusSmall (ShapeExtend_DONE); | |
263 | } | |
264 | ||
265 | //======================================================================= | |
266 | //function : CheckConnected | |
267 | //purpose : | |
268 | //======================================================================= | |
269 | ||
270 | Standard_Boolean ShapeAnalysis_Wire::CheckConnected(const Standard_Real prec) | |
271 | { | |
272 | for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) { | |
273 | CheckConnected ( i, prec ); | |
274 | myStatusConnected |= myStatus; | |
275 | } | |
276 | return StatusConnected (ShapeExtend_DONE); | |
277 | } | |
278 | ||
279 | //======================================================================= | |
280 | //function : CheckEdgeCurves | |
281 | //purpose : | |
282 | //======================================================================= | |
283 | ||
284 | Standard_Boolean ShapeAnalysis_Wire::CheckEdgeCurves() | |
285 | { | |
286 | myStatusEdgeCurves = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
287 | if ( ! IsReady() ) return Standard_False; | |
288 | ||
289 | Standard_Integer i, nb = myWire->NbEdges(); | |
290 | ShapeAnalysis_Edge SAE; | |
291 | ||
292 | for (i = 1; i <= nb; i++) { | |
293 | TopoDS_Edge E = myWire->Edge (i); | |
294 | ||
295 | SAE.CheckCurve3dWithPCurve (E, myFace); | |
296 | if (SAE.Status (ShapeExtend_DONE)) | |
297 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
298 | if (SAE.Status ( ShapeExtend_FAIL)) | |
299 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
300 | ||
301 | SAE.CheckVerticesWithPCurve (E, myFace); | |
302 | if (SAE.Status (ShapeExtend_DONE)) | |
303 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
304 | if (SAE.Status ( ShapeExtend_FAIL)) | |
305 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
306 | ||
307 | SAE.CheckVerticesWithCurve3d (E); | |
308 | if (SAE.Status (ShapeExtend_DONE)) | |
309 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3); | |
310 | if (SAE.Status ( ShapeExtend_FAIL)) | |
311 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
312 | ||
313 | CheckSeam (i); | |
314 | if (LastCheckStatus (ShapeExtend_DONE)) | |
315 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE4); | |
316 | if (LastCheckStatus (ShapeExtend_FAIL)) | |
317 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL4); | |
318 | ||
319 | CheckGap3d (i); | |
320 | if (LastCheckStatus (ShapeExtend_DONE)) | |
321 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5); | |
322 | if (LastCheckStatus (ShapeExtend_FAIL)) | |
323 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL5); | |
324 | ||
325 | CheckGap2d (i); | |
326 | if (LastCheckStatus (ShapeExtend_DONE)) | |
327 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6); | |
328 | if (LastCheckStatus (ShapeExtend_FAIL)) | |
329 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL6); | |
330 | ||
331 | Standard_Real maxdev = 0.0; | |
332 | SAE.CheckSameParameter (myWire->Edge (i), maxdev); | |
333 | if (SAE.Status (ShapeExtend_DONE)) | |
334 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE7); | |
335 | if (SAE.Status ( ShapeExtend_FAIL)) | |
336 | myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL7); | |
337 | } | |
338 | return StatusEdgeCurves (ShapeExtend_DONE); | |
339 | } | |
340 | ||
341 | //======================================================================= | |
342 | //function : CheckDegenerated | |
343 | //purpose : | |
344 | //======================================================================= | |
345 | ||
346 | Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated() | |
347 | { | |
348 | for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) { | |
349 | CheckDegenerated (i); | |
350 | myStatusDegenerated |= myStatus; | |
351 | } | |
352 | return StatusDegenerated (ShapeExtend_DONE); | |
353 | } | |
354 | ||
355 | //======================================================================= | |
356 | //function : CheckSelfIntersection | |
357 | //purpose : | |
358 | //======================================================================= | |
359 | ||
360 | Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersection() | |
361 | { | |
362 | myStatusSelfIntersection = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
363 | if (!IsReady()) return Standard_False; | |
364 | Standard_Integer i, nb = myWire->NbEdges(); | |
365 | for (i = 1; i <= nb; i++) { | |
366 | CheckSelfIntersectingEdge (i); | |
367 | if (LastCheckStatus (ShapeExtend_DONE)) | |
368 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
369 | if (LastCheckStatus (ShapeExtend_FAIL)) | |
370 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
371 | ||
372 | CheckIntersectingEdges (i); | |
373 | if (LastCheckStatus (ShapeExtend_DONE)) | |
374 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
375 | if (LastCheckStatus (ShapeExtend_FAIL)) | |
376 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
377 | } | |
378 | ||
379 | Bnd_Array1OfBox2d boxes(1,nb); | |
380 | TopLoc_Location L; | |
381 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(Face(), L); | |
382 | Handle(Geom2d_Curve) c2d; | |
383 | Standard_Real cf,cl; | |
384 | ShapeAnalysis_Edge sae; | |
385 | Handle(ShapeExtend_WireData) sbwd = WireData(); | |
386 | for(i = 1; i <= nb; i++){ | |
387 | TopoDS_Edge E = sbwd->Edge (i); | |
388 | if(sae.PCurve (E,S,L,c2d,cf,cl,Standard_False)) { | |
389 | Bnd_Box2d box; | |
390 | Geom2dAdaptor_Curve gac(c2d,cf,cl); | |
391 | BndLib_Add2dCurve::Add(gac,::Precision::Confusion(),box); | |
392 | boxes(i) = box; | |
393 | } | |
394 | } | |
395 | ||
396 | Standard_Boolean isFail = Standard_False, isDone = Standard_False; | |
397 | for(Standard_Integer num1 = 1; num1 < nb-1; num1++) { | |
398 | Standard_Integer fin = (num1 == 1 ? nb-1 : nb); | |
399 | for(Standard_Integer num2 = num1+2; num2 <= fin; num2++) | |
400 | if(!boxes(num1).IsOut(boxes(num2))){ | |
401 | CheckIntersectingEdges(num1, num2); | |
402 | isFail |= LastCheckStatus ( ShapeExtend_FAIL1 ); | |
403 | isDone |= LastCheckStatus ( ShapeExtend_DONE1 ); | |
404 | } | |
405 | } | |
406 | if(isFail) | |
407 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 ); | |
408 | if(isDone) | |
409 | myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 ); | |
410 | ||
411 | return StatusSelfIntersection (ShapeExtend_DONE); | |
412 | } | |
413 | ||
414 | //======================================================================= | |
415 | //function : CheckLacking | |
416 | //purpose : | |
417 | //======================================================================= | |
418 | ||
419 | Standard_Boolean ShapeAnalysis_Wire::CheckLacking() | |
420 | { | |
421 | if (!IsReady() || NbEdges() < 2) return Standard_False; | |
422 | for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) { | |
423 | CheckLacking (i); | |
424 | myStatusLacking |= myStatus; | |
425 | } | |
426 | return StatusLacking (ShapeExtend_DONE); | |
427 | } | |
428 | ||
429 | //======================================================================= | |
430 | //function : CheckClosed | |
431 | //purpose : | |
432 | //======================================================================= | |
433 | ||
434 | Standard_Boolean ShapeAnalysis_Wire::CheckClosed(const Standard_Real prec) | |
435 | { | |
436 | myStatusClosed = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
437 | if (!IsReady() || NbEdges() < 1) return Standard_False; | |
438 | ||
439 | CheckConnected (1, prec); | |
440 | if ( LastCheckStatus ( ShapeExtend_DONE ) ) | |
441 | myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); | |
442 | if ( LastCheckStatus ( ShapeExtend_FAIL ) ) | |
443 | myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); | |
444 | ||
445 | CheckDegenerated ( 1 ); | |
446 | if ( LastCheckStatus ( ShapeExtend_DONE ) ) | |
447 | myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 ); | |
448 | if ( LastCheckStatus ( ShapeExtend_FAIL ) ) | |
449 | myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
450 | ||
451 | return StatusClosed ( ShapeExtend_DONE ); | |
452 | } | |
453 | ||
454 | //======================================================================= | |
455 | //function : CheckGaps3d | |
456 | //purpose : | |
457 | //======================================================================= | |
458 | ||
459 | Standard_Boolean ShapeAnalysis_Wire::CheckGaps3d () | |
460 | { | |
461 | myStatusGaps3d = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
462 | if (!IsLoaded() || NbEdges() < 1) return Standard_False; //gka IsLoaded | |
463 | ||
464 | Standard_Real dist, maxdist = 0.; | |
465 | ||
466 | for (Standard_Integer i = 1; i <= NbEdges(); i++) { | |
467 | CheckGap3d(i); | |
468 | myStatusGaps3d |= myStatus; | |
469 | if (!LastCheckStatus(ShapeExtend_FAIL1)) { | |
470 | dist = MinDistance3d(); | |
471 | if (maxdist<dist) maxdist = dist; | |
472 | } | |
473 | } | |
474 | myMin3d = myMax3d = maxdist; | |
475 | ||
476 | return StatusGaps3d ( ShapeExtend_DONE ); | |
477 | } | |
478 | ||
479 | //======================================================================= | |
480 | //function : CheckGaps2d | |
481 | //purpose : | |
482 | //======================================================================= | |
483 | ||
484 | Standard_Boolean ShapeAnalysis_Wire::CheckGaps2d () | |
485 | { | |
486 | myStatusGaps2d = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
487 | if (!IsReady() || NbEdges() < 1) return Standard_False; | |
488 | ||
489 | Standard_Real dist, maxdist = 0.; | |
490 | ||
491 | for (Standard_Integer i = 1; i <= NbEdges(); i++) { | |
492 | CheckGap2d(i); | |
493 | myStatusGaps2d |= myStatus; | |
494 | if (!LastCheckStatus(ShapeExtend_FAIL1)) { | |
495 | dist = MinDistance2d(); | |
496 | if (maxdist<dist) maxdist = dist; | |
497 | } | |
498 | } | |
499 | myMin2d = myMax2d = maxdist; | |
500 | ||
501 | return StatusGaps2d ( ShapeExtend_DONE ); | |
502 | } | |
503 | ||
504 | //======================================================================= | |
505 | //function : CheckCurveGaps | |
506 | //purpose : | |
507 | //======================================================================= | |
508 | ||
509 | Standard_Boolean ShapeAnalysis_Wire::CheckCurveGaps () | |
510 | { | |
511 | myStatusCurveGaps = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
512 | if (!IsReady() || NbEdges() < 1) return Standard_False; | |
513 | ||
514 | Standard_Real dist, maxdist = 0.; | |
515 | ||
516 | for (Standard_Integer i = 1; i <= NbEdges(); i++) { | |
517 | CheckCurveGap(i); | |
518 | myStatusCurveGaps |= myStatus; | |
519 | if (!LastCheckStatus(ShapeExtend_FAIL1)) { | |
520 | dist = MinDistance3d(); | |
521 | if (maxdist<dist) maxdist = dist; | |
522 | } | |
523 | } | |
524 | myMin3d = myMax3d = maxdist; | |
525 | ||
526 | return StatusCurveGaps ( ShapeExtend_DONE ); | |
527 | } | |
528 | ||
529 | //======================================================================= | |
530 | //function : CheckOrder | |
531 | //purpose : | |
532 | //======================================================================= | |
533 | ||
534 | Standard_Boolean ShapeAnalysis_Wire::CheckOrder(ShapeAnalysis_WireOrder& sawo, | |
535 | const Standard_Boolean isClosed, | |
536 | const Standard_Boolean mode3d) | |
537 | { | |
538 | if ( ! mode3d && myFace.IsNull() ) { | |
539 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
540 | return Standard_False; | |
541 | } | |
542 | ||
543 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
544 | sawo.SetMode ( mode3d, ( mode3d ? myPrecision : ::Precision::PConfusion() ) ); | |
545 | Standard_Integer i, nb = myWire->NbEdges(); | |
546 | ShapeAnalysis_Edge EA; | |
547 | for (i = 1; i <= nb; i ++) { | |
548 | TopoDS_Edge E = myWire->Edge(i); | |
549 | if ( mode3d ) { | |
550 | TopoDS_Vertex V1 = EA.FirstVertex (E); | |
551 | TopoDS_Vertex V2 = EA.LastVertex (E); | |
552 | gp_Pnt p1 = BRep_Tool::Pnt (V1); | |
553 | gp_Pnt p2 = BRep_Tool::Pnt (V2); | |
554 | sawo.Add (p1.XYZ(),p2.XYZ()); | |
555 | } | |
556 | else { | |
557 | Standard_Real f,l; | |
558 | Handle(Geom2d_Curve) c2d; | |
559 | TopoDS_Shape tmpF = myFace.Oriented(TopAbs_FORWARD); | |
560 | if ( ! EA.PCurve(E,TopoDS::Face(tmpF),c2d,f,l) ) { | |
561 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
562 | return Standard_False; | |
563 | } | |
564 | sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY()); | |
565 | } | |
566 | } | |
567 | sawo.Perform(isClosed); | |
568 | Standard_Integer stat = sawo.Status(); | |
569 | switch (stat) { | |
570 | case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); break; | |
571 | case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break; | |
572 | case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break; | |
573 | case -1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break; | |
574 | case -2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break; | |
575 | case -10: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); break; | |
576 | } | |
577 | return LastCheckStatus (ShapeExtend_DONE); | |
578 | } | |
579 | ||
580 | //======================================================================= | |
581 | //function : CheckConnected | |
582 | //purpose : | |
583 | //======================================================================= | |
584 | ||
585 | Standard_Boolean ShapeAnalysis_Wire::CheckConnected (const Standard_Integer num, | |
586 | const Standard_Real prec) | |
587 | { | |
588 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
589 | if ( ! IsLoaded() || NbEdges() < 1 ) return Standard_False; | |
590 | ||
591 | Standard_Integer n2 = ( num >0 ? num : NbEdges() ); | |
592 | Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() ); | |
593 | // if (n1 == n2) return 0; | |
594 | ||
595 | TopoDS_Edge E1 = WireData()->Edge ( n1 ); | |
596 | TopoDS_Edge E2 = WireData()->Edge ( n2 ); | |
597 | ||
598 | ShapeAnalysis_Edge sae; | |
599 | TopoDS_Vertex V1 = sae.LastVertex (E1); | |
600 | TopoDS_Vertex V2 = sae.FirstVertex (E2); | |
601 | if (V1.IsSame(V2)) return Standard_False; | |
602 | ||
603 | gp_Pnt p1 = BRep_Tool::Pnt (V1); | |
604 | gp_Pnt p2 = BRep_Tool::Pnt (V2); | |
605 | myMin3d = p1.Distance(p2); | |
606 | if ( myMin3d <= gp::Resolution() ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
607 | else if ( myMin3d <= myPrecision ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
608 | else if ( myMin3d <= prec ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3); | |
609 | else { | |
610 | // et en inversant la derniere edge ? | |
611 | if ( n1 == n2 ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
612 | else { | |
613 | V2 = sae.LastVertex (E2); | |
614 | p2 = BRep_Tool::Pnt (V2); | |
615 | Standard_Real dist = p1.Distance(p2); | |
616 | if ( dist > myPrecision ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
617 | else { | |
618 | myMin3d = dist; | |
619 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
620 | } | |
621 | } | |
622 | return Standard_False; | |
623 | } | |
624 | return Standard_True; | |
625 | } | |
626 | ||
627 | //======================================================================= | |
628 | //function : CheckSmall | |
629 | //purpose : | |
630 | //======================================================================= | |
631 | ||
632 | Standard_Boolean ShapeAnalysis_Wire::CheckSmall (const Standard_Integer num, | |
633 | const Standard_Real precsmall) | |
634 | { | |
635 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
636 | if ( ! IsLoaded() || NbEdges() <= 1 ) return Standard_False; | |
637 | ||
638 | //Standard_Integer n = ( num ? num : NbEdges() ); //szv#4:S4163:12Mar99 not needed | |
639 | TopoDS_Edge E = myWire->Edge ( num ? num : NbEdges() ); | |
640 | ShapeAnalysis_Edge sae; | |
641 | ||
642 | if ( BRep_Tool::Degenerated ( E ) ) { | |
643 | //:n2 abv 22 Jan 99: ma-test5.igs -> IGES (brep) -> read (pref3d): | |
644 | // degen edge with no pcurve should be removed | |
645 | if ( ! myFace.IsNull() && sae.HasPCurve ( E, Face() ) ) return Standard_False; | |
646 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
647 | } | |
648 | ||
649 | TopoDS_Vertex V1 = sae.FirstVertex (E); | |
650 | TopoDS_Vertex V2 = sae.LastVertex (E); | |
651 | gp_Pnt p1 = BRep_Tool::Pnt (V1); | |
652 | gp_Pnt p2 = BRep_Tool::Pnt (V2); | |
653 | Standard_Real dist = p1.Distance(p2); | |
654 | Standard_Real prec = precsmall;//Min ( myPrecision, precsmall ); | |
655 | //Standard_Real prec = Min(BRep_Tool::Tolerance(V1),BRep_Tool::Tolerance(V2)); //skl | |
656 | if (dist > prec) return Standard_False; // pas nulle | |
657 | ||
658 | // La courbe 3D a present : est-elle FERMEE ou DE LONGUEUR NULLE ... ??? | |
659 | // Pour cela on prend le point milieu (y a-t-il mieux) | |
660 | // Si pas de C3D, on essaie la C2D ... | |
661 | ||
662 | gp_Pnt Pm; | |
663 | Standard_Real cf,cl; | |
664 | Handle(Geom_Curve) c3d; | |
665 | if ( sae.Curve3d (E,c3d,cf,cl,Standard_False) ) Pm = c3d->Value ( (cf+cl)/2. ); | |
666 | else { | |
667 | Handle(Geom2d_Curve) c2d; | |
668 | if ( ! myFace.IsNull() && sae.PCurve (E,myFace,c2d,cf,cl,Standard_False)) { | |
669 | gp_Pnt2d p2m = c2d->Value ( (cf+cl)/2. ); | |
670 | Pm = mySurf->Value (p2m); | |
671 | } | |
672 | else { | |
673 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
674 | Pm = p1; | |
675 | //:n2 return Standard_False; | |
676 | } | |
677 | } | |
678 | if ( Pm.Distance(p1) > prec || Pm.Distance(p2) > prec ) return Standard_False; | |
679 | ||
680 | myStatus |= ShapeExtend::EncodeStatus ( V1.IsSame(V2) ? ShapeExtend_DONE1 : ShapeExtend_DONE2 ); | |
681 | return Standard_True; | |
682 | } | |
683 | ||
684 | //======================================================================= | |
685 | //function : CheckSeam | |
686 | //purpose : | |
687 | //======================================================================= | |
688 | ||
689 | Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num, | |
690 | Handle(Geom2d_Curve)& C1, | |
691 | Handle(Geom2d_Curve)& C2, | |
692 | Standard_Real& cf, | |
693 | Standard_Real& cl) | |
694 | { | |
695 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
696 | if (!IsReady()) return Standard_False; | |
697 | Standard_Integer n = num; if (n == 0) n = NbEdges(); | |
698 | TopoDS_Edge E = myWire->Edge (n); | |
699 | if ( ! ShapeAnalysis_Edge().IsSeam ( E, myFace ) ) return Standard_False; | |
700 | // Extract the Two PCurves of the Seam | |
701 | TopoDS_Face ForwardFace = myFace; ForwardFace.Orientation (TopAbs_FORWARD); | |
702 | //szv#4:S4163:12Mar99 SGI warns | |
703 | TopoDS_Shape EF = E.Oriented(TopAbs_FORWARD); | |
704 | TopoDS_Shape ER = E.Oriented(TopAbs_REVERSED); | |
705 | C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(EF), ForwardFace, cf, cl); | |
706 | C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(ER), ForwardFace, cf, cl); | |
707 | if (C1.IsNull() || C2.IsNull()) return Standard_False; | |
708 | ||
709 | // SelectForward est destine a devenir un outil distinct | |
710 | ||
711 | Standard_Integer theCurveIndice = ShapeAnalysis_Curve().SelectForwardSeam (C1,C2); | |
712 | if ( theCurveIndice != 2 ) return Standard_False; | |
713 | ||
714 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
715 | return Standard_True; | |
716 | } | |
717 | ||
718 | //======================================================================= | |
719 | //function : CheckSeam | |
720 | //purpose : | |
721 | //======================================================================= | |
722 | ||
723 | Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num) | |
724 | { | |
725 | Handle(Geom2d_Curve) C1, C2; | |
726 | Standard_Real cf, cl; | |
727 | return CheckSeam (num, C1, C2, cf, cl); | |
728 | } | |
729 | ||
730 | //======================================================================= | |
731 | //function : CheckDegenerated | |
732 | //purpose : | |
733 | //======================================================================= | |
734 | ||
735 | Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num, | |
736 | gp_Pnt2d& p2d1, gp_Pnt2d& p2d2) | |
737 | { | |
738 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
739 | if ( ! IsReady() || NbEdges() < 1 ) return Standard_False; | |
740 | ||
741 | Standard_Integer n2 = (num > 0)? num : NbEdges(); | |
742 | Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges(); | |
743 | Standard_Integer n3 = (n2 < NbEdges())? n2+1 : 1; | |
744 | TopoDS_Edge E1 = myWire->Edge ( n1 ); | |
745 | TopoDS_Edge E2 = myWire->Edge ( n2 ); | |
746 | TopoDS_Edge E3 = myWire->Edge ( n3 ); | |
747 | ||
748 | ShapeAnalysis_Edge sae; | |
749 | ||
750 | // skip if edge is already marked as degenerated and has pcurve | |
751 | if ( BRep_Tool::Degenerated ( E2 ) && sae.HasPCurve ( E2, Face() ) ) { | |
752 | // skl 30.12.2004 for OCC7630 - we have to check pcurve | |
753 | if( sae.HasPCurve(E1,Face()) && sae.HasPCurve(E3,Face()) ) { | |
754 | Handle(Geom2d_Curve) c2d; | |
755 | Standard_Real fp,lp; | |
756 | sae.PCurve ( E2, myFace, c2d, fp, lp, Standard_True ); | |
757 | gp_Pnt2d p21 = c2d->Value(fp); | |
758 | gp_Pnt2d p22 = c2d->Value(lp); | |
759 | sae.PCurve ( E1, myFace, c2d, fp, lp, Standard_True ); | |
760 | gp_Pnt2d p12 = c2d->Value(lp); | |
761 | sae.PCurve ( E3, myFace, c2d, fp, lp, Standard_True ); | |
762 | gp_Pnt2d p31 = c2d->Value(fp); | |
763 | if( fabs(p12.Distance(p31)-p21.Distance(p22)) > 2*Precision::PConfusion() ) { | |
764 | // pcurve is bad => we can remove this edge in ShapeFix | |
765 | // if set needed status | |
766 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
767 | } | |
768 | } | |
769 | return Standard_False; | |
770 | } | |
771 | ||
772 | //pdn allows to insert two sequences of degenerated edges (on separate bounds of surfaces) | |
773 | if ( n1 != n2 && BRep_Tool::Degenerated ( E1 ) && | |
774 | ! sae.HasPCurve ( E1, Face() ) ) { | |
775 | //:abv 13.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves | |
776 | if ( BRep_Tool::Degenerated ( E2 ) ) | |
777 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
778 | return Standard_False; | |
779 | } | |
780 | //:i8 if ( BRep_Tool::Degenerated ( E1 ) || | |
781 | //:i8 BRep_Tool::Degenerated ( E2 ) ) return Standard_False; // deja OK | |
782 | ||
783 | TopoDS_Vertex Vp = sae.FirstVertex (E1); //:i9 | |
784 | TopoDS_Vertex V0 = sae.LastVertex (E1); | |
785 | TopoDS_Vertex V1 = sae.FirstVertex (E2); | |
786 | TopoDS_Vertex V2 = sae.LastVertex (E2); | |
787 | gp_Pnt pp = BRep_Tool::Pnt (Vp); //:i9 | |
788 | gp_Pnt p0 = BRep_Tool::Pnt (V0); | |
789 | gp_Pnt p1 = BRep_Tool::Pnt (V1); | |
790 | gp_Pnt p2 = BRep_Tool::Pnt (V2); | |
791 | Standard_Real par1, par2; | |
792 | Standard_Boolean lack = Standard_False; | |
793 | Standard_Boolean dgnr = Standard_False; | |
794 | //pdn 12.03.99 minimal value processing first | |
795 | Standard_Real precFirst = Min(myPrecision,BRep_Tool::Tolerance(V1)); | |
796 | Standard_Real precFin = Max(myPrecision,BRep_Tool::Tolerance(V1)); | |
797 | Standard_Real precVtx = (myPrecision<BRep_Tool::Tolerance(V1) ? 2*precFin : precFin); | |
798 | // forward : si Edge <num> FWD/REV. Si LACK, toujours True | |
799 | Standard_Boolean forward = ( E2.Orientation() == TopAbs_FORWARD ); | |
800 | // FIX FEV 1998 : recompute singularity according precision | |
801 | ||
802 | if (p1.Distance(p2) <= precFirst) { // edge DGNR | |
803 | dgnr = mySurf->DegeneratedValues ( p1, precVtx, p2d1, p2d2, par1, par2, forward ); //smh#9 | |
804 | if ( dgnr ) { // abv 24 Feb 00: trj3_as1-ac-214.stp #6065: avoid making closed edge degenerated | |
805 | Standard_Real a, b; | |
806 | Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E2, a, b ); | |
807 | if ( ! C3d.IsNull() ) { | |
808 | gp_Pnt p = C3d->Value ( 0.5 * ( a + b ) ); | |
809 | if ( p.SquareDistance ( p1 ) > precVtx * precVtx ) dgnr = Standard_False; | |
810 | } | |
811 | } | |
812 | } | |
813 | if ( ! dgnr ) { | |
814 | //:i9 abv 23 Sep 98: CTS20315-2 #63231: check that previous edge is not degenerated | |
815 | if ( n1 != n2 && p1.Distance(pp) <= precFirst && | |
816 | mySurf->IsDegenerated ( pp, precFirst ) && | |
817 | ! BRep_Tool::Degenerated ( E1 ) ) return Standard_False; | |
818 | //rln S4135 ShapeAnalysis_Surface new algorithms for singularities | |
819 | //:45 by abv 16 Dec 97: BUC60035 2659: precision increased to vertex tolerance | |
820 | //Standard_Real prec = Max ( myPrecision, BRep_Tool::Tolerance(V1) ); | |
821 | //:51 abv 22 Dec 97: recompute singularities if necessary | |
822 | //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( 2 * prec ); //:51 //:74 abv 15 Jan 97: *2 | |
823 | ||
824 | if ( p0.Distance ( p1 ) <= precFin ) {// ou DGNR manquante ? | |
825 | //rln S4135 singularity with precision = 2 * prec, but distance <= prec | |
826 | //lack = mySurf->DegeneratedValues ( p1, prec, p2d1, p2d2, par1, par2, forward); | |
827 | Standard_Real tmpPreci; | |
828 | gp_Pnt tmpP3d; | |
829 | Standard_Boolean tmpUIsoDeg; | |
830 | //#77 rln S4135: using singularity which has minimum gap between singular point and input 3D point | |
831 | Standard_Integer indMin = -1; | |
832 | Standard_Real gapMin2 = RealLast(); | |
833 | for (Standard_Integer i = 1; i <= mySurf->NbSingularities (precVtx); i++) { | |
834 | mySurf->Singularity (i, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg); | |
835 | Standard_Real gap2 = p1.SquareDistance (tmpP3d); | |
836 | if (gap2 <= precVtx * precVtx) | |
837 | if (gapMin2 > gap2) { | |
838 | gapMin2 = gap2; | |
839 | indMin = i; | |
840 | } | |
841 | } | |
842 | if (indMin >= 1) { | |
843 | mySurf->Singularity (indMin, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg); | |
844 | lack = Standard_True; | |
845 | } | |
846 | } | |
847 | ||
848 | //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( myPrecision ); //:51 | |
849 | } | |
850 | ||
851 | // voila, on a soit dgnr soit lack | |
852 | if ( ! lack && ! dgnr ) { | |
853 | //:abv 29.08.01: if singularity not detected but edge is marked | |
854 | // as degenerated, report fail | |
855 | if ( BRep_Tool::Degenerated ( E2 ) && ! sae.HasPCurve ( E2, Face() ) ) | |
856 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
857 | return Standard_False; | |
858 | } | |
859 | ||
860 | // OK, degenerated case detected; we will find its start and end in 2d | |
861 | ||
862 | if ( lack ) forward = Standard_True; | |
863 | ||
864 | //:24 by abv 28 Nov 97: | |
865 | // make degenerative pcurve parametrized exactly from end of pcurve of the | |
866 | // previous edge to the start of the next one | |
867 | if ( lack || n1 != n2 ) { //:i8 abv 18 Sep 98: ProSTEP TR9 r0501-ug.stp #182180: single degedge is a wire at apex of a cone | |
868 | Standard_Real a, b; | |
869 | Handle(Geom2d_Curve) c2d; | |
870 | if ( sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) { | |
871 | p2d1 = c2d->Value ( b ); | |
872 | //#84 rln gp_Pnt2d p2d = c2d->Value ( b ); | |
873 | //#84 rln par1 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY(); | |
874 | } | |
875 | else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
876 | //pdn pcurves (fixing regression in f0 in degenerated case) | |
877 | if ( sae.PCurve ( ( dgnr ? E3 : E2 ), myFace, c2d, a, b, Standard_True ) ) { | |
878 | p2d2 = c2d->Value ( a ); | |
879 | //#84 rln gp_Pnt2d p2d = c2d->Value ( a ); | |
880 | //#84 rln par2 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY(); | |
881 | } | |
882 | else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
883 | } | |
884 | /* | |
885 | if ( par2 < par1 ) { | |
886 | par1 = -par1; | |
887 | par2 = -par2; | |
888 | theDir2d.Reverse(); | |
889 | } | |
890 | */ | |
891 | ||
892 | //#84 rln 18.03.99 if pcurve is not degenerate anymore, the fix is postponned | |
893 | //to ShapeFix_Wire::FixLacking | |
894 | if ( ! mySurf->IsDegenerated ( p2d1, p2d2, precVtx, 10. ) ) { //:s1 abv 22 Apr 99: PRO7226 #489490 //smh#9 | |
895 | //:abv 24.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves | |
896 | if ( BRep_Tool::Degenerated ( E2 ) ) | |
897 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
898 | return Standard_False; | |
899 | } | |
900 | ||
901 | //added by rln 18/12/97 CSR# CTS18544 entity 13638 | |
902 | //the situation when degenerated edge already exists but flag is not set | |
903 | //(i.e. the parametric space is closed) | |
904 | GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface(); | |
905 | Standard_Real max = Max ( Ads.UResolution(myPrecision), | |
906 | Ads.VResolution(myPrecision) ); | |
907 | if ( p2d1.Distance (p2d2) /*Abs (par1 - par2)*/ <= max + gp::Resolution() ) return Standard_False; | |
908 | ||
909 | //#84 rln p2d1 = aP2d.XY() + par1 * theDir2d.XY(); | |
910 | //#84 rln p2d2 = aP2d.XY() + par2 * theDir2d.XY(); | |
911 | myStatus = ShapeExtend::EncodeStatus ( dgnr ? ShapeExtend_DONE2 : ShapeExtend_DONE1 ); | |
912 | return Standard_True; | |
913 | } | |
914 | ||
915 | //======================================================================= | |
916 | //function : CheckDegenerated | |
917 | //purpose : | |
918 | //======================================================================= | |
919 | ||
920 | Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num) | |
921 | { | |
922 | gp_Pnt2d p2d1, p2d2; | |
923 | return CheckDegenerated ( num, p2d1, p2d2 ); | |
924 | } | |
925 | ||
926 | //======================================================================= | |
927 | //function : CheckGap3d | |
928 | //purpose : | |
929 | //======================================================================= | |
930 | ||
931 | Standard_Boolean ShapeAnalysis_Wire::CheckGap3d(const Standard_Integer num) | |
932 | { | |
933 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
934 | //szv#4:S4163:12Mar99 optimized | |
935 | if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2 | |
936 | Standard_Integer n2 = ( num >0 ? num : NbEdges() ); | |
937 | Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() ); | |
938 | TopoDS_Edge E1 = myWire->Edge(n1); | |
939 | TopoDS_Edge E2 = myWire->Edge(n2); | |
940 | Standard_Real uf1,ul1,uf2,ul2; | |
941 | Handle(Geom_Curve) C1,C2; | |
942 | ShapeAnalysis_Edge SAE; | |
943 | if (!SAE.Curve3d (E1,C1,uf1,ul1) || !SAE.Curve3d (E2,C2,uf2,ul2)) { | |
944 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
945 | return Standard_False; | |
946 | } | |
947 | gp_Pnt p1 = C1->Value (ul1); | |
948 | gp_Pnt p2 = C2->Value (uf2); | |
949 | myMin3d = myMax3d = p1.Distance (p2); | |
950 | if (myMin3d > myPrecision) | |
951 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
952 | return LastCheckStatus (ShapeExtend_DONE); | |
953 | } | |
954 | ||
955 | //======================================================================= | |
956 | //function : CheckGap2d | |
957 | //purpose : | |
958 | //======================================================================= | |
959 | ||
960 | Standard_Boolean ShapeAnalysis_Wire::CheckGap2d(const Standard_Integer num) | |
961 | { | |
962 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
963 | //szv#4:S4163:12Mar99 optimized | |
964 | if ( !IsReady() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2 | |
965 | Standard_Integer n2 = ( num >0 ? num : NbEdges() ); | |
966 | Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() ); | |
967 | TopoDS_Edge E1 = myWire->Edge(n1); | |
968 | TopoDS_Edge E2 = myWire->Edge(n2); | |
969 | Standard_Real uf1,ul1,uf2,ul2; | |
970 | Handle(Geom2d_Curve) C1,C2; | |
971 | ShapeAnalysis_Edge SAE; | |
972 | if (!SAE.PCurve (E1,myFace,C1,uf1,ul1) || !SAE.PCurve (E2,myFace,C2,uf2,ul2)) { | |
973 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
974 | return Standard_False; | |
975 | } | |
976 | gp_Pnt2d p1 = C1->Value (ul1); | |
977 | gp_Pnt2d p2 = C2->Value (uf2); | |
978 | myMin2d = myMax2d = p1.Distance (p2); | |
979 | GeomAdaptor_Surface& SA = mySurf->Adaptor3d()->ChangeSurface(); | |
980 | if (myMin2d > (Max (SA.UResolution (myPrecision), SA.VResolution (myPrecision)) + Precision::PConfusion())) | |
981 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
982 | return LastCheckStatus (ShapeExtend_DONE); | |
983 | } | |
984 | ||
985 | //======================================================================= | |
986 | //function : CheckCurveGap | |
987 | //purpose : | |
988 | //======================================================================= | |
989 | ||
990 | Standard_Boolean ShapeAnalysis_Wire::CheckCurveGap(const Standard_Integer num) | |
991 | { | |
992 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
993 | if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False; | |
994 | Standard_Integer n = ( num >0 ? num : NbEdges() ); | |
995 | TopoDS_Edge E = myWire->Edge(n); | |
996 | Standard_Real cuf,cul,pcuf,pcul; | |
997 | Handle(Geom_Curve) c; | |
998 | ShapeAnalysis_Edge SAE; | |
999 | if (!SAE.Curve3d (E,c,cuf,cul,Standard_False)) { | |
1000 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1001 | return Standard_False; | |
1002 | } | |
1003 | Handle(Geom2d_Curve) pc; | |
1004 | if (!SAE.PCurve (E,myFace,pc,pcuf,pcul,Standard_False)) { | |
1005 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1006 | return Standard_False; | |
1007 | } | |
1008 | Handle(Geom2dAdaptor_HCurve) AC = new Geom2dAdaptor_HCurve(pc,pcuf,pcul); | |
1009 | Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(mySurf->Surface()); | |
1010 | Adaptor3d_CurveOnSurface ACS(AC,AS); | |
1011 | gp_Pnt cpnt, pcpnt; | |
1012 | Standard_Integer nbp = 45; | |
1013 | Standard_Real dist, maxdist=0.; | |
1014 | for (Standard_Integer i=0; i<nbp; i++) { | |
1015 | cpnt = c->Value(cuf + i*(cul-cuf)/(nbp-1)); | |
1016 | pcpnt = ACS.Value(pcuf + i*(pcul-pcuf)/(nbp-1)); | |
1017 | dist = cpnt.SquareDistance(pcpnt); | |
1018 | if (maxdist<dist) maxdist = dist; | |
1019 | } | |
1020 | myMin3d = myMax3d = Sqrt(maxdist); | |
1021 | if (myMin3d > myPrecision) | |
1022 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1023 | return LastCheckStatus (ShapeExtend_DONE); | |
1024 | } | |
1025 | ||
1026 | //======================================================================= | |
1027 | //function : CheckSelfIntersectingEdge | |
1028 | //purpose : | |
1029 | //======================================================================= | |
1030 | ||
1031 | // auxiliary function | |
1032 | //:h0 abv 29 May 98: PRO10105 1949: like in BRepCheck, point is to be taken | |
1033 | // from 3d curve (but only if edge is SameParameter) | |
1034 | static gp_Pnt GetPointOnEdge ( const TopoDS_Edge &edge, | |
1035 | const Handle(ShapeAnalysis_Surface) &surf, | |
1036 | const Handle(Geom2d_Curve) &Crv2d, | |
1037 | const Standard_Real param ) | |
1038 | { | |
1039 | if ( BRep_Tool::SameParameter ( edge ) ) { | |
1040 | Standard_Real f,l; | |
1041 | TopLoc_Location L; | |
1042 | const Handle(Geom_Curve) ConS = BRep_Tool::Curve ( edge, L, f, l ); | |
1043 | if ( ! ConS.IsNull() ) | |
1044 | return ConS->Value ( param ).Transformed ( L.Transformation() ); | |
1045 | } | |
1046 | return surf->Value ( Crv2d->Value ( param ) ); | |
1047 | } | |
1048 | ||
1049 | //======================================================================= | |
1050 | //function : CheckSelfIntersectingEdge | |
1051 | //purpose : | |
1052 | //======================================================================= | |
1053 | ||
1054 | Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num, | |
1055 | IntRes2d_SequenceOfIntersectionPoint& points2d, | |
1056 | TColgp_SequenceOfPnt& points3d) | |
1057 | { | |
1058 | points2d.Clear(); | |
1059 | points3d.Clear(); | |
1060 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1061 | if ( ! IsReady() ) return Standard_False; | |
1062 | ||
1063 | TopoDS_Edge edge = WireData()->Edge ( num >0 ? num : NbEdges() ); | |
1064 | ShapeAnalysis_Edge sae; | |
1065 | ||
1066 | Standard_Real a, b; | |
1067 | Handle(Geom2d_Curve) Crv; | |
1068 | if ( ! sae.PCurve ( edge, myFace, Crv, a, b, Standard_False ) ) { | |
1069 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1070 | return Standard_False; | |
1071 | } | |
1072 | if ( Abs ( a - b ) <= ::Precision::PConfusion() ) return Standard_False; | |
1073 | ||
1074 | Standard_Real tolint = 1.0e-10; | |
1075 | //szv#4:S4163:12Mar99 warning | |
1076 | IntRes2d_Domain domain ( Crv->Value ( a ), a, tolint, Crv->Value ( b ), b, tolint ); | |
1077 | Geom2dAdaptor_Curve AC ( Crv ); | |
1078 | Geom2dInt_GInter Inter ( AC, domain, tolint, tolint ); | |
1079 | ||
1080 | if ( ! Inter.IsDone() ) return Standard_False; | |
1081 | ||
1082 | TopoDS_Vertex V1 = sae.FirstVertex ( edge ); | |
1083 | TopoDS_Vertex V2 = sae.LastVertex ( edge ); | |
1084 | if ( V1.IsNull() || V2.IsNull() ) { | |
1085 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1086 | return Standard_False; | |
1087 | } | |
1088 | Standard_Real tol1 = BRep_Tool::Tolerance ( V1 ); | |
1089 | Standard_Real tol2 = BRep_Tool::Tolerance ( V2 ); | |
1090 | ||
1091 | gp_Pnt pnt1 = BRep_Tool::Pnt ( V1 ); | |
1092 | gp_Pnt pnt2 = BRep_Tool::Pnt ( V2 ); | |
1093 | ||
1094 | for ( Standard_Integer i=1; i <= Inter.NbPoints(); i++ ) { | |
1095 | const IntRes2d_IntersectionPoint &IP = Inter.Point ( i ); | |
1096 | const IntRes2d_Transition &Tr1 = IP.TransitionOfFirst(); | |
1097 | const IntRes2d_Transition &Tr2 = IP.TransitionOfSecond(); | |
1098 | if ( Tr1.PositionOnCurve() != IntRes2d_Middle && | |
1099 | Tr2.PositionOnCurve() != IntRes2d_Middle ) continue; | |
1100 | gp_Pnt pint = GetPointOnEdge ( edge, mySurf, Crv, IP.ParamOnFirst() ); | |
1101 | Standard_Real dist21 = pnt1.SquareDistance ( pint ); | |
1102 | Standard_Real dist22 = pnt2.SquareDistance ( pint ); | |
1103 | if ( dist21 > tol1 * tol1 && dist22 > tol2 * tol2 ) { | |
1104 | points2d.Append ( IP ); | |
1105 | points3d.Append ( pint ); | |
1106 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | return LastCheckStatus ( ShapeExtend_DONE ); | |
1111 | } | |
1112 | ||
1113 | //======================================================================= | |
1114 | //function : CheckSelfIntersectingEdge | |
1115 | //purpose : | |
1116 | //======================================================================= | |
1117 | ||
1118 | Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num) | |
1119 | { | |
1120 | IntRes2d_SequenceOfIntersectionPoint points2d; | |
1121 | TColgp_SequenceOfPnt points3d; | |
1122 | return CheckSelfIntersectingEdge ( num, points2d, points3d ); | |
1123 | } | |
1124 | ||
1125 | //======================================================================= | |
1126 | //function : CheckIntersectingEdges | |
1127 | //purpose : Test if two consequent edges are intersecting | |
1128 | // It is made in accordance with the following check in BRepCheck: | |
1129 | // - in BRepCheck_Wire::Orientation(), test for self-intersection | |
1130 | //======================================================================= | |
1131 | ||
1132 | Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num, | |
1133 | IntRes2d_SequenceOfIntersectionPoint& points2d, | |
1134 | TColgp_SequenceOfPnt& points3d, | |
1135 | TColStd_SequenceOfReal& errors) | |
1136 | { | |
1137 | points2d.Clear(); | |
1138 | points3d.Clear(); | |
1139 | errors.Clear(); | |
1140 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1141 | if ( ! IsReady() || NbEdges() <2 ) return Standard_False; | |
1142 | ||
1143 | //szv#4:S4163:12Mar99 optimized | |
1144 | Standard_Integer n2 = (num > 0)? num : NbEdges(); | |
1145 | Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges(); | |
1146 | TopoDS_Edge edge1 = myWire->Edge ( n1 ); | |
1147 | TopoDS_Edge edge2 = myWire->Edge ( n2 ); | |
1148 | ||
1149 | ShapeAnalysis_Edge sae; | |
1150 | TopoDS_Vertex V1 = sae.LastVertex ( edge1 ); | |
1151 | TopoDS_Vertex V2 = sae.FirstVertex ( edge2 ); | |
1152 | if ( V1.IsNull() || V2.IsNull() ) { | |
1153 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1154 | return Standard_False; | |
1155 | } | |
1156 | if ( ! BRepTools::Compare ( V1, V2 ) ) { | |
1157 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1158 | return Standard_False; | |
1159 | } | |
1160 | ||
1161 | TopoDS_Vertex Vp = sae.FirstVertex ( edge1 ); | |
1162 | TopoDS_Vertex Vn = sae.LastVertex ( edge2 ); | |
1163 | ||
1164 | Standard_Real a1, b1, a2, b2; | |
1165 | Handle(Geom2d_Curve) Crv1, Crv2; | |
1166 | if ( ! sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False ) ) { | |
1167 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1168 | return Standard_False; | |
1169 | } | |
1170 | if ( ! sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False ) ) { | |
1171 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1172 | return Standard_False; | |
1173 | } | |
1174 | if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() || | |
1175 | Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False; //:f7 abv 6 May 98: BUC50070 on #42276 | |
1176 | ||
1177 | Standard_Boolean isForward1 = ( edge1.Orientation() == TopAbs_FORWARD ); | |
1178 | Standard_Boolean isForward2 = ( edge2.Orientation() == TopAbs_FORWARD ); | |
1179 | ||
1180 | Standard_Real tol0 = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) ); | |
1181 | Standard_Real tol = tol0; | |
1182 | ||
1183 | gp_Pnt pnt = BRep_Tool::Pnt ( V1 ); | |
1184 | ||
1185 | // Standard_Boolean Status = Standard_False; | |
1186 | ||
1187 | Standard_Real tolint = 1.0e-10; | |
1188 | ||
1189 | //szv#4:S4163:12Mar99 warning | |
1190 | IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint, | |
1191 | Crv1->Value ( b1 ), b1, tolint ); | |
1192 | IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint, | |
1193 | Crv2->Value ( b2 ), b2, tolint ); | |
1194 | Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 ); | |
1195 | ||
1196 | //:64 abv 25 Dec 97: Attention! | |
1197 | // Since Intersection algorithm is not symmetrical, for consistency with BRepCheck | |
1198 | // edge with lower order number shoud be intersecting with edge with higher one | |
1199 | // i.e., for intersection of last and first edges, they should go in reversed order | |
1200 | // Example: entity #38285 from bug CSR #CTS17806 | |
1201 | // NOTE: Tr1 and Tr2 are not reordered because they are used in the same manner | |
1202 | Geom2dInt_GInter Inter; | |
1203 | if ( num ==1 ) Inter.Perform ( C2, d2, C1, d1, tolint, tolint ); | |
1204 | else Inter.Perform ( C1, d1, C2, d2, tolint, tolint ); | |
1205 | if ( ! Inter.IsDone() ) return Standard_False; | |
1206 | ||
1207 | //:86 abv 22 Jan 98: fix self-intersection even if tolerance of vertex is enough | |
1208 | // to annihilate it. This is done to prevent wrong effects if vertex tolerance | |
1209 | // will be decreased (e.g., in FixLacking) | |
1210 | Standard_Real tole = Max ( ( BRep_Tool::SameParameter ( edge1 ) ? | |
1211 | BRep_Tool::Tolerance ( edge1 ) : tol0 ), | |
1212 | ( BRep_Tool::SameParameter ( edge2 ) ? | |
1213 | BRep_Tool::Tolerance ( edge2 ) : tol0 ) ); | |
1214 | Standard_Real tolt = Min ( tol, Max ( tole, myPrecision ) ); | |
1215 | //Standard_Real prevRange1 = RealLast(), prevRange2 = RealLast(); //SK | |
1216 | Standard_Integer isLacking = -1; //:l0 abv: CATIA01 #1727: protect against adding lacking | |
1217 | //#83 rln 19.03.99 sim2.igs, entity 4292 | |
1218 | //processing also segments as in BRepCheck | |
1219 | Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments(); | |
1220 | for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) { | |
1221 | IntRes2d_IntersectionPoint IP; | |
1222 | IntRes2d_Transition Tr1, Tr2; | |
1223 | if (i <= NbPoints) | |
1224 | IP = Inter.Point ( i ); | |
1225 | else { | |
1226 | const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints ); | |
1227 | if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue; | |
1228 | IP = Seg.FirstPoint(); | |
1229 | Tr1 = IP.TransitionOfFirst(); | |
1230 | Tr2 = IP.TransitionOfSecond(); | |
1231 | if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle) | |
1232 | IP = Seg.LastPoint(); | |
1233 | } | |
1234 | Tr1 = IP.TransitionOfFirst(); | |
1235 | Tr2 = IP.TransitionOfSecond(); | |
1236 | ||
1237 | if ( Tr1.PositionOnCurve() != IntRes2d_Middle && | |
1238 | Tr2.PositionOnCurve() != IntRes2d_Middle ) continue; | |
1239 | Standard_Real param1, param2; | |
1240 | param1 = ( num ==1 ? IP.ParamOnSecond() : IP.ParamOnFirst() ); | |
1241 | param2 = ( num ==1 ? IP.ParamOnFirst() : IP.ParamOnSecond() ); | |
1242 | ||
1243 | //:r6 abv 8 Apr 99: r_47-sd.stp #173850: protect against working out of curve range | |
1244 | if ( a1-param1 > ::Precision::PConfusion() || | |
1245 | param1-b1 > ::Precision::PConfusion() || | |
1246 | a2-param2 > ::Precision::PConfusion() || | |
1247 | param2-b2 > ::Precision::PConfusion() ) continue; | |
1248 | ||
1249 | //:82 abv 21 Jan 98: point of intersection on Crv1 and Crv2 is different | |
1250 | gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, Crv1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) ); | |
1251 | gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, Crv2, param2 ); //:h0: thesurf.Value ( Crv2->Value ( param2 ) ); | |
1252 | gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() ); | |
1253 | Standard_Real di1 = pi1.SquareDistance ( pnt ); | |
1254 | Standard_Real di2 = pi2.SquareDistance ( pnt ); | |
1255 | Standard_Real dist2 = Max ( di1, di2 ); | |
1256 | ||
1257 | //rln 03/02/98: CSR#BUC50004 entity 56 (to avoid later inserting lacking edge) | |
1258 | if ( isLacking <0 ) { //:l0 | |
1259 | gp_Pnt2d end1 = Crv1->Value ( isForward1 ? b1 : a1 ); | |
1260 | gp_Pnt2d end2 = Crv2->Value ( isForward2 ? a2 : b2 ); | |
1261 | //:l0 Standard_Real distab2 = mySurf->Value ( end1 ).SquareDistance ( mySurf->Value ( end2 ) ); | |
1262 | //:l0: test like in BRepCheck | |
1263 | GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface(); | |
1264 | Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) ); | |
1265 | isLacking = ( end1.SquareDistance(end2) >= tol2d * tol2d ); | |
1266 | } | |
1267 | ||
1268 | if ( ( dist2 > tolt * tolt || //:86: tol -> tolt | |
1269 | isLacking ) && //:l0 | |
1270 | //:l0 distab2 > BRep_Tool::Tolerance ( edge1 ) + BRep_Tool::Tolerance ( edge2 ) ) && //rln | |
1271 | ( ! BRepTools::Compare ( Vp, Vn ) || //:63 | |
1272 | dist2 < pint.SquareDistance ( BRep_Tool::Pnt ( Vp ) ) ) ) { //:63 | |
1273 | points2d.Append ( IP ); | |
1274 | points3d.Append ( pint ); | |
1275 | errors.Append ( 0.5 * pi1.Distance ( pi2 ) ); | |
1276 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1277 | } | |
1278 | } | |
1279 | ||
1280 | return LastCheckStatus ( ShapeExtend_DONE ); | |
1281 | } | |
1282 | ||
1283 | //======================================================================= | |
1284 | //function : CheckIntersectingEdges | |
1285 | //purpose : | |
1286 | //======================================================================= | |
1287 | ||
1288 | Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num) | |
1289 | { | |
1290 | IntRes2d_SequenceOfIntersectionPoint points2d; | |
1291 | TColgp_SequenceOfPnt points3d; | |
1292 | TColStd_SequenceOfReal errors; | |
1293 | return CheckIntersectingEdges ( num, points2d, points3d, errors ); | |
1294 | } | |
1295 | ||
1296 | //======================================================================= | |
1297 | //function : CheckIntersectingEdges | |
1298 | //purpose : | |
1299 | //======================================================================= | |
1300 | ||
1301 | Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges(const Standard_Integer num1, | |
1302 | const Standard_Integer num2, | |
1303 | IntRes2d_SequenceOfIntersectionPoint& points2d, | |
1304 | TColgp_SequenceOfPnt& points3d, | |
1305 | TColStd_SequenceOfReal& errors) | |
1306 | { | |
1307 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1308 | if ( ! IsReady() ) return Standard_False; | |
1309 | Handle(ShapeExtend_WireData) sbwd = WireData(); | |
1310 | Standard_Integer n2 = ( num2 >0 ? num2 : sbwd->NbEdges() ); | |
1311 | Standard_Integer n1 = ( num1 >0 ? num1 : sbwd->NbEdges() ); | |
1312 | ||
1313 | TopoDS_Edge edge1 = sbwd->Edge ( n1 ); | |
1314 | TopoDS_Edge edge2 = sbwd->Edge ( n2 ); | |
1315 | ||
1316 | ShapeAnalysis_Edge sae; | |
1317 | Standard_Real a1, b1, a2, b2; | |
1318 | Handle(Geom2d_Curve) Crv1, Crv2; | |
1319 | if(!sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False )){ | |
1320 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1321 | return Standard_False; | |
1322 | } | |
1323 | ||
1324 | if(!sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False )){ | |
1325 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1326 | return Standard_False; | |
1327 | } | |
1328 | ||
1329 | if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() || | |
1330 | Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False; | |
1331 | ||
1332 | points2d.Clear(); | |
1333 | points3d.Clear(); | |
1334 | errors.Clear(); | |
1335 | TColgp_Array1OfPnt vertexPoints(1,4); | |
1336 | TColStd_Array1OfReal vertexTolers(1,4); | |
1337 | vertexPoints(1) = BRep_Tool::Pnt(sae.FirstVertex(edge1)); | |
1338 | vertexTolers(1) = BRep_Tool::Tolerance(sae.FirstVertex(edge1)); | |
1339 | vertexPoints(2) = BRep_Tool::Pnt(sae.LastVertex(edge1)); | |
1340 | vertexTolers(2) = BRep_Tool::Tolerance(sae.LastVertex(edge1)); | |
1341 | vertexPoints(3) = BRep_Tool::Pnt(sae.FirstVertex(edge2)); | |
1342 | vertexTolers(3) = BRep_Tool::Tolerance(sae.FirstVertex(edge2)); | |
1343 | vertexPoints(4) = BRep_Tool::Pnt(sae.LastVertex(edge2)); | |
1344 | vertexTolers(4) = BRep_Tool::Tolerance(sae.LastVertex(edge2)); | |
1345 | ||
1346 | Standard_Real tolint = 1.0e-10; | |
1347 | ||
1348 | IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint, | |
1349 | Crv1->Value ( b1 ), b1, tolint ); | |
1350 | IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint, | |
1351 | Crv2->Value ( b2 ), b2, tolint ); | |
1352 | Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 ); | |
1353 | ||
1354 | Geom2dInt_GInter Inter; | |
1355 | Inter.Perform ( C1, d1, C2, d2, tolint, tolint ); | |
1356 | if ( ! Inter.IsDone() ) return Standard_False; | |
1357 | ||
1358 | //#83 rln 19.03.99 sim2.igs, entity 4292 | |
1359 | //processing also segments as in BRepCheck | |
1360 | Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments(); | |
1361 | for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) { | |
1362 | IntRes2d_IntersectionPoint IP; | |
1363 | IntRes2d_Transition Tr1, Tr2; | |
1364 | if (i <= NbPoints) | |
1365 | IP = Inter.Point ( i ); | |
1366 | else { | |
1367 | const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints ); | |
1368 | if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue; | |
1369 | IP = Seg.FirstPoint(); | |
1370 | Tr1 = IP.TransitionOfFirst(); | |
1371 | Tr2 = IP.TransitionOfSecond(); | |
1372 | if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle) | |
1373 | IP = Seg.LastPoint(); | |
1374 | } | |
1375 | Tr1 = IP.TransitionOfFirst(); | |
1376 | Tr2 = IP.TransitionOfSecond(); | |
1377 | if ( Tr1.PositionOnCurve() != IntRes2d_Middle && | |
1378 | Tr2.PositionOnCurve() != IntRes2d_Middle ) continue; | |
1379 | Standard_Real param1 = IP.ParamOnFirst(); | |
1380 | Standard_Real param2 = IP.ParamOnSecond(); | |
1381 | gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, Crv1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) ); | |
1382 | gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, Crv2, param2 ); | |
1383 | Standard_Boolean OK = Standard_False; | |
1384 | for(Standard_Integer j=1; (j<=4)&&!OK; j++) { | |
1385 | Standard_Real di1 = pi1.SquareDistance (vertexPoints(j)); | |
1386 | Standard_Real di2 = pi2.SquareDistance (vertexPoints(j)); | |
1387 | Standard_Real dist2 = Max ( di1, di2 ); | |
1388 | if(dist2 < vertexTolers(j) * vertexTolers(j)) | |
1389 | OK = Standard_True; | |
1390 | } | |
1391 | if(!OK) { | |
1392 | gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() ); | |
1393 | points2d.Append ( IP ); | |
1394 | points3d.Append ( pint ); | |
1395 | errors.Append ( 0.5 * pi1.Distance ( pi2 ) ); | |
1396 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1397 | } | |
1398 | } | |
1399 | return LastCheckStatus ( ShapeExtend_DONE ); | |
1400 | } | |
1401 | ||
1402 | //======================================================================= | |
1403 | //function : CheckIntersectingEdges | |
1404 | //purpose : | |
1405 | //======================================================================= | |
1406 | ||
1407 | Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num1, | |
1408 | const Standard_Integer num2) | |
1409 | { | |
1410 | IntRes2d_SequenceOfIntersectionPoint points2d; | |
1411 | TColgp_SequenceOfPnt points3d; | |
1412 | TColStd_SequenceOfReal errors; | |
1413 | return CheckIntersectingEdges(num1, num2, points2d, points3d, errors); | |
1414 | } | |
1415 | ||
1416 | //======================================================================= | |
1417 | //function : CheckLacking | |
1418 | //purpose : Test if two edges are disconnected in 2d according to the | |
1419 | // Adaptor_Surface::Resolution | |
1420 | //======================================================================= | |
1421 | ||
1422 | Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num, | |
1423 | const Standard_Real Tolerance, | |
1424 | gp_Pnt2d &p2d1, gp_Pnt2d &p2d2) | |
1425 | { | |
1426 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1427 | if ( ! IsReady() ) return Standard_False; | |
1428 | ||
1429 | //szv#4:S4163:12Mar99 optimized | |
1430 | Standard_Integer n2 = (num > 0)? num : NbEdges(); | |
1431 | Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges(); | |
1432 | TopoDS_Edge E1 = myWire->Edge ( n1 ); | |
1433 | TopoDS_Edge E2 = myWire->Edge ( n2 ); | |
1434 | ||
1435 | ShapeAnalysis_Edge sae; | |
1436 | TopoDS_Vertex V1 = sae.LastVertex ( E1 ); | |
1437 | TopoDS_Vertex V2 = sae.FirstVertex ( E2 ); | |
1438 | // CKY 4 MAR 1998 : protection against null vertex | |
1439 | if ( V1.IsNull() || V2.IsNull() ) { | |
1440 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1441 | return Standard_False; | |
1442 | } | |
1443 | if ( ! BRepTools::Compare ( V1, V2 ) ) { | |
1444 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1445 | return Standard_False; | |
1446 | } | |
1447 | ||
1448 | Standard_Real a, b; | |
1449 | gp_Vec2d v1, v2, v12; | |
1450 | Handle(Geom2d_Curve) c2d; | |
1451 | if ( ! sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) { | |
1452 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1453 | return Standard_False; | |
1454 | } | |
1455 | c2d->D1 ( b, p2d1, v1 ); | |
1456 | if ( E1.Orientation() == TopAbs_REVERSED ) v1.Reverse(); | |
1457 | if ( ! sae.PCurve ( E2, myFace, c2d, a, b, Standard_True ) ) { | |
1458 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1459 | return Standard_False; | |
1460 | } | |
1461 | c2d->D1 ( a, p2d2, v2 ); | |
1462 | if ( E2.Orientation() == TopAbs_REVERSED ) v2.Reverse(); | |
1463 | v12 = p2d2.XY() - p2d1.XY(); | |
1464 | myMax2d = v12.SquareMagnitude(); | |
1465 | ||
1466 | // test like in BRepCheck | |
1467 | Standard_Real tol = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) ); | |
1468 | tol = ( Tolerance > gp::Resolution() && Tolerance < tol ? Tolerance : tol ); | |
1469 | GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface(); | |
1470 | Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) ); | |
1471 | if ( // tol2d < gp::Resolution() || //#2 smh 26.03.99 S4163 Zero divide | |
1472 | myMax2d < tol2d * tol2d ) return Standard_False; | |
1473 | ||
1474 | myMax2d = Sqrt ( myMax2d ); | |
1475 | myMax3d = tol * myMax2d / Max ( tol2d, gp::Resolution() ); | |
1476 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); | |
1477 | ||
1478 | if ( myMax2d < Precision::PConfusion() || //:abv 03.06.02 CTS21866.stp | |
c6541a0c D |
1479 | ( v1.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v1 ) ) > 0.9 * M_PI ) || |
1480 | ( v2.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v2 ) ) > 0.9 * M_PI ) ) | |
7fd59977 | 1481 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 ); |
1482 | return Standard_True; | |
1483 | } | |
1484 | ||
1485 | //======================================================================= | |
1486 | //function : CheckLacking | |
1487 | //purpose : | |
1488 | // | |
1489 | //======================================================================= | |
1490 | ||
1491 | Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num, | |
1492 | const Standard_Real Tolerance) | |
1493 | { | |
1494 | gp_Pnt2d p1, p2; | |
1495 | return CheckLacking (num, Tolerance, p1, p2); | |
1496 | } | |
1497 | ||
1498 | //======================================================================= | |
1499 | //function : CheckOuterBound | |
1500 | //purpose : | |
1501 | //======================================================================= | |
1502 | ||
1503 | Standard_Boolean ShapeAnalysis_Wire::CheckOuterBound(const Standard_Boolean APIMake) | |
1504 | { | |
1505 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1506 | if ( ! IsReady() ) return Standard_False; | |
1507 | ||
1508 | TopoDS_Wire wire; | |
1509 | if (APIMake) wire = myWire->WireAPIMake(); | |
1510 | else wire = myWire->Wire(); | |
1511 | ||
1512 | TopoDS_Shape sh = myFace.EmptyCopied(); //szv#4:S4163:12Mar99 SGI warns | |
1513 | TopoDS_Face face = TopoDS::Face(sh); | |
1514 | BRep_Builder B; | |
1515 | B.Add (face, wire); | |
1516 | if (ShapeAnalysis::IsOuterBound (face)) return Standard_False; | |
1517 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1518 | return Standard_True; | |
1519 | } | |
1520 | ||
1521 | //======================================================================= | |
1522 | //function : CheckNotchedEdges | |
1523 | //purpose : | |
1524 | //======================================================================= | |
1525 | ||
1526 | static Standard_Real ProjectInside(const Adaptor3d_CurveOnSurface AD, | |
1527 | const gp_Pnt pnt, | |
1528 | const Standard_Real preci, | |
1529 | gp_Pnt& proj, | |
1530 | Standard_Real& param, | |
1531 | const Standard_Boolean adjustToEnds = Standard_True) | |
1532 | { | |
1533 | ShapeAnalysis_Curve sac; | |
1534 | Standard_Real dist = sac.Project(AD,pnt,preci,proj,param,adjustToEnds); | |
1535 | Standard_Real uFirst = AD.FirstParameter(); | |
1536 | Standard_Real uLast = AD.LastParameter(); | |
1537 | if(param<uFirst) { | |
1538 | param = uFirst; | |
1539 | proj = AD.Value(uFirst); | |
1540 | return proj.Distance(pnt); | |
1541 | } | |
1542 | ||
1543 | if(param>uLast) { | |
1544 | param = uLast; | |
1545 | proj = AD.Value(uLast); | |
1546 | return proj.Distance(pnt); | |
1547 | } | |
1548 | return dist; | |
1549 | } | |
1550 | ||
1551 | Standard_Boolean ShapeAnalysis_Wire::CheckNotchedEdges(const Standard_Integer num, | |
1552 | Standard_Integer& shortNum, | |
1553 | Standard_Real& param, | |
1554 | const Standard_Real Tolerance) | |
1555 | { | |
1556 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1557 | if ( ! IsReady() ) return Standard_False; | |
1558 | ||
1559 | Standard_Integer n2 = (num > 0)? num : NbEdges(); | |
1560 | Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges(); | |
1561 | TopoDS_Edge E1 = myWire->Edge ( n1 ); | |
1562 | TopoDS_Edge E2 = myWire->Edge ( n2 ); | |
1563 | ||
1564 | if(BRep_Tool::Degenerated(E1)||BRep_Tool::Degenerated(E2)) | |
1565 | return Standard_False; | |
1566 | ||
1567 | ShapeAnalysis_Edge sae; | |
1568 | TopoDS_Vertex V1 = sae.LastVertex ( E1 ); | |
1569 | TopoDS_Vertex V2 = sae.FirstVertex ( E2 ); | |
1570 | ||
1571 | if ( V1.IsNull() || V2.IsNull() ) { | |
1572 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1573 | return Standard_False; | |
1574 | } | |
1575 | if ( ! BRepTools::Compare ( V1, V2 ) ) { | |
1576 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1577 | return Standard_False; | |
1578 | } | |
1579 | ||
1580 | Standard_Real a1, b1, a2, b2; | |
1581 | gp_Pnt2d p2d1, p2d2; | |
1582 | gp_Vec2d v1, v2; | |
1583 | Handle(Geom2d_Curve) c2d1, c2d2; | |
1584 | if ( ! sae.PCurve ( E1, myFace, c2d1, a1, b1, Standard_False ) ) { | |
1585 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1586 | return Standard_False; | |
1587 | } | |
1588 | ||
1589 | if(E1.Orientation()==TopAbs_REVERSED) | |
1590 | c2d1->D1 ( a1, p2d1, v1 ); | |
1591 | else { | |
1592 | c2d1->D1 ( b1, p2d1, v1 ); | |
1593 | v1.Reverse(); | |
1594 | } | |
1595 | ||
1596 | if ( ! sae.PCurve ( E2, myFace, c2d2, a2, b2, Standard_False ) ) { | |
1597 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3); | |
1598 | return Standard_False; | |
1599 | } | |
1600 | if(E2.Orientation()==TopAbs_REVERSED) { | |
1601 | c2d2->D1 ( b2, p2d2, v2 ); | |
1602 | v2.Reverse(); | |
1603 | } | |
1604 | else | |
1605 | c2d2->D1 ( a2, p2d2, v2 ); | |
1606 | ||
1607 | if ( v2.Magnitude() < gp::Resolution() || v1.Magnitude() < gp::Resolution()) | |
1608 | return Standard_False; | |
1609 | ||
1610 | if ( Abs ( v2.Angle ( v1 ) ) > 0.1 || p2d1.Distance(p2d2) > Tolerance) | |
1611 | return Standard_False; | |
1612 | ||
1613 | Handle(Geom2dAdaptor_HCurve) AC2d1 = new Geom2dAdaptor_HCurve(c2d1,a1,b1); | |
1614 | Handle(GeomAdaptor_HSurface) AdS1 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln())); | |
1615 | Adaptor3d_CurveOnSurface Ad1(AC2d1,AdS1); | |
1616 | ||
1617 | Handle(Geom2dAdaptor_HCurve) AC2d2 = new Geom2dAdaptor_HCurve(c2d2,a2,b2); | |
1618 | Handle(GeomAdaptor_HSurface) AdS2 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln())); | |
1619 | Adaptor3d_CurveOnSurface Ad2(AC2d2,AdS2); | |
1620 | ||
1621 | Adaptor3d_CurveOnSurface longAD, shortAD; | |
1622 | Standard_Real lenP, firstP; | |
1623 | ||
1624 | ShapeAnalysis_Curve sac; | |
1625 | ||
1626 | gp_Pnt Proj1, Proj2; | |
bbf32d01 | 1627 | Standard_Real param1 = 0., param2 = 0.; |
7fd59977 | 1628 | p2d2=c2d2->Value(E2.Orientation()==TopAbs_FORWARD ? b2 : a2); |
1629 | p2d1=c2d1->Value(E1.Orientation()==TopAbs_FORWARD ? a1 : b1); | |
1630 | Standard_Real dist1 = ProjectInside(Ad1,gp_Pnt(p2d2.X(),p2d2.Y(),0),Tolerance,Proj1,param1,Standard_False); | |
1631 | Standard_Real dist2 = ProjectInside(Ad2,gp_Pnt(p2d1.X(),p2d1.Y(),0),Tolerance,Proj2,param2,Standard_False); | |
1632 | ||
1633 | if ( dist1 > Tolerance && dist2 > Tolerance) | |
1634 | return Standard_False; | |
1635 | ||
1636 | if (dist1 < dist2 ) { | |
1637 | shortAD = Ad2; | |
1638 | longAD = Ad1; | |
1639 | lenP = b2 - a2; | |
1640 | firstP = a2; | |
1641 | shortNum=n2; | |
1642 | param=param1; | |
1643 | ||
1644 | } | |
1645 | else { | |
1646 | shortAD = Ad1; | |
1647 | longAD = Ad2; | |
1648 | lenP = b1 - a1; | |
1649 | firstP = a1; | |
1650 | shortNum=n1; | |
1651 | param=param2; | |
1652 | } | |
1653 | ||
1654 | Standard_Real step = lenP/23; | |
1655 | for (Standard_Integer i = 1; i < 23; i++,firstP+=step) { | |
1656 | Standard_Real d1 = sac.Project(longAD,shortAD.Value(firstP),Tolerance,Proj1,param1); | |
1657 | if (d1 > Tolerance) { | |
1658 | return Standard_False; | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | return Standard_True; | |
1663 | } | |
1664 | ||
1665 | //======================================================================= | |
1666 | //function : CheckSmallArea | |
1667 | //purpose : | |
1668 | //======================================================================= | |
1669 | ||
1670 | Standard_Boolean ShapeAnalysis_Wire::CheckSmallArea(const Standard_Real prec2d) | |
1671 | { | |
1672 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1673 | Standard_Integer NbEdges = myWire->NbEdges(); | |
1674 | if ( !IsReady() || NbEdges <1 ) return Standard_False; | |
1675 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
1676 | ||
1677 | Standard_Integer NbControl=23; | |
1678 | Standard_Real area=0; | |
1679 | gp_XY prev, cont; | |
1680 | for (Standard_Integer nbe = 1; nbe <= NbEdges; nbe++) { | |
1681 | Standard_Real First, Last; | |
1682 | Handle(Geom2d_Curve) c2d; | |
1683 | ShapeAnalysis_Edge sae; | |
1684 | if (!sae.PCurve(myWire->Edge(nbe),myFace,c2d,First,Last)) { | |
1685 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1686 | return Standard_False; | |
1687 | } | |
1688 | ||
1689 | Standard_Integer ibeg = 0; | |
1690 | if( nbe == 1 ) { | |
1691 | gp_Pnt2d pntIni = c2d->Value(First); | |
1692 | prev = pntIni.XY(); | |
1693 | cont = prev; | |
1694 | ibeg = 1; | |
1695 | } | |
1696 | for ( Standard_Integer i = ibeg; i < NbControl; i++) { | |
1697 | Standard_Real prm = ((NbControl-1-i)*First + i*Last)/(NbControl-1); | |
1698 | gp_Pnt2d pntCurr = c2d->Value(prm); | |
1699 | gp_XY curr = pntCurr.XY(); | |
1700 | area += curr ^ prev; | |
1701 | prev = curr; | |
1702 | } | |
1703 | } | |
1704 | area += cont ^ prev; | |
1705 | if ( Abs(area) < 2*prec2d*prec2d ) { | |
1706 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1707 | return Standard_True; | |
1708 | } | |
1709 | return Standard_False; | |
1710 | } | |
1711 | ||
1712 | //======================================================================= | |
1713 | //function : CheckShapeConnect | |
1714 | //purpose : | |
1715 | //======================================================================= | |
1716 | ||
1717 | Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(const TopoDS_Shape& shape,const Standard_Real prec) | |
1718 | { | |
1719 | Standard_Real tailhead, tailtail, headhead, headtail; | |
1720 | return CheckShapeConnect (tailhead, tailtail, headtail, headhead, shape, prec); | |
1721 | } | |
1722 | ||
1723 | //======================================================================= | |
1724 | //function : CheckShapeConnect | |
1725 | //purpose : | |
1726 | //======================================================================= | |
1727 | ||
1728 | Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(Standard_Real& tailhead, Standard_Real& tailtail, | |
1729 | Standard_Real& headtail, Standard_Real& headhead, | |
1730 | const TopoDS_Shape& shape, const Standard_Real prec) | |
1731 | { | |
1732 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
1733 | if (!IsLoaded () || shape.IsNull()) return Standard_False; | |
1734 | TopoDS_Vertex V1,V2; | |
1735 | TopoDS_Edge E; TopoDS_Wire W; | |
1736 | ShapeAnalysis_Edge SAE; | |
1737 | if (shape.ShapeType() == TopAbs_EDGE) { | |
1738 | E = TopoDS::Edge (shape); | |
1739 | V1 = SAE.FirstVertex (E); V2 = SAE.LastVertex (E); | |
1740 | } else if (shape.ShapeType() == TopAbs_WIRE) { | |
1741 | W = TopoDS::Wire (shape); | |
1742 | ShapeAnalysis::FindBounds (W,V1,V2); | |
1743 | } | |
1744 | else return Standard_False; | |
1745 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1746 | // on va comparer les points avec ceux de thevfirst et thevlast | |
1747 | gp_Pnt p1 = BRep_Tool::Pnt(V1); | |
1748 | gp_Pnt p2 = BRep_Tool::Pnt(V2); | |
1749 | ||
1750 | TopoDS_Vertex vfirst = SAE.FirstVertex (myWire->Edge (1)), | |
1751 | vlast = SAE.LastVertex (myWire->Edge (NbEdges())); | |
1752 | gp_Pnt pf = BRep_Tool::Pnt(vfirst); | |
1753 | gp_Pnt pl = BRep_Tool::Pnt(vlast); | |
1754 | ||
1755 | tailhead = p1.Distance(pl); | |
1756 | tailtail = p2.Distance(pl); | |
1757 | headhead = p1.Distance(pf); | |
1758 | headtail = p2.Distance(pf); | |
1759 | Standard_Real dm1 = tailhead, dm2 = headtail; | |
1760 | Standard_Integer res1 = 0, res2 = 0; | |
1761 | ||
1762 | if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;} | |
1763 | if (headtail > headhead) {res2 = 1; dm2 = headhead;} | |
1764 | Standard_Integer result = res1; | |
1765 | myMin3d = Min (dm1, dm2); | |
1766 | myMax3d = Max (dm1, dm2); | |
1767 | if (dm1 > dm2) {dm1 = dm2; result = res2 + 2;} | |
1768 | switch (result) { | |
1769 | case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break; | |
1770 | case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break; | |
1771 | case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break; | |
1772 | } | |
1773 | if (!res1) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5); | |
1774 | if (!res2) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6); | |
1775 | ||
1776 | if (myMin3d > Max (myPrecision, prec)) | |
1777 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
1778 | return LastCheckStatus (ShapeExtend_DONE); | |
1779 | } | |
1780 | ||
1781 | //======================================================================= | |
1782 | //function : CheckLoop | |
1783 | //purpose : | |
1784 | //======================================================================= | |
1785 | Standard_Boolean isMultiVertex(const TopTools_ListOfShape& alshape, | |
1786 | const TopTools_MapOfShape& aMapSmallEdges, | |
1787 | const TopTools_MapOfShape& aMapSeemEdges) | |
1788 | { | |
1789 | TopTools_ListIteratorOfListOfShape lIt1(alshape); | |
1790 | Standard_Integer nbNotAccount =0; | |
1791 | ||
1792 | for( ; lIt1.More() ; lIt1.Next()) | |
1793 | { | |
1794 | if(aMapSmallEdges.Contains(lIt1.Value())) | |
1795 | nbNotAccount++; | |
1796 | else if(aMapSeemEdges.Contains(lIt1.Value())) | |
1797 | nbNotAccount++; | |
1798 | } | |
1799 | return ((alshape.Extent() -nbNotAccount) >2); | |
1800 | } | |
1801 | Standard_Boolean ShapeAnalysis_Wire::CheckLoop(TopTools_IndexedMapOfShape& aMapLoopVertices, | |
1802 | TopTools_DataMapOfShapeListOfShape& aMapVertexEdges, | |
1803 | TopTools_MapOfShape& aMapSmallEdges, | |
1804 | TopTools_MapOfShape& aMapSeemEdges) | |
1805 | { | |
1806 | myStatus = ShapeExtend::EncodeStatus(ShapeExtend_OK); | |
1807 | if (!IsLoaded() || NbEdges() < 2) return Standard_False; | |
1808 | Standard_Real aSavPreci = Precision(); | |
1809 | SetPrecision(Precision::Infinite()); | |
1810 | Standard_Integer i =1; | |
1811 | ||
1812 | for( ; i <= myWire->NbEdges(); i++) { | |
1813 | TopoDS_Edge aedge = myWire->Edge(i); | |
1814 | TopoDS_Vertex aV1,aV2; | |
1815 | TopExp::Vertices(aedge,aV1,aV2); | |
1816 | Standard_Boolean isSame = aV1.IsSame(aV2); | |
1817 | if(myWire->IsSeam(i)) | |
1818 | aMapSeemEdges.Add(aedge); ///continue; | |
1819 | else if(BRep_Tool::Degenerated(aedge)) | |
1820 | aMapSmallEdges.Add(aedge); | |
1821 | else if(isSame && CheckSmall(i,BRep_Tool::Tolerance(aV1))) | |
1822 | aMapSmallEdges.Add(aedge); | |
1823 | ||
1824 | if(!aMapVertexEdges.IsBound(aV1)) { | |
1825 | TopTools_ListOfShape alshape; | |
1826 | aMapVertexEdges.Bind(aV1,alshape); | |
1827 | } | |
1828 | if(!aMapVertexEdges.IsBound(aV2)) { | |
1829 | TopTools_ListOfShape alshape; | |
1830 | aMapVertexEdges.Bind(aV2,alshape); | |
1831 | } | |
1832 | if(isSame) | |
1833 | { | |
1834 | TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1); | |
1835 | alshape.Append(aedge); | |
1836 | alshape.Append(aedge); | |
1837 | if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges)) | |
1838 | aMapLoopVertices.Add(aV1); | |
1839 | } | |
1840 | else { | |
1841 | TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1); | |
1842 | alshape.Append(aedge); | |
1843 | if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges)) | |
1844 | aMapLoopVertices.Add(aV1); | |
1845 | TopTools_ListOfShape& alshape2 = aMapVertexEdges.ChangeFind(aV2); | |
1846 | alshape2.Append(aedge); | |
1847 | if(alshape2.Extent() >2 && isMultiVertex( alshape2,aMapSmallEdges,aMapSeemEdges)) | |
1848 | aMapLoopVertices.Add(aV2); | |
1849 | } | |
1850 | } | |
1851 | SetPrecision(aSavPreci); | |
1852 | if(aMapLoopVertices.Extent()) | |
1853 | { | |
1854 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
1855 | myStatusLoop |= myStatus; | |
1856 | return Standard_True; | |
1857 | } | |
1858 | return Standard_False; | |
1859 | } |