1 // Created on: 2000-01-20
2 // Created by: data exchange team
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //:pdn 11.12.98: FixDegenerated improved
17 //:pdn 05.01.99: renaming method CheckLittle to CheckSmall
18 //:l0 abv 10.01.99: CATIA01 #1727: fix intersecting edges always if edge is lacking
19 //:n2 abv 22.01.99: ma-test5.igs: IGES read (pref3d): remove degen edge with no pcurve
20 //:o4 abv 17.02.99: r0301_db.stp #53082: adding parameter isClosed to CheckOrder
21 // rln 03.03.99 S4135: using updated ShapeAnalysis_Surface for checking of singularities
22 //:p9 abv 11.03.99: PRO7226 #489490: fix :i9 moved to allow fixing a set of degenerated edges
23 //#77 rln 11.03.99: S4135: using singularity which has minimum gap between singular point and input 3D point
24 //#84 rln 18.03.99: inserting degenerated edge between ends of pcurves
25 //pdn 12.03.99 S4135 check degenerated applies minimal tolerance first.
26 //pdn 16.03.99 S4135 adding check of non adjacent edjes.
27 //#83 rln 19.03.99: processing segments in intersection as in BRepCheck
28 //%15 pdn 15.03.99 checking of small area wire added
29 //#2 smh 26.03.99 S4163 Zero divide
30 //#4 szv S4163 optimizing
31 //:r6 abv 08.04.99: protect FixIE against working out of curve range
32 //:s1 abv 22.04.99: PRO7226 #489490: ensure fixing of degenerated edge
33 //#9 smh 14.12.99 BUC60615 Using tolerance of verteces during checking degenerated edge.
35 #include <ShapeAnalysis_Wire.ixx>
37 #include <Precision.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom2d_Curve.hxx>
41 #include <GeomAdaptor_HSurface.hxx>
42 #include <Geom2dAdaptor_Curve.hxx>
43 #include <Geom2dInt_GInter.hxx>
44 #include <GProp_GProps.hxx>
45 #include <IntRes2d_Domain.hxx>
46 #include <IntRes2d_Transition.hxx>
47 #include <IntRes2d_IntersectionPoint.hxx>
48 #include <IntRes2d_IntersectionSegment.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Vertex.hxx>
52 #include <BRepGProp.hxx>
53 #include <BRep_Builder.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepTools.hxx>
56 #include <BRepBuilderAPI_MakeFace.hxx>
58 #include <ShapeExtend.hxx>
59 #include <ShapeAnalysis.hxx>
60 #include <ShapeAnalysis_Curve.hxx>
61 #include <ShapeAnalysis_Edge.hxx>
64 #include <Precision.hxx>
65 #include <TColgp_Array1OfPnt.hxx>
66 #include <TColStd_Array1OfReal.hxx>
67 #include <Bnd_Array1OfBox2d.hxx>
68 #include <BndLib_Add2dCurve.hxx>
69 #include <Bnd_Box2d.hxx>
72 #include <Geom2dAdaptor_HCurve.hxx>
73 #include <Adaptor3d_CurveOnSurface.hxx>
74 #include <TColgp_SequenceOfPnt.hxx>
75 #include <ShapeAnalysis_Surface.hxx>
76 #include <TopoDS_Wire.hxx>
77 #include <ShapeAnalysis.hxx>
78 #include <Geom_Plane.hxx>
79 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
80 #include <TopoDS_Iterator.hxx>
81 #include <TopTools_DataMapOfShapeListOfShape.hxx>
82 #include <TopTools_ListOfShape.hxx>
83 #include <TopTools_IndexedMapOfShape.hxx>
84 #include <TopTools_ListIteratorOfListOfShape.hxx>
87 //=======================================================================
88 //function : ShapeAnalysis_Wire
90 //=======================================================================
92 ShapeAnalysis_Wire::ShapeAnalysis_Wire()
95 myPrecision = ::Precision::Confusion();
98 //=======================================================================
99 //function : ShapeAnalysis_Wire
101 //=======================================================================
103 ShapeAnalysis_Wire::ShapeAnalysis_Wire (const TopoDS_Wire& wire,
104 const TopoDS_Face& face,
105 const Standard_Real precision)
107 Init (wire, face, precision);
110 //=======================================================================
111 //function : ShapeAnalysis_Wire
113 //=======================================================================
115 ShapeAnalysis_Wire::ShapeAnalysis_Wire (const Handle(ShapeExtend_WireData)& sbwd,
116 const TopoDS_Face& face,
117 const Standard_Real precision)
119 Init (sbwd, face, precision);
122 //=======================================================================
125 //=======================================================================
127 void ShapeAnalysis_Wire::Init (const TopoDS_Wire& wire,
128 const TopoDS_Face& face, const Standard_Real precision)
130 Init (new ShapeExtend_WireData (wire), face, precision);
133 //=======================================================================
136 //=======================================================================
138 void ShapeAnalysis_Wire::Init (const Handle(ShapeExtend_WireData)& sbwd,
139 const TopoDS_Face& face, const Standard_Real precision)
143 SetPrecision (precision);
146 //=======================================================================
149 //=======================================================================
151 void ShapeAnalysis_Wire::Load (const TopoDS_Wire& wire)
154 myWire = new ShapeExtend_WireData (wire);
157 //=======================================================================
160 //=======================================================================
162 void ShapeAnalysis_Wire::Load (const Handle(ShapeExtend_WireData)& sbwd)
168 //=======================================================================
171 //=======================================================================
173 void ShapeAnalysis_Wire::SetFace(const TopoDS_Face& face)
177 mySurf = new ShapeAnalysis_Surface ( BRep_Tool::Surface ( myFace ) );
180 //=======================================================================
181 //function : SetSurface
183 //=======================================================================
185 void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface)
187 SetSurface ( surface, TopLoc_Location() );
190 //=======================================================================
191 //function : SetSurface
193 //=======================================================================
195 void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface,
196 const TopLoc_Location& location)
200 B.MakeFace ( face, surface, location, ::Precision::Confusion() );
204 //=======================================================================
205 //function : SetPrecision
207 //=======================================================================
209 void ShapeAnalysis_Wire::SetPrecision(const Standard_Real precision)
211 myPrecision = precision;
214 //=======================================================================
215 //function : ClearStatuses
217 //=======================================================================
219 void ShapeAnalysis_Wire::ClearStatuses()
221 myStatusOrder = myStatusConnected =
222 myStatusEdgeCurves = myStatusDegenerated =
223 myStatusClosed = myStatusLacking =
224 myStatusSelfIntersection = myStatusSmall =
225 myStatusGaps3d = myStatusGaps2d =
226 myStatusCurveGaps = myStatusLoop = myStatus = 0;
228 myMin3d = myMin2d = myMax3d = myMax2d = 0.;
231 //=======================================================================
234 //=======================================================================
236 Standard_Boolean ShapeAnalysis_Wire::Perform()
238 Standard_Boolean result = Standard_False;
239 result |= CheckOrder();
240 result |= CheckSmall();
241 result |= CheckConnected();
242 result |= CheckEdgeCurves();
243 result |= CheckDegenerated();
244 result |= CheckSelfIntersection();
245 result |= CheckLacking();
246 result |= CheckClosed();
250 //=======================================================================
251 //function : CheckOrder
253 //=======================================================================
255 Standard_Boolean ShapeAnalysis_Wire::CheckOrder (const Standard_Boolean isClosed,
256 const Standard_Boolean mode3d)
258 ShapeAnalysis_WireOrder sawo;
259 CheckOrder (sawo, isClosed, mode3d);
260 myStatusOrder = myStatus;
261 return StatusOrder (ShapeExtend_DONE);
264 //=======================================================================
265 //function : CheckSmall
267 //=======================================================================
269 Standard_Boolean ShapeAnalysis_Wire::CheckSmall(const Standard_Real precsmall)
271 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
272 CheckSmall (i, precsmall);
273 myStatusSmall |= myStatus;
275 return StatusSmall (ShapeExtend_DONE);
278 //=======================================================================
279 //function : CheckConnected
281 //=======================================================================
283 Standard_Boolean ShapeAnalysis_Wire::CheckConnected(const Standard_Real prec)
285 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
286 CheckConnected ( i, prec );
287 myStatusConnected |= myStatus;
289 return StatusConnected (ShapeExtend_DONE);
292 //=======================================================================
293 //function : CheckEdgeCurves
295 //=======================================================================
297 Standard_Boolean ShapeAnalysis_Wire::CheckEdgeCurves()
299 myStatusEdgeCurves = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
300 if ( ! IsReady() ) return Standard_False;
302 Standard_Integer i, nb = myWire->NbEdges();
303 ShapeAnalysis_Edge SAE;
305 for (i = 1; i <= nb; i++) {
306 TopoDS_Edge E = myWire->Edge (i);
308 SAE.CheckCurve3dWithPCurve (E, myFace);
309 if (SAE.Status (ShapeExtend_DONE))
310 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
311 if (SAE.Status ( ShapeExtend_FAIL))
312 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
314 SAE.CheckVerticesWithPCurve (E, myFace);
315 if (SAE.Status (ShapeExtend_DONE))
316 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
317 if (SAE.Status ( ShapeExtend_FAIL))
318 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
320 SAE.CheckVerticesWithCurve3d (E);
321 if (SAE.Status (ShapeExtend_DONE))
322 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
323 if (SAE.Status ( ShapeExtend_FAIL))
324 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
327 if (LastCheckStatus (ShapeExtend_DONE))
328 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
329 if (LastCheckStatus (ShapeExtend_FAIL))
330 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL4);
333 if (LastCheckStatus (ShapeExtend_DONE))
334 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
335 if (LastCheckStatus (ShapeExtend_FAIL))
336 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL5);
339 if (LastCheckStatus (ShapeExtend_DONE))
340 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
341 if (LastCheckStatus (ShapeExtend_FAIL))
342 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL6);
344 Standard_Real maxdev = 0.0;
345 SAE.CheckSameParameter (myWire->Edge (i), maxdev);
346 if (SAE.Status (ShapeExtend_DONE))
347 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE7);
348 if (SAE.Status ( ShapeExtend_FAIL))
349 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL7);
351 return StatusEdgeCurves (ShapeExtend_DONE);
354 //=======================================================================
355 //function : CheckDegenerated
357 //=======================================================================
359 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated()
361 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
362 CheckDegenerated (i);
363 myStatusDegenerated |= myStatus;
365 return StatusDegenerated (ShapeExtend_DONE);
368 //=======================================================================
369 //function : CheckSelfIntersection
371 //=======================================================================
373 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersection()
375 myStatusSelfIntersection = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
376 if (!IsReady()) return Standard_False;
377 Standard_Integer i, nb = myWire->NbEdges();
378 for (i = 1; i <= nb; i++) {
379 CheckSelfIntersectingEdge (i);
380 if (LastCheckStatus (ShapeExtend_DONE))
381 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
382 if (LastCheckStatus (ShapeExtend_FAIL))
383 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
385 CheckIntersectingEdges (i);
386 if (LastCheckStatus (ShapeExtend_DONE))
387 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
388 if (LastCheckStatus (ShapeExtend_FAIL))
389 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
392 Bnd_Array1OfBox2d boxes(1,nb);
394 const Handle(Geom_Surface)& S = BRep_Tool::Surface(Face(), L);
395 Handle(Geom2d_Curve) c2d;
397 ShapeAnalysis_Edge sae;
398 Handle(ShapeExtend_WireData) sbwd = WireData();
399 for(i = 1; i <= nb; i++){
400 TopoDS_Edge E = sbwd->Edge (i);
401 if(sae.PCurve (E,S,L,c2d,cf,cl,Standard_False)) {
403 Geom2dAdaptor_Curve gac(c2d,cf,cl);
404 BndLib_Add2dCurve::Add(gac,::Precision::Confusion(),box);
409 Standard_Boolean isFail = Standard_False, isDone = Standard_False;
410 for(Standard_Integer num1 = 1; num1 < nb-1; num1++) {
411 Standard_Integer fin = nb;
412 if (CheckClosed(Precision::Confusion()) && 1 == num1)
414 for(Standard_Integer num2 = num1+2; num2 <= fin; num2++)
415 if(!boxes(num1).IsOut(boxes(num2))){
416 CheckIntersectingEdges(num1, num2);
417 isFail |= LastCheckStatus ( ShapeExtend_FAIL1 );
418 isDone |= LastCheckStatus ( ShapeExtend_DONE1 );
422 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
424 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
426 return StatusSelfIntersection (ShapeExtend_DONE);
429 //=======================================================================
430 //function : CheckLacking
432 //=======================================================================
434 Standard_Boolean ShapeAnalysis_Wire::CheckLacking()
436 if (!IsReady() || NbEdges() < 2) return Standard_False;
437 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
439 myStatusLacking |= myStatus;
441 return StatusLacking (ShapeExtend_DONE);
444 //=======================================================================
445 //function : CheckClosed
447 //=======================================================================
449 Standard_Boolean ShapeAnalysis_Wire::CheckClosed(const Standard_Real prec)
451 myStatusClosed = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
452 if (!IsReady() || NbEdges() < 1) return Standard_False;
454 CheckConnected (1, prec);
455 if ( LastCheckStatus ( ShapeExtend_DONE ) )
456 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
457 if ( LastCheckStatus ( ShapeExtend_FAIL ) )
458 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
460 CheckDegenerated ( 1 );
461 if ( LastCheckStatus ( ShapeExtend_DONE ) )
462 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
463 if ( LastCheckStatus ( ShapeExtend_FAIL ) )
464 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
466 return StatusClosed ( ShapeExtend_DONE );
469 //=======================================================================
470 //function : CheckGaps3d
472 //=======================================================================
474 Standard_Boolean ShapeAnalysis_Wire::CheckGaps3d ()
476 myStatusGaps3d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
477 if (!IsLoaded() || NbEdges() < 1) return Standard_False; //gka IsLoaded
479 Standard_Real dist, maxdist = 0.;
481 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
483 myStatusGaps3d |= myStatus;
484 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
485 dist = MinDistance3d();
486 if (maxdist<dist) maxdist = dist;
489 myMin3d = myMax3d = maxdist;
491 return StatusGaps3d ( ShapeExtend_DONE );
494 //=======================================================================
495 //function : CheckGaps2d
497 //=======================================================================
499 Standard_Boolean ShapeAnalysis_Wire::CheckGaps2d ()
501 myStatusGaps2d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
502 if (!IsReady() || NbEdges() < 1) return Standard_False;
504 Standard_Real dist, maxdist = 0.;
506 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
508 myStatusGaps2d |= myStatus;
509 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
510 dist = MinDistance2d();
511 if (maxdist<dist) maxdist = dist;
514 myMin2d = myMax2d = maxdist;
516 return StatusGaps2d ( ShapeExtend_DONE );
519 //=======================================================================
520 //function : CheckCurveGaps
522 //=======================================================================
524 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGaps ()
526 myStatusCurveGaps = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
527 if (!IsReady() || NbEdges() < 1) return Standard_False;
529 Standard_Real dist, maxdist = 0.;
531 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
533 myStatusCurveGaps |= myStatus;
534 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
535 dist = MinDistance3d();
536 if (maxdist<dist) maxdist = dist;
539 myMin3d = myMax3d = maxdist;
541 return StatusCurveGaps ( ShapeExtend_DONE );
544 //=======================================================================
545 //function : CheckOrder
547 //=======================================================================
549 Standard_Boolean ShapeAnalysis_Wire::CheckOrder(ShapeAnalysis_WireOrder& sawo,
550 const Standard_Boolean isClosed,
551 const Standard_Boolean mode3d)
553 if ( ! mode3d && myFace.IsNull() ) {
554 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
555 return Standard_False;
558 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
559 sawo.SetMode ( mode3d, ( mode3d ? myPrecision : ::Precision::PConfusion() ) );
560 Standard_Integer i, nb = myWire->NbEdges();
561 ShapeAnalysis_Edge EA;
562 for (i = 1; i <= nb; i ++) {
563 TopoDS_Edge E = myWire->Edge(i);
565 TopoDS_Vertex V1 = EA.FirstVertex (E);
566 TopoDS_Vertex V2 = EA.LastVertex (E);
567 if (V1.IsNull() || V2.IsNull())
569 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
570 return Standard_False;
572 gp_Pnt p1 = BRep_Tool::Pnt (V1);
573 gp_Pnt p2 = BRep_Tool::Pnt (V2);
574 sawo.Add (p1.XYZ(),p2.XYZ());
578 Handle(Geom2d_Curve) c2d;
579 TopoDS_Shape tmpF = myFace.Oriented(TopAbs_FORWARD);
580 if ( ! EA.PCurve(E,TopoDS::Face(tmpF),c2d,f,l) ) {
581 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
582 return Standard_False;
584 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
587 sawo.Perform(isClosed);
588 Standard_Integer stat = sawo.Status();
590 case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); break;
591 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break;
592 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
593 case -1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
594 case -2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
595 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE5); break;//only shifted
596 case -10: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); break;
598 return LastCheckStatus (ShapeExtend_DONE);
601 //=======================================================================
602 //function : CheckConnected
604 //=======================================================================
606 Standard_Boolean ShapeAnalysis_Wire::CheckConnected (const Standard_Integer num,
607 const Standard_Real prec)
609 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
610 if ( ! IsLoaded() || NbEdges() < 1 ) return Standard_False;
612 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
613 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
614 // if (n1 == n2) return 0;
616 TopoDS_Edge E1 = WireData()->Edge ( n1 );
617 TopoDS_Edge E2 = WireData()->Edge ( n2 );
619 ShapeAnalysis_Edge sae;
620 TopoDS_Vertex V1 = sae.LastVertex (E1);
621 TopoDS_Vertex V2 = sae.FirstVertex (E2);
622 if (V1.IsNull() || V2.IsNull())
624 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
625 return Standard_False;
627 if (V1.IsSame(V2)) return Standard_False;
629 gp_Pnt p1 = BRep_Tool::Pnt (V1);
630 gp_Pnt p2 = BRep_Tool::Pnt (V2);
631 myMin3d = p1.Distance(p2);
632 if ( myMin3d <= gp::Resolution() ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
633 else if ( myMin3d <= myPrecision ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
634 else if ( myMin3d <= prec ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
636 // et en inversant la derniere edge ?
637 if ( n1 == n2 ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
639 V2 = sae.LastVertex (E2);
640 p2 = BRep_Tool::Pnt (V2);
641 Standard_Real dist = p1.Distance(p2);
642 if ( dist > myPrecision ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
645 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
648 return Standard_False;
650 return Standard_True;
653 //=======================================================================
654 //function : CheckSmall
656 //=======================================================================
658 Standard_Boolean ShapeAnalysis_Wire::CheckSmall (const Standard_Integer num,
659 const Standard_Real precsmall)
661 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
662 if ( ! IsLoaded() || NbEdges() <= 1 ) return Standard_False;
664 //Standard_Integer n = ( num ? num : NbEdges() ); //szv#4:S4163:12Mar99 not needed
665 TopoDS_Edge E = myWire->Edge ( num ? num : NbEdges() );
666 ShapeAnalysis_Edge sae;
668 if ( BRep_Tool::Degenerated ( E ) ) {
669 //:n2 abv 22 Jan 99: ma-test5.igs -> IGES (brep) -> read (pref3d):
670 // degen edge with no pcurve should be removed
671 if ( ! myFace.IsNull() && sae.HasPCurve ( E, Face() ) ) return Standard_False;
672 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
675 TopoDS_Vertex V1 = sae.FirstVertex (E);
676 TopoDS_Vertex V2 = sae.LastVertex (E);
677 if (V1.IsNull() || V2.IsNull())
679 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
680 return Standard_False;
682 gp_Pnt p1 = BRep_Tool::Pnt (V1);
683 gp_Pnt p2 = BRep_Tool::Pnt (V2);
684 Standard_Real dist = p1.Distance(p2);
685 Standard_Real prec = precsmall;//Min ( myPrecision, precsmall );
686 //Standard_Real prec = Min(BRep_Tool::Tolerance(V1),BRep_Tool::Tolerance(V2)); //skl
687 if (dist > prec) return Standard_False; // pas nulle
689 // La courbe 3D a present : est-elle FERMEE ou DE LONGUEUR NULLE ... ???
690 // Pour cela on prend le point milieu (y a-t-il mieux)
691 // Si pas de C3D, on essaie la C2D ...
695 Handle(Geom_Curve) c3d;
696 if ( sae.Curve3d (E,c3d,cf,cl,Standard_False) ) Pm = c3d->Value ( (cf+cl)/2. );
698 Handle(Geom2d_Curve) c2d;
699 if ( ! myFace.IsNull() && sae.PCurve (E,myFace,c2d,cf,cl,Standard_False)) {
700 gp_Pnt2d p2m = c2d->Value ( (cf+cl)/2. );
701 Pm = mySurf->Value (p2m);
704 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
706 //:n2 return Standard_False;
709 if ( Pm.Distance(p1) > prec || Pm.Distance(p2) > prec ) return Standard_False;
711 myStatus |= ShapeExtend::EncodeStatus ( V1.IsSame(V2) ? ShapeExtend_DONE1 : ShapeExtend_DONE2 );
712 return Standard_True;
715 //=======================================================================
716 //function : CheckSeam
718 //=======================================================================
720 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num,
721 Handle(Geom2d_Curve)& C1,
722 Handle(Geom2d_Curve)& C2,
726 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
727 if (!IsReady()) return Standard_False;
728 Standard_Integer n = num; if (n == 0) n = NbEdges();
729 TopoDS_Edge E = myWire->Edge (n);
730 if ( ! ShapeAnalysis_Edge().IsSeam ( E, myFace ) ) return Standard_False;
731 // Extract the Two PCurves of the Seam
732 TopoDS_Face ForwardFace = myFace; ForwardFace.Orientation (TopAbs_FORWARD);
733 //szv#4:S4163:12Mar99 SGI warns
734 TopoDS_Shape EF = E.Oriented(TopAbs_FORWARD);
735 TopoDS_Shape ER = E.Oriented(TopAbs_REVERSED);
736 C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(EF), ForwardFace, cf, cl);
737 C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(ER), ForwardFace, cf, cl);
738 if (C1.IsNull() || C2.IsNull()) return Standard_False;
740 // SelectForward est destine a devenir un outil distinct
742 Standard_Integer theCurveIndice = ShapeAnalysis_Curve().SelectForwardSeam (C1,C2);
743 if ( theCurveIndice != 2 ) return Standard_False;
745 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
746 return Standard_True;
749 //=======================================================================
750 //function : CheckSeam
752 //=======================================================================
754 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num)
756 Handle(Geom2d_Curve) C1, C2;
757 Standard_Real cf, cl;
758 return CheckSeam (num, C1, C2, cf, cl);
761 //=======================================================================
762 //function : CheckDegenerated
764 //=======================================================================
766 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num,
767 gp_Pnt2d& p2d1, gp_Pnt2d& p2d2)
769 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
770 if ( ! IsReady() || NbEdges() < 1 ) return Standard_False;
772 Standard_Integer n2 = (num > 0)? num : NbEdges();
773 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
774 Standard_Integer n3 = (n2 < NbEdges())? n2+1 : 1;
775 TopoDS_Edge E1 = myWire->Edge ( n1 );
776 TopoDS_Edge E2 = myWire->Edge ( n2 );
777 TopoDS_Edge E3 = myWire->Edge ( n3 );
779 ShapeAnalysis_Edge sae;
781 // skip if edge is already marked as degenerated and has pcurve
782 if ( BRep_Tool::Degenerated ( E2 ) && sae.HasPCurve ( E2, Face() ) ) {
783 // skl 30.12.2004 for OCC7630 - we have to check pcurve
784 if( sae.HasPCurve(E1,Face()) && sae.HasPCurve(E3,Face()) ) {
785 Handle(Geom2d_Curve) c2d;
787 sae.PCurve ( E2, myFace, c2d, fp, lp, Standard_True );
788 gp_Pnt2d p21 = c2d->Value(fp);
789 gp_Pnt2d p22 = c2d->Value(lp);
790 sae.PCurve ( E1, myFace, c2d, fp, lp, Standard_True );
791 gp_Pnt2d p12 = c2d->Value(lp);
792 sae.PCurve ( E3, myFace, c2d, fp, lp, Standard_True );
793 gp_Pnt2d p31 = c2d->Value(fp);
794 if( fabs(p12.Distance(p31)-p21.Distance(p22)) > 2*Precision::PConfusion() ) {
795 // pcurve is bad => we can remove this edge in ShapeFix
796 // if set needed status
797 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
800 return Standard_False;
803 //pdn allows to insert two sequences of degenerated edges (on separate bounds of surfaces)
804 if ( n1 != n2 && BRep_Tool::Degenerated ( E1 ) &&
805 ! sae.HasPCurve ( E1, Face() ) ) {
806 //:abv 13.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
807 if ( BRep_Tool::Degenerated ( E2 ) )
808 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
809 return Standard_False;
811 //:i8 if ( BRep_Tool::Degenerated ( E1 ) ||
812 //:i8 BRep_Tool::Degenerated ( E2 ) ) return Standard_False; // deja OK
814 TopoDS_Vertex Vp = sae.FirstVertex (E1); //:i9
815 TopoDS_Vertex V0 = sae.LastVertex (E1);
816 TopoDS_Vertex V1 = sae.FirstVertex (E2);
817 TopoDS_Vertex V2 = sae.LastVertex (E2);
819 if (Vp.IsNull() || V0.IsNull() || V1.IsNull() || V2.IsNull())
820 return Standard_False;
822 gp_Pnt pp = BRep_Tool::Pnt (Vp); //:i9
823 gp_Pnt p0 = BRep_Tool::Pnt (V0);
824 gp_Pnt p1 = BRep_Tool::Pnt (V1);
825 gp_Pnt p2 = BRep_Tool::Pnt (V2);
826 Standard_Real par1, par2;
827 Standard_Boolean lack = Standard_False;
828 Standard_Boolean dgnr = Standard_False;
829 //pdn 12.03.99 minimal value processing first
830 Standard_Real precFirst = Min(myPrecision,BRep_Tool::Tolerance(V1));
831 Standard_Real precFin = Max(myPrecision,BRep_Tool::Tolerance(V1));
832 Standard_Real precVtx = (myPrecision<BRep_Tool::Tolerance(V1) ? 2*precFin : precFin);
833 // forward : si Edge <num> FWD/REV. Si LACK, toujours True
834 Standard_Boolean forward = ( E2.Orientation() == TopAbs_FORWARD );
835 // FIX FEV 1998 : recompute singularity according precision
837 if (p1.Distance(p2) <= precFirst) { // edge DGNR
838 dgnr = mySurf->DegeneratedValues ( p1, precVtx, p2d1, p2d2, par1, par2, forward ); //smh#9
839 if ( dgnr ) { // abv 24 Feb 00: trj3_as1-ac-214.stp #6065: avoid making closed edge degenerated
841 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E2, a, b );
842 if ( ! C3d.IsNull() ) {
843 gp_Pnt p = C3d->Value ( 0.5 * ( a + b ) );
844 if ( p.SquareDistance ( p1 ) > precVtx * precVtx ) dgnr = Standard_False;
849 //:i9 abv 23 Sep 98: CTS20315-2 #63231: check that previous edge is not degenerated
850 if ( n1 != n2 && p1.Distance(pp) <= precFirst &&
851 mySurf->IsDegenerated ( pp, precFirst ) &&
852 ! BRep_Tool::Degenerated ( E1 ) ) return Standard_False;
853 //rln S4135 ShapeAnalysis_Surface new algorithms for singularities
854 //:45 by abv 16 Dec 97: BUC60035 2659: precision increased to vertex tolerance
855 //Standard_Real prec = Max ( myPrecision, BRep_Tool::Tolerance(V1) );
856 //:51 abv 22 Dec 97: recompute singularities if necessary
857 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( 2 * prec ); //:51 //:74 abv 15 Jan 97: *2
859 if ( p0.Distance ( p1 ) <= precFin ) {// ou DGNR manquante ?
860 //rln S4135 singularity with precision = 2 * prec, but distance <= prec
861 //lack = mySurf->DegeneratedValues ( p1, prec, p2d1, p2d2, par1, par2, forward);
862 Standard_Real tmpPreci;
864 Standard_Boolean tmpUIsoDeg;
865 //#77 rln S4135: using singularity which has minimum gap between singular point and input 3D point
866 Standard_Integer indMin = -1;
867 Standard_Real gapMin2 = RealLast();
868 for (Standard_Integer i = 1; i <= mySurf->NbSingularities (precVtx); i++) {
869 mySurf->Singularity (i, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
870 Standard_Real gap2 = p1.SquareDistance (tmpP3d);
871 if (gap2 <= precVtx * precVtx)
872 if (gapMin2 > gap2) {
878 mySurf->Singularity (indMin, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
879 lack = Standard_True;
883 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( myPrecision ); //:51
886 // voila, on a soit dgnr soit lack
887 if ( ! lack && ! dgnr ) {
888 //:abv 29.08.01: if singularity not detected but edge is marked
889 // as degenerated, report fail
890 if ( BRep_Tool::Degenerated ( E2 ) && ! sae.HasPCurve ( E2, Face() ) )
891 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
892 return Standard_False;
895 // OK, degenerated case detected; we will find its start and end in 2d
897 if ( lack ) forward = Standard_True;
899 //:24 by abv 28 Nov 97:
900 // make degenerative pcurve parametrized exactly from end of pcurve of the
901 // previous edge to the start of the next one
902 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
904 Handle(Geom2d_Curve) c2d;
905 if ( sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
906 p2d1 = c2d->Value ( b );
907 //#84 rln gp_Pnt2d p2d = c2d->Value ( b );
908 //#84 rln par1 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
910 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
911 //pdn pcurves (fixing regression in f0 in degenerated case)
912 if ( sae.PCurve ( ( dgnr ? E3 : E2 ), myFace, c2d, a, b, Standard_True ) ) {
913 p2d2 = c2d->Value ( a );
914 //#84 rln gp_Pnt2d p2d = c2d->Value ( a );
915 //#84 rln par2 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
917 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
927 //#84 rln 18.03.99 if pcurve is not degenerate anymore, the fix is postponned
928 //to ShapeFix_Wire::FixLacking
929 if ( ! mySurf->IsDegenerated ( p2d1, p2d2, precVtx, 10. ) ) { //:s1 abv 22 Apr 99: PRO7226 #489490 //smh#9
930 //:abv 24.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
931 if ( BRep_Tool::Degenerated ( E2 ) )
932 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
933 return Standard_False;
936 //added by rln 18/12/97 CSR# CTS18544 entity 13638
937 //the situation when degenerated edge already exists but flag is not set
938 //(i.e. the parametric space is closed)
939 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
940 Standard_Real max = Max ( Ads.UResolution(myPrecision),
941 Ads.VResolution(myPrecision) );
942 if ( p2d1.Distance (p2d2) /*Abs (par1 - par2)*/ <= max + gp::Resolution() ) return Standard_False;
944 //#84 rln p2d1 = aP2d.XY() + par1 * theDir2d.XY();
945 //#84 rln p2d2 = aP2d.XY() + par2 * theDir2d.XY();
946 myStatus = ShapeExtend::EncodeStatus ( dgnr ? ShapeExtend_DONE2 : ShapeExtend_DONE1 );
947 return Standard_True;
950 //=======================================================================
951 //function : CheckDegenerated
953 //=======================================================================
955 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num)
958 return CheckDegenerated ( num, p2d1, p2d2 );
961 //=======================================================================
962 //function : CheckGap3d
964 //=======================================================================
966 Standard_Boolean ShapeAnalysis_Wire::CheckGap3d(const Standard_Integer num)
968 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
969 //szv#4:S4163:12Mar99 optimized
970 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
971 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
972 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
973 TopoDS_Edge E1 = myWire->Edge(n1);
974 TopoDS_Edge E2 = myWire->Edge(n2);
975 Standard_Real uf1,ul1,uf2,ul2;
976 Handle(Geom_Curve) C1,C2;
977 ShapeAnalysis_Edge SAE;
978 if (!SAE.Curve3d (E1,C1,uf1,ul1) || !SAE.Curve3d (E2,C2,uf2,ul2)) {
979 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
980 return Standard_False;
982 gp_Pnt p1 = C1->Value (ul1);
983 gp_Pnt p2 = C2->Value (uf2);
984 myMin3d = myMax3d = p1.Distance (p2);
985 if (myMin3d > myPrecision)
986 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
987 return LastCheckStatus (ShapeExtend_DONE);
990 //=======================================================================
991 //function : CheckGap2d
993 //=======================================================================
995 Standard_Boolean ShapeAnalysis_Wire::CheckGap2d(const Standard_Integer num)
997 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
998 //szv#4:S4163:12Mar99 optimized
999 if ( !IsReady() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
1000 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
1001 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
1002 TopoDS_Edge E1 = myWire->Edge(n1);
1003 TopoDS_Edge E2 = myWire->Edge(n2);
1004 Standard_Real uf1,ul1,uf2,ul2;
1005 Handle(Geom2d_Curve) C1,C2;
1006 ShapeAnalysis_Edge SAE;
1007 if (!SAE.PCurve (E1,myFace,C1,uf1,ul1) || !SAE.PCurve (E2,myFace,C2,uf2,ul2)) {
1008 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1009 return Standard_False;
1011 gp_Pnt2d p1 = C1->Value (ul1);
1012 gp_Pnt2d p2 = C2->Value (uf2);
1013 myMin2d = myMax2d = p1.Distance (p2);
1014 GeomAdaptor_Surface& SA = mySurf->Adaptor3d()->ChangeSurface();
1015 if (myMin2d > (Max (SA.UResolution (myPrecision), SA.VResolution (myPrecision)) + Precision::PConfusion()))
1016 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1017 return LastCheckStatus (ShapeExtend_DONE);
1020 //=======================================================================
1021 //function : CheckCurveGap
1023 //=======================================================================
1025 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGap(const Standard_Integer num)
1027 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1028 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False;
1029 Standard_Integer n = ( num >0 ? num : NbEdges() );
1030 TopoDS_Edge E = myWire->Edge(n);
1031 Standard_Real cuf,cul,pcuf,pcul;
1032 Handle(Geom_Curve) c;
1033 ShapeAnalysis_Edge SAE;
1034 if (!SAE.Curve3d (E,c,cuf,cul,Standard_False)) {
1035 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1036 return Standard_False;
1038 Handle(Geom2d_Curve) pc;
1039 if (!SAE.PCurve (E,myFace,pc,pcuf,pcul,Standard_False)) {
1040 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1041 return Standard_False;
1043 Handle(Geom2dAdaptor_HCurve) AC = new Geom2dAdaptor_HCurve(pc,pcuf,pcul);
1044 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(mySurf->Surface());
1045 Adaptor3d_CurveOnSurface ACS(AC,AS);
1047 Standard_Integer nbp = 45;
1048 Standard_Real dist, maxdist=0.;
1049 for (Standard_Integer i=0; i<nbp; i++) {
1050 cpnt = c->Value(cuf + i*(cul-cuf)/(nbp-1));
1051 pcpnt = ACS.Value(pcuf + i*(pcul-pcuf)/(nbp-1));
1052 dist = cpnt.SquareDistance(pcpnt);
1053 if (maxdist<dist) maxdist = dist;
1055 myMin3d = myMax3d = Sqrt(maxdist);
1056 if (myMin3d > myPrecision)
1057 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1058 return LastCheckStatus (ShapeExtend_DONE);
1061 //=======================================================================
1062 //function : CheckSelfIntersectingEdge
1064 //=======================================================================
1066 // auxiliary function
1067 //:h0 abv 29 May 98: PRO10105 1949: like in BRepCheck, point is to be taken
1068 // from 3d curve (but only if edge is SameParameter)
1069 static gp_Pnt GetPointOnEdge ( const TopoDS_Edge &edge,
1070 const Handle(ShapeAnalysis_Surface) &surf,
1071 const Geom2dAdaptor_Curve &Crv2d,
1072 const Standard_Real param )
1074 if ( BRep_Tool::SameParameter ( edge ) ) {
1077 const Handle(Geom_Curve) ConS = BRep_Tool::Curve ( edge, L, f, l );
1078 if ( ! ConS.IsNull() )
1079 return ConS->Value ( param ).Transformed ( L.Transformation() );
1081 gp_Pnt2d aP2d = Crv2d.Value(param);
1082 return surf->Adaptor3d()->Value(aP2d.X(), aP2d.Y());
1085 //=======================================================================
1086 //function : CheckSelfIntersectingEdge
1088 //=======================================================================
1090 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num,
1091 IntRes2d_SequenceOfIntersectionPoint& points2d,
1092 TColgp_SequenceOfPnt& points3d)
1096 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1097 if ( ! IsReady() ) return Standard_False;
1099 TopoDS_Edge edge = WireData()->Edge ( num >0 ? num : NbEdges() );
1100 ShapeAnalysis_Edge sae;
1103 Handle(Geom2d_Curve) Crv;
1104 if ( ! sae.PCurve ( edge, myFace, Crv, a, b, Standard_False ) ) {
1105 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1106 return Standard_False;
1108 if ( Abs ( a - b ) <= ::Precision::PConfusion() ) return Standard_False;
1110 Standard_Real tolint = 1.0e-10;
1111 //szv#4:S4163:12Mar99 warning
1112 IntRes2d_Domain domain ( Crv->Value ( a ), a, tolint, Crv->Value ( b ), b, tolint );
1113 Geom2dAdaptor_Curve AC ( Crv );
1114 Geom2dInt_GInter Inter ( AC, domain, tolint, tolint );
1116 if ( ! Inter.IsDone() ) return Standard_False;
1118 TopoDS_Vertex V1 = sae.FirstVertex ( edge );
1119 TopoDS_Vertex V2 = sae.LastVertex ( edge );
1120 if ( V1.IsNull() || V2.IsNull() ) {
1121 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1122 return Standard_False;
1124 Standard_Real tol1 = BRep_Tool::Tolerance ( V1 );
1125 Standard_Real tol2 = BRep_Tool::Tolerance ( V2 );
1127 gp_Pnt pnt1 = BRep_Tool::Pnt ( V1 );
1128 gp_Pnt pnt2 = BRep_Tool::Pnt ( V2 );
1130 for ( Standard_Integer i=1; i <= Inter.NbPoints(); i++ ) {
1131 const IntRes2d_IntersectionPoint &IP = Inter.Point ( i );
1132 const IntRes2d_Transition &Tr1 = IP.TransitionOfFirst();
1133 const IntRes2d_Transition &Tr2 = IP.TransitionOfSecond();
1134 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1135 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1136 gp_Pnt pint = GetPointOnEdge ( edge, mySurf, AC, IP.ParamOnFirst() );
1137 Standard_Real dist21 = pnt1.SquareDistance ( pint );
1138 Standard_Real dist22 = pnt2.SquareDistance ( pint );
1139 if ( dist21 > tol1 * tol1 && dist22 > tol2 * tol2 ) {
1140 points2d.Append ( IP );
1141 points3d.Append ( pint );
1142 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1146 return LastCheckStatus ( ShapeExtend_DONE );
1149 //=======================================================================
1150 //function : CheckSelfIntersectingEdge
1152 //=======================================================================
1154 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num)
1156 IntRes2d_SequenceOfIntersectionPoint points2d;
1157 TColgp_SequenceOfPnt points3d;
1158 return CheckSelfIntersectingEdge ( num, points2d, points3d );
1161 //=======================================================================
1162 //function : CheckIntersectingEdges
1163 //purpose : Test if two consequent edges are intersecting
1164 // It is made in accordance with the following check in BRepCheck:
1165 // - in BRepCheck_Wire::Orientation(), test for self-intersection
1166 //=======================================================================
1168 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num,
1169 IntRes2d_SequenceOfIntersectionPoint& points2d,
1170 TColgp_SequenceOfPnt& points3d,
1171 TColStd_SequenceOfReal& errors)
1176 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1177 if ( ! IsReady() || NbEdges() <2 ) return Standard_False;
1179 //szv#4:S4163:12Mar99 optimized
1180 Standard_Integer n2 = (num > 0)? num : NbEdges();
1181 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1182 TopoDS_Edge edge1 = myWire->Edge ( n1 );
1183 TopoDS_Edge edge2 = myWire->Edge ( n2 );
1185 ShapeAnalysis_Edge sae;
1186 TopoDS_Vertex V1 = sae.LastVertex ( edge1 );
1187 TopoDS_Vertex V2 = sae.FirstVertex ( edge2 );
1188 if ( V1.IsNull() || V2.IsNull() ) {
1189 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1190 return Standard_False;
1192 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1193 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1194 return Standard_False;
1197 TopoDS_Vertex Vp = sae.FirstVertex ( edge1 );
1198 TopoDS_Vertex Vn = sae.LastVertex ( edge2 );
1200 Standard_Real a1, b1, a2, b2;
1201 Handle(Geom2d_Curve) Crv1, Crv2;
1202 if ( ! sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False ) ) {
1203 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1204 return Standard_False;
1206 if ( ! sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False ) ) {
1207 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1208 return Standard_False;
1210 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1211 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False; //:f7 abv 6 May 98: BUC50070 on #42276
1213 Standard_Boolean isForward1 = ( edge1.Orientation() == TopAbs_FORWARD );
1214 Standard_Boolean isForward2 = ( edge2.Orientation() == TopAbs_FORWARD );
1216 Standard_Real tol0 = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1217 Standard_Real tol = tol0;
1219 gp_Pnt pnt = BRep_Tool::Pnt ( V1 );
1221 // Standard_Boolean Status = Standard_False;
1223 Standard_Real tolint = 1.0e-10;
1225 //szv#4:S4163:12Mar99 warning
1226 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
1227 IntRes2d_Domain d1 ( C1.Value ( a1 ), a1, tolint,
1228 C1.Value ( b1 ), b1, tolint );
1229 IntRes2d_Domain d2 ( C2.Value ( a2 ), a2, tolint,
1230 C2.Value ( b2 ), b2, tolint );
1232 //:64 abv 25 Dec 97: Attention!
1233 // Since Intersection algorithm is not symmetrical, for consistency with BRepCheck
1234 // edge with lower order number shoud be intersecting with edge with higher one
1235 // i.e., for intersection of last and first edges, they should go in reversed order
1236 // Example: entity #38285 from bug CSR #CTS17806
1237 // NOTE: Tr1 and Tr2 are not reordered because they are used in the same manner
1238 Geom2dInt_GInter Inter;
1239 if ( num ==1 ) Inter.Perform ( C2, d2, C1, d1, tolint, tolint );
1240 else Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1241 if ( ! Inter.IsDone() ) return Standard_False;
1243 //:86 abv 22 Jan 98: fix self-intersection even if tolerance of vertex is enough
1244 // to annihilate it. This is done to prevent wrong effects if vertex tolerance
1245 // will be decreased (e.g., in FixLacking)
1246 Standard_Real tole = Max ( ( BRep_Tool::SameParameter ( edge1 ) ?
1247 BRep_Tool::Tolerance ( edge1 ) : tol0 ),
1248 ( BRep_Tool::SameParameter ( edge2 ) ?
1249 BRep_Tool::Tolerance ( edge2 ) : tol0 ) );
1250 Standard_Real tolt = Min ( tol, Max ( tole, myPrecision ) );
1251 //Standard_Real prevRange1 = RealLast(), prevRange2 = RealLast(); //SK
1252 Standard_Integer isLacking = -1; //:l0 abv: CATIA01 #1727: protect against adding lacking
1253 //#83 rln 19.03.99 sim2.igs, entity 4292
1254 //processing also segments as in BRepCheck
1255 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1256 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1257 IntRes2d_IntersectionPoint IP;
1258 IntRes2d_Transition Tr1, Tr2;
1260 IP = Inter.Point ( i );
1262 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1263 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1264 IP = Seg.FirstPoint();
1265 Tr1 = IP.TransitionOfFirst();
1266 Tr2 = IP.TransitionOfSecond();
1267 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1268 IP = Seg.LastPoint();
1270 Tr1 = IP.TransitionOfFirst();
1271 Tr2 = IP.TransitionOfSecond();
1273 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1274 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1275 Standard_Real param1, param2;
1276 param1 = ( num ==1 ? IP.ParamOnSecond() : IP.ParamOnFirst() );
1277 param2 = ( num ==1 ? IP.ParamOnFirst() : IP.ParamOnSecond() );
1279 //:r6 abv 8 Apr 99: r_47-sd.stp #173850: protect against working out of curve range
1280 if ( a1-param1 > ::Precision::PConfusion() ||
1281 param1-b1 > ::Precision::PConfusion() ||
1282 a2-param2 > ::Precision::PConfusion() ||
1283 param2-b2 > ::Precision::PConfusion() ) continue;
1285 //:82 abv 21 Jan 98: point of intersection on Crv1 and Crv2 is different
1286 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, C1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1287 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, C2, param2 ); //:h0: thesurf.Value ( Crv2->Value ( param2 ) );
1288 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1289 Standard_Real di1 = pi1.SquareDistance ( pnt );
1290 Standard_Real di2 = pi2.SquareDistance ( pnt );
1291 Standard_Real dist2 = Max ( di1, di2 );
1293 //rln 03/02/98: CSR#BUC50004 entity 56 (to avoid later inserting lacking edge)
1294 if ( isLacking <0 ) { //:l0
1295 gp_Pnt2d end1 = Crv1->Value ( isForward1 ? b1 : a1 );
1296 gp_Pnt2d end2 = Crv2->Value ( isForward2 ? a2 : b2 );
1297 //:l0 Standard_Real distab2 = mySurf->Value ( end1 ).SquareDistance ( mySurf->Value ( end2 ) );
1298 //:l0: test like in BRepCheck
1299 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1300 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1301 isLacking = ( end1.SquareDistance(end2) >= tol2d * tol2d );
1304 if ( ( dist2 > tolt * tolt || //:86: tol -> tolt
1305 isLacking ) && //:l0
1306 //:l0 distab2 > BRep_Tool::Tolerance ( edge1 ) + BRep_Tool::Tolerance ( edge2 ) ) && //rln
1307 ( ! BRepTools::Compare ( Vp, Vn ) || //:63
1308 dist2 < pint.SquareDistance ( BRep_Tool::Pnt ( Vp ) ) ) ) { //:63
1309 points2d.Append ( IP );
1310 points3d.Append ( pint );
1311 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1312 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1316 return LastCheckStatus ( ShapeExtend_DONE );
1319 //=======================================================================
1320 //function : CheckIntersectingEdges
1322 //=======================================================================
1324 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num)
1326 IntRes2d_SequenceOfIntersectionPoint points2d;
1327 TColgp_SequenceOfPnt points3d;
1328 TColStd_SequenceOfReal errors;
1329 return CheckIntersectingEdges ( num, points2d, points3d, errors );
1332 //=======================================================================
1333 //function : CheckIntersectingEdges
1335 //=======================================================================
1337 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges(const Standard_Integer num1,
1338 const Standard_Integer num2,
1339 IntRes2d_SequenceOfIntersectionPoint& points2d,
1340 TColgp_SequenceOfPnt& points3d,
1341 TColStd_SequenceOfReal& errors)
1343 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1344 if ( ! IsReady() ) return Standard_False;
1345 Handle(ShapeExtend_WireData) sbwd = WireData();
1346 Standard_Integer n2 = ( num2 >0 ? num2 : sbwd->NbEdges() );
1347 Standard_Integer n1 = ( num1 >0 ? num1 : sbwd->NbEdges() );
1349 TopoDS_Edge edge1 = sbwd->Edge ( n1 );
1350 TopoDS_Edge edge2 = sbwd->Edge ( n2 );
1352 ShapeAnalysis_Edge sae;
1353 Standard_Real a1, b1, a2, b2;
1354 Handle(Geom2d_Curve) Crv1, Crv2;
1355 if(!sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False )){
1356 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1357 return Standard_False;
1360 if(!sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False )){
1361 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1362 return Standard_False;
1365 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1366 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False;
1371 TColgp_Array1OfPnt vertexPoints(1,4);
1372 TColStd_Array1OfReal vertexTolers(1,4);
1373 vertexPoints(1) = BRep_Tool::Pnt(sae.FirstVertex(edge1));
1374 vertexTolers(1) = BRep_Tool::Tolerance(sae.FirstVertex(edge1));
1375 vertexPoints(2) = BRep_Tool::Pnt(sae.LastVertex(edge1));
1376 vertexTolers(2) = BRep_Tool::Tolerance(sae.LastVertex(edge1));
1377 vertexPoints(3) = BRep_Tool::Pnt(sae.FirstVertex(edge2));
1378 vertexTolers(3) = BRep_Tool::Tolerance(sae.FirstVertex(edge2));
1379 vertexPoints(4) = BRep_Tool::Pnt(sae.LastVertex(edge2));
1380 vertexTolers(4) = BRep_Tool::Tolerance(sae.LastVertex(edge2));
1382 Standard_Real tolint = 1.0e-10;
1384 IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint,
1385 Crv1->Value ( b1 ), b1, tolint );
1386 IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint,
1387 Crv2->Value ( b2 ), b2, tolint );
1388 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
1390 Geom2dInt_GInter Inter;
1391 Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1392 if ( ! Inter.IsDone() ) return Standard_False;
1394 //#83 rln 19.03.99 sim2.igs, entity 4292
1395 //processing also segments as in BRepCheck
1396 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1397 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1398 IntRes2d_IntersectionPoint IP;
1399 IntRes2d_Transition Tr1, Tr2;
1401 IP = Inter.Point ( i );
1403 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1404 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1405 IP = Seg.FirstPoint();
1406 Tr1 = IP.TransitionOfFirst();
1407 Tr2 = IP.TransitionOfSecond();
1408 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1409 IP = Seg.LastPoint();
1411 Tr1 = IP.TransitionOfFirst();
1412 Tr2 = IP.TransitionOfSecond();
1413 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1414 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1415 Standard_Real param1 = IP.ParamOnFirst();
1416 Standard_Real param2 = IP.ParamOnSecond();
1417 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, C1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1418 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, C2, param2 );
1419 Standard_Boolean OK1 = Standard_False;
1420 Standard_Boolean OK2 = Standard_False;
1422 for(Standard_Integer j=1; (j<=2)&&!OK1; j++) {
1423 Standard_Real di1 = pi1.SquareDistance (vertexPoints(j));
1424 if(di1 < vertexTolers(j) * vertexTolers(j))
1425 OK1 = Standard_True;
1428 for(Standard_Integer j=3; (j<=4)&&!OK2; j++) {
1429 Standard_Real di2 = pi2.SquareDistance (vertexPoints(j));
1430 if(di2 < vertexTolers(j) * vertexTolers(j))
1431 OK2 = Standard_True;
1435 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1436 points2d.Append ( IP );
1437 points3d.Append ( pint );
1438 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1439 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1442 return LastCheckStatus ( ShapeExtend_DONE );
1445 //=======================================================================
1446 //function : CheckIntersectingEdges
1448 //=======================================================================
1450 Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num1,
1451 const Standard_Integer num2)
1453 IntRes2d_SequenceOfIntersectionPoint points2d;
1454 TColgp_SequenceOfPnt points3d;
1455 TColStd_SequenceOfReal errors;
1456 return CheckIntersectingEdges(num1, num2, points2d, points3d, errors);
1459 //=======================================================================
1460 //function : CheckLacking
1461 //purpose : Test if two edges are disconnected in 2d according to the
1462 // Adaptor_Surface::Resolution
1463 //=======================================================================
1465 Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1466 const Standard_Real Tolerance,
1467 gp_Pnt2d &p2d1, gp_Pnt2d &p2d2)
1469 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1470 if ( ! IsReady() ) return Standard_False;
1472 //szv#4:S4163:12Mar99 optimized
1473 Standard_Integer n2 = (num > 0)? num : NbEdges();
1474 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1475 TopoDS_Edge E1 = myWire->Edge ( n1 );
1476 TopoDS_Edge E2 = myWire->Edge ( n2 );
1478 ShapeAnalysis_Edge sae;
1479 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1480 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1481 // CKY 4 MAR 1998 : protection against null vertex
1482 if ( V1.IsNull() || V2.IsNull() ) {
1483 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1484 return Standard_False;
1486 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1487 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1488 return Standard_False;
1492 gp_Vec2d v1, v2, v12;
1493 Handle(Geom2d_Curve) c2d;
1494 if ( ! sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
1495 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1496 return Standard_False;
1498 Geom2dAdaptor_Curve anAdapt(c2d);
1499 anAdapt.D1(b, p2d1, v1);
1500 if ( E1.Orientation() == TopAbs_REVERSED ) v1.Reverse();
1501 if ( ! sae.PCurve ( E2, myFace, c2d, a, b, Standard_True ) ) {
1502 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1503 return Standard_False;
1506 anAdapt.D1(a, p2d2, v2);
1507 if ( E2.Orientation() == TopAbs_REVERSED ) v2.Reverse();
1508 v12 = p2d2.XY() - p2d1.XY();
1509 myMax2d = v12.SquareMagnitude();
1511 // test like in BRepCheck
1512 Standard_Real tol = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1513 tol = ( Tolerance > gp::Resolution() && Tolerance < tol ? Tolerance : tol );
1514 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1515 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1516 if ( // tol2d < gp::Resolution() || //#2 smh 26.03.99 S4163 Zero divide
1517 myMax2d < tol2d * tol2d ) return Standard_False;
1519 myMax2d = Sqrt ( myMax2d );
1520 myMax3d = tol * myMax2d / Max ( tol2d, gp::Resolution() );
1521 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
1523 if ( myMax2d < Precision::PConfusion() || //:abv 03.06.02 CTS21866.stp
1524 ( v1.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v1 ) ) > 0.9 * M_PI ) ||
1525 ( v2.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v2 ) ) > 0.9 * M_PI ) )
1526 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
1527 return Standard_True;
1530 //=======================================================================
1531 //function : CheckLacking
1534 //=======================================================================
1536 Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1537 const Standard_Real Tolerance)
1540 return CheckLacking (num, Tolerance, p1, p2);
1543 //=======================================================================
1544 //function : CheckOuterBound
1546 //=======================================================================
1548 Standard_Boolean ShapeAnalysis_Wire::CheckOuterBound(const Standard_Boolean APIMake)
1550 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1551 if ( ! IsReady() ) return Standard_False;
1554 if (APIMake) wire = myWire->WireAPIMake();
1555 else wire = myWire->Wire();
1557 TopoDS_Shape sh = myFace.EmptyCopied(); //szv#4:S4163:12Mar99 SGI warns
1558 TopoDS_Face face = TopoDS::Face(sh);
1561 if (ShapeAnalysis::IsOuterBound (face)) return Standard_False;
1562 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1563 return Standard_True;
1566 //=======================================================================
1567 //function : CheckNotchedEdges
1569 //=======================================================================
1571 static Standard_Real ProjectInside(const Adaptor3d_CurveOnSurface AD,
1573 const Standard_Real preci,
1575 Standard_Real& param,
1576 const Standard_Boolean adjustToEnds = Standard_True)
1578 ShapeAnalysis_Curve sac;
1579 Standard_Real dist = sac.Project(AD,pnt,preci,proj,param,adjustToEnds);
1580 Standard_Real uFirst = AD.FirstParameter();
1581 Standard_Real uLast = AD.LastParameter();
1584 proj = AD.Value(uFirst);
1585 return proj.Distance(pnt);
1590 proj = AD.Value(uLast);
1591 return proj.Distance(pnt);
1596 Standard_Boolean ShapeAnalysis_Wire::CheckNotchedEdges(const Standard_Integer num,
1597 Standard_Integer& shortNum,
1598 Standard_Real& param,
1599 const Standard_Real Tolerance)
1601 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1602 if ( ! IsReady() ) return Standard_False;
1604 Standard_Integer n2 = (num > 0)? num : NbEdges();
1605 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1606 TopoDS_Edge E1 = myWire->Edge ( n1 );
1607 TopoDS_Edge E2 = myWire->Edge ( n2 );
1609 if(BRep_Tool::Degenerated(E1)||BRep_Tool::Degenerated(E2))
1610 return Standard_False;
1612 ShapeAnalysis_Edge sae;
1613 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1614 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1616 if ( V1.IsNull() || V2.IsNull() ) {
1617 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1618 return Standard_False;
1620 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1621 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1622 return Standard_False;
1625 Standard_Real a1, b1, a2, b2;
1626 gp_Pnt2d p2d1, p2d2;
1628 Handle(Geom2d_Curve) c2d1, c2d2;
1629 if ( ! sae.PCurve ( E1, myFace, c2d1, a1, b1, Standard_False ) ) {
1630 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1631 return Standard_False;
1634 if(E1.Orientation()==TopAbs_REVERSED)
1635 c2d1->D1 ( a1, p2d1, v1 );
1637 c2d1->D1 ( b1, p2d1, v1 );
1641 if ( ! sae.PCurve ( E2, myFace, c2d2, a2, b2, Standard_False ) ) {
1642 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1643 return Standard_False;
1645 if(E2.Orientation()==TopAbs_REVERSED) {
1646 c2d2->D1 ( b2, p2d2, v2 );
1650 c2d2->D1 ( a2, p2d2, v2 );
1652 if ( v2.Magnitude() < gp::Resolution() || v1.Magnitude() < gp::Resolution())
1653 return Standard_False;
1655 if ( Abs ( v2.Angle ( v1 ) ) > 0.1 || p2d1.Distance(p2d2) > Tolerance)
1656 return Standard_False;
1658 Handle(Geom2dAdaptor_HCurve) AC2d1 = new Geom2dAdaptor_HCurve(c2d1,a1,b1);
1659 Handle(GeomAdaptor_HSurface) AdS1 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1660 Adaptor3d_CurveOnSurface Ad1(AC2d1,AdS1);
1662 Handle(Geom2dAdaptor_HCurve) AC2d2 = new Geom2dAdaptor_HCurve(c2d2,a2,b2);
1663 Handle(GeomAdaptor_HSurface) AdS2 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1664 Adaptor3d_CurveOnSurface Ad2(AC2d2,AdS2);
1666 Adaptor3d_CurveOnSurface longAD, shortAD;
1667 Standard_Real lenP, firstP;
1669 ShapeAnalysis_Curve sac;
1671 gp_Pnt Proj1, Proj2;
1672 Standard_Real param1 = 0., param2 = 0.;
1673 p2d2=c2d2->Value(E2.Orientation()==TopAbs_FORWARD ? b2 : a2);
1674 p2d1=c2d1->Value(E1.Orientation()==TopAbs_FORWARD ? a1 : b1);
1675 Standard_Real dist1 = ProjectInside(Ad1,gp_Pnt(p2d2.X(),p2d2.Y(),0),Tolerance,Proj1,param1,Standard_False);
1676 Standard_Real dist2 = ProjectInside(Ad2,gp_Pnt(p2d1.X(),p2d1.Y(),0),Tolerance,Proj2,param2,Standard_False);
1678 if ( dist1 > Tolerance && dist2 > Tolerance)
1679 return Standard_False;
1681 if (dist1 < dist2 ) {
1699 Standard_Real step = lenP/23;
1700 for (Standard_Integer i = 1; i < 23; i++,firstP+=step) {
1701 Standard_Real d1 = sac.Project(longAD,shortAD.Value(firstP),Tolerance,Proj1,param1);
1702 if (d1 > Tolerance) {
1703 return Standard_False;
1707 return Standard_True;
1710 //=======================================================================
1711 //function : CheckSmallArea
1713 //=======================================================================
1714 Standard_Boolean ShapeAnalysis_Wire::CheckSmallArea(const TopoDS_Wire& theWire,
1715 const Standard_Boolean theIsOuterWire)
1717 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1718 const Standard_Integer aNbControl = 23;
1719 const Standard_Integer NbEdges = myWire->NbEdges();
1720 if ( !IsReady() || NbEdges < 1 )
1721 return Standard_False;
1722 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1724 Standard_Real aF, aL, aLength(0.0);
1725 const Standard_Real anInv = 1.0 / static_cast<Standard_Real>(aNbControl - 1);
1726 gp_XY aCenter2d(0., 0.);
1728 // try to find mid point for closed contour
1729 Handle(Geom2d_Curve) aCurve2d;
1730 for (Standard_Integer j = 1; j <= NbEdges; ++j)
1732 const ShapeAnalysis_Edge anAnalyzer;
1733 if (!anAnalyzer.PCurve(myWire->Edge(j),myFace,aCurve2d,aF,aL))
1735 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1736 return Standard_False;
1739 for (Standard_Integer i = 1; i < aNbControl; ++i)
1741 const Standard_Real aV = anInv * ((aNbControl - 1 - i) * aF+ i * aL);
1742 aCenter2d += aCurve2d->Value(aV).XY();
1745 aCenter2d *= 1.0 / static_cast<Standard_Real>(NbEdges * (aNbControl - 1));
1747 // check approximated area in 3D
1749 gp_XYZ aPrev3d, aCross(0., 0., 0.);
1750 gp_XYZ aCenter(mySurf->Value(aCenter2d.X(), aCenter2d.Y()).XYZ());
1752 Handle(Geom_Curve) aCurve3d;
1753 for (Standard_Integer j = 1; j <= NbEdges; ++j)
1755 const ShapeAnalysis_Edge anAnalizer;
1756 if (!anAnalizer.Curve3d(myWire->Edge(j), aCurve3d, aF, aL))
1758 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1759 return Standard_False;
1762 Standard_Integer aBegin = 0;
1766 aPnt3d = aCurve3d->Value(aF);
1767 aPrev3d = aPnt3d.XYZ() - aCenter;
1769 for (Standard_Integer i = aBegin; i < aNbControl; ++i)
1771 const Standard_Real anU =
1772 anInv * ( (aNbControl - 1 - i) * aF + i * aL );
1773 const gp_Pnt aPnt = aCurve3d->Value(anU);
1774 const gp_XYZ& aCurrent = aPnt.XYZ();
1775 const gp_XYZ aVec = aCurrent - aCenter;
1777 aCross += aPrev3d ^ aVec;
1778 aLength += aPnt3d.Distance(aPnt);
1785 Standard_Real aTolerance = aLength * myPrecision;
1786 if ( aCross.Modulus() < aTolerance )
1788 // check real area in 3D
1789 GProp_GProps aProps;
1790 GProp_GProps aLProps;
1793 BRepGProp::SurfaceProperties(myFace, aProps);
1794 BRepGProp::LinearProperties(myFace, aLProps);
1798 BRepBuilderAPI_MakeFace aFace(mySurf->Surface(), theWire);
1799 BRepGProp::SurfaceProperties(aFace.Face(), aProps);
1800 BRepGProp::LinearProperties(aFace.Face(), aLProps);
1803 Standard_Real aNewTolerance = aLProps.Mass() * myPrecision;
1804 if ( aProps.Mass() < 0.5 * aNewTolerance )
1806 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1807 return Standard_True;
1811 return Standard_False;
1814 //=======================================================================
1815 //function : CheckShapeConnect
1817 //=======================================================================
1819 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(const TopoDS_Shape& shape,const Standard_Real prec)
1821 Standard_Real tailhead, tailtail, headhead, headtail;
1822 return CheckShapeConnect (tailhead, tailtail, headtail, headhead, shape, prec);
1825 //=======================================================================
1826 //function : CheckShapeConnect
1828 //=======================================================================
1830 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(Standard_Real& tailhead, Standard_Real& tailtail,
1831 Standard_Real& headtail, Standard_Real& headhead,
1832 const TopoDS_Shape& shape, const Standard_Real prec)
1834 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1835 if (!IsLoaded () || shape.IsNull()) return Standard_False;
1836 TopoDS_Vertex V1,V2;
1837 TopoDS_Edge E; TopoDS_Wire W;
1838 ShapeAnalysis_Edge SAE;
1839 if (shape.ShapeType() == TopAbs_EDGE) {
1840 E = TopoDS::Edge (shape);
1841 V1 = SAE.FirstVertex (E); V2 = SAE.LastVertex (E);
1842 } else if (shape.ShapeType() == TopAbs_WIRE) {
1843 W = TopoDS::Wire (shape);
1844 ShapeAnalysis::FindBounds (W,V1,V2);
1846 else return Standard_False;
1847 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1848 // on va comparer les points avec ceux de thevfirst et thevlast
1849 gp_Pnt p1 = BRep_Tool::Pnt(V1);
1850 gp_Pnt p2 = BRep_Tool::Pnt(V2);
1852 TopoDS_Vertex vfirst = SAE.FirstVertex (myWire->Edge (1)),
1853 vlast = SAE.LastVertex (myWire->Edge (NbEdges()));
1854 gp_Pnt pf = BRep_Tool::Pnt(vfirst);
1855 gp_Pnt pl = BRep_Tool::Pnt(vlast);
1857 tailhead = p1.Distance(pl);
1858 tailtail = p2.Distance(pl);
1859 headhead = p1.Distance(pf);
1860 headtail = p2.Distance(pf);
1861 Standard_Real dm1 = tailhead, dm2 = headtail;
1862 Standard_Integer res1 = 0, res2 = 0;
1864 if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
1865 if (headtail > headhead) {res2 = 1; dm2 = headhead;}
1866 Standard_Integer result = res1;
1867 myMin3d = Min (dm1, dm2);
1868 myMax3d = Max (dm1, dm2);
1869 if (dm1 > dm2) {dm1 = dm2; result = res2 + 2;}
1871 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
1872 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
1873 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
1875 if (!res1) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
1876 if (!res2) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
1878 if (myMin3d > Max (myPrecision, prec))
1879 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1880 return LastCheckStatus (ShapeExtend_DONE);
1883 //=======================================================================
1884 //function : CheckLoop
1886 //=======================================================================
1887 Standard_Boolean isMultiVertex(const TopTools_ListOfShape& alshape,
1888 const TopTools_MapOfShape& aMapSmallEdges,
1889 const TopTools_MapOfShape& aMapSeemEdges)
1891 TopTools_ListIteratorOfListOfShape lIt1(alshape);
1892 Standard_Integer nbNotAccount =0;
1894 for( ; lIt1.More() ; lIt1.Next())
1896 if(aMapSmallEdges.Contains(lIt1.Value()))
1898 else if(aMapSeemEdges.Contains(lIt1.Value()))
1901 return ((alshape.Extent() -nbNotAccount) >2);
1903 Standard_Boolean ShapeAnalysis_Wire::CheckLoop(TopTools_IndexedMapOfShape& aMapLoopVertices,
1904 TopTools_DataMapOfShapeListOfShape& aMapVertexEdges,
1905 TopTools_MapOfShape& aMapSmallEdges,
1906 TopTools_MapOfShape& aMapSeemEdges)
1908 myStatus = ShapeExtend::EncodeStatus(ShapeExtend_OK);
1909 if (!IsLoaded() || NbEdges() < 2) return Standard_False;
1910 Standard_Real aSavPreci = Precision();
1911 SetPrecision(Precision::Infinite());
1912 Standard_Integer i =1;
1914 for( ; i <= myWire->NbEdges(); i++) {
1915 TopoDS_Edge aedge = myWire->Edge(i);
1916 TopoDS_Vertex aV1,aV2;
1917 TopExp::Vertices(aedge,aV1,aV2);
1918 if (aV1.IsNull() || aV2.IsNull())
1920 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1921 return Standard_False;
1923 Standard_Boolean isSame = aV1.IsSame(aV2);
1924 if(myWire->IsSeam(i))
1925 aMapSeemEdges.Add(aedge); ///continue;
1926 else if(BRep_Tool::Degenerated(aedge))
1927 aMapSmallEdges.Add(aedge);
1928 else if(isSame && CheckSmall(i,BRep_Tool::Tolerance(aV1)))
1929 aMapSmallEdges.Add(aedge);
1931 if(!aMapVertexEdges.IsBound(aV1)) {
1932 TopTools_ListOfShape alshape;
1933 aMapVertexEdges.Bind(aV1,alshape);
1935 if(!aMapVertexEdges.IsBound(aV2)) {
1936 TopTools_ListOfShape alshape;
1937 aMapVertexEdges.Bind(aV2,alshape);
1941 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1942 alshape.Append(aedge);
1943 alshape.Append(aedge);
1944 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1945 aMapLoopVertices.Add(aV1);
1948 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1949 alshape.Append(aedge);
1950 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1951 aMapLoopVertices.Add(aV1);
1952 TopTools_ListOfShape& alshape2 = aMapVertexEdges.ChangeFind(aV2);
1953 alshape2.Append(aedge);
1954 if(alshape2.Extent() >2 && isMultiVertex( alshape2,aMapSmallEdges,aMapSeemEdges))
1955 aMapLoopVertices.Add(aV2);
1958 SetPrecision(aSavPreci);
1959 if(aMapLoopVertices.Extent())
1961 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1962 myStatusLoop |= myStatus;
1963 return Standard_True;
1965 return Standard_False;