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