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)
24 // Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764
26 #include <BRepCheck_Wire.ixx>
27 #include <BRepCheck_ListOfStatus.hxx>
28 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
29 #include <TopTools_MapOfShape.hxx>
30 #include <TopTools_MapIteratorOfMapOfShape.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
33 #include <TopTools_DataMapOfShapeListOfShape.hxx>
34 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Iterator.hxx>
39 #include <TopLoc_Location.hxx>
40 #include <TColGeom2d_Array1OfCurve.hxx>
41 #include <IntRes2d_Intersection.hxx>
42 #include <IntRes2d_IntersectionPoint.hxx>
43 #include <IntRes2d_IntersectionSegment.hxx>
44 #include <IntRes2d_Transition.hxx>
45 #include <IntRes2d_Domain.hxx>
46 #include <Geom2dInt_GInter.hxx>
47 #include <gp_Pnt2d.hxx>
50 #include <Geom2d_Curve.hxx>
51 #include <Geom_Curve.hxx>
52 #include <Geom2dAdaptor_Curve.hxx>
53 #include <Geom2dAdaptor_HCurve.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepAdaptor_Curve.hxx>
56 #include <BRepAdaptor_Surface.hxx>
57 #include <BRepAdaptor_HSurface.hxx>
58 #include <BRepCheck.hxx>
60 #include <TopoDS_Vertex.hxx>
61 #include <TopTools_MapOfOrientedShape.hxx>
62 #include <TopTools_HArray1OfShape.hxx>
63 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
66 #include <Precision.hxx>
67 #include <Bnd_Array1OfBox2d.hxx>
68 #include <BndLib_Add2dCurve.hxx>
72 #include <BRepTools_WireExplorer.hxx>
76 #include <TopTools_IndexedMapOfOrientedShape.hxx>
80 static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape&,
81 const TopoDS_Shape&, // edge
82 TopTools_MapOfShape&); // mapofedge
85 static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape&,
90 void ChoixUV(const TopoDS_Vertex&,
93 TopTools_ListOfShape&);
95 // 20/03/02 akm vvv (OCC234)
97 // Standard_Boolean CheckLoopOrientation( const TopoDS_Vertex&,
98 // const TopoDS_Edge&,
99 // const TopoDS_Edge&,
100 // const TopoDS_Face&,
101 // TopTools_ListOfShape&);
104 inline Standard_Boolean IsOriented(const TopoDS_Shape& S)
106 return (S.Orientation() == TopAbs_FORWARD ||
107 S.Orientation() == TopAbs_REVERSED);
111 void CurveDirForParameter(const Handle(Geom2d_Curve)& aC2d,
112 const Standard_Real aPrm,
116 // Modified by Sergey KHROMOV - Thu Jun 20 11:21:51 2002 OCC325 Begin
117 static Standard_Boolean IsClosed2dForPeriodicFace
118 (const TopoDS_Face &theFace,
119 const gp_Pnt2d &theP1,
120 const gp_Pnt2d &theP2,
121 const TopoDS_Vertex &theVertex);
123 static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
124 const TopoDS_Edge &theEdge,
125 const TopoDS_Face &theFace,
127 // Modified by Sergey KHROMOV - Wed May 22 10:44:08 2002 End
129 //=======================================================================
130 //function : BRepCheck_Wire
132 //=======================================================================
133 BRepCheck_Wire::BRepCheck_Wire(const TopoDS_Wire& W)
137 //=======================================================================
140 //=======================================================================
141 void BRepCheck_Wire::Minimum()
143 myCdone = Standard_False;
144 myGctrl = Standard_True;
146 BRepCheck_ListOfStatus thelist;
147 myMap.Bind(myShape, thelist);
148 BRepCheck_ListOfStatus& lst = myMap(myShape);
150 // check that the wire is "connex"
151 TopExp_Explorer exp(myShape,TopAbs_EDGE);
152 Standard_Integer nbedge = 0;
155 for (; exp.More(); exp.Next()) {
157 TopExp_Explorer expv;
158 for (expv.Init(exp.Current(),TopAbs_VERTEX);
159 expv.More(); expv.Next()) {
160 const TopoDS_Shape& vtx = expv.Current();
161 Standard_Integer index = myMapVE.FindIndex(vtx);
163 TopTools_ListOfShape theListOfShape;
164 index = myMapVE.Add(vtx, theListOfShape);
166 myMapVE(index).Append(exp.Current());
169 // wire must have at least one edge
171 BRepCheck::Add(lst,BRepCheck_EmptyWire);
173 // check if all edges are connected through vertices
174 else if (nbedge >= 2) {
175 TopTools_MapOfShape mapE;
177 Propagate(myMapVE,exp.Current(),mapE);
178 for (exp.ReInit(); exp.More(); exp.Next()) {
179 if (!mapE.Contains(exp.Current())) {
180 BRepCheck::Add(lst,BRepCheck_NotConnected);
186 lst.Append(BRepCheck_NoError);
189 myMin = Standard_True;
192 //=======================================================================
193 //function : InContext
195 //=======================================================================
196 void BRepCheck_Wire::InContext(const TopoDS_Shape& S)
199 if (myMap.IsBound(S)) {
202 BRepCheck_ListOfStatus thelist;
203 myMap.Bind(S, thelist);
205 BRepCheck_ListOfStatus& lst = myMap(S);
207 // check if my wire is in <S>
208 TopExp_Explorer exp(S,TopAbs_WIRE);
209 for ( ; exp.More(); exp.Next()) {
210 if (exp.Current().IsSame(myShape)) {
215 BRepCheck::Add(lst,BRepCheck_SubshapeNotInShape);
219 BRepCheck_Status st = BRepCheck_NoError;
220 TopAbs_ShapeEnum styp = S.ShapeType();
227 st = SelfIntersect(TopoDS::Face(S),ed1,ed2,Standard_True);
228 if (st != BRepCheck_NoError) break;
230 if (st != BRepCheck_NoError) break;
231 st = Orientation(TopoDS::Face(S));
232 if (st != BRepCheck_NoError) break;
233 st = Closed2d(TopoDS::Face(S));
240 if (st != BRepCheck_NoError)
241 BRepCheck::Add(lst,st);
244 lst.Append(BRepCheck_NoError);
246 //=======================================================================
249 //=======================================================================
250 void BRepCheck_Wire::Blind()
253 // nothing more that the minimum
254 myBlind = Standard_True;
257 //=======================================================================
260 //=======================================================================
261 BRepCheck_Status BRepCheck_Wire::Closed(const Standard_Boolean Update)
266 BRepCheck::Add(myMap(myShape),myCstat);
271 myCdone = Standard_True;
273 BRepCheck_ListIteratorOfListOfStatus itl(myMap(myShape));
274 if (itl.Value() != BRepCheck_NoError) {
275 myCstat = itl.Value();
276 return myCstat; // already saved
279 myCstat = BRepCheck_NoError;
281 TopExp_Explorer exp,expv;
282 TopTools_MapOfShape mapS;
283 TopTools_DataMapOfShapeListOfShape Cradoc;
285 // Checks if the oriented edges of the wire give a "closed" wire,
286 // i-e if each oriented vertex on oriented edges is found 2 times...
288 for (exp.Init(myShape,TopAbs_EDGE);exp.More(); exp.Next()) {
289 if (IsOriented(exp.Current())) {
291 if (!Cradoc.IsBound(exp.Current())) {
292 TopTools_ListOfShape theListOfShape;
293 Cradoc.Bind(exp.Current(), theListOfShape);
295 Cradoc(exp.Current()).Append(exp.Current());
297 mapS.Add(exp.Current());
298 for (expv.Init(exp.Current(),TopAbs_VERTEX); expv.More(); expv.Next()) {
299 if (IsOriented(expv.Current())) {
300 Standard_Integer index = myMapVE.FindIndex(expv.Current());
302 TopTools_ListOfShape theListOfShape1;
303 index = myMapVE.Add(expv.Current(), theListOfShape1);
305 myMapVE(index).Append(exp.Current());
311 Standard_Integer theNbori = mapS.Extent();
314 for (exp.ReInit(); exp.More(); exp.Next()) {
315 if (IsOriented(exp.Current())) {
319 Propagate(myMapVE,exp.Current(),mapS);
321 if (theNbori != mapS.Extent()) {
322 myCstat = BRepCheck_NotConnected;
324 BRepCheck::Add(myMap(myShape),myCstat);
329 // Checks the number of occurence of an edge : maximum 2, and in this
330 // case, one time FORWARD and one time REVERSED
332 Standard_Boolean yabug = Standard_False;
333 for (TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm(Cradoc);
334 itdm.More(); itdm.Next()) {
335 if (itdm.Value().Extent() >= 3) {
336 yabug = Standard_True;
338 else if (itdm.Value().Extent() == 2) {
339 if (itdm.Value().First().Orientation() ==
340 itdm.Value().Last().Orientation()) {
341 yabug = Standard_True;
345 myCstat = BRepCheck_RedundantEdge;
347 BRepCheck::Add(myMap(myShape),myCstat);
353 for (Standard_Integer i = 1; i<= myMapVE.Extent(); i++) {
354 if (myMapVE(i).Extent()%2 != 0) {
355 myCstat=BRepCheck_NotClosed;
357 BRepCheck::Add(myMap(myShape),myCstat);
364 BRepCheck::Add(myMap(myShape),myCstat);
369 //=======================================================================
370 //function : IsDistanceIn3DTolerance
371 //purpose : Return Standard_True if distance between thePnt_f and
372 // thePnt_l is not more, than aTol3d
373 //=======================================================================
374 Standard_Boolean IsDistanceIn3DTolerance (const BRepAdaptor_Surface& /*aFaceSurface*/,
375 const gp_Pnt& thePnt_f,
376 const gp_Pnt& thePnt_l,
377 const Standard_Real aTol3d)
379 Standard_Real Dist = thePnt_f.Distance(thePnt_l);
382 return Standard_True;
386 cout << "--------Function IsDistanceIn3DTolerance(...)----------" << endl;
387 cout << "--- BRepCheck Wire: Closed3d -> Error" << endl;
388 cout << "--- Dist (" << Dist << ") > Tol3d (" << aTol3d << ")" << endl;
389 cout << "Pnt1(" << thePnt_f.X() << "; " << thePnt_f.Y() << "; " << thePnt_f.Z() << ")" << endl;
390 cout << "Pnt2(" << thePnt_l.X() << "; " << thePnt_l.Y() << "; " << thePnt_l.Z() << ")" << endl;
391 cout << "------------------------------------------------------" << endl;
394 return Standard_False;
397 //=======================================================================
398 //function : IsDistanceIn3DTolerance
400 //=======================================================================
402 Standard_Boolean IsDistanceIn2DTolerance (const BRepAdaptor_Surface& aFaceSurface,
403 const gp_Pnt2d& thePnt,
404 const gp_Pnt2d& thePntRef,
405 const Standard_Real aTol3d,
407 const Standard_Boolean PrintWarnings = Standard_True)
409 const Standard_Boolean = Standard_True)
412 Standard_Real dumax = 0.01 * (aFaceSurface.LastUParameter() - aFaceSurface.FirstUParameter());
413 Standard_Real dvmax = 0.01 * (aFaceSurface.LastVParameter() - aFaceSurface.FirstVParameter());
414 Standard_Real dumin = Abs(thePnt.X() - thePntRef.X());
415 Standard_Real dvmin = Abs(thePnt.Y() - thePntRef.Y());
417 if((dumin < dumax) && (dvmin < dvmax))
418 return Standard_True;
424 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
425 cout << "--- BRepCheck Wire: Not closed in 2d" << endl;
426 cout << "*****************************************************" << endl;
427 cout << "*dumin = " << dumin << "; dumax = " << dumax << endl;
428 cout << "* dvmin = " << dvmin << "; dvmax = " << dvmax << endl;
429 cout << "* (dumin > dumax) or (dvmin > dvmax)." << endl;
430 cout << "*****************************************************" << endl;
432 cout << "UFirst = " << aFaceSurface.FirstUParameter();
433 cout << "; ULast = " << aFaceSurface.LastUParameter() << endl;
434 cout << "VFirst = " << aFaceSurface.FirstVParameter();
435 cout << "; VLast = " << aFaceSurface.LastVParameter() << endl;
438 dumax = aFaceSurface.UResolution(aTol3d);
439 dvmax = aFaceSurface.VResolution(aTol3d);
443 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
444 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
445 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
449 dumax = aFaceSurface.UResolution(aTol3d);
450 dvmax = aFaceSurface.VResolution(aTol3d);
453 Standard_Real aTol2d = 2*Max( dumax, dvmax);
456 if((aTol2d <= 0.0) && (PrintWarnings))
458 cout<<"BRepCheck_Wire : UResolution and VResolution = 0.0 (Face too small ?)"<<endl;
463 //Standard_Real Dist = thePntRef.Distance(thePnt);
464 Standard_Real Dist = Max(dumin, dvmin);
467 return Standard_True;
473 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
474 cout << "--- BRepCheck Wire: Not closed in 2d" << endl;
475 cout << "*****************************************************" << endl;
476 cout << "* Dist = " << Dist << " > Tol2d = " << aTol2d << endl;
477 cout << "*****************************************************" << endl;
478 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
479 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
480 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
484 return Standard_False;
487 //=======================================================================
488 //function : Closed2d
489 //purpose : for periodic faces
490 //=======================================================================
491 BRepCheck_Status BRepCheck_Wire::Closed2d(const TopoDS_Face& theFace,
492 const Standard_Boolean Update)
494 // 3d closure checked too
495 BRepCheck_Status aClosedStat = Closed();
496 if (aClosedStat != BRepCheck_NoError)
499 BRepCheck::Add(myMap(myShape),aClosedStat);
504 // 20/03/02 akm vvv : (OCC234) Hence this method will be used to check
505 // both periodic and non-periodic faces
506 // // this check is for periodic faces
507 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
508 // if (!aFaceSurface.IsUPeriodic() && !aFaceSurface.IsVPeriodic())
511 // BRepCheck::Add(myMap(myShape),aClosedStat);
512 // return aClosedStat;
516 // count edges having FORWARD or REVERSED orientation
517 Standard_Integer aNbOrirntedEdges = 0;
518 TopExp_Explorer anEdgeExp(myShape,TopAbs_EDGE);
519 for (;anEdgeExp.More(); anEdgeExp.Next())
521 if (IsOriented(anEdgeExp.Current()))
525 if (aNbOrirntedEdges==0)
528 BRepCheck::Add(myMap(myShape),aClosedStat);
533 // all those edges must form a closed 2d contour and be found by WireExplorer
535 Standard_Integer aNbFoundEdges = 0;
536 BRepTools_WireExplorer aWireExp(TopoDS::Wire(myShape), theFace);
537 TopoDS_Edge aFirstEdge = aWireExp.Current();
538 TopoDS_Vertex aFirstVertex = aWireExp.CurrentVertex();
539 TopoDS_Edge aLastEdge;
541 for (;aWireExp.More(); aWireExp.Next())
544 aLastEdge = aWireExp.Current();
547 if (aNbFoundEdges != aNbOrirntedEdges)
549 aClosedStat = BRepCheck_NotClosed;
551 BRepCheck::Add(myMap(myShape),aClosedStat);
556 // Check distance between 2d ends of first and last edges
557 // Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 Begin
558 // First check if first and last edges are infinite:
561 Standard_Boolean isFirstInfinite = Standard_False;
562 Standard_Boolean isLastInfinite = Standard_False;
563 TopAbs_Orientation anOri;
565 anOri = aFirstEdge.Orientation();
566 BRep_Tool::Range(aFirstEdge, aF, aL);
567 if ((anOri == TopAbs_FORWARD && Precision::IsNegativeInfinite( aF )) ||
568 (anOri == TopAbs_REVERSED && Precision::IsPositiveInfinite( aL )))
569 isFirstInfinite = Standard_True;
571 anOri = aLastEdge.Orientation();
572 BRep_Tool::Range(aLastEdge, aF, aL);
574 if ((anOri == TopAbs_FORWARD && Precision::IsPositiveInfinite( aL )) ||
575 (anOri == TopAbs_REVERSED && Precision::IsNegativeInfinite( aF )))
576 isLastInfinite = Standard_True;
578 if (isFirstInfinite && isLastInfinite)
581 BRepCheck::Add(myMap(myShape),aClosedStat);
585 else if (aFirstVertex.IsNull())
587 aClosedStat = BRepCheck_NotClosed;
590 BRepCheck::Add(myMap(myShape),aClosedStat);
594 // Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 End
596 gp_Pnt2d aP_first, aP_last, aP_temp; // ends of prev edge, next edge, bidon
599 BRep_Tool::UVPoints(aLastEdge, theFace, aP_temp, aP_last);
600 if (aLastEdge.Orientation() == TopAbs_REVERSED)
603 // Modified by Sergey KHROMOV - Mon Apr 22 10:36:33 2002 Begin
604 // Standard_Real aTol, aUResol, aVResol;
605 // // find 2d tolerance
606 // aTol = BRep_Tool::Tolerance(aFirstVertex);
607 // aUResol = 2*aFaceSurface.UResolution(aTol);
608 // aVResol = 2*aFaceSurface.VResolution(aTol);
611 if (aFirstEdge.Orientation() == TopAbs_REVERSED)
612 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_temp, aP_first);
614 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_first, aP_temp);
616 // Modified by Sergey KHROMOV - Thu Jun 20 10:55:42 2002 OCC325 Begin
617 // Check 2d distance for periodic faces with seam edge
618 if (!IsClosed2dForPeriodicFace(theFace, aP_first, aP_last, aFirstVertex))
620 aClosedStat = BRepCheck_NotClosed;
622 BRepCheck::Add(myMap(myShape),aClosedStat);
626 // Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End
629 // Standard_Real dfUDist=Abs(p.X()-p1.X());
630 // Standard_Real dfVDist=Abs(p.Y()-p1.Y());
631 // if (dfUDist > aUResol || dfVDist > aVResol)
634 Standard_Real aTol3d = Max(BRep_Tool::Tolerance(aFirstVertex),BRep_Tool::Tolerance(aWireExp.CurrentVertex()));
636 gp_Pnt aPntRef = BRep_Tool::Pnt(aFirstVertex);
637 gp_Pnt aPnt = BRep_Tool::Pnt(aWireExp.CurrentVertex());
639 if (!(IsDistanceIn2DTolerance(aFaceSurface, aP_first, aP_last, aTol3d)))
640 aClosedStat = BRepCheck_NotClosed;
642 if(!IsDistanceIn3DTolerance(aFaceSurface, aPntRef, aPnt, aTol3d))
643 aClosedStat = BRepCheck_NotClosed;
646 BRepCheck::Add(myMap(myShape),aClosedStat);
650 //=======================================================================
651 //function : Orientation
653 //=======================================================================
654 BRepCheck_Status BRepCheck_Wire::Orientation(const TopoDS_Face& F,
655 const Standard_Boolean Update)
657 BRepCheck_Status theOstat = Closed();
658 if (theOstat != BRepCheck_NotClosed && theOstat != BRepCheck_NoError) {
660 BRepCheck::Add(myMap(myShape),theOstat);
665 theOstat = BRepCheck_NoError;
668 TopAbs_Orientation orient, ortmp = TopAbs_FORWARD;
669 TopTools_ListOfShape ledge, ListOfPassedEdge;
670 TopExp_Explorer exp,vte;
671 TopTools_MapOfShape mapS;
672 TopoDS_Edge theEdge,theRef;
674 // Checks the orientation of the edges
675 for (exp.Init(myShape,TopAbs_EDGE); exp.More(); exp.Next()) {
676 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
677 orient = edg.Orientation();
678 if (IsOriented(edg)) {
682 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
683 TopAbs_Orientation vto = vte.Current().Orientation();
684 if (vto == TopAbs_FORWARD) {
685 VF = TopoDS::Vertex(vte.Current());
687 else if (vto == TopAbs_REVERSED) {
688 VL = TopoDS::Vertex(vte.Current());
690 if (!VF.IsNull() && !VL.IsNull()) {
694 if (VF.IsNull() && VL.IsNull())
695 theOstat = BRepCheck_InvalidDegeneratedFlag;
700 if (theOstat == BRepCheck_NoError) {
701 Standard_Integer Index = 1;
702 Standard_Integer nbOriNoDegen=myMapVE.Extent();
703 // Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 Begin
704 Standard_Boolean isGoFwd = Standard_True;
707 isGoFwd = Standard_False;
708 // Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 End
710 while (Index < nbOriNoDegen) {
712 ListOfPassedEdge.Clear();
713 // find edges that make a chain on VL if !VL.IsNull
716 Standard_Integer ind;
718 ind = myMapVE.FindIndex(VL);
720 else if (!VF.IsNull()) {
721 ind = myMapVE.FindIndex(VF);
724 theOstat = BRepCheck_InvalidDegeneratedFlag;
728 for (TopTools_ListIteratorOfListOfShape itls(myMapVE(ind));
729 itls.More(); itls.Next()) {
730 const TopoDS_Edge & edg = TopoDS::Edge(itls.Value());
732 orient = edg.Orientation();
733 if (mapS.Contains(edg)) ortmp = GetOrientation(mapS,edg);
735 //Add to list already passed outcoming edges
736 if (mapS.Contains(edg) && ortmp == orient && !edg.IsSame(theEdge))
737 for (vte.Init(edg,TopAbs_VERTEX); vte.More(); vte.Next())
739 TopAbs_Orientation vto = vte.Current().Orientation();
742 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current()))
744 ListOfPassedEdge.Append(edg);
748 else // VF is not null
750 if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current()))
752 ListOfPassedEdge.Append(edg);
758 if (!mapS.Contains(edg) || ortmp != orient) {
759 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
760 TopAbs_Orientation vto = vte.Current().Orientation();
762 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current())) {
763 // If the processing is in 2d (face not null) or
764 // if the edge is not degenerated it is added
765 if (!F.IsNull() || !BRep_Tool::Degenerated(edg))
770 else { // VF is not null
771 if (vto == TopAbs_REVERSED && VF.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))
782 Standard_Integer nbconnex = ledge.Extent();
783 Standard_Boolean Changedesens = Standard_False;
785 if (myCstat == BRepCheck_NotClosed) {
788 BRepCheck::Add(myMap(myShape),theOstat);
790 return theOstat; // leave
793 Index--; // because after Index++ and if there is no chain,
794 VL.Nullify(); // chain on VF is forced
796 Changedesens = Standard_True;
800 theOstat = BRepCheck_BadOrientationOfSubshape;
802 BRepCheck::Add(myMap(myShape),theOstat);
808 // JAG 03/07 else if (nbconnex >= 2 && !F.IsNull()) // Try to see in 2d
809 else if (!F.IsNull()) { // Try to see in 2d
818 ChoixUV(pivot,theEdge,F,ledge);
819 nbconnex = ledge.Extent();
820 // 20/03/02 akm vvv : (OCC234) - The 2d exploration of wire with necessary
821 // checks is performed in Closed2d, here it's useless
822 // if (nbconnex == 1 && !CheckLoopOrientation( pivot, theEdge, TopoDS::Edge(ledge.First()), F, ListOfPassedEdge ))
824 // theOstat = BRepCheck_BadOrientationOfSubshape;
826 // BRepCheck::Add(myMap(myShape),theOstat);
833 theOstat = BRepCheck_BadOrientationOfSubshape;
835 BRepCheck::Add(myMap(myShape),theOstat);
839 else if (nbconnex == 1) {
841 for (vte.Init(ledge.First(),TopAbs_VERTEX);vte.More(); vte.Next()) {
842 TopAbs_Orientation vto = vte.Current().Orientation();
844 if (vto == TopAbs_REVERSED) {
845 VL = TopoDS::Vertex(vte.Current());
849 else { // VF is not null
850 if (vto == TopAbs_FORWARD) {
851 VF = TopoDS::Vertex(vte.Current());
856 mapS.Add(ledge.First());
857 theEdge = TopoDS::Edge(ledge.First());
867 else if (!Changedesens) { //nbconnex == 0
868 theOstat = BRepCheck_NotClosed;
870 BRepCheck::Add(myMap(myShape),theOstat);
875 // Check the closure of the wire in 2d (not done in Closed())
878 Standard_Boolean isCheckClose = Standard_False;
880 if (isGoFwd && !VF.IsNull()) {
882 isCheckClose = Standard_True;
883 } else if (!isGoFwd && !VL.IsNull()) {
885 isCheckClose = Standard_True;
888 // if (Index==1 && myCstat!=BRepCheck_NotClosed &&
889 // !VF.IsNull() && !F.IsNull()) {
890 if (Index==1 && myCstat!=BRepCheck_NotClosed &&
891 isCheckClose && !F.IsNull()) {
893 // ind = myMapVE.FindIndex(VF);
894 ind = myMapVE.FindIndex(aVRef);
895 for (TopTools_ListIteratorOfListOfShape itlsh(myMapVE(ind));
896 itlsh.More(); itlsh.Next()) {
897 const TopoDS_Edge & edg = TopoDS::Edge(itlsh.Value());
898 orient = edg.Orientation();
899 if (!theRef.IsSame(edg)) {
900 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
901 TopAbs_Orientation vto = vte.Current().Orientation();
902 // if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current())) {
903 if (vto == TopAbs_REVERSED && aVRef.IsSame(vte.Current())) {
910 // ChoixUV(VF, theRef, F, ledge);
911 ChoixUV(aVRef, theRef, F, ledge);
912 if (ledge.Extent()==0) {
913 theOstat = BRepCheck_NotClosed;
915 BRepCheck::Add(myMap(myShape),theOstat);
920 // End control closure 2d
926 BRepCheck::Add(myMap(myShape),theOstat);
930 //=======================================================================
931 //function : SelfIntersect
933 //=======================================================================
934 BRepCheck_Status BRepCheck_Wire::SelfIntersect(const TopoDS_Face& F,
937 const Standard_Boolean Update)
941 Standard_Integer i,j,Nbedges;
942 Standard_Real first1,last1,first2,last2, tolint;
943 gp_Pnt2d pfirst1,plast1,pfirst2,plast2;
945 Handle(BRepAdaptor_HSurface) HS;
946 Geom2dAdaptor_Curve C1, C2;
947 Geom2dInt_GInter Inter;
948 IntRes2d_Domain myDomain1;
949 TopTools_IndexedMapOfOrientedShape EMap;
950 TopTools_MapOfOrientedShape auxmape;
952 //-- check with proper tolerances if there is no
953 //-- point in the tolerance of a vertex.
955 HS = new BRepAdaptor_HSurface();
956 HS->ChangeSurface().Initialize(F,Standard_False);
958 for (TopoDS_Iterator Iter1(myShape);Iter1.More();Iter1.Next()) {
959 if (Iter1.Value().ShapeType() == TopAbs_EDGE) {
960 EMap.Add(Iter1.Value());
964 Nbedges=EMap.Extent();
967 BRepCheck::Add(myMap(myShape),BRepCheck_EmptyWire);
969 return(BRepCheck_EmptyWire);
972 IntRes2d_Domain *tabDom = new IntRes2d_Domain[Nbedges];
973 TColGeom2d_Array1OfCurve tabCur(1,Nbedges);
974 Bnd_Array1OfBox2d boxes(1,Nbedges);
976 for(i = 1; i <= Nbedges; i++) {
977 const TopoDS_Edge& E1 = TopoDS::Edge(EMap.FindKey(i));
979 Handle(Geom2d_Curve) pcu = BRep_Tool::CurveOnSurface(E1, F, first1, last1);
983 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
986 return(BRepCheck_SelfIntersectingWire);
990 // To avoid exeption in Segment if C1 is BSpline - IFV
991 if(!C1.IsPeriodic()) {
992 if(C1.FirstParameter() > first1) {
993 first1 = C1.FirstParameter();
995 if(C1.LastParameter() < last1 ){
996 last1 = C1.LastParameter();
1000 BRep_Tool::UVPoints(E1, F, pfirst1, plast1);
1001 myDomain1.SetValues(pfirst1,first1,tolint, plast1,last1,tolint);
1003 BndLib_Add2dCurve::Add(C1, first1, last1, Precision::PConfusion(), boxes(i));
1007 myDomain1 = tabDom[i-1];
1010 // Self intersect of C1
1011 Inter.Perform(C1, myDomain1, tolint, tolint);
1013 if(Inter.IsDone()) {
1014 Standard_Integer nbp = Inter.NbPoints();
1015 //Standard_Integer nbs = Inter.NbSegments();
1017 for(Standard_Integer p=1;p<=nbp;p++) {
1018 const IntRes2d_IntersectionPoint& IP=Inter.Point(p);
1019 const IntRes2d_Transition& Tr1 = IP.TransitionOfFirst();
1020 const IntRes2d_Transition& Tr2 = IP.TransitionOfSecond();
1021 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1022 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
1023 //-- Checking of points with true tolerances (ie Tol in 3d)
1024 //-- If the point of intersection is within the tolearnce of a vertex
1025 //-- this intersection is considered correct (no error)
1026 Standard_Boolean localok = Standard_False;
1029 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f,l);
1030 if(!ConS.IsNull()) {
1031 //-- try to test in 3d. (ParamOnSecond gives the same result)
1032 P3d = ConS->Value(IP.ParamOnFirst());
1033 P3d.Transform(L.Transformation());
1034 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1037 gp_Pnt2d aP2d = C1.Value(IP.ParamOnFirst());
1038 P3d = HS->Value(aP2d.X(), aP2d.Y());
1040 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1041 TopExp_Explorer ExplVtx;
1042 for(ExplVtx.Init(E1,TopAbs_VERTEX);
1043 localok==Standard_False && ExplVtx.More();
1046 Standard_Real tolvtt, p3dvttDistanceP3d;
1048 const TopoDS_Vertex& vtt = TopoDS::Vertex(ExplVtx.Current());
1049 p3dvtt = BRep_Tool::Pnt(vtt);
1050 tolvtt = BRep_Tool::Tolerance(vtt);
1051 tolvtt=tolvtt*tolvtt;
1052 p3dvttDistanceP3d=p3dvtt.SquareDistance(P3d);
1053 if(p3dvttDistanceP3d <= tolvtt) {
1054 localok=Standard_True;
1057 if(localok==Standard_False) {
1060 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1064 static Standard_Integer numpoint=0;
1065 cout<<"point p"<<++numpoint<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;cout.flush();
1067 return(BRepCheck_SelfIntersectingWire);
1071 }// if(Inter.IsDone()) {
1073 for(j=i+1; j<=Nbedges; j++) {
1074 const TopoDS_Edge& E2 = TopoDS::Edge(EMap.FindKey(j));
1076 tabCur(j) = BRep_Tool::CurveOnSurface(E2,F,first2,last2);
1077 if (!tabCur(j).IsNull() && last2 > first2) {
1079 // To avoid exeption in Segment if C2 is BSpline - IFV
1080 if(!C2.IsPeriodic()) {
1081 if(C2.FirstParameter() > first2) {
1082 first2 = C2.FirstParameter();
1084 if(C2.LastParameter() < last2 ) {
1085 last2 = C2.LastParameter();
1089 BRep_Tool::UVPoints(E2,F,pfirst2,plast2);
1090 tabDom[j-1].SetValues(pfirst2,first2,tolint,plast2,last2,tolint);
1092 BndLib_Add2dCurve::Add( C2, first2, last2, Precision::PConfusion(), boxes(j) );
1097 cout<<"BRepCheck_NoCurveOnSurface or BRepCheck_InvalidRange"<<endl;cout.flush();
1099 if(tabCur(j).IsNull()) {
1100 return(BRepCheck_NoCurveOnSurface);
1102 return (BRepCheck_InvalidRange);
1109 if (boxes(i).IsOut( boxes(j))) {
1112 //modified by NIZNHY-PKV Fri Oct 29 10:09:01 2010f
1113 if (E1.IsSame(E2)) {
1116 //modified by NIZNHY-PKV Fri Oct 29 10:09:02 2010t
1118 //-- ************************************************************
1119 //-- ******* I n t e r s e c t i o n C 1 and C 2 ********
1120 //-- ************************************************************
1121 Inter.Perform(C1,myDomain1,C2,tabDom[j-1],tolint,tolint);
1123 if(Inter.IsDone()) {
1124 Standard_Integer nbp, nbs;
1125 Standard_Real IP_ParamOnFirst, IP_ParamOnSecond;
1126 IntRes2d_Transition Tr1,Tr2;
1127 TopTools_ListOfShape CommonVertices;
1128 TopTools_ListIteratorOfListOfShape itl;
1129 TopTools_MapOfShape Vmap;
1131 TopoDS_Iterator it( E1 );
1132 for (; it.More(); it.Next()) {
1133 Vmap.Add( it.Value() );
1136 it.Initialize( E2 );
1137 for (; it.More(); it.Next()) {
1138 const TopoDS_Shape& V = it.Value();
1139 if (Vmap.Contains( V )) {
1140 CommonVertices.Append( V );
1144 nbp = Inter.NbPoints();
1145 nbs = Inter.NbSegments();
1146 IP_ParamOnFirst = 0.;
1147 IP_ParamOnSecond = 0.;
1149 //// **** Points of intersection **** ////
1150 for (Standard_Integer p = 1; p <= nbp; p++) {
1151 const IntRes2d_IntersectionPoint& IP = Inter.Point(p);
1152 IP_ParamOnFirst = IP.ParamOnFirst();
1153 IP_ParamOnSecond = IP.ParamOnSecond();
1154 Tr1 = IP.TransitionOfFirst();
1155 Tr2 = IP.TransitionOfSecond();
1156 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1157 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
1158 //-- Checking of points with true tolerances (ie Tol in 3d)
1159 //-- If the point of intersection is within the tolerance of a vertex
1160 //-- this intersection is considered correct (no error)
1161 Standard_Boolean localok = Standard_False;
1162 Standard_Real f1,l1, f2, l2;
1163 TopLoc_Location L, L2;
1165 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f1,l1);
1166 const Handle(Geom_Curve) ConS2 = BRep_Tool::Curve(E2,L2,f2,l2);
1167 //gka protect against working out of edge range
1168 if ( f1-IP_ParamOnFirst > ::Precision::PConfusion() ||
1169 IP_ParamOnFirst-l1 > ::Precision::PConfusion() ||
1170 f2-IP_ParamOnSecond > ::Precision::PConfusion() ||
1171 IP_ParamOnSecond-l2 > ::Precision::PConfusion() )
1173 Standard_Real tolvtt = 0.;
1174 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1175 if (!ConS.IsNull()) {
1176 P3d = ConS->Value(IP_ParamOnFirst);
1177 P3d.Transform(L.Transformation());
1180 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1181 P3d = HS->Value(aP2d.X(), aP2d.Y());
1184 if (!ConS2.IsNull()) {
1185 P3d2 = ConS2->Value(IP_ParamOnSecond);
1186 P3d2.Transform(L2.Transformation());
1189 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1190 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1192 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1193 itl.Initialize( CommonVertices );
1194 for (; itl.More(); itl.Next()) {
1195 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1198 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1199 p3dvtt = BRep_Tool::Pnt(vtt);
1200 tolvtt = BRep_Tool::Tolerance(vtt);
1202 tolvtt=tolvtt*tolvtt;
1203 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1204 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1206 if (p3dvttDistanceP3d<=tolvtt && p3dvttDistanceP3d2<=tolvtt) {
1207 localok = Standard_True;
1212 //-- --------------------------------------------------------
1213 //-- Check maximum yawn between 2 edges
1215 //-- Check distance from edges to the curve joining
1216 //-- the point of intersection with vertex (if exists)
1217 if (localok == Standard_False && !CommonVertices.IsEmpty()) {
1219 cout << "\n------------------------------------------------------\n" <<endl;
1220 cout << "\n--- BRepCheck Wire: AutoIntersection Phase1 -> Erreur \n" <<endl;
1223 Standard_Real distauvtxleplusproche,VParaOnEdge1,VParaOnEdge2;
1224 gp_Pnt VertexLePlusProche;
1228 distauvtxleplusproche=RealLast();
1229 //Find the nearest common vertex
1230 itl.Initialize( CommonVertices );
1231 for (; itl.More(); itl.Next()) {
1232 Standard_Real disptvtx;
1235 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1236 p3dvtt = BRep_Tool::Pnt(vtt);
1237 disptvtx = P3d.Distance(p3dvtt);
1238 if (disptvtx < distauvtxleplusproche) {
1239 VertexLePlusProche = p3dvtt;
1240 distauvtxleplusproche = disptvtx;
1241 VParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1242 VParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1244 // eap: case of closed edge
1245 else if (IsEqual(distauvtxleplusproche, disptvtx)) {
1246 Standard_Real newVParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1247 Standard_Real newVParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1248 if (Abs(IP_ParamOnFirst - VParaOnEdge1) + Abs(IP_ParamOnSecond - VParaOnEdge2)
1250 Abs(IP_ParamOnFirst - newVParaOnEdge1) + Abs(IP_ParamOnSecond - newVParaOnEdge2)) {
1251 VertexLePlusProche = p3dvtt;
1252 VParaOnEdge1 = newVParaOnEdge1;
1253 VParaOnEdge2 = newVParaOnEdge2;
1257 //Patch: extraordinar situation (e.g. tolerance(v) == 0.)
1258 // Modified by skv - Wed Jul 23 12:28:11 2003 OCC1764 Begin
1259 // if (VertexLePlusProche.Distance( P3d ) <= gp::Resolution())
1260 if (VertexLePlusProche.Distance(P3d) <= gp::Resolution() ||
1261 VertexLePlusProche.Distance(P3d2) <= gp::Resolution()) {
1262 // Modified by skv - Wed Jul 23 12:28:12 2003 OCC1764 End
1263 localok = Standard_True;
1266 gp_Lin Lig( VertexLePlusProche, gp_Vec(VertexLePlusProche,P3d) );
1267 Standard_Real du1 = 0.1*(IP_ParamOnFirst -VParaOnEdge1);
1268 Standard_Real du2 = 0.1*(IP_ParamOnSecond-VParaOnEdge2);
1269 Standard_Real maxd1 = 0., maxd2 = 0.;
1272 localok = Standard_True;
1273 Standard_Real tole1 = BRep_Tool::Tolerance(E1);
1274 for (k = 2; localok && k < 9; k++) {
1275 Standard_Real u = VParaOnEdge1 + k*du1; // check if it works
1277 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1278 if (!ConS.IsNull()) {
1279 P1 = ConS->Value(u);
1280 P1.Transform(L.Transformation());
1283 gp_Pnt2d aP2d = C1.Value(u);
1284 P1 = HS->Value(aP2d.X(), aP2d.Y());
1286 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1287 Standard_Real d1 = Lig.Distance(P1);
1291 if (d1 > tole1*2.0){
1292 localok = Standard_False;
1296 // Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764 Begin
1297 gp_Dir aTmpDir(P3d2.XYZ().Subtracted(VertexLePlusProche.XYZ()));
1299 Lig.SetDirection(aTmpDir);
1300 // Modified by skv - Wed Jul 23 12:22:23 2003 OCC1764 End
1301 Standard_Real tole2 = BRep_Tool::Tolerance(E2);
1302 for (k = 2; localok && k < 9; k++) {
1303 Standard_Real u = VParaOnEdge2 + k*du2; // check if it works
1305 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1306 if (!ConS2.IsNull()) {
1307 P2 = ConS2->Value(u);
1308 P2.Transform(L2.Transformation());
1311 gp_Pnt2d aP2d = C2.Value(u);
1312 P2 = HS->Value(aP2d.X(), aP2d.Y());
1314 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1315 Standard_Real d2 = Lig.Distance(P2);
1319 if (d2 > tole2*2.0){
1320 localok = Standard_False;
1323 #ifdef BREPCHECK_DEB
1325 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Bon \n");
1326 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1327 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1328 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1332 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Erreur \n");
1333 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1334 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1335 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1339 } //end of else (construction of the line Lig)
1340 } //end of if (localok == Standard_False && !CommonVertices.IsEmpty())
1342 if(localok==Standard_False) {
1346 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1349 static Standard_Integer numpoint1=0;
1350 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1354 return(BRepCheck_SelfIntersectingWire);
1355 } //-- localok == False
1356 } //end of if(Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1357 } //end of for (Standard_Integer p=1; p <= nbp; p++)
1359 //// **** Segments of intersection **** ////
1360 for (Standard_Integer s = 1; s <= nbs; ++s) {
1361 const IntRes2d_IntersectionSegment& Seg = Inter.Segment(s);
1362 if (Seg.HasFirstPoint() && Seg.HasLastPoint()) {
1363 Standard_Boolean localok;
1365 IntRes2d_IntersectionPoint PSeg [2];
1366 IntRes2d_Position aPCR1, aPCR2;
1368 localok = Standard_False;
1369 PSeg[0] = Seg.FirstPoint();
1370 PSeg[1] = Seg.LastPoint();
1371 // At least one of extremities of the segment must be inside
1372 // the tolerance of a common vertex
1373 for (k = 0; k < 2; ++k) {
1374 IP_ParamOnFirst = PSeg[k].ParamOnFirst();
1375 IP_ParamOnSecond = PSeg[k].ParamOnSecond();
1376 Tr1 = PSeg[k].TransitionOfFirst();
1377 Tr2 = PSeg[k].TransitionOfSecond();
1378 aPCR1=Tr1.PositionOnCurve();
1379 aPCR2=Tr2.PositionOnCurve();
1381 if(aPCR1!=IntRes2d_Middle && aPCR2!=IntRes2d_Middle) {
1382 GeomAbs_CurveType aCT1, aCT2;
1386 if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1387 // check for the two lines coincidence
1388 Standard_Real aPAR_T, aT11, aT12, aT21, aT22, aT1m, aT2m;
1389 Standard_Real aD2, aTolE1, aTolE2, aTol2, aDot;
1395 aTolE1=BRep_Tool::Tolerance(E1);
1396 aTolE2=BRep_Tool::Tolerance(E2);
1397 aTol2=aTolE1+aTolE2;
1403 aT11=PSeg[0].ParamOnFirst();
1404 aT12=PSeg[1].ParamOnFirst();
1405 aT21=PSeg[0].ParamOnSecond();
1406 aT22=PSeg[1].ParamOnSecond();
1408 aT1m=(1.-aPAR_T)*aT11 + aPAR_T*aT12;
1409 aP1m=C1.Value(aT1m);
1411 aD2=aL2.SquareDistance(aP1m);
1413 aT2m=ElCLib::Parameter(aL2, aP1m);
1414 if (aT2m>aT21 && aT2m<aT22) {
1415 const gp_Dir2d& aDir1=aL1.Direction();
1416 const gp_Dir2d& aDir2=aL2.Direction();
1422 if ((1.-aDot)<5.e-11){//0.00001 rad
1423 localok = Standard_False;
1424 break;// from for (k = 0; k < 2; ++k){...
1426 }//if (aT2m>aT21 && aT2m<aT22) {
1428 }//if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1430 localok = Standard_True;
1434 Standard_Real f,l, tolvtt;
1435 TopLoc_Location L, L2;
1436 const Handle(Geom_Curve)& ConS = BRep_Tool::Curve(E1,L,f,l);
1437 const Handle(Geom_Curve)& ConS2 = BRep_Tool::Curve(E2,L2,f,l);
1438 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1439 if (!ConS.IsNull()) {
1440 P3d = ConS->Value(IP_ParamOnFirst);
1441 P3d.Transform(L.Transformation());
1443 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1444 P3d = HS->Value(aP2d.X(), aP2d.Y());
1446 if (!ConS2.IsNull()) {
1447 P3d2 = ConS2->Value(IP_ParamOnSecond);
1448 P3d2.Transform(L2.Transformation());
1450 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1451 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1453 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1454 itl.Initialize( CommonVertices );
1455 for (; itl.More(); itl.Next()) {
1456 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1459 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1460 p3dvtt = BRep_Tool::Pnt(vtt);
1461 tolvtt = BRep_Tool::Tolerance(vtt);
1463 tolvtt=tolvtt*tolvtt;
1464 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1465 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1466 if (p3dvttDistanceP3d <= tolvtt && p3dvttDistanceP3d2 <= tolvtt) {
1467 localok = Standard_True;
1471 if (localok == Standard_True) {
1474 } //end of for (k = 0; k < 2; k++)
1476 if(localok==Standard_False) {
1480 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1483 static Standard_Integer numpoint1=0;
1484 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1488 return(BRepCheck_SelfIntersectingWire);
1489 } //-- localok == False
1490 } //end of if(Seg.HasFirstPoint() && Seg.HasLastPoint())
1491 } //end of for (Standard_Integer s = 1; s <= nbs; p++)
1492 } //-- Inter.IsDone()
1493 } //end of for( j = i+1; j<=Nbedges; j++)
1494 } //end of for(i = 1; i <= Nbedges; i++)
1498 BRepCheck::Add(myMap(myShape),BRepCheck_NoError);
1501 return (BRepCheck_NoError);
1504 //=======================================================================
1505 //function : SetStatus
1507 //=======================================================================
1509 void BRepCheck_Wire::SetStatus(const BRepCheck_Status theStatus)
1511 BRepCheck::Add(myMap(myShape),theStatus);
1514 //=======================================================================
1515 //function : GeometricControls
1517 //=======================================================================
1518 void BRepCheck_Wire::GeometricControls(const Standard_Boolean B)
1522 myCdone = Standard_False;
1527 //=======================================================================
1528 //function : GeometricControls
1530 //=======================================================================
1531 Standard_Boolean BRepCheck_Wire::GeometricControls() const
1536 //=======================================================================
1537 //function : Propagate
1538 //purpose : fill <mapE> with edges connected to <edg> through vertices
1539 // contained in <mapVE>
1540 //=======================================================================
1541 static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape& mapVE,
1542 const TopoDS_Shape& edg,
1543 TopTools_MapOfShape& mapE)
1545 TopTools_ListOfShape currentEdges;
1546 currentEdges.Append(edg);
1550 TopTools_ListOfShape nextEdges;
1551 TopTools_ListIteratorOfListOfShape itrc(currentEdges);
1552 for (; itrc.More(); itrc.Next())
1554 const TopoDS_Shape& Edge = itrc.Value();
1557 TopExp_Explorer ex(Edge, TopAbs_VERTEX);
1558 for (; ex.More(); ex.Next())
1560 const TopoDS_Vertex& vtx = TopoDS::Vertex(ex.Current());
1561 Standard_Integer indv = mapVE.FindIndex(vtx);
1564 const TopTools_ListOfShape& edges = mapVE(indv);
1566 TopTools_ListIteratorOfListOfShape itl(edges);
1567 for (; itl.More(); itl.Next())
1569 const TopoDS_Shape& E = itl.Value();
1570 if (!Edge.IsSame(E) && !mapE.Contains(E))
1571 nextEdges.Append(E);
1576 currentEdges = nextEdges;
1578 while (!currentEdges.IsEmpty());
1581 //=======================================================================
1582 //function : GetOrientation
1584 //=======================================================================
1586 static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape& mapE,
1587 const TopoDS_Edge& edg)
1589 TopTools_MapIteratorOfMapOfShape itm(mapE);
1590 for ( ; itm.More(); itm.Next()) {
1591 if (itm.Key().IsSame(edg)) {
1595 return itm.Key().Orientation();
1597 //=======================================================================
1598 //function : ChoixUV
1599 //purpose : For vertex theVertex given function find an edge along
1600 // that we should go further.
1601 //=======================================================================
1602 void ChoixUV(const TopoDS_Vertex& theVertex,
1603 const TopoDS_Edge& theEdge,
1604 const TopoDS_Face& theFace,
1605 TopTools_ListOfShape& theLOfShape)
1607 TopTools_ListIteratorOfListOfShape It( theLOfShape );
1610 if (theEdge.IsSame( It.Value() ))
1611 theLOfShape.Remove( It );
1616 Standard_Real aTol3d = BRep_Tool::Tolerance(theVertex);
1618 Standard_Integer anIndex = 0, anIndMin = 0;
1619 TopoDS_Edge anEFound;
1620 gp_Pnt2d aPntRef, aPnt;
1621 gp_Vec2d aDerRef, aDer;
1622 Standard_Real aMinAngle, aMaxAngle, anAngle;
1623 Standard_Real a_gpResolution=gp::Resolution();
1624 TopAbs_Orientation aVOrientation, anEdgOrientation;
1625 Standard_Real aParam = 0.0, aFirstParam = 0.0, aLastParam = 0.0, aParPiv = 0.0;
1626 BRepAdaptor_Surface aFaceSurface(theFace,Standard_False); // no restriction
1628 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirstParam, aLastParam);
1629 if (C2d.IsNull())// JAG 10.12.96
1632 aVOrientation = theVertex.Orientation();
1633 anEdgOrientation = theEdge.Orientation();
1635 aParPiv =(aVOrientation==anEdgOrientation) ? aFirstParam : aLastParam;
1636 aMinAngle = RealLast();
1637 aMaxAngle = RealFirst();
1639 CurveDirForParameter(C2d, aParPiv, aPntRef, aDerRef);
1641 if (aVOrientation != anEdgOrientation)
1644 It.Initialize(theLOfShape);
1646 for (; It.More(); It.Next())
1649 const TopoDS_Edge& anE=TopoDS::Edge(It.Value());
1650 C2d = BRep_Tool::CurveOnSurface(anE, theFace, aFirstParam, aLastParam);
1654 aParam =(aVOrientation != anE.Orientation()) ? aFirstParam : aLastParam;
1655 aPnt = C2d->Value(aParam);
1657 if(!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d, Standard_False))
1660 CurveDirForParameter(C2d, aParam, aPnt, aDer);
1662 if (aVOrientation == anE.Orientation())
1665 if ((aDerRef.Magnitude() <= a_gpResolution) ||
1666 (aDer.Magnitude() <= a_gpResolution))
1667 //Vector length is too small
1670 anAngle = -aDerRef.Angle( aDer );
1675 if ( theFace.Orientation() == TopAbs_FORWARD )
1677 if ( anAngle < aMinAngle )
1680 aMinAngle = anAngle;
1683 else //theFace.Orientation() != TopAbs_FORWARD
1685 if ( anAngle > aMaxAngle )
1688 aMaxAngle = anAngle;
1695 if (theLOfShape.Extent() == 1)
1697 Standard_Boolean IsFound = Standard_True; //all right
1698 anEFound = TopoDS::Edge(theLOfShape.First());
1700 if(anEFound.IsNull() || BRep_Tool::Degenerated(theEdge) ||
1701 BRep_Tool::Degenerated(anEFound))
1702 IsFound = Standard_False; //bad
1703 else if (!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d))
1704 IsFound = Standard_False; //bad
1706 // clousureness in 3D
1708 //IsDistanceIn3DTolerance
1709 BRepAdaptor_Curve bcEdg(theEdge, theFace);
1710 BRepAdaptor_Curve bcEvois(anEFound, theFace);
1711 gp_Pnt pEdg = bcEdg.Value(aParPiv);
1712 gp_Pnt pEFound = bcEvois.Value(aParam);
1714 if(!IsDistanceIn3DTolerance(theFace, pEdg, pEFound, aTol3d))
1715 IsFound = Standard_False;
1717 //angle was not defined but points are close
1718 IsFound = Standard_True; //all right
1723 theLOfShape.Clear();
1725 }//if (theLOfShape.Extent() == 1)
1726 else //if (anIndMin == 0)
1728 theLOfShape.Clear();
1734 while (anIndex < anIndMin)
1736 theLOfShape.RemoveFirst();
1740 It.Initialize(theLOfShape);
1744 theLOfShape.Remove(It);
1749 //=======================================================================
1750 //function : CurveDirForParameter
1752 //=======================================================================
1753 void CurveDirForParameter(const Handle(Geom2d_Curve)& aC2d,
1754 const Standard_Real aPrm,
1758 Standard_Real aTol=gp::Resolution();
1761 aC2d->D1(aPrm, Pnt, aVec2d);
1763 if (aVec2d.Magnitude() <= aTol) {
1764 for (i = 2; i <= 100; i++){
1765 aVec2d = aC2d->DN(aPrm, i);
1766 if (aVec2d.Magnitude() > aTol) {
1773 // Modified by Sergey KHROMOV - Wed May 22 10:44:06 2002 OCC325 Begin
1774 //=======================================================================
1775 //function : GetPnts2d
1776 //purpose : this function returns the parametric points of theVertex on theFace.
1777 // If theVertex is a start and end vertex of theEdge hasSecondPnt
1778 // becomes Standard_True and aPnt2 returns the second parametric point.
1779 // Returns Standard_True if paraametric points are successfully found.
1780 //=======================================================================
1782 static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
1783 const TopoDS_Edge &theEdge,
1784 const TopoDS_Face &theFace,
1787 Handle(Geom2d_Curve) aPCurve;
1788 Standard_Real aFPar;
1789 Standard_Real aLPar;
1790 Standard_Real aParOnEdge;
1791 TopoDS_Vertex aFirstVtx;
1792 TopoDS_Vertex aLastVtx;
1794 TopExp::Vertices(theEdge, aFirstVtx, aLastVtx);
1796 if (!theVertex.IsSame(aFirstVtx) && !theVertex.IsSame(aLastVtx))
1797 return Standard_False;
1799 aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFPar, aLPar);
1801 if (aPCurve.IsNull())
1802 return Standard_False;
1804 aParOnEdge = BRep_Tool::Parameter(theVertex, theEdge);
1805 aPnt = aPCurve->Value(aParOnEdge);
1807 return Standard_True;
1810 //=======================================================================
1811 //function : Closed2dForPeriodicFace
1812 //purpose : Checks the distance between first point of the first edge
1813 // and last point of the last edge in 2d for periodic face.
1814 //=======================================================================
1815 static Standard_Boolean IsClosed2dForPeriodicFace
1816 (const TopoDS_Face &theFace,
1817 const gp_Pnt2d &theP1,
1818 const gp_Pnt2d &theP2,
1819 const TopoDS_Vertex &theVertex)
1821 // Check 2d distance for periodic faces with seam edge.
1822 // Searching for seam edges
1823 TopTools_ListOfShape aSeamEdges;
1824 TopTools_MapOfShape NotSeams;
1825 TopTools_MapOfShape ClosedEdges;
1826 TopExp_Explorer anExp(theFace, TopAbs_EDGE);
1828 for (;anExp.More(); anExp.Next()) {
1829 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
1831 if (NotSeams.Contains(anEdge))
1834 if (!IsOriented(anEdge) ||
1835 !BRep_Tool::IsClosed(anEdge, theFace)) {
1836 NotSeams.Add(anEdge);
1840 if (!ClosedEdges.Add(anEdge))
1841 aSeamEdges.Append(anEdge);
1844 if (aSeamEdges.Extent() == 0)
1845 return Standard_True;
1847 // check if theVertex lies on one of the seam edges
1848 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
1849 Standard_Real aTol = BRep_Tool::Tolerance(theVertex);
1850 Standard_Real aUResol = aFaceSurface.UResolution(aTol);
1851 Standard_Real aVResol = aFaceSurface.VResolution(aTol);
1852 Standard_Real aVicinity = Sqrt(aUResol*aUResol + aVResol*aVResol);
1853 Standard_Real aDistP1P2 = theP1.Distance(theP2);
1856 TopTools_ListIteratorOfListOfShape anIter(aSeamEdges);
1858 for (; anIter.More(); anIter.Next()) {
1859 TopoDS_Edge aSeamEdge = TopoDS::Edge(anIter.Value());
1861 anExp.Init(aSeamEdge, TopAbs_VERTEX);
1862 for (; anExp.More(); anExp.Next()) {
1863 const TopoDS_Shape &aVtx = anExp.Current();
1865 // We found an edge. Check the distance between two given points
1866 // to be lower than the computed tolerance.
1867 if (IsOriented(aVtx) && aVtx.IsSame(theVertex)) {
1870 Standard_Real a2dTol;
1872 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt1))
1875 aSeamEdge = TopoDS::Edge(aSeamEdge.Reversed());
1877 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt2))
1880 a2dTol = aPnt1.Distance(aPnt2)*1.e-2;
1881 a2dTol = Max(a2dTol, aVicinity);
1883 if (aDistP1P2 > a2dTol)
1884 return Standard_False;
1889 return Standard_True;
1891 // Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End