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