1 // File: ShapeAnalysis_Wire.cxx
2 // Created: Thu Jan 20 14:46:55 2000
3 // Author: data exchange team
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.
25 #include <ShapeAnalysis_Wire.ixx>
27 #include <Precision.hxx>
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>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <BRep_Builder.hxx>
42 #include <BRep_Tool.hxx>
43 #include <BRepTools.hxx>
45 #include <ShapeExtend.hxx>
46 #include <ShapeAnalysis.hxx>
47 #include <ShapeAnalysis_Curve.hxx>
48 #include <ShapeAnalysis_Edge.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>
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>
74 //=======================================================================
75 //function : ShapeAnalysis_Wire
77 //=======================================================================
79 ShapeAnalysis_Wire::ShapeAnalysis_Wire()
82 myPrecision = ::Precision::Confusion();
85 //=======================================================================
86 //function : ShapeAnalysis_Wire
88 //=======================================================================
90 ShapeAnalysis_Wire::ShapeAnalysis_Wire (const TopoDS_Wire& wire,
91 const TopoDS_Face& face,
92 const Standard_Real precision)
94 Init (wire, face, precision);
97 //=======================================================================
98 //function : ShapeAnalysis_Wire
100 //=======================================================================
102 ShapeAnalysis_Wire::ShapeAnalysis_Wire (const Handle(ShapeExtend_WireData)& sbwd,
103 const TopoDS_Face& face,
104 const Standard_Real precision)
106 Init (sbwd, face, precision);
109 //=======================================================================
112 //=======================================================================
114 void ShapeAnalysis_Wire::Init (const TopoDS_Wire& wire,
115 const TopoDS_Face& face, const Standard_Real precision)
117 Init (new ShapeExtend_WireData (wire), face, precision);
120 //=======================================================================
123 //=======================================================================
125 void ShapeAnalysis_Wire::Init (const Handle(ShapeExtend_WireData)& sbwd,
126 const TopoDS_Face& face, const Standard_Real precision)
130 SetPrecision (precision);
133 //=======================================================================
136 //=======================================================================
138 void ShapeAnalysis_Wire::Load (const TopoDS_Wire& wire)
141 myWire = new ShapeExtend_WireData (wire);
144 //=======================================================================
147 //=======================================================================
149 void ShapeAnalysis_Wire::Load (const Handle(ShapeExtend_WireData)& sbwd)
155 //=======================================================================
158 //=======================================================================
160 void ShapeAnalysis_Wire::SetFace(const TopoDS_Face& face)
164 mySurf = new ShapeAnalysis_Surface ( BRep_Tool::Surface ( myFace ) );
167 //=======================================================================
168 //function : SetSurface
170 //=======================================================================
172 void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface)
174 SetSurface ( surface, TopLoc_Location() );
177 //=======================================================================
178 //function : SetSurface
180 //=======================================================================
182 void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface,
183 const TopLoc_Location& location)
187 B.MakeFace ( face, surface, location, ::Precision::Confusion() );
191 //=======================================================================
192 //function : SetPrecision
194 //=======================================================================
196 void ShapeAnalysis_Wire::SetPrecision(const Standard_Real precision)
198 myPrecision = precision;
201 //=======================================================================
202 //function : ClearStatuses
204 //=======================================================================
206 void ShapeAnalysis_Wire::ClearStatuses()
208 myStatusOrder = myStatusConnected =
209 myStatusEdgeCurves = myStatusDegenerated =
210 myStatusClosed = myStatusLacking =
211 myStatusSelfIntersection = myStatusSmall =
212 myStatusGaps3d = myStatusGaps2d =
213 myStatusCurveGaps = myStatusLoop = myStatus = 0;
215 myMin3d = myMin2d = myMax3d = myMax2d = 0.;
218 //=======================================================================
221 //=======================================================================
223 Standard_Boolean ShapeAnalysis_Wire::Perform()
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();
237 //=======================================================================
238 //function : CheckOrder
240 //=======================================================================
242 Standard_Boolean ShapeAnalysis_Wire::CheckOrder (const Standard_Boolean isClosed,
243 const Standard_Boolean mode3d)
245 ShapeAnalysis_WireOrder sawo;
246 CheckOrder (sawo, isClosed, mode3d);
247 myStatusOrder = myStatus;
248 return StatusOrder (ShapeExtend_DONE);
251 //=======================================================================
252 //function : CheckSmall
254 //=======================================================================
256 Standard_Boolean ShapeAnalysis_Wire::CheckSmall(const Standard_Real precsmall)
258 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
259 CheckSmall (i, precsmall);
260 myStatusSmall |= myStatus;
262 return StatusSmall (ShapeExtend_DONE);
265 //=======================================================================
266 //function : CheckConnected
268 //=======================================================================
270 Standard_Boolean ShapeAnalysis_Wire::CheckConnected(const Standard_Real prec)
272 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
273 CheckConnected ( i, prec );
274 myStatusConnected |= myStatus;
276 return StatusConnected (ShapeExtend_DONE);
279 //=======================================================================
280 //function : CheckEdgeCurves
282 //=======================================================================
284 Standard_Boolean ShapeAnalysis_Wire::CheckEdgeCurves()
286 myStatusEdgeCurves = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
287 if ( ! IsReady() ) return Standard_False;
289 Standard_Integer i, nb = myWire->NbEdges();
290 ShapeAnalysis_Edge SAE;
292 for (i = 1; i <= nb; i++) {
293 TopoDS_Edge E = myWire->Edge (i);
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);
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);
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);
314 if (LastCheckStatus (ShapeExtend_DONE))
315 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
316 if (LastCheckStatus (ShapeExtend_FAIL))
317 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL4);
320 if (LastCheckStatus (ShapeExtend_DONE))
321 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
322 if (LastCheckStatus (ShapeExtend_FAIL))
323 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL5);
326 if (LastCheckStatus (ShapeExtend_DONE))
327 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
328 if (LastCheckStatus (ShapeExtend_FAIL))
329 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL6);
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);
338 return StatusEdgeCurves (ShapeExtend_DONE);
341 //=======================================================================
342 //function : CheckDegenerated
344 //=======================================================================
346 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated()
348 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
349 CheckDegenerated (i);
350 myStatusDegenerated |= myStatus;
352 return StatusDegenerated (ShapeExtend_DONE);
355 //=======================================================================
356 //function : CheckSelfIntersection
358 //=======================================================================
360 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersection()
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);
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);
379 Bnd_Array1OfBox2d boxes(1,nb);
381 const Handle(Geom_Surface)& S = BRep_Tool::Surface(Face(), L);
382 Handle(Geom2d_Curve) c2d;
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)) {
390 Geom2dAdaptor_Curve gac(c2d,cf,cl);
391 BndLib_Add2dCurve::Add(gac,::Precision::Confusion(),box);
396 Standard_Boolean isFail = Standard_False, isDone = Standard_False;
397 for(Standard_Integer num1 = 1; num1 < nb-1; num1++) {
398 Standard_Integer fin = nb;
399 if (CheckClosed(Precision::Confusion()) && 1 == num1)
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 );
409 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
411 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
413 return StatusSelfIntersection (ShapeExtend_DONE);
416 //=======================================================================
417 //function : CheckLacking
419 //=======================================================================
421 Standard_Boolean ShapeAnalysis_Wire::CheckLacking()
423 if (!IsReady() || NbEdges() < 2) return Standard_False;
424 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
426 myStatusLacking |= myStatus;
428 return StatusLacking (ShapeExtend_DONE);
431 //=======================================================================
432 //function : CheckClosed
434 //=======================================================================
436 Standard_Boolean ShapeAnalysis_Wire::CheckClosed(const Standard_Real prec)
438 myStatusClosed = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
439 if (!IsReady() || NbEdges() < 1) return Standard_False;
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 );
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 );
453 return StatusClosed ( ShapeExtend_DONE );
456 //=======================================================================
457 //function : CheckGaps3d
459 //=======================================================================
461 Standard_Boolean ShapeAnalysis_Wire::CheckGaps3d ()
463 myStatusGaps3d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
464 if (!IsLoaded() || NbEdges() < 1) return Standard_False; //gka IsLoaded
466 Standard_Real dist, maxdist = 0.;
468 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
470 myStatusGaps3d |= myStatus;
471 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
472 dist = MinDistance3d();
473 if (maxdist<dist) maxdist = dist;
476 myMin3d = myMax3d = maxdist;
478 return StatusGaps3d ( ShapeExtend_DONE );
481 //=======================================================================
482 //function : CheckGaps2d
484 //=======================================================================
486 Standard_Boolean ShapeAnalysis_Wire::CheckGaps2d ()
488 myStatusGaps2d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
489 if (!IsReady() || NbEdges() < 1) return Standard_False;
491 Standard_Real dist, maxdist = 0.;
493 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
495 myStatusGaps2d |= myStatus;
496 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
497 dist = MinDistance2d();
498 if (maxdist<dist) maxdist = dist;
501 myMin2d = myMax2d = maxdist;
503 return StatusGaps2d ( ShapeExtend_DONE );
506 //=======================================================================
507 //function : CheckCurveGaps
509 //=======================================================================
511 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGaps ()
513 myStatusCurveGaps = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
514 if (!IsReady() || NbEdges() < 1) return Standard_False;
516 Standard_Real dist, maxdist = 0.;
518 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
520 myStatusCurveGaps |= myStatus;
521 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
522 dist = MinDistance3d();
523 if (maxdist<dist) maxdist = dist;
526 myMin3d = myMax3d = maxdist;
528 return StatusCurveGaps ( ShapeExtend_DONE );
531 //=======================================================================
532 //function : CheckOrder
534 //=======================================================================
536 Standard_Boolean ShapeAnalysis_Wire::CheckOrder(ShapeAnalysis_WireOrder& sawo,
537 const Standard_Boolean isClosed,
538 const Standard_Boolean mode3d)
540 if ( ! mode3d && myFace.IsNull() ) {
541 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
542 return Standard_False;
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);
552 TopoDS_Vertex V1 = EA.FirstVertex (E);
553 TopoDS_Vertex V2 = EA.LastVertex (E);
554 if (V1.IsNull() || V2.IsNull())
556 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
557 return Standard_False;
559 gp_Pnt p1 = BRep_Tool::Pnt (V1);
560 gp_Pnt p2 = BRep_Tool::Pnt (V2);
561 sawo.Add (p1.XYZ(),p2.XYZ());
565 Handle(Geom2d_Curve) c2d;
566 TopoDS_Shape tmpF = myFace.Oriented(TopAbs_FORWARD);
567 if ( ! EA.PCurve(E,TopoDS::Face(tmpF),c2d,f,l) ) {
568 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
569 return Standard_False;
571 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
574 sawo.Perform(isClosed);
575 Standard_Integer stat = sawo.Status();
577 case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); break;
578 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break;
579 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
580 case -1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
581 case -2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
582 case -10: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); break;
584 return LastCheckStatus (ShapeExtend_DONE);
587 //=======================================================================
588 //function : CheckConnected
590 //=======================================================================
592 Standard_Boolean ShapeAnalysis_Wire::CheckConnected (const Standard_Integer num,
593 const Standard_Real prec)
595 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
596 if ( ! IsLoaded() || NbEdges() < 1 ) return Standard_False;
598 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
599 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
600 // if (n1 == n2) return 0;
602 TopoDS_Edge E1 = WireData()->Edge ( n1 );
603 TopoDS_Edge E2 = WireData()->Edge ( n2 );
605 ShapeAnalysis_Edge sae;
606 TopoDS_Vertex V1 = sae.LastVertex (E1);
607 TopoDS_Vertex V2 = sae.FirstVertex (E2);
608 if (V1.IsNull() || V2.IsNull())
610 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
611 return Standard_False;
613 if (V1.IsSame(V2)) return Standard_False;
615 gp_Pnt p1 = BRep_Tool::Pnt (V1);
616 gp_Pnt p2 = BRep_Tool::Pnt (V2);
617 myMin3d = p1.Distance(p2);
618 if ( myMin3d <= gp::Resolution() ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
619 else if ( myMin3d <= myPrecision ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
620 else if ( myMin3d <= prec ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
622 // et en inversant la derniere edge ?
623 if ( n1 == n2 ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
625 V2 = sae.LastVertex (E2);
626 p2 = BRep_Tool::Pnt (V2);
627 Standard_Real dist = p1.Distance(p2);
628 if ( dist > myPrecision ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
631 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
634 return Standard_False;
636 return Standard_True;
639 //=======================================================================
640 //function : CheckSmall
642 //=======================================================================
644 Standard_Boolean ShapeAnalysis_Wire::CheckSmall (const Standard_Integer num,
645 const Standard_Real precsmall)
647 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
648 if ( ! IsLoaded() || NbEdges() <= 1 ) return Standard_False;
650 //Standard_Integer n = ( num ? num : NbEdges() ); //szv#4:S4163:12Mar99 not needed
651 TopoDS_Edge E = myWire->Edge ( num ? num : NbEdges() );
652 ShapeAnalysis_Edge sae;
654 if ( BRep_Tool::Degenerated ( E ) ) {
655 //:n2 abv 22 Jan 99: ma-test5.igs -> IGES (brep) -> read (pref3d):
656 // degen edge with no pcurve should be removed
657 if ( ! myFace.IsNull() && sae.HasPCurve ( E, Face() ) ) return Standard_False;
658 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
661 TopoDS_Vertex V1 = sae.FirstVertex (E);
662 TopoDS_Vertex V2 = sae.LastVertex (E);
663 gp_Pnt p1 = BRep_Tool::Pnt (V1);
664 gp_Pnt p2 = BRep_Tool::Pnt (V2);
665 Standard_Real dist = p1.Distance(p2);
666 Standard_Real prec = precsmall;//Min ( myPrecision, precsmall );
667 //Standard_Real prec = Min(BRep_Tool::Tolerance(V1),BRep_Tool::Tolerance(V2)); //skl
668 if (dist > prec) return Standard_False; // pas nulle
670 // La courbe 3D a present : est-elle FERMEE ou DE LONGUEUR NULLE ... ???
671 // Pour cela on prend le point milieu (y a-t-il mieux)
672 // Si pas de C3D, on essaie la C2D ...
676 Handle(Geom_Curve) c3d;
677 if ( sae.Curve3d (E,c3d,cf,cl,Standard_False) ) Pm = c3d->Value ( (cf+cl)/2. );
679 Handle(Geom2d_Curve) c2d;
680 if ( ! myFace.IsNull() && sae.PCurve (E,myFace,c2d,cf,cl,Standard_False)) {
681 gp_Pnt2d p2m = c2d->Value ( (cf+cl)/2. );
682 Pm = mySurf->Value (p2m);
685 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
687 //:n2 return Standard_False;
690 if ( Pm.Distance(p1) > prec || Pm.Distance(p2) > prec ) return Standard_False;
692 myStatus |= ShapeExtend::EncodeStatus ( V1.IsSame(V2) ? ShapeExtend_DONE1 : ShapeExtend_DONE2 );
693 return Standard_True;
696 //=======================================================================
697 //function : CheckSeam
699 //=======================================================================
701 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num,
702 Handle(Geom2d_Curve)& C1,
703 Handle(Geom2d_Curve)& C2,
707 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
708 if (!IsReady()) return Standard_False;
709 Standard_Integer n = num; if (n == 0) n = NbEdges();
710 TopoDS_Edge E = myWire->Edge (n);
711 if ( ! ShapeAnalysis_Edge().IsSeam ( E, myFace ) ) return Standard_False;
712 // Extract the Two PCurves of the Seam
713 TopoDS_Face ForwardFace = myFace; ForwardFace.Orientation (TopAbs_FORWARD);
714 //szv#4:S4163:12Mar99 SGI warns
715 TopoDS_Shape EF = E.Oriented(TopAbs_FORWARD);
716 TopoDS_Shape ER = E.Oriented(TopAbs_REVERSED);
717 C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(EF), ForwardFace, cf, cl);
718 C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(ER), ForwardFace, cf, cl);
719 if (C1.IsNull() || C2.IsNull()) return Standard_False;
721 // SelectForward est destine a devenir un outil distinct
723 Standard_Integer theCurveIndice = ShapeAnalysis_Curve().SelectForwardSeam (C1,C2);
724 if ( theCurveIndice != 2 ) return Standard_False;
726 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
727 return Standard_True;
730 //=======================================================================
731 //function : CheckSeam
733 //=======================================================================
735 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num)
737 Handle(Geom2d_Curve) C1, C2;
738 Standard_Real cf, cl;
739 return CheckSeam (num, C1, C2, cf, cl);
742 //=======================================================================
743 //function : CheckDegenerated
745 //=======================================================================
747 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num,
748 gp_Pnt2d& p2d1, gp_Pnt2d& p2d2)
750 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
751 if ( ! IsReady() || NbEdges() < 1 ) return Standard_False;
753 Standard_Integer n2 = (num > 0)? num : NbEdges();
754 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
755 Standard_Integer n3 = (n2 < NbEdges())? n2+1 : 1;
756 TopoDS_Edge E1 = myWire->Edge ( n1 );
757 TopoDS_Edge E2 = myWire->Edge ( n2 );
758 TopoDS_Edge E3 = myWire->Edge ( n3 );
760 ShapeAnalysis_Edge sae;
762 // skip if edge is already marked as degenerated and has pcurve
763 if ( BRep_Tool::Degenerated ( E2 ) && sae.HasPCurve ( E2, Face() ) ) {
764 // skl 30.12.2004 for OCC7630 - we have to check pcurve
765 if( sae.HasPCurve(E1,Face()) && sae.HasPCurve(E3,Face()) ) {
766 Handle(Geom2d_Curve) c2d;
768 sae.PCurve ( E2, myFace, c2d, fp, lp, Standard_True );
769 gp_Pnt2d p21 = c2d->Value(fp);
770 gp_Pnt2d p22 = c2d->Value(lp);
771 sae.PCurve ( E1, myFace, c2d, fp, lp, Standard_True );
772 gp_Pnt2d p12 = c2d->Value(lp);
773 sae.PCurve ( E3, myFace, c2d, fp, lp, Standard_True );
774 gp_Pnt2d p31 = c2d->Value(fp);
775 if( fabs(p12.Distance(p31)-p21.Distance(p22)) > 2*Precision::PConfusion() ) {
776 // pcurve is bad => we can remove this edge in ShapeFix
777 // if set needed status
778 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
781 return Standard_False;
784 //pdn allows to insert two sequences of degenerated edges (on separate bounds of surfaces)
785 if ( n1 != n2 && BRep_Tool::Degenerated ( E1 ) &&
786 ! sae.HasPCurve ( E1, Face() ) ) {
787 //:abv 13.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
788 if ( BRep_Tool::Degenerated ( E2 ) )
789 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
790 return Standard_False;
792 //:i8 if ( BRep_Tool::Degenerated ( E1 ) ||
793 //:i8 BRep_Tool::Degenerated ( E2 ) ) return Standard_False; // deja OK
795 TopoDS_Vertex Vp = sae.FirstVertex (E1); //:i9
796 TopoDS_Vertex V0 = sae.LastVertex (E1);
797 TopoDS_Vertex V1 = sae.FirstVertex (E2);
798 TopoDS_Vertex V2 = sae.LastVertex (E2);
799 gp_Pnt pp = BRep_Tool::Pnt (Vp); //:i9
800 gp_Pnt p0 = BRep_Tool::Pnt (V0);
801 gp_Pnt p1 = BRep_Tool::Pnt (V1);
802 gp_Pnt p2 = BRep_Tool::Pnt (V2);
803 Standard_Real par1, par2;
804 Standard_Boolean lack = Standard_False;
805 Standard_Boolean dgnr = Standard_False;
806 //pdn 12.03.99 minimal value processing first
807 Standard_Real precFirst = Min(myPrecision,BRep_Tool::Tolerance(V1));
808 Standard_Real precFin = Max(myPrecision,BRep_Tool::Tolerance(V1));
809 Standard_Real precVtx = (myPrecision<BRep_Tool::Tolerance(V1) ? 2*precFin : precFin);
810 // forward : si Edge <num> FWD/REV. Si LACK, toujours True
811 Standard_Boolean forward = ( E2.Orientation() == TopAbs_FORWARD );
812 // FIX FEV 1998 : recompute singularity according precision
814 if (p1.Distance(p2) <= precFirst) { // edge DGNR
815 dgnr = mySurf->DegeneratedValues ( p1, precVtx, p2d1, p2d2, par1, par2, forward ); //smh#9
816 if ( dgnr ) { // abv 24 Feb 00: trj3_as1-ac-214.stp #6065: avoid making closed edge degenerated
818 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E2, a, b );
819 if ( ! C3d.IsNull() ) {
820 gp_Pnt p = C3d->Value ( 0.5 * ( a + b ) );
821 if ( p.SquareDistance ( p1 ) > precVtx * precVtx ) dgnr = Standard_False;
826 //:i9 abv 23 Sep 98: CTS20315-2 #63231: check that previous edge is not degenerated
827 if ( n1 != n2 && p1.Distance(pp) <= precFirst &&
828 mySurf->IsDegenerated ( pp, precFirst ) &&
829 ! BRep_Tool::Degenerated ( E1 ) ) return Standard_False;
830 //rln S4135 ShapeAnalysis_Surface new algorithms for singularities
831 //:45 by abv 16 Dec 97: BUC60035 2659: precision increased to vertex tolerance
832 //Standard_Real prec = Max ( myPrecision, BRep_Tool::Tolerance(V1) );
833 //:51 abv 22 Dec 97: recompute singularities if necessary
834 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( 2 * prec ); //:51 //:74 abv 15 Jan 97: *2
836 if ( p0.Distance ( p1 ) <= precFin ) {// ou DGNR manquante ?
837 //rln S4135 singularity with precision = 2 * prec, but distance <= prec
838 //lack = mySurf->DegeneratedValues ( p1, prec, p2d1, p2d2, par1, par2, forward);
839 Standard_Real tmpPreci;
841 Standard_Boolean tmpUIsoDeg;
842 //#77 rln S4135: using singularity which has minimum gap between singular point and input 3D point
843 Standard_Integer indMin = -1;
844 Standard_Real gapMin2 = RealLast();
845 for (Standard_Integer i = 1; i <= mySurf->NbSingularities (precVtx); i++) {
846 mySurf->Singularity (i, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
847 Standard_Real gap2 = p1.SquareDistance (tmpP3d);
848 if (gap2 <= precVtx * precVtx)
849 if (gapMin2 > gap2) {
855 mySurf->Singularity (indMin, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
856 lack = Standard_True;
860 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( myPrecision ); //:51
863 // voila, on a soit dgnr soit lack
864 if ( ! lack && ! dgnr ) {
865 //:abv 29.08.01: if singularity not detected but edge is marked
866 // as degenerated, report fail
867 if ( BRep_Tool::Degenerated ( E2 ) && ! sae.HasPCurve ( E2, Face() ) )
868 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
869 return Standard_False;
872 // OK, degenerated case detected; we will find its start and end in 2d
874 if ( lack ) forward = Standard_True;
876 //:24 by abv 28 Nov 97:
877 // make degenerative pcurve parametrized exactly from end of pcurve of the
878 // previous edge to the start of the next one
879 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
881 Handle(Geom2d_Curve) c2d;
882 if ( sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
883 p2d1 = c2d->Value ( b );
884 //#84 rln gp_Pnt2d p2d = c2d->Value ( b );
885 //#84 rln par1 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
887 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
888 //pdn pcurves (fixing regression in f0 in degenerated case)
889 if ( sae.PCurve ( ( dgnr ? E3 : E2 ), myFace, c2d, a, b, Standard_True ) ) {
890 p2d2 = c2d->Value ( a );
891 //#84 rln gp_Pnt2d p2d = c2d->Value ( a );
892 //#84 rln par2 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
894 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
904 //#84 rln 18.03.99 if pcurve is not degenerate anymore, the fix is postponned
905 //to ShapeFix_Wire::FixLacking
906 if ( ! mySurf->IsDegenerated ( p2d1, p2d2, precVtx, 10. ) ) { //:s1 abv 22 Apr 99: PRO7226 #489490 //smh#9
907 //:abv 24.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
908 if ( BRep_Tool::Degenerated ( E2 ) )
909 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
910 return Standard_False;
913 //added by rln 18/12/97 CSR# CTS18544 entity 13638
914 //the situation when degenerated edge already exists but flag is not set
915 //(i.e. the parametric space is closed)
916 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
917 Standard_Real max = Max ( Ads.UResolution(myPrecision),
918 Ads.VResolution(myPrecision) );
919 if ( p2d1.Distance (p2d2) /*Abs (par1 - par2)*/ <= max + gp::Resolution() ) return Standard_False;
921 //#84 rln p2d1 = aP2d.XY() + par1 * theDir2d.XY();
922 //#84 rln p2d2 = aP2d.XY() + par2 * theDir2d.XY();
923 myStatus = ShapeExtend::EncodeStatus ( dgnr ? ShapeExtend_DONE2 : ShapeExtend_DONE1 );
924 return Standard_True;
927 //=======================================================================
928 //function : CheckDegenerated
930 //=======================================================================
932 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num)
935 return CheckDegenerated ( num, p2d1, p2d2 );
938 //=======================================================================
939 //function : CheckGap3d
941 //=======================================================================
943 Standard_Boolean ShapeAnalysis_Wire::CheckGap3d(const Standard_Integer num)
945 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
946 //szv#4:S4163:12Mar99 optimized
947 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
948 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
949 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
950 TopoDS_Edge E1 = myWire->Edge(n1);
951 TopoDS_Edge E2 = myWire->Edge(n2);
952 Standard_Real uf1,ul1,uf2,ul2;
953 Handle(Geom_Curve) C1,C2;
954 ShapeAnalysis_Edge SAE;
955 if (!SAE.Curve3d (E1,C1,uf1,ul1) || !SAE.Curve3d (E2,C2,uf2,ul2)) {
956 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
957 return Standard_False;
959 gp_Pnt p1 = C1->Value (ul1);
960 gp_Pnt p2 = C2->Value (uf2);
961 myMin3d = myMax3d = p1.Distance (p2);
962 if (myMin3d > myPrecision)
963 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
964 return LastCheckStatus (ShapeExtend_DONE);
967 //=======================================================================
968 //function : CheckGap2d
970 //=======================================================================
972 Standard_Boolean ShapeAnalysis_Wire::CheckGap2d(const Standard_Integer num)
974 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
975 //szv#4:S4163:12Mar99 optimized
976 if ( !IsReady() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
977 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
978 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
979 TopoDS_Edge E1 = myWire->Edge(n1);
980 TopoDS_Edge E2 = myWire->Edge(n2);
981 Standard_Real uf1,ul1,uf2,ul2;
982 Handle(Geom2d_Curve) C1,C2;
983 ShapeAnalysis_Edge SAE;
984 if (!SAE.PCurve (E1,myFace,C1,uf1,ul1) || !SAE.PCurve (E2,myFace,C2,uf2,ul2)) {
985 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
986 return Standard_False;
988 gp_Pnt2d p1 = C1->Value (ul1);
989 gp_Pnt2d p2 = C2->Value (uf2);
990 myMin2d = myMax2d = p1.Distance (p2);
991 GeomAdaptor_Surface& SA = mySurf->Adaptor3d()->ChangeSurface();
992 if (myMin2d > (Max (SA.UResolution (myPrecision), SA.VResolution (myPrecision)) + Precision::PConfusion()))
993 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
994 return LastCheckStatus (ShapeExtend_DONE);
997 //=======================================================================
998 //function : CheckCurveGap
1000 //=======================================================================
1002 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGap(const Standard_Integer num)
1004 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1005 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False;
1006 Standard_Integer n = ( num >0 ? num : NbEdges() );
1007 TopoDS_Edge E = myWire->Edge(n);
1008 Standard_Real cuf,cul,pcuf,pcul;
1009 Handle(Geom_Curve) c;
1010 ShapeAnalysis_Edge SAE;
1011 if (!SAE.Curve3d (E,c,cuf,cul,Standard_False)) {
1012 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1013 return Standard_False;
1015 Handle(Geom2d_Curve) pc;
1016 if (!SAE.PCurve (E,myFace,pc,pcuf,pcul,Standard_False)) {
1017 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1018 return Standard_False;
1020 Handle(Geom2dAdaptor_HCurve) AC = new Geom2dAdaptor_HCurve(pc,pcuf,pcul);
1021 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(mySurf->Surface());
1022 Adaptor3d_CurveOnSurface ACS(AC,AS);
1024 Standard_Integer nbp = 45;
1025 Standard_Real dist, maxdist=0.;
1026 for (Standard_Integer i=0; i<nbp; i++) {
1027 cpnt = c->Value(cuf + i*(cul-cuf)/(nbp-1));
1028 pcpnt = ACS.Value(pcuf + i*(pcul-pcuf)/(nbp-1));
1029 dist = cpnt.SquareDistance(pcpnt);
1030 if (maxdist<dist) maxdist = dist;
1032 myMin3d = myMax3d = Sqrt(maxdist);
1033 if (myMin3d > myPrecision)
1034 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1035 return LastCheckStatus (ShapeExtend_DONE);
1038 //=======================================================================
1039 //function : CheckSelfIntersectingEdge
1041 //=======================================================================
1043 // auxiliary function
1044 //:h0 abv 29 May 98: PRO10105 1949: like in BRepCheck, point is to be taken
1045 // from 3d curve (but only if edge is SameParameter)
1046 static gp_Pnt GetPointOnEdge ( const TopoDS_Edge &edge,
1047 const Handle(ShapeAnalysis_Surface) &surf,
1048 const Handle(Geom2d_Curve) &Crv2d,
1049 const Standard_Real param )
1051 if ( BRep_Tool::SameParameter ( edge ) ) {
1054 const Handle(Geom_Curve) ConS = BRep_Tool::Curve ( edge, L, f, l );
1055 if ( ! ConS.IsNull() )
1056 return ConS->Value ( param ).Transformed ( L.Transformation() );
1058 return surf->Value ( Crv2d->Value ( param ) );
1061 //=======================================================================
1062 //function : CheckSelfIntersectingEdge
1064 //=======================================================================
1066 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num,
1067 IntRes2d_SequenceOfIntersectionPoint& points2d,
1068 TColgp_SequenceOfPnt& points3d)
1072 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1073 if ( ! IsReady() ) return Standard_False;
1075 TopoDS_Edge edge = WireData()->Edge ( num >0 ? num : NbEdges() );
1076 ShapeAnalysis_Edge sae;
1079 Handle(Geom2d_Curve) Crv;
1080 if ( ! sae.PCurve ( edge, myFace, Crv, a, b, Standard_False ) ) {
1081 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1082 return Standard_False;
1084 if ( Abs ( a - b ) <= ::Precision::PConfusion() ) return Standard_False;
1086 Standard_Real tolint = 1.0e-10;
1087 //szv#4:S4163:12Mar99 warning
1088 IntRes2d_Domain domain ( Crv->Value ( a ), a, tolint, Crv->Value ( b ), b, tolint );
1089 Geom2dAdaptor_Curve AC ( Crv );
1090 Geom2dInt_GInter Inter ( AC, domain, tolint, tolint );
1092 if ( ! Inter.IsDone() ) return Standard_False;
1094 TopoDS_Vertex V1 = sae.FirstVertex ( edge );
1095 TopoDS_Vertex V2 = sae.LastVertex ( edge );
1096 if ( V1.IsNull() || V2.IsNull() ) {
1097 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1098 return Standard_False;
1100 Standard_Real tol1 = BRep_Tool::Tolerance ( V1 );
1101 Standard_Real tol2 = BRep_Tool::Tolerance ( V2 );
1103 gp_Pnt pnt1 = BRep_Tool::Pnt ( V1 );
1104 gp_Pnt pnt2 = BRep_Tool::Pnt ( V2 );
1106 for ( Standard_Integer i=1; i <= Inter.NbPoints(); i++ ) {
1107 const IntRes2d_IntersectionPoint &IP = Inter.Point ( i );
1108 const IntRes2d_Transition &Tr1 = IP.TransitionOfFirst();
1109 const IntRes2d_Transition &Tr2 = IP.TransitionOfSecond();
1110 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1111 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1112 gp_Pnt pint = GetPointOnEdge ( edge, mySurf, Crv, IP.ParamOnFirst() );
1113 Standard_Real dist21 = pnt1.SquareDistance ( pint );
1114 Standard_Real dist22 = pnt2.SquareDistance ( pint );
1115 if ( dist21 > tol1 * tol1 && dist22 > tol2 * tol2 ) {
1116 points2d.Append ( IP );
1117 points3d.Append ( pint );
1118 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1122 return LastCheckStatus ( ShapeExtend_DONE );
1125 //=======================================================================
1126 //function : CheckSelfIntersectingEdge
1128 //=======================================================================
1130 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num)
1132 IntRes2d_SequenceOfIntersectionPoint points2d;
1133 TColgp_SequenceOfPnt points3d;
1134 return CheckSelfIntersectingEdge ( num, points2d, points3d );
1137 //=======================================================================
1138 //function : CheckIntersectingEdges
1139 //purpose : Test if two consequent edges are intersecting
1140 // It is made in accordance with the following check in BRepCheck:
1141 // - in BRepCheck_Wire::Orientation(), test for self-intersection
1142 //=======================================================================
1144 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num,
1145 IntRes2d_SequenceOfIntersectionPoint& points2d,
1146 TColgp_SequenceOfPnt& points3d,
1147 TColStd_SequenceOfReal& errors)
1152 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1153 if ( ! IsReady() || NbEdges() <2 ) return Standard_False;
1155 //szv#4:S4163:12Mar99 optimized
1156 Standard_Integer n2 = (num > 0)? num : NbEdges();
1157 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1158 TopoDS_Edge edge1 = myWire->Edge ( n1 );
1159 TopoDS_Edge edge2 = myWire->Edge ( n2 );
1161 ShapeAnalysis_Edge sae;
1162 TopoDS_Vertex V1 = sae.LastVertex ( edge1 );
1163 TopoDS_Vertex V2 = sae.FirstVertex ( edge2 );
1164 if ( V1.IsNull() || V2.IsNull() ) {
1165 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1166 return Standard_False;
1168 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1169 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1170 return Standard_False;
1173 TopoDS_Vertex Vp = sae.FirstVertex ( edge1 );
1174 TopoDS_Vertex Vn = sae.LastVertex ( edge2 );
1176 Standard_Real a1, b1, a2, b2;
1177 Handle(Geom2d_Curve) Crv1, Crv2;
1178 if ( ! sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False ) ) {
1179 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1180 return Standard_False;
1182 if ( ! sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False ) ) {
1183 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1184 return Standard_False;
1186 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1187 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False; //:f7 abv 6 May 98: BUC50070 on #42276
1189 Standard_Boolean isForward1 = ( edge1.Orientation() == TopAbs_FORWARD );
1190 Standard_Boolean isForward2 = ( edge2.Orientation() == TopAbs_FORWARD );
1192 Standard_Real tol0 = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1193 Standard_Real tol = tol0;
1195 gp_Pnt pnt = BRep_Tool::Pnt ( V1 );
1197 // Standard_Boolean Status = Standard_False;
1199 Standard_Real tolint = 1.0e-10;
1201 //szv#4:S4163:12Mar99 warning
1202 IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint,
1203 Crv1->Value ( b1 ), b1, tolint );
1204 IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint,
1205 Crv2->Value ( b2 ), b2, tolint );
1206 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
1208 //:64 abv 25 Dec 97: Attention!
1209 // Since Intersection algorithm is not symmetrical, for consistency with BRepCheck
1210 // edge with lower order number shoud be intersecting with edge with higher one
1211 // i.e., for intersection of last and first edges, they should go in reversed order
1212 // Example: entity #38285 from bug CSR #CTS17806
1213 // NOTE: Tr1 and Tr2 are not reordered because they are used in the same manner
1214 Geom2dInt_GInter Inter;
1215 if ( num ==1 ) Inter.Perform ( C2, d2, C1, d1, tolint, tolint );
1216 else Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1217 if ( ! Inter.IsDone() ) return Standard_False;
1219 //:86 abv 22 Jan 98: fix self-intersection even if tolerance of vertex is enough
1220 // to annihilate it. This is done to prevent wrong effects if vertex tolerance
1221 // will be decreased (e.g., in FixLacking)
1222 Standard_Real tole = Max ( ( BRep_Tool::SameParameter ( edge1 ) ?
1223 BRep_Tool::Tolerance ( edge1 ) : tol0 ),
1224 ( BRep_Tool::SameParameter ( edge2 ) ?
1225 BRep_Tool::Tolerance ( edge2 ) : tol0 ) );
1226 Standard_Real tolt = Min ( tol, Max ( tole, myPrecision ) );
1227 //Standard_Real prevRange1 = RealLast(), prevRange2 = RealLast(); //SK
1228 Standard_Integer isLacking = -1; //:l0 abv: CATIA01 #1727: protect against adding lacking
1229 //#83 rln 19.03.99 sim2.igs, entity 4292
1230 //processing also segments as in BRepCheck
1231 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1232 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1233 IntRes2d_IntersectionPoint IP;
1234 IntRes2d_Transition Tr1, Tr2;
1236 IP = Inter.Point ( i );
1238 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1239 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1240 IP = Seg.FirstPoint();
1241 Tr1 = IP.TransitionOfFirst();
1242 Tr2 = IP.TransitionOfSecond();
1243 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1244 IP = Seg.LastPoint();
1246 Tr1 = IP.TransitionOfFirst();
1247 Tr2 = IP.TransitionOfSecond();
1249 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1250 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1251 Standard_Real param1, param2;
1252 param1 = ( num ==1 ? IP.ParamOnSecond() : IP.ParamOnFirst() );
1253 param2 = ( num ==1 ? IP.ParamOnFirst() : IP.ParamOnSecond() );
1255 //:r6 abv 8 Apr 99: r_47-sd.stp #173850: protect against working out of curve range
1256 if ( a1-param1 > ::Precision::PConfusion() ||
1257 param1-b1 > ::Precision::PConfusion() ||
1258 a2-param2 > ::Precision::PConfusion() ||
1259 param2-b2 > ::Precision::PConfusion() ) continue;
1261 //:82 abv 21 Jan 98: point of intersection on Crv1 and Crv2 is different
1262 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, Crv1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1263 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, Crv2, param2 ); //:h0: thesurf.Value ( Crv2->Value ( param2 ) );
1264 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1265 Standard_Real di1 = pi1.SquareDistance ( pnt );
1266 Standard_Real di2 = pi2.SquareDistance ( pnt );
1267 Standard_Real dist2 = Max ( di1, di2 );
1269 //rln 03/02/98: CSR#BUC50004 entity 56 (to avoid later inserting lacking edge)
1270 if ( isLacking <0 ) { //:l0
1271 gp_Pnt2d end1 = Crv1->Value ( isForward1 ? b1 : a1 );
1272 gp_Pnt2d end2 = Crv2->Value ( isForward2 ? a2 : b2 );
1273 //:l0 Standard_Real distab2 = mySurf->Value ( end1 ).SquareDistance ( mySurf->Value ( end2 ) );
1274 //:l0: test like in BRepCheck
1275 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1276 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1277 isLacking = ( end1.SquareDistance(end2) >= tol2d * tol2d );
1280 if ( ( dist2 > tolt * tolt || //:86: tol -> tolt
1281 isLacking ) && //:l0
1282 //:l0 distab2 > BRep_Tool::Tolerance ( edge1 ) + BRep_Tool::Tolerance ( edge2 ) ) && //rln
1283 ( ! BRepTools::Compare ( Vp, Vn ) || //:63
1284 dist2 < pint.SquareDistance ( BRep_Tool::Pnt ( Vp ) ) ) ) { //:63
1285 points2d.Append ( IP );
1286 points3d.Append ( pint );
1287 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1288 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1292 return LastCheckStatus ( ShapeExtend_DONE );
1295 //=======================================================================
1296 //function : CheckIntersectingEdges
1298 //=======================================================================
1300 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num)
1302 IntRes2d_SequenceOfIntersectionPoint points2d;
1303 TColgp_SequenceOfPnt points3d;
1304 TColStd_SequenceOfReal errors;
1305 return CheckIntersectingEdges ( num, points2d, points3d, errors );
1308 //=======================================================================
1309 //function : CheckIntersectingEdges
1311 //=======================================================================
1313 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges(const Standard_Integer num1,
1314 const Standard_Integer num2,
1315 IntRes2d_SequenceOfIntersectionPoint& points2d,
1316 TColgp_SequenceOfPnt& points3d,
1317 TColStd_SequenceOfReal& errors)
1319 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1320 if ( ! IsReady() ) return Standard_False;
1321 Handle(ShapeExtend_WireData) sbwd = WireData();
1322 Standard_Integer n2 = ( num2 >0 ? num2 : sbwd->NbEdges() );
1323 Standard_Integer n1 = ( num1 >0 ? num1 : sbwd->NbEdges() );
1325 TopoDS_Edge edge1 = sbwd->Edge ( n1 );
1326 TopoDS_Edge edge2 = sbwd->Edge ( n2 );
1328 ShapeAnalysis_Edge sae;
1329 Standard_Real a1, b1, a2, b2;
1330 Handle(Geom2d_Curve) Crv1, Crv2;
1331 if(!sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False )){
1332 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1333 return Standard_False;
1336 if(!sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False )){
1337 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1338 return Standard_False;
1341 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1342 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False;
1347 TColgp_Array1OfPnt vertexPoints(1,4);
1348 TColStd_Array1OfReal vertexTolers(1,4);
1349 vertexPoints(1) = BRep_Tool::Pnt(sae.FirstVertex(edge1));
1350 vertexTolers(1) = BRep_Tool::Tolerance(sae.FirstVertex(edge1));
1351 vertexPoints(2) = BRep_Tool::Pnt(sae.LastVertex(edge1));
1352 vertexTolers(2) = BRep_Tool::Tolerance(sae.LastVertex(edge1));
1353 vertexPoints(3) = BRep_Tool::Pnt(sae.FirstVertex(edge2));
1354 vertexTolers(3) = BRep_Tool::Tolerance(sae.FirstVertex(edge2));
1355 vertexPoints(4) = BRep_Tool::Pnt(sae.LastVertex(edge2));
1356 vertexTolers(4) = BRep_Tool::Tolerance(sae.LastVertex(edge2));
1358 Standard_Real tolint = 1.0e-10;
1360 IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint,
1361 Crv1->Value ( b1 ), b1, tolint );
1362 IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint,
1363 Crv2->Value ( b2 ), b2, tolint );
1364 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
1366 Geom2dInt_GInter Inter;
1367 Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1368 if ( ! Inter.IsDone() ) return Standard_False;
1370 //#83 rln 19.03.99 sim2.igs, entity 4292
1371 //processing also segments as in BRepCheck
1372 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1373 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1374 IntRes2d_IntersectionPoint IP;
1375 IntRes2d_Transition Tr1, Tr2;
1377 IP = Inter.Point ( i );
1379 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1380 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1381 IP = Seg.FirstPoint();
1382 Tr1 = IP.TransitionOfFirst();
1383 Tr2 = IP.TransitionOfSecond();
1384 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1385 IP = Seg.LastPoint();
1387 Tr1 = IP.TransitionOfFirst();
1388 Tr2 = IP.TransitionOfSecond();
1389 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1390 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1391 Standard_Real param1 = IP.ParamOnFirst();
1392 Standard_Real param2 = IP.ParamOnSecond();
1393 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, Crv1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1394 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, Crv2, param2 );
1395 Standard_Boolean OK = Standard_False;
1396 for(Standard_Integer j=1; (j<=4)&&!OK; j++) {
1397 Standard_Real di1 = pi1.SquareDistance (vertexPoints(j));
1398 Standard_Real di2 = pi2.SquareDistance (vertexPoints(j));
1399 Standard_Real dist2 = Max ( di1, di2 );
1400 if(dist2 < vertexTolers(j) * vertexTolers(j))
1404 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1405 points2d.Append ( IP );
1406 points3d.Append ( pint );
1407 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1408 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1411 return LastCheckStatus ( ShapeExtend_DONE );
1414 //=======================================================================
1415 //function : CheckIntersectingEdges
1417 //=======================================================================
1419 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num1,
1420 const Standard_Integer num2)
1422 IntRes2d_SequenceOfIntersectionPoint points2d;
1423 TColgp_SequenceOfPnt points3d;
1424 TColStd_SequenceOfReal errors;
1425 return CheckIntersectingEdges(num1, num2, points2d, points3d, errors);
1428 //=======================================================================
1429 //function : CheckLacking
1430 //purpose : Test if two edges are disconnected in 2d according to the
1431 // Adaptor_Surface::Resolution
1432 //=======================================================================
1434 Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1435 const Standard_Real Tolerance,
1436 gp_Pnt2d &p2d1, gp_Pnt2d &p2d2)
1438 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1439 if ( ! IsReady() ) return Standard_False;
1441 //szv#4:S4163:12Mar99 optimized
1442 Standard_Integer n2 = (num > 0)? num : NbEdges();
1443 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1444 TopoDS_Edge E1 = myWire->Edge ( n1 );
1445 TopoDS_Edge E2 = myWire->Edge ( n2 );
1447 ShapeAnalysis_Edge sae;
1448 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1449 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1450 // CKY 4 MAR 1998 : protection against null vertex
1451 if ( V1.IsNull() || V2.IsNull() ) {
1452 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1453 return Standard_False;
1455 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1456 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1457 return Standard_False;
1461 gp_Vec2d v1, v2, v12;
1462 Handle(Geom2d_Curve) c2d;
1463 if ( ! sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
1464 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1465 return Standard_False;
1467 c2d->D1 ( b, p2d1, v1 );
1468 if ( E1.Orientation() == TopAbs_REVERSED ) v1.Reverse();
1469 if ( ! sae.PCurve ( E2, myFace, c2d, a, b, Standard_True ) ) {
1470 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1471 return Standard_False;
1473 c2d->D1 ( a, p2d2, v2 );
1474 if ( E2.Orientation() == TopAbs_REVERSED ) v2.Reverse();
1475 v12 = p2d2.XY() - p2d1.XY();
1476 myMax2d = v12.SquareMagnitude();
1478 // test like in BRepCheck
1479 Standard_Real tol = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1480 tol = ( Tolerance > gp::Resolution() && Tolerance < tol ? Tolerance : tol );
1481 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1482 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1483 if ( // tol2d < gp::Resolution() || //#2 smh 26.03.99 S4163 Zero divide
1484 myMax2d < tol2d * tol2d ) return Standard_False;
1486 myMax2d = Sqrt ( myMax2d );
1487 myMax3d = tol * myMax2d / Max ( tol2d, gp::Resolution() );
1488 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
1490 if ( myMax2d < Precision::PConfusion() || //:abv 03.06.02 CTS21866.stp
1491 ( v1.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v1 ) ) > 0.9 * M_PI ) ||
1492 ( v2.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v2 ) ) > 0.9 * M_PI ) )
1493 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
1494 return Standard_True;
1497 //=======================================================================
1498 //function : CheckLacking
1501 //=======================================================================
1503 Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1504 const Standard_Real Tolerance)
1507 return CheckLacking (num, Tolerance, p1, p2);
1510 //=======================================================================
1511 //function : CheckOuterBound
1513 //=======================================================================
1515 Standard_Boolean ShapeAnalysis_Wire::CheckOuterBound(const Standard_Boolean APIMake)
1517 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1518 if ( ! IsReady() ) return Standard_False;
1521 if (APIMake) wire = myWire->WireAPIMake();
1522 else wire = myWire->Wire();
1524 TopoDS_Shape sh = myFace.EmptyCopied(); //szv#4:S4163:12Mar99 SGI warns
1525 TopoDS_Face face = TopoDS::Face(sh);
1528 if (ShapeAnalysis::IsOuterBound (face)) return Standard_False;
1529 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1530 return Standard_True;
1533 //=======================================================================
1534 //function : CheckNotchedEdges
1536 //=======================================================================
1538 static Standard_Real ProjectInside(const Adaptor3d_CurveOnSurface AD,
1540 const Standard_Real preci,
1542 Standard_Real& param,
1543 const Standard_Boolean adjustToEnds = Standard_True)
1545 ShapeAnalysis_Curve sac;
1546 Standard_Real dist = sac.Project(AD,pnt,preci,proj,param,adjustToEnds);
1547 Standard_Real uFirst = AD.FirstParameter();
1548 Standard_Real uLast = AD.LastParameter();
1551 proj = AD.Value(uFirst);
1552 return proj.Distance(pnt);
1557 proj = AD.Value(uLast);
1558 return proj.Distance(pnt);
1563 Standard_Boolean ShapeAnalysis_Wire::CheckNotchedEdges(const Standard_Integer num,
1564 Standard_Integer& shortNum,
1565 Standard_Real& param,
1566 const Standard_Real Tolerance)
1568 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1569 if ( ! IsReady() ) return Standard_False;
1571 Standard_Integer n2 = (num > 0)? num : NbEdges();
1572 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1573 TopoDS_Edge E1 = myWire->Edge ( n1 );
1574 TopoDS_Edge E2 = myWire->Edge ( n2 );
1576 if(BRep_Tool::Degenerated(E1)||BRep_Tool::Degenerated(E2))
1577 return Standard_False;
1579 ShapeAnalysis_Edge sae;
1580 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1581 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1583 if ( V1.IsNull() || V2.IsNull() ) {
1584 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1585 return Standard_False;
1587 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1588 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1589 return Standard_False;
1592 Standard_Real a1, b1, a2, b2;
1593 gp_Pnt2d p2d1, p2d2;
1595 Handle(Geom2d_Curve) c2d1, c2d2;
1596 if ( ! sae.PCurve ( E1, myFace, c2d1, a1, b1, Standard_False ) ) {
1597 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1598 return Standard_False;
1601 if(E1.Orientation()==TopAbs_REVERSED)
1602 c2d1->D1 ( a1, p2d1, v1 );
1604 c2d1->D1 ( b1, p2d1, v1 );
1608 if ( ! sae.PCurve ( E2, myFace, c2d2, a2, b2, Standard_False ) ) {
1609 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1610 return Standard_False;
1612 if(E2.Orientation()==TopAbs_REVERSED) {
1613 c2d2->D1 ( b2, p2d2, v2 );
1617 c2d2->D1 ( a2, p2d2, v2 );
1619 if ( v2.Magnitude() < gp::Resolution() || v1.Magnitude() < gp::Resolution())
1620 return Standard_False;
1622 if ( Abs ( v2.Angle ( v1 ) ) > 0.1 || p2d1.Distance(p2d2) > Tolerance)
1623 return Standard_False;
1625 Handle(Geom2dAdaptor_HCurve) AC2d1 = new Geom2dAdaptor_HCurve(c2d1,a1,b1);
1626 Handle(GeomAdaptor_HSurface) AdS1 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1627 Adaptor3d_CurveOnSurface Ad1(AC2d1,AdS1);
1629 Handle(Geom2dAdaptor_HCurve) AC2d2 = new Geom2dAdaptor_HCurve(c2d2,a2,b2);
1630 Handle(GeomAdaptor_HSurface) AdS2 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1631 Adaptor3d_CurveOnSurface Ad2(AC2d2,AdS2);
1633 Adaptor3d_CurveOnSurface longAD, shortAD;
1634 Standard_Real lenP, firstP;
1636 ShapeAnalysis_Curve sac;
1638 gp_Pnt Proj1, Proj2;
1639 Standard_Real param1 = 0., param2 = 0.;
1640 p2d2=c2d2->Value(E2.Orientation()==TopAbs_FORWARD ? b2 : a2);
1641 p2d1=c2d1->Value(E1.Orientation()==TopAbs_FORWARD ? a1 : b1);
1642 Standard_Real dist1 = ProjectInside(Ad1,gp_Pnt(p2d2.X(),p2d2.Y(),0),Tolerance,Proj1,param1,Standard_False);
1643 Standard_Real dist2 = ProjectInside(Ad2,gp_Pnt(p2d1.X(),p2d1.Y(),0),Tolerance,Proj2,param2,Standard_False);
1645 if ( dist1 > Tolerance && dist2 > Tolerance)
1646 return Standard_False;
1648 if (dist1 < dist2 ) {
1666 Standard_Real step = lenP/23;
1667 for (Standard_Integer i = 1; i < 23; i++,firstP+=step) {
1668 Standard_Real d1 = sac.Project(longAD,shortAD.Value(firstP),Tolerance,Proj1,param1);
1669 if (d1 > Tolerance) {
1670 return Standard_False;
1674 return Standard_True;
1677 //=======================================================================
1678 //function : CheckSmallArea
1680 //=======================================================================
1682 Standard_Boolean ShapeAnalysis_Wire::CheckSmallArea(const Standard_Real prec2d)
1684 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1685 Standard_Integer NbEdges = myWire->NbEdges();
1686 if ( !IsReady() || NbEdges <1 ) return Standard_False;
1687 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1689 Standard_Integer NbControl=23;
1690 Standard_Real area=0;
1692 for (Standard_Integer nbe = 1; nbe <= NbEdges; nbe++) {
1693 Standard_Real First, Last;
1694 Handle(Geom2d_Curve) c2d;
1695 ShapeAnalysis_Edge sae;
1696 if (!sae.PCurve(myWire->Edge(nbe),myFace,c2d,First,Last)) {
1697 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1698 return Standard_False;
1701 Standard_Integer ibeg = 0;
1703 gp_Pnt2d pntIni = c2d->Value(First);
1708 for ( Standard_Integer i = ibeg; i < NbControl; i++) {
1709 Standard_Real prm = ((NbControl-1-i)*First + i*Last)/(NbControl-1);
1710 gp_Pnt2d pntCurr = c2d->Value(prm);
1711 gp_XY curr = pntCurr.XY();
1712 area += curr ^ prev;
1716 area += cont ^ prev;
1717 if ( Abs(area) < 2*prec2d*prec2d ) {
1718 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1719 return Standard_True;
1721 return Standard_False;
1724 //=======================================================================
1725 //function : CheckShapeConnect
1727 //=======================================================================
1729 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(const TopoDS_Shape& shape,const Standard_Real prec)
1731 Standard_Real tailhead, tailtail, headhead, headtail;
1732 return CheckShapeConnect (tailhead, tailtail, headtail, headhead, shape, prec);
1735 //=======================================================================
1736 //function : CheckShapeConnect
1738 //=======================================================================
1740 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(Standard_Real& tailhead, Standard_Real& tailtail,
1741 Standard_Real& headtail, Standard_Real& headhead,
1742 const TopoDS_Shape& shape, const Standard_Real prec)
1744 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1745 if (!IsLoaded () || shape.IsNull()) return Standard_False;
1746 TopoDS_Vertex V1,V2;
1747 TopoDS_Edge E; TopoDS_Wire W;
1748 ShapeAnalysis_Edge SAE;
1749 if (shape.ShapeType() == TopAbs_EDGE) {
1750 E = TopoDS::Edge (shape);
1751 V1 = SAE.FirstVertex (E); V2 = SAE.LastVertex (E);
1752 } else if (shape.ShapeType() == TopAbs_WIRE) {
1753 W = TopoDS::Wire (shape);
1754 ShapeAnalysis::FindBounds (W,V1,V2);
1756 else return Standard_False;
1757 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1758 // on va comparer les points avec ceux de thevfirst et thevlast
1759 gp_Pnt p1 = BRep_Tool::Pnt(V1);
1760 gp_Pnt p2 = BRep_Tool::Pnt(V2);
1762 TopoDS_Vertex vfirst = SAE.FirstVertex (myWire->Edge (1)),
1763 vlast = SAE.LastVertex (myWire->Edge (NbEdges()));
1764 gp_Pnt pf = BRep_Tool::Pnt(vfirst);
1765 gp_Pnt pl = BRep_Tool::Pnt(vlast);
1767 tailhead = p1.Distance(pl);
1768 tailtail = p2.Distance(pl);
1769 headhead = p1.Distance(pf);
1770 headtail = p2.Distance(pf);
1771 Standard_Real dm1 = tailhead, dm2 = headtail;
1772 Standard_Integer res1 = 0, res2 = 0;
1774 if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
1775 if (headtail > headhead) {res2 = 1; dm2 = headhead;}
1776 Standard_Integer result = res1;
1777 myMin3d = Min (dm1, dm2);
1778 myMax3d = Max (dm1, dm2);
1779 if (dm1 > dm2) {dm1 = dm2; result = res2 + 2;}
1781 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
1782 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
1783 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
1785 if (!res1) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
1786 if (!res2) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
1788 if (myMin3d > Max (myPrecision, prec))
1789 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1790 return LastCheckStatus (ShapeExtend_DONE);
1793 //=======================================================================
1794 //function : CheckLoop
1796 //=======================================================================
1797 Standard_Boolean isMultiVertex(const TopTools_ListOfShape& alshape,
1798 const TopTools_MapOfShape& aMapSmallEdges,
1799 const TopTools_MapOfShape& aMapSeemEdges)
1801 TopTools_ListIteratorOfListOfShape lIt1(alshape);
1802 Standard_Integer nbNotAccount =0;
1804 for( ; lIt1.More() ; lIt1.Next())
1806 if(aMapSmallEdges.Contains(lIt1.Value()))
1808 else if(aMapSeemEdges.Contains(lIt1.Value()))
1811 return ((alshape.Extent() -nbNotAccount) >2);
1813 Standard_Boolean ShapeAnalysis_Wire::CheckLoop(TopTools_IndexedMapOfShape& aMapLoopVertices,
1814 TopTools_DataMapOfShapeListOfShape& aMapVertexEdges,
1815 TopTools_MapOfShape& aMapSmallEdges,
1816 TopTools_MapOfShape& aMapSeemEdges)
1818 myStatus = ShapeExtend::EncodeStatus(ShapeExtend_OK);
1819 if (!IsLoaded() || NbEdges() < 2) return Standard_False;
1820 Standard_Real aSavPreci = Precision();
1821 SetPrecision(Precision::Infinite());
1822 Standard_Integer i =1;
1824 for( ; i <= myWire->NbEdges(); i++) {
1825 TopoDS_Edge aedge = myWire->Edge(i);
1826 TopoDS_Vertex aV1,aV2;
1827 TopExp::Vertices(aedge,aV1,aV2);
1828 Standard_Boolean isSame = aV1.IsSame(aV2);
1829 if(myWire->IsSeam(i))
1830 aMapSeemEdges.Add(aedge); ///continue;
1831 else if(BRep_Tool::Degenerated(aedge))
1832 aMapSmallEdges.Add(aedge);
1833 else if(isSame && CheckSmall(i,BRep_Tool::Tolerance(aV1)))
1834 aMapSmallEdges.Add(aedge);
1836 if(!aMapVertexEdges.IsBound(aV1)) {
1837 TopTools_ListOfShape alshape;
1838 aMapVertexEdges.Bind(aV1,alshape);
1840 if(!aMapVertexEdges.IsBound(aV2)) {
1841 TopTools_ListOfShape alshape;
1842 aMapVertexEdges.Bind(aV2,alshape);
1846 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1847 alshape.Append(aedge);
1848 alshape.Append(aedge);
1849 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1850 aMapLoopVertices.Add(aV1);
1853 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1854 alshape.Append(aedge);
1855 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1856 aMapLoopVertices.Add(aV1);
1857 TopTools_ListOfShape& alshape2 = aMapVertexEdges.ChangeFind(aV2);
1858 alshape2.Append(aedge);
1859 if(alshape2.Extent() >2 && isMultiVertex( alshape2,aMapSmallEdges,aMapSeemEdges))
1860 aMapLoopVertices.Add(aV2);
1863 SetPrecision(aSavPreci);
1864 if(aMapLoopVertices.Extent())
1866 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1867 myStatusLoop |= myStatus;
1868 return Standard_True;
1870 return Standard_False;