1 // Created on: 1995-12-12
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by dpf, Fri Dec 19 15:31:03 1997
18 // Processing of closing in 2d.
19 // modified by eap Tue Dec 18 14:14:25 2001 (bug OCC23)
20 // Check self-intersection in case of closed edge
21 // modified by eap Fri Dec 21 17:36:55 2001 (bug OCC35)
23 // Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764
25 #include <Bnd_Array1OfBox2d.hxx>
26 #include <BndLib_Add2dCurve.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <BRepAdaptor_HSurface.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepCheck.hxx>
32 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
33 #include <BRepCheck_ListOfStatus.hxx>
34 #include <BRepCheck_Wire.hxx>
35 #include <BRepTools_WireExplorer.hxx>
37 #include <Geom2d_Curve.hxx>
38 #include <Geom2dAdaptor_Curve.hxx>
39 #include <Geom2dAdaptor_HCurve.hxx>
40 #include <Geom2dInt_GInter.hxx>
41 #include <Geom_Curve.hxx>
44 #include <gp_Pnt2d.hxx>
45 #include <IntRes2d_Domain.hxx>
46 #include <IntRes2d_Intersection.hxx>
47 #include <IntRes2d_IntersectionPoint.hxx>
48 #include <IntRes2d_IntersectionSegment.hxx>
49 #include <IntRes2d_Transition.hxx>
50 #include <Precision.hxx>
51 #include <Standard_Type.hxx>
52 #include <TColGeom2d_Array1OfCurve.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopLoc_Location.hxx>
57 #include <TopoDS_Edge.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Iterator.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Wire.hxx>
63 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
64 #include <TopTools_DataMapOfShapeListOfShape.hxx>
65 #include <TopTools_HArray1OfShape.hxx>
66 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
67 #include <TopTools_IndexedMapOfOrientedShape.hxx>
68 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
72 #include <TopTools_MapIteratorOfMapOfShape.hxx>
73 #include <TopTools_MapOfOrientedShape.hxx>
74 #include <TopTools_MapOfShape.hxx>
77 IMPLEMENT_STANDARD_RTTIEXT(BRepCheck_Wire,BRepCheck_Result)
79 static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape&,
80 const TopoDS_Shape&, // edge
81 TopTools_MapOfShape&); // mapofedge
84 static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape&,
89 void ChoixUV(const TopoDS_Vertex&,
92 TopTools_ListOfShape&);
94 // 20/03/02 akm vvv (OCC234)
96 // Standard_Boolean CheckLoopOrientation( const TopoDS_Vertex&,
97 // const TopoDS_Edge&,
98 // const TopoDS_Edge&,
99 // const TopoDS_Face&,
100 // TopTools_ListOfShape&);
103 inline Standard_Boolean IsOriented(const TopoDS_Shape& S)
105 return (S.Orientation() == TopAbs_FORWARD ||
106 S.Orientation() == TopAbs_REVERSED);
110 void CurveDirForParameter(const Geom2dAdaptor_Curve& aC2d,
111 const Standard_Real aPrm,
115 // Modified by Sergey KHROMOV - Thu Jun 20 11:21:51 2002 OCC325 Begin
116 static Standard_Boolean IsClosed2dForPeriodicFace
117 (const TopoDS_Face &theFace,
118 const gp_Pnt2d &theP1,
119 const gp_Pnt2d &theP2,
120 const TopoDS_Vertex &theVertex);
122 static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
123 const TopoDS_Edge &theEdge,
124 const TopoDS_Face &theFace,
126 // Modified by Sergey KHROMOV - Wed May 22 10:44:08 2002 End
128 //=======================================================================
129 //function : BRepCheck_Wire
131 //=======================================================================
132 BRepCheck_Wire::BRepCheck_Wire(const TopoDS_Wire& W)
136 //=======================================================================
139 //=======================================================================
140 void BRepCheck_Wire::Minimum()
142 myCdone = Standard_False;
143 myGctrl = Standard_True;
145 BRepCheck_ListOfStatus thelist;
146 myMap.Bind(myShape, thelist);
147 BRepCheck_ListOfStatus& lst = myMap(myShape);
149 // check that the wire is "connex"
150 TopExp_Explorer exp(myShape,TopAbs_EDGE);
151 Standard_Integer nbedge = 0;
154 for (; exp.More(); exp.Next()) {
156 TopExp_Explorer expv;
157 for (expv.Init(exp.Current(),TopAbs_VERTEX);
158 expv.More(); expv.Next()) {
159 const TopoDS_Shape& vtx = expv.Current();
160 Standard_Integer index = myMapVE.FindIndex(vtx);
162 TopTools_ListOfShape theListOfShape;
163 index = myMapVE.Add(vtx, theListOfShape);
165 myMapVE(index).Append(exp.Current());
168 // wire must have at least one edge
170 BRepCheck::Add(lst,BRepCheck_EmptyWire);
172 // check if all edges are connected through vertices
173 else if (nbedge >= 2) {
174 TopTools_MapOfShape mapE;
176 Propagate(myMapVE,exp.Current(),mapE);
177 for (exp.ReInit(); exp.More(); exp.Next()) {
178 if (!mapE.Contains(exp.Current())) {
179 BRepCheck::Add(lst,BRepCheck_NotConnected);
185 lst.Append(BRepCheck_NoError);
188 myMin = Standard_True;
191 //=======================================================================
192 //function : InContext
194 //=======================================================================
195 void BRepCheck_Wire::InContext(const TopoDS_Shape& S)
198 if (myMap.IsBound(S)) {
201 BRepCheck_ListOfStatus thelist;
202 myMap.Bind(S, thelist);
204 BRepCheck_ListOfStatus& lst = myMap(S);
206 // check if my wire is in <S>
207 TopExp_Explorer exp(S,TopAbs_WIRE);
208 for ( ; exp.More(); exp.Next()) {
209 if (exp.Current().IsSame(myShape)) {
214 BRepCheck::Add(lst,BRepCheck_SubshapeNotInShape);
218 BRepCheck_Status st = BRepCheck_NoError;
219 TopAbs_ShapeEnum styp = S.ShapeType();
226 st = SelfIntersect(TopoDS::Face(S),ed1,ed2,Standard_True);
227 if (st != BRepCheck_NoError) break;
229 if (st != BRepCheck_NoError) break;
230 st = Orientation(TopoDS::Face(S));
231 if (st != BRepCheck_NoError) break;
232 st = Closed2d(TopoDS::Face(S));
239 if (st != BRepCheck_NoError)
240 BRepCheck::Add(lst,st);
243 lst.Append(BRepCheck_NoError);
245 //=======================================================================
248 //=======================================================================
249 void BRepCheck_Wire::Blind()
252 // nothing more that the minimum
253 myBlind = Standard_True;
256 //=======================================================================
259 //=======================================================================
260 BRepCheck_Status BRepCheck_Wire::Closed(const Standard_Boolean Update)
265 BRepCheck::Add(myMap(myShape),myCstat);
270 myCdone = Standard_True;
272 BRepCheck_ListIteratorOfListOfStatus itl(myMap(myShape));
273 if (itl.Value() != BRepCheck_NoError) {
274 myCstat = itl.Value();
275 return myCstat; // already saved
278 myCstat = BRepCheck_NoError;
280 TopExp_Explorer exp,expv;
281 TopTools_MapOfShape mapS;
282 TopTools_DataMapOfShapeListOfShape Cradoc;
284 // Checks if the oriented edges of the wire give a "closed" wire,
285 // i-e if each oriented vertex on oriented edges is found 2 times...
287 for (exp.Init(myShape,TopAbs_EDGE);exp.More(); exp.Next()) {
288 if (IsOriented(exp.Current())) {
290 if (!Cradoc.IsBound(exp.Current())) {
291 TopTools_ListOfShape theListOfShape;
292 Cradoc.Bind(exp.Current(), theListOfShape);
294 Cradoc(exp.Current()).Append(exp.Current());
296 mapS.Add(exp.Current());
297 for (expv.Init(exp.Current(),TopAbs_VERTEX); expv.More(); expv.Next()) {
298 if (IsOriented(expv.Current())) {
299 Standard_Integer index = myMapVE.FindIndex(expv.Current());
301 TopTools_ListOfShape theListOfShape1;
302 index = myMapVE.Add(expv.Current(), theListOfShape1);
304 myMapVE(index).Append(exp.Current());
310 Standard_Integer theNbori = mapS.Extent();
313 for (exp.ReInit(); exp.More(); exp.Next()) {
314 if (IsOriented(exp.Current())) {
318 Propagate(myMapVE,exp.Current(),mapS);
320 if (theNbori != mapS.Extent()) {
321 myCstat = BRepCheck_NotConnected;
323 BRepCheck::Add(myMap(myShape),myCstat);
328 // Checks the number of occurence of an edge : maximum 2, and in this
329 // case, one time FORWARD and one time REVERSED
331 Standard_Boolean yabug = Standard_False;
332 for (TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm(Cradoc);
333 itdm.More(); itdm.Next()) {
334 if (itdm.Value().Extent() >= 3) {
335 yabug = Standard_True;
337 else if (itdm.Value().Extent() == 2) {
338 if (itdm.Value().First().Orientation() ==
339 itdm.Value().Last().Orientation()) {
340 yabug = Standard_True;
344 myCstat = BRepCheck_RedundantEdge;
346 BRepCheck::Add(myMap(myShape),myCstat);
352 for (Standard_Integer i = 1; i<= myMapVE.Extent(); i++) {
353 if (myMapVE(i).Extent()%2 != 0) {
354 myCstat=BRepCheck_NotClosed;
356 BRepCheck::Add(myMap(myShape),myCstat);
363 BRepCheck::Add(myMap(myShape),myCstat);
368 //=======================================================================
369 //function : IsDistanceIn3DTolerance
370 //purpose : Return Standard_True if distance between thePnt_f and
371 // thePnt_l is not more, than aTol3d
372 //=======================================================================
373 Standard_Boolean IsDistanceIn3DTolerance (const gp_Pnt& thePnt_f,
374 const gp_Pnt& thePnt_l,
375 const Standard_Real aTol3d)
377 Standard_Real Dist = thePnt_f.Distance(thePnt_l);
380 return Standard_True;
384 cout << "--------Function IsDistanceIn3DTolerance(...)----------" << endl;
385 cout << "--- BRepCheck Wire: Closed3d -> Error" << endl;
386 cout << "--- Dist (" << Dist << ") > Tol3d (" << aTol3d << ")" << endl;
387 cout << "Pnt1(" << thePnt_f.X() << "; " << thePnt_f.Y() << "; " << thePnt_f.Z() << ")" << endl;
388 cout << "Pnt2(" << thePnt_l.X() << "; " << thePnt_l.Y() << "; " << thePnt_l.Z() << ")" << endl;
389 cout << "------------------------------------------------------" << endl;
392 return Standard_False;
395 //=======================================================================
396 //function : IsDistanceIn2DTolerance
398 //=======================================================================
400 Standard_Boolean IsDistanceIn2DTolerance (const BRepAdaptor_Surface& aFaceSurface,
401 const gp_Pnt2d& thePnt,
402 const gp_Pnt2d& thePntRef,
403 const Standard_Real aTol3d,
405 const Standard_Boolean PrintWarnings = Standard_True)
407 const Standard_Boolean = Standard_True)
410 Standard_Real dumax = 0.01 * (aFaceSurface.LastUParameter() - aFaceSurface.FirstUParameter());
411 Standard_Real dvmax = 0.01 * (aFaceSurface.LastVParameter() - aFaceSurface.FirstVParameter());
412 Standard_Real dumin = Abs(thePnt.X() - thePntRef.X());
413 Standard_Real dvmin = Abs(thePnt.Y() - thePntRef.Y());
415 if((dumin < dumax) && (dvmin < dvmax))
416 return Standard_True;
422 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
423 cout << "--- BRepCheck Wire: Not closed in 2D" << endl;
424 cout << "*****************************************************" << endl;
425 cout << "*dumin = " << dumin << "; dumax = " << dumax << endl;
426 cout << "* dvmin = " << dvmin << "; dvmax = " << dvmax << endl;
427 cout << "* (dumin > dumax) or (dvmin > dvmax)." << endl;
428 cout << "*****************************************************" << endl;
430 cout << "UFirst = " << aFaceSurface.FirstUParameter();
431 cout << "; ULast = " << aFaceSurface.LastUParameter() << endl;
432 cout << "VFirst = " << aFaceSurface.FirstVParameter();
433 cout << "; VLast = " << aFaceSurface.LastVParameter() << endl;
436 dumax = aFaceSurface.UResolution(aTol3d);
437 dvmax = aFaceSurface.VResolution(aTol3d);
440 Standard_Real um = (thePnt.X() + thePntRef.X()) / 2.;
441 Standard_Real vm = (thePnt.Y() + thePntRef.Y()) / 2.;
442 aFaceSurface.D1(um, vm, aP, aDU, aDV);
443 Standard_Real aMDU = aDU.Magnitude();
444 if (aMDU > Precision::Confusion())
446 dumax = Max((aTol3d / aMDU), dumax);
448 Standard_Real aMDV = aDV.Magnitude();
449 if (aMDV > Precision::Confusion())
451 dvmax = Max((aTol3d / aMDV), dvmax);
457 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
458 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
459 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
463 Standard_Real aTol2d = 2*Max( dumax, dvmax);
466 if((aTol2d <= 0.0) && (PrintWarnings))
468 cout<<"BRepCheck_Wire : UResolution and VResolution = 0.0 (Face too small ?)"<<endl;
473 Standard_Real Dist = Max(dumin, dvmin);
476 return Standard_True;
482 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
483 cout << "--- BRepCheck Wire: Not closed in 2d" << endl;
484 cout << "*****************************************************" << endl;
485 cout << "* Dist = " << Dist << " > Tol2d = " << aTol2d << endl;
486 cout << "*****************************************************" << endl;
487 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
488 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
489 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
493 return Standard_False;
496 //=======================================================================
497 //function : Closed2d
498 //purpose : for periodic faces
499 //=======================================================================
500 BRepCheck_Status BRepCheck_Wire::Closed2d(const TopoDS_Face& theFace,
501 const Standard_Boolean Update)
503 // 3d closure checked too
504 BRepCheck_Status aClosedStat = Closed();
505 if (aClosedStat != BRepCheck_NoError)
508 BRepCheck::Add(myMap(myShape),aClosedStat);
513 // 20/03/02 akm vvv : (OCC234) Hence this method will be used to check
514 // both periodic and non-periodic faces
515 // // this check is for periodic faces
516 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
517 // if (!aFaceSurface.IsUPeriodic() && !aFaceSurface.IsVPeriodic())
520 // BRepCheck::Add(myMap(myShape),aClosedStat);
521 // return aClosedStat;
525 // count edges having FORWARD or REVERSED orientation
526 Standard_Integer aNbOrirntedEdges = 0;
527 TopExp_Explorer anEdgeExp(myShape,TopAbs_EDGE);
528 for (;anEdgeExp.More(); anEdgeExp.Next())
530 if (IsOriented(anEdgeExp.Current()))
534 if (aNbOrirntedEdges==0)
537 BRepCheck::Add(myMap(myShape),aClosedStat);
542 // all those edges must form a closed 2d contour and be found by WireExplorer
544 Standard_Integer aNbFoundEdges = 0;
545 BRepTools_WireExplorer aWireExp(TopoDS::Wire(myShape), theFace);
546 TopoDS_Edge aFirstEdge = aWireExp.Current();
547 TopoDS_Vertex aFirstVertex = aWireExp.CurrentVertex();
548 TopoDS_Edge aLastEdge;
550 for (;aWireExp.More(); aWireExp.Next())
553 aLastEdge = aWireExp.Current();
556 if (aNbFoundEdges != aNbOrirntedEdges)
558 aClosedStat = BRepCheck_NotClosed;
560 BRepCheck::Add(myMap(myShape),aClosedStat);
565 // Check distance between 2d ends of first and last edges
566 // Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 Begin
567 // First check if first and last edges are infinite:
570 Standard_Boolean isFirstInfinite = Standard_False;
571 Standard_Boolean isLastInfinite = Standard_False;
572 TopAbs_Orientation anOri;
574 anOri = aFirstEdge.Orientation();
575 BRep_Tool::Range(aFirstEdge, aF, aL);
576 if ((anOri == TopAbs_FORWARD && Precision::IsNegativeInfinite( aF )) ||
577 (anOri == TopAbs_REVERSED && Precision::IsPositiveInfinite( aL )))
578 isFirstInfinite = Standard_True;
580 anOri = aLastEdge.Orientation();
581 BRep_Tool::Range(aLastEdge, aF, aL);
583 if ((anOri == TopAbs_FORWARD && Precision::IsPositiveInfinite( aL )) ||
584 (anOri == TopAbs_REVERSED && Precision::IsNegativeInfinite( aF )))
585 isLastInfinite = Standard_True;
587 if (isFirstInfinite && isLastInfinite)
590 BRepCheck::Add(myMap(myShape),aClosedStat);
594 else if (aFirstVertex.IsNull())
596 aClosedStat = BRepCheck_NotClosed;
599 BRepCheck::Add(myMap(myShape),aClosedStat);
603 // Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 End
605 gp_Pnt2d aP_first, aP_last, aP_temp; // ends of prev edge, next edge, bidon
608 BRep_Tool::UVPoints(aLastEdge, theFace, aP_temp, aP_last);
609 if (aLastEdge.Orientation() == TopAbs_REVERSED)
612 // Modified by Sergey KHROMOV - Mon Apr 22 10:36:33 2002 Begin
613 // Standard_Real aTol, aUResol, aVResol;
614 // // find 2d tolerance
615 // aTol = BRep_Tool::Tolerance(aFirstVertex);
616 // aUResol = 2*aFaceSurface.UResolution(aTol);
617 // aVResol = 2*aFaceSurface.VResolution(aTol);
620 if (aFirstEdge.Orientation() == TopAbs_REVERSED)
621 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_temp, aP_first);
623 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_first, aP_temp);
625 // Modified by Sergey KHROMOV - Thu Jun 20 10:55:42 2002 OCC325 Begin
626 // Check 2d distance for periodic faces with seam edge
627 if (!IsClosed2dForPeriodicFace(theFace, aP_first, aP_last, aFirstVertex))
629 aClosedStat = BRepCheck_NotClosed;
631 BRepCheck::Add(myMap(myShape),aClosedStat);
635 // Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End
638 // Standard_Real dfUDist=Abs(p.X()-p1.X());
639 // Standard_Real dfVDist=Abs(p.Y()-p1.Y());
640 // if (dfUDist > aUResol || dfVDist > aVResol)
643 Standard_Real aTol3d = Max(BRep_Tool::Tolerance(aFirstVertex),BRep_Tool::Tolerance(aWireExp.CurrentVertex()));
645 gp_Pnt aPntRef = BRep_Tool::Pnt(aFirstVertex);
646 gp_Pnt aPnt = BRep_Tool::Pnt(aWireExp.CurrentVertex());
648 if (!(IsDistanceIn2DTolerance(aFaceSurface, aP_first, aP_last, aTol3d)))
649 aClosedStat = BRepCheck_NotClosed;
651 if(!IsDistanceIn3DTolerance(aPntRef, aPnt, aTol3d))
652 aClosedStat = BRepCheck_NotClosed;
655 BRepCheck::Add(myMap(myShape),aClosedStat);
659 //=======================================================================
660 //function : Orientation
662 //=======================================================================
663 BRepCheck_Status BRepCheck_Wire::Orientation(const TopoDS_Face& F,
664 const Standard_Boolean Update)
666 BRepCheck_Status theOstat = Closed();
667 if (theOstat != BRepCheck_NotClosed && theOstat != BRepCheck_NoError) {
669 BRepCheck::Add(myMap(myShape),theOstat);
674 theOstat = BRepCheck_NoError;
677 TopAbs_Orientation orient, ortmp = TopAbs_FORWARD;
678 TopTools_ListOfShape ledge, ListOfPassedEdge;
679 TopExp_Explorer exp,vte;
680 TopTools_MapOfShape mapS;
681 TopoDS_Edge theEdge,theRef;
683 // Checks the orientation of the edges
684 for (exp.Init(myShape,TopAbs_EDGE); exp.More(); exp.Next()) {
685 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
686 orient = edg.Orientation();
687 if (IsOriented(edg)) {
691 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
692 TopAbs_Orientation vto = vte.Current().Orientation();
693 if (vto == TopAbs_FORWARD) {
694 VF = TopoDS::Vertex(vte.Current());
696 else if (vto == TopAbs_REVERSED) {
697 VL = TopoDS::Vertex(vte.Current());
699 if (!VF.IsNull() && !VL.IsNull()) {
703 if (VF.IsNull() && VL.IsNull())
704 theOstat = BRepCheck_InvalidDegeneratedFlag;
709 if (theOstat == BRepCheck_NoError) {
710 Standard_Integer Index = 1;
711 Standard_Integer nbOriNoDegen=myMapVE.Extent();
712 // Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 Begin
713 Standard_Boolean isGoFwd = Standard_True;
716 isGoFwd = Standard_False;
717 // Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 End
719 while (Index < nbOriNoDegen) {
721 ListOfPassedEdge.Clear();
722 // find edges that make a chain on VL if !VL.IsNull
725 Standard_Integer ind;
727 ind = myMapVE.FindIndex(VL);
729 else if (!VF.IsNull()) {
730 ind = myMapVE.FindIndex(VF);
733 theOstat = BRepCheck_InvalidDegeneratedFlag;
737 for (TopTools_ListIteratorOfListOfShape itls(myMapVE(ind));
738 itls.More(); itls.Next()) {
739 const TopoDS_Edge & edg = TopoDS::Edge(itls.Value());
741 orient = edg.Orientation();
742 if (mapS.Contains(edg)) ortmp = GetOrientation(mapS,edg);
744 //Add to list already passed outcoming edges
745 if (mapS.Contains(edg) && ortmp == orient && !edg.IsSame(theEdge))
746 for (vte.Init(edg,TopAbs_VERTEX); vte.More(); vte.Next())
748 TopAbs_Orientation vto = vte.Current().Orientation();
751 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current()))
753 ListOfPassedEdge.Append(edg);
757 else // VF is not null
759 if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current()))
761 ListOfPassedEdge.Append(edg);
767 if (!mapS.Contains(edg) || ortmp != orient) {
768 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
769 TopAbs_Orientation vto = vte.Current().Orientation();
771 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current())) {
772 // If the processing is in 2d (face not null) or
773 // if the edge is not degenerated it is added
774 if (!F.IsNull() || !BRep_Tool::Degenerated(edg))
779 else { // VF is not null
780 if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current())) {
781 // // If the processing is in 2d (face not null) or
782 // if the edge is not degenerated it is added
783 if (!F.IsNull() || !BRep_Tool::Degenerated(edg))
791 Standard_Integer nbconnex = ledge.Extent();
792 Standard_Boolean Changedesens = Standard_False;
794 if (myCstat == BRepCheck_NotClosed) {
797 BRepCheck::Add(myMap(myShape),theOstat);
799 return theOstat; // leave
802 Index--; // because after Index++ and if there is no chain,
803 VL.Nullify(); // chain on VF is forced
805 Changedesens = Standard_True;
809 theOstat = BRepCheck_BadOrientationOfSubshape;
811 BRepCheck::Add(myMap(myShape),theOstat);
817 // JAG 03/07 else if (nbconnex >= 2 && !F.IsNull()) // Try to see in 2d
818 else if (!F.IsNull()) { // Try to see in 2d
827 ChoixUV(pivot,theEdge,F,ledge);
828 nbconnex = ledge.Extent();
829 // 20/03/02 akm vvv : (OCC234) - The 2d exploration of wire with necessary
830 // checks is performed in Closed2d, here it's useless
831 // if (nbconnex == 1 && !CheckLoopOrientation( pivot, theEdge, TopoDS::Edge(ledge.First()), F, ListOfPassedEdge ))
833 // theOstat = BRepCheck_BadOrientationOfSubshape;
835 // BRepCheck::Add(myMap(myShape),theOstat);
842 theOstat = BRepCheck_BadOrientationOfSubshape;
844 BRepCheck::Add(myMap(myShape),theOstat);
848 else if (nbconnex == 1) {
850 for (vte.Init(ledge.First(),TopAbs_VERTEX);vte.More(); vte.Next()) {
851 TopAbs_Orientation vto = vte.Current().Orientation();
853 if (vto == TopAbs_REVERSED) {
854 VL = TopoDS::Vertex(vte.Current());
858 else { // VF is not null
859 if (vto == TopAbs_FORWARD) {
860 VF = TopoDS::Vertex(vte.Current());
865 mapS.Add(ledge.First());
866 theEdge = TopoDS::Edge(ledge.First());
876 else if (!Changedesens) { //nbconnex == 0
877 theOstat = BRepCheck_NotClosed;
879 BRepCheck::Add(myMap(myShape),theOstat);
884 // Check the closure of the wire in 2d (not done in Closed())
887 Standard_Boolean isCheckClose = Standard_False;
889 if (isGoFwd && !VF.IsNull()) {
891 isCheckClose = Standard_True;
892 } else if (!isGoFwd && !VL.IsNull()) {
894 isCheckClose = Standard_True;
897 // if (Index==1 && myCstat!=BRepCheck_NotClosed &&
898 // !VF.IsNull() && !F.IsNull()) {
899 if (Index==1 && myCstat!=BRepCheck_NotClosed &&
900 isCheckClose && !F.IsNull()) {
902 // ind = myMapVE.FindIndex(VF);
903 ind = myMapVE.FindIndex(aVRef);
904 for (TopTools_ListIteratorOfListOfShape itlsh(myMapVE(ind));
905 itlsh.More(); itlsh.Next()) {
906 const TopoDS_Edge & edg = TopoDS::Edge(itlsh.Value());
907 orient = edg.Orientation();
908 if (!theRef.IsSame(edg)) {
909 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
910 TopAbs_Orientation vto = vte.Current().Orientation();
911 // if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current())) {
912 if (vto == TopAbs_REVERSED && aVRef.IsSame(vte.Current())) {
919 // ChoixUV(VF, theRef, F, ledge);
920 ChoixUV(aVRef, theRef, F, ledge);
921 if (ledge.Extent()==0) {
922 theOstat = BRepCheck_NotClosed;
924 BRepCheck::Add(myMap(myShape),theOstat);
929 // End control closure 2d
935 BRepCheck::Add(myMap(myShape),theOstat);
939 //=======================================================================
940 //function : SelfIntersect
942 //=======================================================================
943 BRepCheck_Status BRepCheck_Wire::SelfIntersect(const TopoDS_Face& F,
946 const Standard_Boolean Update)
950 Standard_Integer i,j,Nbedges;
951 Standard_Real first1,last1,first2,last2, tolint;
952 gp_Pnt2d pfirst1,plast1,pfirst2,plast2;
954 Handle(BRepAdaptor_HSurface) HS;
955 Geom2dAdaptor_Curve C1, C2;
956 Geom2dInt_GInter Inter;
957 IntRes2d_Domain myDomain1;
958 TopTools_IndexedMapOfOrientedShape EMap;
959 TopTools_MapOfOrientedShape auxmape;
961 //-- check with proper tolerances if there is no
962 //-- point in the tolerance of a vertex.
964 HS = new BRepAdaptor_HSurface();
965 HS->ChangeSurface().Initialize(F,Standard_False);
967 for (TopoDS_Iterator Iter1(myShape);Iter1.More();Iter1.Next()) {
968 if (Iter1.Value().ShapeType() == TopAbs_EDGE) {
969 EMap.Add(Iter1.Value());
973 Nbedges=EMap.Extent();
976 BRepCheck::Add(myMap(myShape),BRepCheck_EmptyWire);
978 return(BRepCheck_EmptyWire);
981 IntRes2d_Domain *tabDom = new IntRes2d_Domain[Nbedges];
982 TColGeom2d_Array1OfCurve tabCur(1,Nbedges);
983 Bnd_Array1OfBox2d boxes(1,Nbedges);
985 for(i = 1; i <= Nbedges; i++) {
986 const TopoDS_Edge& E1 = TopoDS::Edge(EMap.FindKey(i));
988 Handle(Geom2d_Curve) pcu = BRep_Tool::CurveOnSurface(E1, F, first1, last1);
992 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
995 return(BRepCheck_SelfIntersectingWire);
999 // To avoid exeption in Segment if C1 is BSpline - IFV
1000 if(!C1.IsPeriodic()) {
1001 if(C1.FirstParameter() > first1) {
1002 first1 = C1.FirstParameter();
1004 if(C1.LastParameter() < last1 ){
1005 last1 = C1.LastParameter();
1009 BRep_Tool::UVPoints(E1, F, pfirst1, plast1);
1010 myDomain1.SetValues(pfirst1,first1,tolint, plast1,last1,tolint);
1012 BndLib_Add2dCurve::Add(C1, first1, last1, Precision::PConfusion(), boxes(i));
1016 myDomain1 = tabDom[i-1];
1019 // Self intersect of C1
1020 Inter.Perform(C1, myDomain1, tolint, tolint);
1022 if(Inter.IsDone()) {
1023 Standard_Integer nbp = Inter.NbPoints();
1024 //Standard_Integer nbs = Inter.NbSegments();
1026 for(Standard_Integer p=1;p<=nbp;p++) {
1027 const IntRes2d_IntersectionPoint& IP=Inter.Point(p);
1028 const IntRes2d_Transition& Tr1 = IP.TransitionOfFirst();
1029 const IntRes2d_Transition& Tr2 = IP.TransitionOfSecond();
1030 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1031 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
1032 //-- Checking of points with true tolerances (ie Tol in 3d)
1033 //-- If the point of intersection is within the tolearnce of a vertex
1034 //-- this intersection is considered correct (no error)
1035 Standard_Boolean localok = Standard_False;
1038 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f,l);
1039 if(!ConS.IsNull()) {
1040 //-- try to test in 3d. (ParamOnSecond gives the same result)
1041 P3d = ConS->Value(IP.ParamOnFirst());
1042 P3d.Transform(L.Transformation());
1043 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1046 gp_Pnt2d aP2d = C1.Value(IP.ParamOnFirst());
1047 P3d = HS->Value(aP2d.X(), aP2d.Y());
1049 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1050 TopExp_Explorer ExplVtx;
1051 for(ExplVtx.Init(E1,TopAbs_VERTEX);
1052 localok==Standard_False && ExplVtx.More();
1055 Standard_Real tolvtt, p3dvttDistanceP3d;
1057 const TopoDS_Vertex& vtt = TopoDS::Vertex(ExplVtx.Current());
1058 p3dvtt = BRep_Tool::Pnt(vtt);
1059 tolvtt = BRep_Tool::Tolerance(vtt);
1060 tolvtt=tolvtt*tolvtt;
1061 p3dvttDistanceP3d=p3dvtt.SquareDistance(P3d);
1062 if(p3dvttDistanceP3d <= tolvtt) {
1063 localok=Standard_True;
1066 if(localok==Standard_False) {
1069 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1073 static Standard_Integer numpoint=0;
1074 cout<<"point p"<<++numpoint<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;cout.flush();
1076 return(BRepCheck_SelfIntersectingWire);
1080 }// if(Inter.IsDone()) {
1082 for(j=i+1; j<=Nbedges; j++) {
1083 const TopoDS_Edge& E2 = TopoDS::Edge(EMap.FindKey(j));
1085 tabCur(j) = BRep_Tool::CurveOnSurface(E2,F,first2,last2);
1086 if (!tabCur(j).IsNull() && last2 > first2) {
1088 // To avoid exeption in Segment if C2 is BSpline - IFV
1089 if(!C2.IsPeriodic()) {
1090 if(C2.FirstParameter() > first2) {
1091 first2 = C2.FirstParameter();
1093 if(C2.LastParameter() < last2 ) {
1094 last2 = C2.LastParameter();
1098 BRep_Tool::UVPoints(E2,F,pfirst2,plast2);
1099 tabDom[j-1].SetValues(pfirst2,first2,tolint,plast2,last2,tolint);
1101 BndLib_Add2dCurve::Add( C2, first2, last2, Precision::PConfusion(), boxes(j) );
1106 cout<<"BRepCheck_NoCurveOnSurface or BRepCheck_InvalidRange"<<endl;cout.flush();
1108 if(tabCur(j).IsNull()) {
1109 return(BRepCheck_NoCurveOnSurface);
1111 return (BRepCheck_InvalidRange);
1118 if (boxes(i).IsOut( boxes(j))) {
1121 //modified by NIZNHY-PKV Fri Oct 29 10:09:01 2010f
1122 if (E1.IsSame(E2)) {
1125 //modified by NIZNHY-PKV Fri Oct 29 10:09:02 2010t
1127 //-- ************************************************************
1128 //-- ******* I n t e r s e c t i o n C 1 and C 2 ********
1129 //-- ************************************************************
1130 Inter.Perform(C1,myDomain1,C2,tabDom[j-1],tolint,tolint);
1132 if(Inter.IsDone()) {
1133 Standard_Integer nbp, nbs;
1134 Standard_Real IP_ParamOnFirst, IP_ParamOnSecond;
1135 IntRes2d_Transition Tr1,Tr2;
1136 TopTools_ListOfShape CommonVertices;
1137 TopTools_ListIteratorOfListOfShape itl;
1138 TopTools_MapOfShape Vmap;
1140 TopoDS_Iterator it( E1 );
1141 for (; it.More(); it.Next()) {
1142 Vmap.Add( it.Value() );
1145 it.Initialize( E2 );
1146 for (; it.More(); it.Next()) {
1147 const TopoDS_Shape& V = it.Value();
1148 if (Vmap.Contains( V )) {
1149 CommonVertices.Append( V );
1153 nbp = Inter.NbPoints();
1154 nbs = Inter.NbSegments();
1155 IP_ParamOnFirst = 0.;
1156 IP_ParamOnSecond = 0.;
1158 //// **** Points of intersection **** ////
1159 for (Standard_Integer p = 1; p <= nbp; p++) {
1160 const IntRes2d_IntersectionPoint& IP = Inter.Point(p);
1161 IP_ParamOnFirst = IP.ParamOnFirst();
1162 IP_ParamOnSecond = IP.ParamOnSecond();
1163 Tr1 = IP.TransitionOfFirst();
1164 Tr2 = IP.TransitionOfSecond();
1165 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1166 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
1167 //-- Checking of points with true tolerances (ie Tol in 3d)
1168 //-- If the point of intersection is within the tolerance of a vertex
1169 //-- this intersection is considered correct (no error)
1170 Standard_Boolean localok = Standard_False;
1171 Standard_Real f1,l1, f2, l2;
1172 TopLoc_Location L, L2;
1174 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f1,l1);
1175 const Handle(Geom_Curve) ConS2 = BRep_Tool::Curve(E2,L2,f2,l2);
1176 //gka protect against working out of edge range
1177 if ( f1-IP_ParamOnFirst > ::Precision::PConfusion() ||
1178 IP_ParamOnFirst-l1 > ::Precision::PConfusion() ||
1179 f2-IP_ParamOnSecond > ::Precision::PConfusion() ||
1180 IP_ParamOnSecond-l2 > ::Precision::PConfusion() )
1182 Standard_Real tolvtt = 0.;
1183 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1184 if (!ConS.IsNull()) {
1185 P3d = ConS->Value(IP_ParamOnFirst);
1186 P3d.Transform(L.Transformation());
1189 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1190 P3d = HS->Value(aP2d.X(), aP2d.Y());
1193 if (!ConS2.IsNull()) {
1194 P3d2 = ConS2->Value(IP_ParamOnSecond);
1195 P3d2.Transform(L2.Transformation());
1198 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1199 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1201 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1202 itl.Initialize( CommonVertices );
1203 for (; itl.More(); itl.Next()) {
1204 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1207 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1208 p3dvtt = BRep_Tool::Pnt(vtt);
1209 tolvtt = BRep_Tool::Tolerance(vtt);
1211 tolvtt=tolvtt*tolvtt;
1212 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1213 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1215 if (p3dvttDistanceP3d<=tolvtt && p3dvttDistanceP3d2<=tolvtt) {
1216 localok = Standard_True;
1221 //-- --------------------------------------------------------
1222 //-- Check maximum yawn between 2 edges
1224 //-- Check distance from edges to the curve joining
1225 //-- the point of intersection with vertex (if exists)
1226 if (localok == Standard_False && !CommonVertices.IsEmpty()) {
1228 cout << "\n------------------------------------------------------\n" <<endl;
1229 cout << "\n--- BRepCheck Wire: AutoIntersection Phase1 -> Erreur \n" <<endl;
1232 Standard_Real distauvtxleplusproche,VParaOnEdge1,VParaOnEdge2;
1233 gp_Pnt VertexLePlusProche;
1237 distauvtxleplusproche=RealLast();
1238 //Find the nearest common vertex
1239 itl.Initialize( CommonVertices );
1240 for (; itl.More(); itl.Next()) {
1241 Standard_Real disptvtx;
1244 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1245 p3dvtt = BRep_Tool::Pnt(vtt);
1246 disptvtx = P3d.Distance(p3dvtt);
1247 if (disptvtx < distauvtxleplusproche) {
1248 VertexLePlusProche = p3dvtt;
1249 distauvtxleplusproche = disptvtx;
1250 VParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1251 VParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1253 // eap: case of closed edge
1254 else if (IsEqual(distauvtxleplusproche, disptvtx)) {
1255 Standard_Real newVParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1256 Standard_Real newVParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1257 if (Abs(IP_ParamOnFirst - VParaOnEdge1) + Abs(IP_ParamOnSecond - VParaOnEdge2)
1259 Abs(IP_ParamOnFirst - newVParaOnEdge1) + Abs(IP_ParamOnSecond - newVParaOnEdge2)) {
1260 VertexLePlusProche = p3dvtt;
1261 VParaOnEdge1 = newVParaOnEdge1;
1262 VParaOnEdge2 = newVParaOnEdge2;
1266 //Patch: extraordinar situation (e.g. tolerance(v) == 0.)
1267 // Modified by skv - Wed Jul 23 12:28:11 2003 OCC1764 Begin
1268 // if (VertexLePlusProche.Distance( P3d ) <= gp::Resolution())
1269 if (VertexLePlusProche.Distance(P3d) <= gp::Resolution() ||
1270 VertexLePlusProche.Distance(P3d2) <= gp::Resolution()) {
1271 // Modified by skv - Wed Jul 23 12:28:12 2003 OCC1764 End
1272 localok = Standard_True;
1275 gp_Lin Lig( VertexLePlusProche, gp_Vec(VertexLePlusProche,P3d) );
1276 Standard_Real du1 = 0.1*(IP_ParamOnFirst -VParaOnEdge1);
1277 Standard_Real du2 = 0.1*(IP_ParamOnSecond-VParaOnEdge2);
1278 Standard_Real maxd1 = 0., maxd2 = 0.;
1281 localok = Standard_True;
1282 Standard_Real tole1 = BRep_Tool::Tolerance(E1);
1283 for (k = 2; localok && k < 9; k++) {
1284 Standard_Real u = VParaOnEdge1 + k*du1; // check if it works
1286 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1287 if (!ConS.IsNull()) {
1288 P1 = ConS->Value(u);
1289 P1.Transform(L.Transformation());
1292 gp_Pnt2d aP2d = C1.Value(u);
1293 P1 = HS->Value(aP2d.X(), aP2d.Y());
1295 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1296 Standard_Real d1 = Lig.Distance(P1);
1300 if (d1 > tole1*2.0){
1301 localok = Standard_False;
1305 // Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764 Begin
1306 gp_Dir aTmpDir(P3d2.XYZ().Subtracted(VertexLePlusProche.XYZ()));
1308 Lig.SetDirection(aTmpDir);
1309 // Modified by skv - Wed Jul 23 12:22:23 2003 OCC1764 End
1310 Standard_Real tole2 = BRep_Tool::Tolerance(E2);
1311 for (k = 2; localok && k < 9; k++) {
1312 Standard_Real u = VParaOnEdge2 + k*du2; // check if it works
1314 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1315 if (!ConS2.IsNull()) {
1316 P2 = ConS2->Value(u);
1317 P2.Transform(L2.Transformation());
1320 gp_Pnt2d aP2d = C2.Value(u);
1321 P2 = HS->Value(aP2d.X(), aP2d.Y());
1323 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1324 Standard_Real d2 = Lig.Distance(P2);
1328 if (d2 > tole2*2.0){
1329 localok = Standard_False;
1334 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Bon \n");
1335 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1336 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1337 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1341 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Erreur \n");
1342 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1343 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1344 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1348 } //end of else (construction of the line Lig)
1349 } //end of if (localok == Standard_False && !CommonVertices.IsEmpty())
1351 if(localok==Standard_False) {
1355 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1358 static Standard_Integer numpoint1=0;
1359 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1363 return(BRepCheck_SelfIntersectingWire);
1364 } //-- localok == False
1365 } //end of if(Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1366 } //end of for (Standard_Integer p=1; p <= nbp; p++)
1368 //// **** Segments of intersection **** ////
1369 for (Standard_Integer s = 1; s <= nbs; ++s) {
1370 const IntRes2d_IntersectionSegment& Seg = Inter.Segment(s);
1371 if (Seg.HasFirstPoint() && Seg.HasLastPoint()) {
1372 Standard_Boolean localok;
1374 IntRes2d_IntersectionPoint PSeg [2];
1375 IntRes2d_Position aPCR1, aPCR2;
1377 localok = Standard_False;
1378 PSeg[0] = Seg.FirstPoint();
1379 PSeg[1] = Seg.LastPoint();
1380 // At least one of extremities of the segment must be inside
1381 // the tolerance of a common vertex
1382 for (k = 0; k < 2; ++k) {
1383 IP_ParamOnFirst = PSeg[k].ParamOnFirst();
1384 IP_ParamOnSecond = PSeg[k].ParamOnSecond();
1385 Tr1 = PSeg[k].TransitionOfFirst();
1386 Tr2 = PSeg[k].TransitionOfSecond();
1387 aPCR1=Tr1.PositionOnCurve();
1388 aPCR2=Tr2.PositionOnCurve();
1390 if(aPCR1!=IntRes2d_Middle && aPCR2!=IntRes2d_Middle) {
1391 GeomAbs_CurveType aCT1, aCT2;
1395 if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1396 // check for the two lines coincidence
1397 Standard_Real aPAR_T, aT11, aT12, aT21, aT22, aT1m, aT2m;
1398 Standard_Real aD2, aTolE1, aTolE2, aTol2, aDot;
1404 aTolE1=BRep_Tool::Tolerance(E1);
1405 aTolE2=BRep_Tool::Tolerance(E2);
1406 aTol2=aTolE1+aTolE2;
1412 aT11=PSeg[0].ParamOnFirst();
1413 aT12=PSeg[1].ParamOnFirst();
1414 aT21=PSeg[0].ParamOnSecond();
1415 aT22=PSeg[1].ParamOnSecond();
1417 aT1m=(1.-aPAR_T)*aT11 + aPAR_T*aT12;
1418 aP1m=C1.Value(aT1m);
1420 aD2=aL2.SquareDistance(aP1m);
1422 aT2m=ElCLib::Parameter(aL2, aP1m);
1423 if (aT2m>aT21 && aT2m<aT22) {
1424 const gp_Dir2d& aDir1=aL1.Direction();
1425 const gp_Dir2d& aDir2=aL2.Direction();
1431 if ((1.-aDot)<5.e-11){//0.00001 rad
1432 localok = Standard_False;
1433 break;// from for (k = 0; k < 2; ++k){...
1435 }//if (aT2m>aT21 && aT2m<aT22) {
1437 }//if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1439 localok = Standard_True;
1443 Standard_Real f,l, tolvtt;
1444 TopLoc_Location L, L2;
1445 const Handle(Geom_Curve)& ConS = BRep_Tool::Curve(E1,L,f,l);
1446 const Handle(Geom_Curve)& ConS2 = BRep_Tool::Curve(E2,L2,f,l);
1447 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1448 if (!ConS.IsNull()) {
1449 P3d = ConS->Value(IP_ParamOnFirst);
1450 P3d.Transform(L.Transformation());
1452 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1453 P3d = HS->Value(aP2d.X(), aP2d.Y());
1455 if (!ConS2.IsNull()) {
1456 P3d2 = ConS2->Value(IP_ParamOnSecond);
1457 P3d2.Transform(L2.Transformation());
1459 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1460 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1462 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1463 itl.Initialize( CommonVertices );
1464 for (; itl.More(); itl.Next()) {
1465 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1468 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1469 p3dvtt = BRep_Tool::Pnt(vtt);
1470 tolvtt = BRep_Tool::Tolerance(vtt);
1472 tolvtt=tolvtt*tolvtt;
1473 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1474 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1475 if (p3dvttDistanceP3d <= tolvtt && p3dvttDistanceP3d2 <= tolvtt) {
1476 localok = Standard_True;
1480 if (localok == Standard_True) {
1483 } //end of for (k = 0; k < 2; k++)
1485 if(localok==Standard_False) {
1489 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1492 static Standard_Integer numpoint1=0;
1493 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1497 return(BRepCheck_SelfIntersectingWire);
1498 } //-- localok == False
1499 } //end of if(Seg.HasFirstPoint() && Seg.HasLastPoint())
1500 } //end of for (Standard_Integer s = 1; s <= nbs; p++)
1501 } //-- Inter.IsDone()
1502 } //end of for( j = i+1; j<=Nbedges; j++)
1503 } //end of for(i = 1; i <= Nbedges; i++)
1507 BRepCheck::Add(myMap(myShape),BRepCheck_NoError);
1510 return (BRepCheck_NoError);
1513 //=======================================================================
1514 //function : SetStatus
1516 //=======================================================================
1518 void BRepCheck_Wire::SetStatus(const BRepCheck_Status theStatus)
1520 BRepCheck::Add(myMap(myShape),theStatus);
1523 //=======================================================================
1524 //function : GeometricControls
1526 //=======================================================================
1527 void BRepCheck_Wire::GeometricControls(const Standard_Boolean B)
1531 myCdone = Standard_False;
1536 //=======================================================================
1537 //function : GeometricControls
1539 //=======================================================================
1540 Standard_Boolean BRepCheck_Wire::GeometricControls() const
1545 //=======================================================================
1546 //function : Propagate
1547 //purpose : fill <mapE> with edges connected to <edg> through vertices
1548 // contained in <mapVE>
1549 //=======================================================================
1550 static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape& mapVE,
1551 const TopoDS_Shape& edg,
1552 TopTools_MapOfShape& mapE)
1554 TopTools_ListOfShape currentEdges;
1555 currentEdges.Append(edg);
1559 TopTools_ListOfShape nextEdges;
1560 TopTools_ListIteratorOfListOfShape itrc(currentEdges);
1561 for (; itrc.More(); itrc.Next())
1563 const TopoDS_Shape& Edge = itrc.Value();
1564 if (!mapE.Contains(Edge))
1567 TopExp_Explorer ex(Edge, TopAbs_VERTEX);
1568 for (; ex.More(); ex.Next())
1570 const TopoDS_Vertex& vtx = TopoDS::Vertex(ex.Current());
1571 Standard_Integer indv = mapVE.FindIndex(vtx);
1574 const TopTools_ListOfShape& edges = mapVE(indv);
1576 TopTools_ListIteratorOfListOfShape itl(edges);
1577 for (; itl.More(); itl.Next())
1579 const TopoDS_Shape& E = itl.Value();
1580 if (!Edge.IsSame(E) && !mapE.Contains(E))
1583 nextEdges.Append(E);
1589 currentEdges = nextEdges;
1591 while (!currentEdges.IsEmpty());
1594 //=======================================================================
1595 //function : GetOrientation
1597 //=======================================================================
1599 static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape& mapE,
1600 const TopoDS_Edge& edg)
1602 TopTools_MapIteratorOfMapOfShape itm(mapE);
1603 for ( ; itm.More(); itm.Next()) {
1604 if (itm.Key().IsSame(edg)) {
1608 return itm.Key().Orientation();
1610 //=======================================================================
1611 //function : ChoixUV
1612 //purpose : For vertex theVertex given function find an edge along
1613 // that we should go further.
1614 //=======================================================================
1615 void ChoixUV(const TopoDS_Vertex& theVertex,
1616 const TopoDS_Edge& theEdge,
1617 const TopoDS_Face& theFace,
1618 TopTools_ListOfShape& theLOfShape)
1620 TopTools_ListIteratorOfListOfShape It( theLOfShape );
1623 if (theEdge.IsSame( It.Value() ))
1624 theLOfShape.Remove( It );
1629 Standard_Real aTol3d = BRep_Tool::Tolerance(theVertex);
1631 Standard_Integer anIndex = 0, anIndMin = 0;
1632 TopoDS_Edge anEFound;
1633 gp_Pnt2d aPntRef, aPnt;
1634 gp_Vec2d aDerRef, aDer;
1635 Standard_Real aMinAngle, aMaxAngle, anAngle;
1636 Standard_Real a_gpResolution=gp::Resolution();
1637 TopAbs_Orientation aVOrientation, anEdgOrientation;
1638 Standard_Real aParam = 0.0, aFirstParam = 0.0, aLastParam = 0.0, aParPiv = 0.0;
1639 BRepAdaptor_Surface aFaceSurface(theFace,Standard_False); // no restriction
1641 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirstParam, aLastParam);
1642 if (C2d.IsNull())// JAG 10.12.96
1645 aVOrientation = theVertex.Orientation();
1646 anEdgOrientation = theEdge.Orientation();
1648 aParPiv =(aVOrientation==anEdgOrientation) ? aFirstParam : aLastParam;
1649 aMinAngle = RealLast();
1650 aMaxAngle = RealFirst();
1652 CurveDirForParameter(C2d, aParPiv, aPntRef, aDerRef);
1654 if (aVOrientation != anEdgOrientation)
1657 It.Initialize(theLOfShape);
1659 for (; It.More(); It.Next())
1662 const TopoDS_Edge& anE=TopoDS::Edge(It.Value());
1663 C2d = BRep_Tool::CurveOnSurface(anE, theFace, aFirstParam, aLastParam);
1666 Geom2dAdaptor_Curve aCA(C2d);
1668 aParam =(aVOrientation != anE.Orientation()) ? aFirstParam : aLastParam;
1669 aPnt = aCA.Value(aParam);
1671 if(!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d, Standard_False))
1674 CurveDirForParameter(aCA, aParam, aPnt, aDer);
1676 if (aVOrientation == anE.Orientation())
1679 if ((aDerRef.Magnitude() <= a_gpResolution) ||
1680 (aDer.Magnitude() <= a_gpResolution))
1681 //Vector length is too small
1684 anAngle = -aDerRef.Angle( aDer );
1689 if ( theFace.Orientation() == TopAbs_FORWARD )
1691 if ( anAngle < aMinAngle )
1694 aMinAngle = anAngle;
1697 else //theFace.Orientation() != TopAbs_FORWARD
1699 if ( anAngle > aMaxAngle )
1702 aMaxAngle = anAngle;
1709 if (theLOfShape.Extent() == 1)
1711 Standard_Boolean IsFound = Standard_True; //all right
1712 anEFound = TopoDS::Edge(theLOfShape.First());
1714 if(anEFound.IsNull() || BRep_Tool::Degenerated(theEdge) ||
1715 BRep_Tool::Degenerated(anEFound))
1716 IsFound = Standard_False; //bad
1717 else if (!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d))
1718 IsFound = Standard_False; //bad
1720 // clousureness in 3D
1722 //IsDistanceIn3DTolerance
1723 BRepAdaptor_Curve bcEdg(theEdge, theFace);
1724 BRepAdaptor_Curve bcEvois(anEFound, theFace);
1725 gp_Pnt pEdg = bcEdg.Value(aParPiv);
1726 gp_Pnt pEFound = bcEvois.Value(aParam);
1728 if(!IsDistanceIn3DTolerance(pEdg, pEFound, aTol3d))
1729 IsFound = Standard_False;
1731 //angle was not defined but points are close
1732 IsFound = Standard_True; //all right
1737 theLOfShape.Clear();
1739 }//if (theLOfShape.Extent() == 1)
1740 else //if (anIndMin == 0)
1742 theLOfShape.Clear();
1748 while (anIndex < anIndMin)
1750 theLOfShape.RemoveFirst();
1754 It.Initialize(theLOfShape);
1758 theLOfShape.Remove(It);
1763 //=======================================================================
1764 //function : CurveDirForParameter
1766 //=======================================================================
1767 void CurveDirForParameter(const Geom2dAdaptor_Curve& aC2d,
1768 const Standard_Real aPrm,
1772 Standard_Real aTol=gp::Resolution();
1775 aC2d.D1(aPrm, Pnt, aVec2d);
1777 if (aVec2d.Magnitude() <= aTol) {
1778 for (i = 2; i <= 100; i++){
1779 aVec2d = aC2d.DN(aPrm, i);
1780 if (aVec2d.Magnitude() > aTol) {
1787 // Modified by Sergey KHROMOV - Wed May 22 10:44:06 2002 OCC325 Begin
1788 //=======================================================================
1789 //function : GetPnts2d
1790 //purpose : this function returns the parametric points of theVertex on theFace.
1791 // If theVertex is a start and end vertex of theEdge hasSecondPnt
1792 // becomes Standard_True and aPnt2 returns the second parametric point.
1793 // Returns Standard_True if paraametric points are successfully found.
1794 //=======================================================================
1796 static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
1797 const TopoDS_Edge &theEdge,
1798 const TopoDS_Face &theFace,
1801 Handle(Geom2d_Curve) aPCurve;
1802 Standard_Real aFPar;
1803 Standard_Real aLPar;
1804 Standard_Real aParOnEdge;
1805 TopoDS_Vertex aFirstVtx;
1806 TopoDS_Vertex aLastVtx;
1808 TopExp::Vertices(theEdge, aFirstVtx, aLastVtx);
1810 if (!theVertex.IsSame(aFirstVtx) && !theVertex.IsSame(aLastVtx))
1811 return Standard_False;
1813 aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFPar, aLPar);
1815 if (aPCurve.IsNull())
1816 return Standard_False;
1818 aParOnEdge = BRep_Tool::Parameter(theVertex, theEdge);
1819 aPnt = aPCurve->Value(aParOnEdge);
1821 return Standard_True;
1824 //=======================================================================
1825 //function : Closed2dForPeriodicFace
1826 //purpose : Checks the distance between first point of the first edge
1827 // and last point of the last edge in 2d for periodic face.
1828 //=======================================================================
1829 static Standard_Boolean IsClosed2dForPeriodicFace
1830 (const TopoDS_Face &theFace,
1831 const gp_Pnt2d &theP1,
1832 const gp_Pnt2d &theP2,
1833 const TopoDS_Vertex &theVertex)
1835 // Check 2d distance for periodic faces with seam edge.
1836 // Searching for seam edges
1837 TopTools_ListOfShape aSeamEdges;
1838 TopTools_MapOfShape NotSeams;
1839 TopTools_MapOfShape ClosedEdges;
1840 TopExp_Explorer anExp(theFace, TopAbs_EDGE);
1842 for (;anExp.More(); anExp.Next()) {
1843 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
1845 if (NotSeams.Contains(anEdge))
1848 if (!IsOriented(anEdge) ||
1849 !BRep_Tool::IsClosed(anEdge, theFace)) {
1850 NotSeams.Add(anEdge);
1854 if (!ClosedEdges.Add(anEdge))
1855 aSeamEdges.Append(anEdge);
1858 if (aSeamEdges.Extent() == 0)
1859 return Standard_True;
1861 // check if theVertex lies on one of the seam edges
1862 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
1863 Standard_Real aTol = BRep_Tool::Tolerance(theVertex);
1864 Standard_Real aUResol = aFaceSurface.UResolution(aTol);
1865 Standard_Real aVResol = aFaceSurface.VResolution(aTol);
1866 Standard_Real aVicinity = Sqrt(aUResol*aUResol + aVResol*aVResol);
1867 Standard_Real aDistP1P2 = theP1.Distance(theP2);
1870 TopTools_ListIteratorOfListOfShape anIter(aSeamEdges);
1872 for (; anIter.More(); anIter.Next()) {
1873 TopoDS_Edge aSeamEdge = TopoDS::Edge(anIter.Value());
1875 anExp.Init(aSeamEdge, TopAbs_VERTEX);
1876 for (; anExp.More(); anExp.Next()) {
1877 const TopoDS_Shape &aVtx = anExp.Current();
1879 // We found an edge. Check the distance between two given points
1880 // to be lower than the computed tolerance.
1881 if (IsOriented(aVtx) && aVtx.IsSame(theVertex)) {
1884 Standard_Real a2dTol;
1886 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt1))
1889 aSeamEdge = TopoDS::Edge(aSeamEdge.Reversed());
1891 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt2))
1894 a2dTol = aPnt1.Distance(aPnt2)*1.e-2;
1895 a2dTol = Max(a2dTol, aVicinity);
1897 if (aDistP1P2 > a2dTol)
1898 return Standard_False;
1903 return Standard_True;
1905 // Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End