0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepCheck / BRepCheck_Wire.cxx
CommitLineData
b311480e 1// Created on: 1995-12-12
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// Modified by dpf, Fri Dec 19 15:31:03 1997
0d969553 18// Processing of closing in 2d.
7fd59977 19// modified by eap Tue Dec 18 14:14:25 2001 (bug OCC23)
20// Check self-intersection in case of closed edge
7fd59977 21// modified by eap Fri Dec 21 17:36:55 2001 (bug OCC35)
22// Closed2d() added
7fd59977 23// Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764
24
42cf5bc1 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>
7fd59977 32#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
42cf5bc1 33#include <BRepCheck_ListOfStatus.hxx>
34#include <BRepCheck_Wire.hxx>
35#include <BRepTools_WireExplorer.hxx>
36#include <ElCLib.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>
42#include <gp_Lin.hxx>
43#include <gp_Pnt.hxx>
44#include <gp_Pnt2d.hxx>
45#include <IntRes2d_Domain.hxx>
7fd59977 46#include <IntRes2d_Intersection.hxx>
47#include <IntRes2d_IntersectionPoint.hxx>
48#include <IntRes2d_IntersectionSegment.hxx>
49#include <IntRes2d_Transition.hxx>
42cf5bc1 50#include <Precision.hxx>
51#include <Standard_Type.hxx>
52#include <TColGeom2d_Array1OfCurve.hxx>
53#include <TopExp.hxx>
54#include <TopExp_Explorer.hxx>
55#include <TopLoc_Location.hxx>
7fd59977 56#include <TopoDS.hxx>
42cf5bc1 57#include <TopoDS_Edge.hxx>
58#include <TopoDS_Face.hxx>
59#include <TopoDS_Iterator.hxx>
60#include <TopoDS_Shape.hxx>
7fd59977 61#include <TopoDS_Vertex.hxx>
42cf5bc1 62#include <TopoDS_Wire.hxx>
63#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
64#include <TopTools_DataMapOfShapeListOfShape.hxx>
7fd59977 65#include <TopTools_HArray1OfShape.hxx>
42cf5bc1 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>
7fd59977 71#include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
42cf5bc1 72#include <TopTools_MapIteratorOfMapOfShape.hxx>
73#include <TopTools_MapOfOrientedShape.hxx>
74#include <TopTools_MapOfShape.hxx>
7fd59977 75
42cf5bc1 76#include <stdio.h>
7fd59977 77//Patch
7fd59977 78//#ifdef WNT
7fd59977 79//#endif
7fd59977 80static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape&,
81 const TopoDS_Shape&, // edge
82 TopTools_MapOfShape&); // mapofedge
83
84
85static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape&,
86 const TopoDS_Edge&);
87
88
89static
90 void ChoixUV(const TopoDS_Vertex&,
91 const TopoDS_Edge&,
92 const TopoDS_Face&,
93 TopTools_ListOfShape&);
94
95// 20/03/02 akm vvv (OCC234)
96// static
97// Standard_Boolean CheckLoopOrientation( const TopoDS_Vertex&,
98// const TopoDS_Edge&,
99// const TopoDS_Edge&,
100// const TopoDS_Face&,
101// TopTools_ListOfShape&);
102// 20/03/02 akm ^^^
103
104inline Standard_Boolean IsOriented(const TopoDS_Shape& S)
105{
106 return (S.Orientation() == TopAbs_FORWARD ||
107 S.Orientation() == TopAbs_REVERSED);
108}
109
110static
94f71cad 111 void CurveDirForParameter(const Geom2dAdaptor_Curve& aC2d,
7fd59977 112 const Standard_Real aPrm,
113 gp_Pnt2d& Pnt,
114 gp_Vec2d& aVec2d);
115
116// Modified by Sergey KHROMOV - Thu Jun 20 11:21:51 2002 OCC325 Begin
117static Standard_Boolean IsClosed2dForPeriodicFace
118 (const TopoDS_Face &theFace,
119 const gp_Pnt2d &theP1,
120 const gp_Pnt2d &theP2,
121 const TopoDS_Vertex &theVertex);
122
123static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
124 const TopoDS_Edge &theEdge,
125 const TopoDS_Face &theFace,
126 gp_Pnt2d &aPnt);
127// Modified by Sergey KHROMOV - Wed May 22 10:44:08 2002 End
128
129//=======================================================================
130//function : BRepCheck_Wire
131//purpose :
132//=======================================================================
133BRepCheck_Wire::BRepCheck_Wire(const TopoDS_Wire& W)
134{
135 Init(W);
136}
137//=======================================================================
138//function : Minimum
139//purpose :
140//=======================================================================
141void BRepCheck_Wire::Minimum()
142{
143 myCdone = Standard_False;
144 myGctrl = Standard_True;
145 if (!myMin) {
146 BRepCheck_ListOfStatus thelist;
147 myMap.Bind(myShape, thelist);
148 BRepCheck_ListOfStatus& lst = myMap(myShape);
149
0d969553 150 // check that the wire is "connex"
7fd59977 151 TopExp_Explorer exp(myShape,TopAbs_EDGE);
152 Standard_Integer nbedge = 0;
153 myMapVE.Clear();
154 // fill myMapVE
155 for (; exp.More(); exp.Next()) {
156 nbedge++;
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);
162 if (index == 0) {
163 TopTools_ListOfShape theListOfShape;
164 index = myMapVE.Add(vtx, theListOfShape);
165 }
166 myMapVE(index).Append(exp.Current());
167 }
168 }
169 // wire must have at least one edge
170 if (nbedge == 0) {
171 BRepCheck::Add(lst,BRepCheck_EmptyWire);
172 }
173 // check if all edges are connected through vertices
174 else if (nbedge >= 2) {
175 TopTools_MapOfShape mapE;
176 exp.ReInit();
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);
181 break;
182 }
183 }
184 }
185 if (lst.IsEmpty()) {
186 lst.Append(BRepCheck_NoError);
187 }
188 myMapVE.Clear();
189 myMin = Standard_True;
190 }
191}
192//=======================================================================
193//function : InContext
194//purpose :
195//=======================================================================
196void BRepCheck_Wire::InContext(const TopoDS_Shape& S)
197{
198
199 if (myMap.IsBound(S)) {
200 return;
201 }
202 BRepCheck_ListOfStatus thelist;
203 myMap.Bind(S, thelist);
204
205 BRepCheck_ListOfStatus& lst = myMap(S);
206
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)) {
211 break;
212 }
213 }
214 if (!exp.More()) {
215 BRepCheck::Add(lst,BRepCheck_SubshapeNotInShape);
216 return;
217 }
218
219 BRepCheck_Status st = BRepCheck_NoError;
220 TopAbs_ShapeEnum styp = S.ShapeType();
221 switch (styp) {
222
223 case TopAbs_FACE:
224 {
0d969553 225 TopoDS_Edge ed1,ed2;
7fd59977 226 if (myGctrl)
227 st = SelfIntersect(TopoDS::Face(S),ed1,ed2,Standard_True);
228 if (st != BRepCheck_NoError) break;
229 st = Closed();
230 if (st != BRepCheck_NoError) break;
231 st = Orientation(TopoDS::Face(S));
232 if (st != BRepCheck_NoError) break;
233 st = Closed2d(TopoDS::Face(S));
234 }
235 break;
236 default:
237 break;
238 }
239
240 if (st != BRepCheck_NoError)
241 BRepCheck::Add(lst,st);
242
243 if (lst.IsEmpty())
244 lst.Append(BRepCheck_NoError);
245}
246//=======================================================================
247//function : Blind
248//purpose :
249//=======================================================================
250void BRepCheck_Wire::Blind()
251{
252 if (!myBlind) {
0d969553 253 // nothing more that the minimum
7fd59977 254 myBlind = Standard_True;
255 }
256}
257//=======================================================================
258//function : Closed
259//purpose :
260//=======================================================================
261BRepCheck_Status BRepCheck_Wire::Closed(const Standard_Boolean Update)
262{
263
264 if (myCdone) {
265 if (Update) {
266 BRepCheck::Add(myMap(myShape),myCstat);
267 }
268 return myCstat;
269 }
270
0d969553 271 myCdone = Standard_True;
7fd59977 272
273 BRepCheck_ListIteratorOfListOfStatus itl(myMap(myShape));
274 if (itl.Value() != BRepCheck_NoError) {
275 myCstat = itl.Value();
0d969553 276 return myCstat; // already saved
7fd59977 277 }
278
279 myCstat = BRepCheck_NoError;
280
281 TopExp_Explorer exp,expv;
282 TopTools_MapOfShape mapS;
283 TopTools_DataMapOfShapeListOfShape Cradoc;
284 myMapVE.Clear();
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...
287 // myNbori = 0;
288 for (exp.Init(myShape,TopAbs_EDGE);exp.More(); exp.Next()) {
289 if (IsOriented(exp.Current())) {
290 // myNbori++;
291 if (!Cradoc.IsBound(exp.Current())) {
292 TopTools_ListOfShape theListOfShape;
293 Cradoc.Bind(exp.Current(), theListOfShape);
294 }
295 Cradoc(exp.Current()).Append(exp.Current());
296
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());
301 if (index == 0) {
302 TopTools_ListOfShape theListOfShape1;
303 index = myMapVE.Add(expv.Current(), theListOfShape1);
304 }
305 myMapVE(index).Append(exp.Current());
306 }
307 }
308 }
309 }
310
311 Standard_Integer theNbori = mapS.Extent();
312 if (theNbori >= 2) {
313 mapS.Clear();
314 for (exp.ReInit(); exp.More(); exp.Next()) {
315 if (IsOriented(exp.Current())) {
316 break;
317 }
318 }
319 Propagate(myMapVE,exp.Current(),mapS);
320 }
321 if (theNbori != mapS.Extent()) {
322 myCstat = BRepCheck_NotConnected;
323 if (Update) {
324 BRepCheck::Add(myMap(myShape),myCstat);
325 }
326 return myCstat;
327 }
328
329 // Checks the number of occurence of an edge : maximum 2, and in this
330 // case, one time FORWARD and one time REVERSED
331
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;
337 }
338 else if (itdm.Value().Extent() == 2) {
339 if (itdm.Value().First().Orientation() ==
340 itdm.Value().Last().Orientation()) {
341 yabug = Standard_True;
342 }
343 }
344 if (yabug) {
345 myCstat = BRepCheck_RedundantEdge;
346 if (Update) {
347 BRepCheck::Add(myMap(myShape),myCstat);
348 }
349 return myCstat;
350 }
351 }
352
353 for (Standard_Integer i = 1; i<= myMapVE.Extent(); i++) {
354 if (myMapVE(i).Extent()%2 != 0) {
355 myCstat=BRepCheck_NotClosed;
356 if (Update) {
357 BRepCheck::Add(myMap(myShape),myCstat);
358 }
359 return myCstat;
360 }
361 }
362
363 if (Update) {
364 BRepCheck::Add(myMap(myShape),myCstat);
365 }
366 return myCstat;
367}
3f257c62 368
369//=======================================================================
370//function : IsDistanceIn3DTolerance
371//purpose : Return Standard_True if distance between thePnt_f and
372// thePnt_l is not more, than aTol3d
373//=======================================================================
9e20ed57 374Standard_Boolean IsDistanceIn3DTolerance (const gp_Pnt& thePnt_f,
3f257c62 375 const gp_Pnt& thePnt_l,
376 const Standard_Real aTol3d)
377 {
378 Standard_Real Dist = thePnt_f.Distance(thePnt_l);
379
380 if (Dist < aTol3d)
381 return Standard_True;
382
0797d9d3 383#ifdef OCCT_DEBUG
3f257c62 384 cout << endl;
385 cout << "--------Function IsDistanceIn3DTolerance(...)----------" << endl;
386 cout << "--- BRepCheck Wire: Closed3d -> Error" << endl;
387 cout << "--- Dist (" << Dist << ") > Tol3d (" << aTol3d << ")" << endl;
388 cout << "Pnt1(" << thePnt_f.X() << "; " << thePnt_f.Y() << "; " << thePnt_f.Z() << ")" << endl;
389 cout << "Pnt2(" << thePnt_l.X() << "; " << thePnt_l.Y() << "; " << thePnt_l.Z() << ")" << endl;
390 cout << "------------------------------------------------------" << endl;
391#endif
392
393 return Standard_False;
394 }
395
396//=======================================================================
397//function : IsDistanceIn3DTolerance
398//purpose :
399//=======================================================================
498ce76b 400static
3f257c62 401Standard_Boolean IsDistanceIn2DTolerance (const BRepAdaptor_Surface& aFaceSurface,
402 const gp_Pnt2d& thePnt,
403 const gp_Pnt2d& thePntRef,
404 const Standard_Real aTol3d,
0797d9d3 405#ifdef OCCT_DEBUG
3f257c62 406 const Standard_Boolean PrintWarnings = Standard_True)
498ce76b 407#else
408 const Standard_Boolean = Standard_True)
409#endif
410{
3f257c62 411 Standard_Real dumax = 0.01 * (aFaceSurface.LastUParameter() - aFaceSurface.FirstUParameter());
412 Standard_Real dvmax = 0.01 * (aFaceSurface.LastVParameter() - aFaceSurface.FirstVParameter());
413 Standard_Real dumin = Abs(thePnt.X() - thePntRef.X());
414 Standard_Real dvmin = Abs(thePnt.Y() - thePntRef.Y());
415
416 if((dumin < dumax) && (dvmin < dvmax))
417 return Standard_True;
418
0797d9d3 419#ifdef OCCT_DEBUG
3f257c62 420 if(PrintWarnings)
421 {
422 cout << endl;
423 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
9e20ed57 424 cout << "--- BRepCheck Wire: Not closed in 2D" << endl;
3f257c62 425 cout << "*****************************************************" << endl;
426 cout << "*dumin = " << dumin << "; dumax = " << dumax << endl;
427 cout << "* dvmin = " << dvmin << "; dvmax = " << dvmax << endl;
428 cout << "* (dumin > dumax) or (dvmin > dvmax)." << endl;
429 cout << "*****************************************************" << endl;
430 cout << endl;
431 cout << "UFirst = " << aFaceSurface.FirstUParameter();
432 cout << "; ULast = " << aFaceSurface.LastUParameter() << endl;
433 cout << "VFirst = " << aFaceSurface.FirstVParameter();
434 cout << "; VLast = " << aFaceSurface.LastVParameter() << endl;
435 }
436
437 dumax = aFaceSurface.UResolution(aTol3d);
438 dvmax = aFaceSurface.VResolution(aTol3d);
439
440 if(PrintWarnings)
441 {
442 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
443 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
444 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
445 }
446
447#else
448 dumax = aFaceSurface.UResolution(aTol3d);
449 dvmax = aFaceSurface.VResolution(aTol3d);
450#endif
451
452 Standard_Real aTol2d = 2*Max( dumax, dvmax);
453
0797d9d3 454#ifdef OCCT_DEBUG
3f257c62 455 if((aTol2d <= 0.0) && (PrintWarnings))
456 {
457 cout<<"BRepCheck_Wire : UResolution and VResolution = 0.0 (Face too small ?)"<<endl;
458 cout.flush();
459 }
460#endif
461
462 //Standard_Real Dist = thePntRef.Distance(thePnt);
463 Standard_Real Dist = Max(dumin, dvmin);
464
465 if (Dist < aTol2d)
466 return Standard_True;
467
0797d9d3 468#ifdef OCCT_DEBUG
3f257c62 469 if(PrintWarnings)
470 {
471 cout << endl;
472 cout << "--------Function IsDistanceIn2DTolerance(...)----------" << endl;
ab87e6fc 473 cout << "--- BRepCheck Wire: Not closed in 2d" << endl;
3f257c62 474 cout << "*****************************************************" << endl;
475 cout << "* Dist = " << Dist << " > Tol2d = " << aTol2d << endl;
476 cout << "*****************************************************" << endl;
477 cout << "aTol3d = " << aTol3d <<"; URes = " << dumax << "; VRes = " << dvmax << endl;
478 cout << "thePnt(" << thePnt.X() << "; " << thePnt.Y() << ")" << endl;
479 cout << "thePntRef(" << thePntRef.X() << "; " << thePntRef.Y() << ")" << endl;
480 }
481#endif
482
483 return Standard_False;
484 }
485
7fd59977 486//=======================================================================
487//function : Closed2d
488//purpose : for periodic faces
489//=======================================================================
490BRepCheck_Status BRepCheck_Wire::Closed2d(const TopoDS_Face& theFace,
491 const Standard_Boolean Update)
3f257c62 492 {
493 // 3d closure checked too
7fd59977 494 BRepCheck_Status aClosedStat = Closed();
3f257c62 495 if (aClosedStat != BRepCheck_NoError)
496 {
497 if (Update)
7fd59977 498 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 499
7fd59977 500 return aClosedStat;
3f257c62 501 }
7fd59977 502
3f257c62 503// 20/03/02 akm vvv : (OCC234) Hence this method will be used to check
504// both periodic and non-periodic faces
505// // this check is for periodic faces
7fd59977 506 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
3f257c62 507// if (!aFaceSurface.IsUPeriodic() && !aFaceSurface.IsVPeriodic())
508// {
509// if (Update)
510// BRepCheck::Add(myMap(myShape),aClosedStat);
511// return aClosedStat;
512// }
513// 20/03/02 akm ^^^
514
515// count edges having FORWARD or REVERSED orientation
7fd59977 516 Standard_Integer aNbOrirntedEdges = 0;
517 TopExp_Explorer anEdgeExp(myShape,TopAbs_EDGE);
3f257c62 518 for (;anEdgeExp.More(); anEdgeExp.Next())
519 {
7fd59977 520 if (IsOriented(anEdgeExp.Current()))
521 aNbOrirntedEdges++;
3f257c62 522 }
523
7fd59977 524 if (aNbOrirntedEdges==0)
3f257c62 525 {
526 if (Update)
7fd59977 527 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 528
7fd59977 529 return aClosedStat;
3f257c62 530 }
7fd59977 531
3f257c62 532// all those edges must form a closed 2d contour and be found by WireExplorer
7fd59977 533
3f257c62 534 Standard_Integer aNbFoundEdges = 0;
7fd59977 535 BRepTools_WireExplorer aWireExp(TopoDS::Wire(myShape), theFace);
536 TopoDS_Edge aFirstEdge = aWireExp.Current();
537 TopoDS_Vertex aFirstVertex = aWireExp.CurrentVertex();
538 TopoDS_Edge aLastEdge;
3f257c62 539
7fd59977 540 for (;aWireExp.More(); aWireExp.Next())
3f257c62 541 {
7fd59977 542 aNbFoundEdges++;
543 aLastEdge = aWireExp.Current();
3f257c62 544 }
7fd59977 545
546 if (aNbFoundEdges != aNbOrirntedEdges)
3f257c62 547 {
7fd59977 548 aClosedStat = BRepCheck_NotClosed;
549 if (Update)
550 BRepCheck::Add(myMap(myShape),aClosedStat);
7fd59977 551
3f257c62 552 return aClosedStat;
553 }
554
555// Check distance between 2d ends of first and last edges
7fd59977 556// Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 Begin
557// First check if first and last edges are infinite:
558 Standard_Real aF;
559 Standard_Real aL;
560 Standard_Boolean isFirstInfinite = Standard_False;
561 Standard_Boolean isLastInfinite = Standard_False;
562 TopAbs_Orientation anOri;
563
564 anOri = aFirstEdge.Orientation();
565 BRep_Tool::Range(aFirstEdge, aF, aL);
3f257c62 566 if ((anOri == TopAbs_FORWARD && Precision::IsNegativeInfinite( aF )) ||
567 (anOri == TopAbs_REVERSED && Precision::IsPositiveInfinite( aL )))
7fd59977 568 isFirstInfinite = Standard_True;
569
570 anOri = aLastEdge.Orientation();
571 BRep_Tool::Range(aLastEdge, aF, aL);
3f257c62 572
573 if ((anOri == TopAbs_FORWARD && Precision::IsPositiveInfinite( aL )) ||
574 (anOri == TopAbs_REVERSED && Precision::IsNegativeInfinite( aF )))
7fd59977 575 isLastInfinite = Standard_True;
576
3f257c62 577 if (isFirstInfinite && isLastInfinite)
578 {
579 if (Update)
7fd59977 580 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 581
7fd59977 582 return aClosedStat;
3f257c62 583 }
584 else if (aFirstVertex.IsNull())
585 {
7fd59977 586 aClosedStat = BRepCheck_NotClosed;
3f257c62 587
7fd59977 588 if (Update)
589 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 590
7fd59977 591 return aClosedStat;
3f257c62 592 }
7fd59977 593// Modified by Sergey KHROMOV - Mon May 13 12:42:10 2002 End
594
3f257c62 595 gp_Pnt2d aP_first, aP_last, aP_temp; // ends of prev edge, next edge, bidon
7fd59977 596
3f257c62 597// get last point
598 BRep_Tool::UVPoints(aLastEdge, theFace, aP_temp, aP_last);
599 if (aLastEdge.Orientation() == TopAbs_REVERSED)
600 aP_last = aP_temp;
601
7fd59977 602// Modified by Sergey KHROMOV - Mon Apr 22 10:36:33 2002 Begin
603// Standard_Real aTol, aUResol, aVResol;
7fd59977 604// // find 2d tolerance
605// aTol = BRep_Tool::Tolerance(aFirstVertex);
606// aUResol = 2*aFaceSurface.UResolution(aTol);
607// aVResol = 2*aFaceSurface.VResolution(aTol);
608
3f257c62 609// get first point
7fd59977 610 if (aFirstEdge.Orientation() == TopAbs_REVERSED)
3f257c62 611 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_temp, aP_first);
7fd59977 612 else
3f257c62 613 BRep_Tool::UVPoints(aFirstEdge, theFace, aP_first, aP_temp);
7fd59977 614
615// Modified by Sergey KHROMOV - Thu Jun 20 10:55:42 2002 OCC325 Begin
616// Check 2d distance for periodic faces with seam edge
3f257c62 617 if (!IsClosed2dForPeriodicFace(theFace, aP_first, aP_last, aFirstVertex))
618 {
7fd59977 619 aClosedStat = BRepCheck_NotClosed;
3f257c62 620 if (Update)
7fd59977 621 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 622
7fd59977 623 return aClosedStat;
3f257c62 624 }
7fd59977 625// Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End
626
3f257c62 627// check distance
7fd59977 628// Standard_Real dfUDist=Abs(p.X()-p1.X());
629// Standard_Real dfVDist=Abs(p.Y()-p1.Y());
630// if (dfUDist > aUResol || dfVDist > aVResol)
631// {
3f257c62 632
633 Standard_Real aTol3d = Max(BRep_Tool::Tolerance(aFirstVertex),BRep_Tool::Tolerance(aWireExp.CurrentVertex()));
634
635 gp_Pnt aPntRef = BRep_Tool::Pnt(aFirstVertex);
636 gp_Pnt aPnt = BRep_Tool::Pnt(aWireExp.CurrentVertex());
637
638 if (!(IsDistanceIn2DTolerance(aFaceSurface, aP_first, aP_last, aTol3d)))
7fd59977 639 aClosedStat = BRepCheck_NotClosed;
3f257c62 640
9e20ed57 641 if(!IsDistanceIn3DTolerance(aPntRef, aPnt, aTol3d))
3f257c62 642 aClosedStat = BRepCheck_NotClosed;
643
7fd59977 644 if (Update)
645 BRepCheck::Add(myMap(myShape),aClosedStat);
3f257c62 646
7fd59977 647 return aClosedStat;
3f257c62 648 }
7fd59977 649//=======================================================================
650//function : Orientation
651//purpose :
652//=======================================================================
653BRepCheck_Status BRepCheck_Wire::Orientation(const TopoDS_Face& F,
654 const Standard_Boolean Update)
655{
656 BRepCheck_Status theOstat = Closed();
657 if (theOstat != BRepCheck_NotClosed && theOstat != BRepCheck_NoError) {
658 if (Update) {
659 BRepCheck::Add(myMap(myShape),theOstat);
660 }
661 return theOstat;
662 }
663
664 theOstat = BRepCheck_NoError;
665
666 TopoDS_Vertex VF,VL;
7fd59977 667 TopAbs_Orientation orient, ortmp = TopAbs_FORWARD;
7fd59977 668 TopTools_ListOfShape ledge, ListOfPassedEdge;
669 TopExp_Explorer exp,vte;
670 TopTools_MapOfShape mapS;
671 TopoDS_Edge theEdge,theRef;
672
673 // Checks the orientation of the edges
674 for (exp.Init(myShape,TopAbs_EDGE); exp.More(); exp.Next()) {
675 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
676 orient = edg.Orientation();
677 if (IsOriented(edg)) {
678 mapS.Add(edg);
679 theEdge = edg;
680 theRef = edg;
681 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
682 TopAbs_Orientation vto = vte.Current().Orientation();
683 if (vto == TopAbs_FORWARD) {
684 VF = TopoDS::Vertex(vte.Current());
685 }
686 else if (vto == TopAbs_REVERSED) {
687 VL = TopoDS::Vertex(vte.Current());
688 }
689 if (!VF.IsNull() && !VL.IsNull()) {
690 break;
691 }
692 }
693 if (VF.IsNull() && VL.IsNull())
694 theOstat = BRepCheck_InvalidDegeneratedFlag;
695 break;
696 }
697 }
698
699 if (theOstat == BRepCheck_NoError) {
700 Standard_Integer Index = 1;
701 Standard_Integer nbOriNoDegen=myMapVE.Extent();
702// Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 Begin
703 Standard_Boolean isGoFwd = Standard_True;
704
705 if (VL.IsNull())
706 isGoFwd = Standard_False;
707// Modified by Sergey KHROMOV - Tue May 21 17:12:45 2002 End
708
709 while (Index < nbOriNoDegen) {
710 ledge.Clear();
711 ListOfPassedEdge.Clear();
0d969553
Y
712 // find edges that make a chain on VL if !VL.IsNull
713 // otherwise on VF.
7fd59977 714
715 Standard_Integer ind;
716 if (!VL.IsNull()) {
717 ind = myMapVE.FindIndex(VL);
718 }
719 else if (!VF.IsNull()) {
720 ind = myMapVE.FindIndex(VF);
721 }
722 else {
723 theOstat = BRepCheck_InvalidDegeneratedFlag;
724 break;
725 }
726
727 for (TopTools_ListIteratorOfListOfShape itls(myMapVE(ind));
728 itls.More(); itls.Next()) {
729 const TopoDS_Edge & edg = TopoDS::Edge(itls.Value());
730
731 orient = edg.Orientation();
732 if (mapS.Contains(edg)) ortmp = GetOrientation(mapS,edg);
733
734 //Add to list already passed outcoming edges
735 if (mapS.Contains(edg) && ortmp == orient && !edg.IsSame(theEdge))
736 for (vte.Init(edg,TopAbs_VERTEX); vte.More(); vte.Next())
737 {
738 TopAbs_Orientation vto = vte.Current().Orientation();
739 if (!VL.IsNull())
740 {
741 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current()))
742 {
743 ListOfPassedEdge.Append(edg);
744 break;
745 }
746 }
747 else // VF is not null
748 {
749 if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current()))
750 {
751 ListOfPassedEdge.Append(edg);
752 break;
753 }
754 }
755 }
756
757 if (!mapS.Contains(edg) || ortmp != orient) {
758 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
759 TopAbs_Orientation vto = vte.Current().Orientation();
760 if (!VL.IsNull()) {
761 if (vto == TopAbs_FORWARD && VL.IsSame(vte.Current())) {
0d969553
Y
762 // If the processing is in 2d (face not null) or
763 // if the edge is not degenerated it is added
7fd59977 764 if (!F.IsNull() || !BRep_Tool::Degenerated(edg))
765 ledge.Append(edg);
766 break;
767 }
768 }
0d969553 769 else { // VF is not null
7fd59977 770 if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current())) {
0d969553
Y
771 // // If the processing is in 2d (face not null) or
772 // if the edge is not degenerated it is added
7fd59977 773 if (!F.IsNull() || !BRep_Tool::Degenerated(edg))
774 ledge.Append(edg);
775 break;
776 }
777 }
778 }
779 }
780 }
781 Standard_Integer nbconnex = ledge.Extent();
782 Standard_Boolean Changedesens = Standard_False;
783 if (nbconnex == 0) {
784 if (myCstat == BRepCheck_NotClosed) {
785 if (VL.IsNull()) {
786 if (Update) {
787 BRepCheck::Add(myMap(myShape),theOstat);
788 }
0d969553 789 return theOstat; // leave
7fd59977 790 }
791 else {
0d969553
Y
792 Index--; // because after Index++ and if there is no chain,
793 VL.Nullify(); // chain on VF is forced
7fd59977 794 theEdge = theRef;
795 Changedesens = Standard_True;
796 }
797 }
798 else {
799 theOstat = BRepCheck_BadOrientationOfSubshape;
800 if (Update) {
801 BRepCheck::Add(myMap(myShape),theOstat);
802 }
803 return theOstat;
804 }
805 }
806
0d969553
Y
807 // JAG 03/07 else if (nbconnex >= 2 && !F.IsNull()) // Try to see in 2d
808 else if (!F.IsNull()) { // Try to see in 2d
7fd59977 809 TopoDS_Vertex pivot;
810 if (!VL.IsNull()) {
811 pivot = VL;
812 }
813 else {
814 pivot = VF;
815 }
816
817 ChoixUV(pivot,theEdge,F,ledge);
818 nbconnex = ledge.Extent();
819// 20/03/02 akm vvv : (OCC234) - The 2d exploration of wire with necessary
820// checks is performed in Closed2d, here it's useless
821// if (nbconnex == 1 && !CheckLoopOrientation( pivot, theEdge, TopoDS::Edge(ledge.First()), F, ListOfPassedEdge ))
822// {
823// theOstat = BRepCheck_BadOrientationOfSubshape;
824// if (Update)
825// BRepCheck::Add(myMap(myShape),theOstat);
826// return theOstat;
827// }
828// 20/03/02 akm ^^^
829 }
830
831 if (nbconnex >= 2) {
832 theOstat = BRepCheck_BadOrientationOfSubshape;
833 if (Update) {
834 BRepCheck::Add(myMap(myShape),theOstat);
835 }
836 return theOstat;
837 }
838 else if (nbconnex == 1) {
0d969553 839 // offset the vertex
7fd59977 840 for (vte.Init(ledge.First(),TopAbs_VERTEX);vte.More(); vte.Next()) {
841 TopAbs_Orientation vto = vte.Current().Orientation();
842 if (!VL.IsNull()) {
843 if (vto == TopAbs_REVERSED) {
844 VL = TopoDS::Vertex(vte.Current());
845 break;
846 }
847 }
0d969553 848 else { // VF is not null
7fd59977 849 if (vto == TopAbs_FORWARD) {
850 VF = TopoDS::Vertex(vte.Current());
851 break;
852 }
853 }
854 }
855 mapS.Add(ledge.First());
856 theEdge = TopoDS::Edge(ledge.First());
857 if (!vte.More()) {
858 if (!VL.IsNull()) {
859 VL.Nullify();
860 }
861 else {
862 VF.Nullify();
863 }
864 }
865 }
866 else if (!Changedesens) { //nbconnex == 0
867 theOstat = BRepCheck_NotClosed;
868 if (Update) {
869 BRepCheck::Add(myMap(myShape),theOstat);
870 }
871 return theOstat;
872 }
873
0d969553 874 // Check the closure of the wire in 2d (not done in Closed())
7fd59977 875
876 TopoDS_Vertex aVRef;
877 Standard_Boolean isCheckClose = Standard_False;
878
879 if (isGoFwd && !VF.IsNull()) {
880 aVRef = VF;
881 isCheckClose = Standard_True;
882 } else if (!isGoFwd && !VL.IsNull()) {
883 aVRef = VL;
884 isCheckClose = Standard_True;
885 }
886
887// if (Index==1 && myCstat!=BRepCheck_NotClosed &&
888// !VF.IsNull() && !F.IsNull()) {
889 if (Index==1 && myCstat!=BRepCheck_NotClosed &&
890 isCheckClose && !F.IsNull()) {
891 ledge.Clear();
892// ind = myMapVE.FindIndex(VF);
893 ind = myMapVE.FindIndex(aVRef);
894 for (TopTools_ListIteratorOfListOfShape itlsh(myMapVE(ind));
895 itlsh.More(); itlsh.Next()) {
896 const TopoDS_Edge & edg = TopoDS::Edge(itlsh.Value());
897 orient = edg.Orientation();
898 if (!theRef.IsSame(edg)) {
899 for (vte.Init(edg,TopAbs_VERTEX);vte.More(); vte.Next()) {
900 TopAbs_Orientation vto = vte.Current().Orientation();
901// if (vto == TopAbs_REVERSED && VF.IsSame(vte.Current())) {
902 if (vto == TopAbs_REVERSED && aVRef.IsSame(vte.Current())) {
903 ledge.Append(edg);
904 break;
905 }
906 }
907 }
908 }
909// ChoixUV(VF, theRef, F, ledge);
910 ChoixUV(aVRef, theRef, F, ledge);
911 if (ledge.Extent()==0) {
912 theOstat = BRepCheck_NotClosed;
913 if (Update) {
914 BRepCheck::Add(myMap(myShape),theOstat);
915 }
916 return theOstat;
917 }
918 }
0d969553 919 // End control closure 2d
7fd59977 920
921 Index ++;
922 }
923 }
924 if (Update) {
925 BRepCheck::Add(myMap(myShape),theOstat);
926 }
927 return theOstat;
928}
929//=======================================================================
930//function : SelfIntersect
931//purpose :
932//=======================================================================
933BRepCheck_Status BRepCheck_Wire::SelfIntersect(const TopoDS_Face& F,
934 TopoDS_Edge& retE1,
935 TopoDS_Edge& retE2,
936 const Standard_Boolean Update)
937{
938
939
7fd59977 940 Standard_Integer i,j,Nbedges;
941 Standard_Real first1,last1,first2,last2, tolint;
942 gp_Pnt2d pfirst1,plast1,pfirst2,plast2;
943 gp_Pnt P3d, P3d2;
944 Handle(BRepAdaptor_HSurface) HS;
945 Geom2dAdaptor_Curve C1, C2;
946 Geom2dInt_GInter Inter;
947 IntRes2d_Domain myDomain1;
948 TopTools_IndexedMapOfOrientedShape EMap;
949 TopTools_MapOfOrientedShape auxmape;
950 //
0d969553
Y
951 //-- check with proper tolerances if there is no
952 //-- point in the tolerance of a vertex.
7fd59977 953 tolint = 1.e-10;
954 HS = new BRepAdaptor_HSurface();
955 HS->ChangeSurface().Initialize(F,Standard_False);
956 //
957 for (TopoDS_Iterator Iter1(myShape);Iter1.More();Iter1.Next()) {
958 if (Iter1.Value().ShapeType() == TopAbs_EDGE) {
959 EMap.Add(Iter1.Value());
960 }
961 }
962 //
963 Nbedges=EMap.Extent();
964 if (!Nbedges) {
965 if (Update) {
966 BRepCheck::Add(myMap(myShape),BRepCheck_EmptyWire);
967 }
968 return(BRepCheck_EmptyWire);
969 }
970 //
971 IntRes2d_Domain *tabDom = new IntRes2d_Domain[Nbedges];
972 TColGeom2d_Array1OfCurve tabCur(1,Nbedges);
973 Bnd_Array1OfBox2d boxes(1,Nbedges);
974 //
975 for(i = 1; i <= Nbedges; i++) {
976 const TopoDS_Edge& E1 = TopoDS::Edge(EMap.FindKey(i));
977 if (i == 1) {
978 Handle(Geom2d_Curve) pcu = BRep_Tool::CurveOnSurface(E1, F, first1, last1);
979 if (pcu.IsNull()) {
980 retE1=E1;
981 if (Update) {
982 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
983 }
984 delete [] tabDom;
985 return(BRepCheck_SelfIntersectingWire);
986 }
987 //
988 C1.Load(pcu);
989 // To avoid exeption in Segment if C1 is BSpline - IFV
990 if(!C1.IsPeriodic()) {
991 if(C1.FirstParameter() > first1) {
992 first1 = C1.FirstParameter();
993 }
994 if(C1.LastParameter() < last1 ){
995 last1 = C1.LastParameter();
996 }
997 }
998 //
999 BRep_Tool::UVPoints(E1, F, pfirst1, plast1);
1000 myDomain1.SetValues(pfirst1,first1,tolint, plast1,last1,tolint);
1001 //
1002 BndLib_Add2dCurve::Add(C1, first1, last1, Precision::PConfusion(), boxes(i));
1003 }//if (i == 1) {
1004 else {
1005 C1.Load(tabCur(i));
1006 myDomain1 = tabDom[i-1];
1007 }
1008 //
1009 // Self intersect of C1
1010 Inter.Perform(C1, myDomain1, tolint, tolint);
1011 //
1012 if(Inter.IsDone()) {
1013 Standard_Integer nbp = Inter.NbPoints();
6e6cd5d9 1014 //Standard_Integer nbs = Inter.NbSegments();
7fd59977 1015 //
1016 for(Standard_Integer p=1;p<=nbp;p++) {
1017 const IntRes2d_IntersectionPoint& IP=Inter.Point(p);
1018 const IntRes2d_Transition& Tr1 = IP.TransitionOfFirst();
1019 const IntRes2d_Transition& Tr2 = IP.TransitionOfSecond();
1020 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1021 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
0d969553
Y
1022 //-- Checking of points with true tolerances (ie Tol in 3d)
1023 //-- If the point of intersection is within the tolearnce of a vertex
1024 //-- this intersection is considered correct (no error)
7fd59977 1025 Standard_Boolean localok = Standard_False;
1026 Standard_Real f,l;
1027 TopLoc_Location L;
1028 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f,l);
1029 if(!ConS.IsNull()) {
0d969553 1030 //-- try to test in 3d. (ParamOnSecond gives the same result)
7fd59977 1031 P3d = ConS->Value(IP.ParamOnFirst());
1032 P3d.Transform(L.Transformation());
1033 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1034 }
1035 else {
1036 gp_Pnt2d aP2d = C1.Value(IP.ParamOnFirst());
1037 P3d = HS->Value(aP2d.X(), aP2d.Y());
1038 }
1039 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1040 TopExp_Explorer ExplVtx;
1041 for(ExplVtx.Init(E1,TopAbs_VERTEX);
1042 localok==Standard_False && ExplVtx.More();
1043 ExplVtx.Next()) {
1044 gp_Pnt p3dvtt;
1045 Standard_Real tolvtt, p3dvttDistanceP3d;
1046 //
1047 const TopoDS_Vertex& vtt = TopoDS::Vertex(ExplVtx.Current());
1048 p3dvtt = BRep_Tool::Pnt(vtt);
1049 tolvtt = BRep_Tool::Tolerance(vtt);
1050 tolvtt=tolvtt*tolvtt;
1051 p3dvttDistanceP3d=p3dvtt.SquareDistance(P3d);
1052 if(p3dvttDistanceP3d <= tolvtt) {
1053 localok=Standard_True;
1054 }
1055 }
1056 if(localok==Standard_False) {
7fd59977 1057 retE1=E1;
1058 if (Update) {
1059 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1060 }
1061 delete [] tabDom;
0797d9d3 1062#ifdef OCCT_DEBUG
7fd59977 1063 static Standard_Integer numpoint=0;
1064 cout<<"point p"<<++numpoint<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;cout.flush();
1065#endif
1066 return(BRepCheck_SelfIntersectingWire);
1067 }
1068 }
1069 }
1070 }// if(Inter.IsDone()) {
1071 //
1072 for(j=i+1; j<=Nbedges; j++) {
1073 const TopoDS_Edge& E2 = TopoDS::Edge(EMap.FindKey(j));
1074 if (i == 1) {
1075 tabCur(j) = BRep_Tool::CurveOnSurface(E2,F,first2,last2);
1076 if (!tabCur(j).IsNull() && last2 > first2) {
1077 C2.Load(tabCur(j));
1078 // To avoid exeption in Segment if C2 is BSpline - IFV
1079 if(!C2.IsPeriodic()) {
1080 if(C2.FirstParameter() > first2) {
1081 first2 = C2.FirstParameter();
1082 }
1083 if(C2.LastParameter() < last2 ) {
1084 last2 = C2.LastParameter();
1085 }
1086 }
1087 //
1088 BRep_Tool::UVPoints(E2,F,pfirst2,plast2);
1089 tabDom[j-1].SetValues(pfirst2,first2,tolint,plast2,last2,tolint);
1090
1091 BndLib_Add2dCurve::Add( C2, first2, last2, Precision::PConfusion(), boxes(j) );
1092 }
1093 else {
1094 delete [] tabDom;
0797d9d3 1095#ifdef OCCT_DEBUG
7fd59977 1096 cout<<"BRepCheck_NoCurveOnSurface or BRepCheck_InvalidRange"<<endl;cout.flush();
1097#endif
1098 if(tabCur(j).IsNull()) {
1099 return(BRepCheck_NoCurveOnSurface);
1100 }
1101 return (BRepCheck_InvalidRange);
1102 }
1103 }// if (i == 1) {
1104 else {
1105 C2.Load(tabCur(j));
1106 }
1107 //
1108 if (boxes(i).IsOut( boxes(j))) {
1109 continue;
1110 }
1111 //modified by NIZNHY-PKV Fri Oct 29 10:09:01 2010f
1112 if (E1.IsSame(E2)) {
1113 continue;
1114 }
1115 //modified by NIZNHY-PKV Fri Oct 29 10:09:02 2010t
1116 //
1117 //-- ************************************************************
0d969553 1118 //-- ******* I n t e r s e c t i o n C 1 and C 2 ********
7fd59977 1119 //-- ************************************************************
1120 Inter.Perform(C1,myDomain1,C2,tabDom[j-1],tolint,tolint);
1121 //
1122 if(Inter.IsDone()) {
1123 Standard_Integer nbp, nbs;
1124 Standard_Real IP_ParamOnFirst, IP_ParamOnSecond;
1125 IntRes2d_Transition Tr1,Tr2;
1126 TopTools_ListOfShape CommonVertices;
1127 TopTools_ListIteratorOfListOfShape itl;
1128 TopTools_MapOfShape Vmap;
1129 //
1130 TopoDS_Iterator it( E1 );
1131 for (; it.More(); it.Next()) {
1132 Vmap.Add( it.Value() );
1133 }
1134 //
1135 it.Initialize( E2 );
1136 for (; it.More(); it.Next()) {
1137 const TopoDS_Shape& V = it.Value();
1138 if (Vmap.Contains( V )) {
1139 CommonVertices.Append( V );
1140 }
1141 }
1142 //
1143 nbp = Inter.NbPoints();
1144 nbs = Inter.NbSegments();
1145 IP_ParamOnFirst = 0.;
1146 IP_ParamOnSecond = 0.;
1147 //
1148 //// **** Points of intersection **** ////
1149 for (Standard_Integer p = 1; p <= nbp; p++) {
1150 const IntRes2d_IntersectionPoint& IP = Inter.Point(p);
1151 IP_ParamOnFirst = IP.ParamOnFirst();
1152 IP_ParamOnSecond = IP.ParamOnSecond();
1153 Tr1 = IP.TransitionOfFirst();
1154 Tr2 = IP.TransitionOfSecond();
1155 if( Tr1.PositionOnCurve() == IntRes2d_Middle
1156 || Tr2.PositionOnCurve() == IntRes2d_Middle) {
0d969553
Y
1157 //-- Checking of points with true tolerances (ie Tol in 3d)
1158 //-- If the point of intersection is within the tolerance of a vertex
1159 //-- this intersection is considered correct (no error)
7fd59977 1160 Standard_Boolean localok = Standard_False;
1161 Standard_Real f1,l1, f2, l2;
1162 TopLoc_Location L, L2;
1163 //
1164 const Handle(Geom_Curve) ConS = BRep_Tool::Curve(E1,L,f1,l1);
1165 const Handle(Geom_Curve) ConS2 = BRep_Tool::Curve(E2,L2,f2,l2);
1166 //gka protect against working out of edge range
1167 if ( f1-IP_ParamOnFirst > ::Precision::PConfusion() ||
1168 IP_ParamOnFirst-l1 > ::Precision::PConfusion() ||
1169 f2-IP_ParamOnSecond > ::Precision::PConfusion() ||
1170 IP_ParamOnSecond-l2 > ::Precision::PConfusion() )
1171 continue;
1d47d8d0 1172 Standard_Real tolvtt = 0.;
7fd59977 1173 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1174 if (!ConS.IsNull()) {
1175 P3d = ConS->Value(IP_ParamOnFirst);
1176 P3d.Transform(L.Transformation());
1177 }
1178 else {
1179 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1180 P3d = HS->Value(aP2d.X(), aP2d.Y());
1181 }
1182 //
1183 if (!ConS2.IsNull()) {
1184 P3d2 = ConS2->Value(IP_ParamOnSecond);
1185 P3d2.Transform(L2.Transformation());
1186 }
1187 else {
1188 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1189 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1190 }
1191 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1192 itl.Initialize( CommonVertices );
1193 for (; itl.More(); itl.Next()) {
1194 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1195 gp_Pnt p3dvtt;
1196 //
1197 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1198 p3dvtt = BRep_Tool::Pnt(vtt);
1199 tolvtt = BRep_Tool::Tolerance(vtt);
1200 tolvtt=1.1*tolvtt;
1201 tolvtt=tolvtt*tolvtt;
1202 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1203 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1204 //
1205 if (p3dvttDistanceP3d<=tolvtt && p3dvttDistanceP3d2<=tolvtt) {
1206 localok = Standard_True;
1207 break;
1208 }
1209 }
1210
1211 //-- --------------------------------------------------------
0d969553 1212 //-- Check maximum yawn between 2 edges
7fd59977 1213 //--
0d969553
Y
1214 //-- Check distance from edges to the curve joining
1215 //-- the point of intersection with vertex (if exists)
7fd59977 1216 if (localok == Standard_False && !CommonVertices.IsEmpty()) {
0797d9d3 1217#ifdef OCCT_DEBUG
7fd59977 1218 cout << "\n------------------------------------------------------\n" <<endl;
1219 cout << "\n--- BRepCheck Wire: AutoIntersection Phase1 -> Erreur \n" <<endl;
1220
1221#endif
7fd59977 1222 Standard_Real distauvtxleplusproche,VParaOnEdge1,VParaOnEdge2;
1223 gp_Pnt VertexLePlusProche;
1224 //
7fd59977 1225 VParaOnEdge1 =0.;
1226 VParaOnEdge2 =0.;
1227 distauvtxleplusproche=RealLast();
1228 //Find the nearest common vertex
1229 itl.Initialize( CommonVertices );
1230 for (; itl.More(); itl.Next()) {
96a95605 1231 Standard_Real disptvtx;
7fd59977 1232 gp_Pnt p3dvtt;
1233 //
1234 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1235 p3dvtt = BRep_Tool::Pnt(vtt);
7fd59977 1236 disptvtx = P3d.Distance(p3dvtt);
1237 if (disptvtx < distauvtxleplusproche) {
1238 VertexLePlusProche = p3dvtt;
1239 distauvtxleplusproche = disptvtx;
1240 VParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1241 VParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1242 }
1243 // eap: case of closed edge
1244 else if (IsEqual(distauvtxleplusproche, disptvtx)) {
1245 Standard_Real newVParaOnEdge1 = BRep_Tool::Parameter(vtt,E1);
1246 Standard_Real newVParaOnEdge2 = BRep_Tool::Parameter(vtt,E2);
1247 if (Abs(IP_ParamOnFirst - VParaOnEdge1) + Abs(IP_ParamOnSecond - VParaOnEdge2)
1248 >
1249 Abs(IP_ParamOnFirst - newVParaOnEdge1) + Abs(IP_ParamOnSecond - newVParaOnEdge2)) {
1250 VertexLePlusProche = p3dvtt;
1251 VParaOnEdge1 = newVParaOnEdge1;
1252 VParaOnEdge2 = newVParaOnEdge2;
1253 }
1254 }
1255 }
1256 //Patch: extraordinar situation (e.g. tolerance(v) == 0.)
1257 // Modified by skv - Wed Jul 23 12:28:11 2003 OCC1764 Begin
1258 // if (VertexLePlusProche.Distance( P3d ) <= gp::Resolution())
1259 if (VertexLePlusProche.Distance(P3d) <= gp::Resolution() ||
1260 VertexLePlusProche.Distance(P3d2) <= gp::Resolution()) {
1261 // Modified by skv - Wed Jul 23 12:28:12 2003 OCC1764 End
1262 localok = Standard_True;
1263 }
1264 else {
1265 gp_Lin Lig( VertexLePlusProche, gp_Vec(VertexLePlusProche,P3d) );
1266 Standard_Real du1 = 0.1*(IP_ParamOnFirst -VParaOnEdge1);
1267 Standard_Real du2 = 0.1*(IP_ParamOnSecond-VParaOnEdge2);
1268 Standard_Real maxd1 = 0., maxd2 = 0.;
1269 Standard_Integer k;
1270
1271 localok = Standard_True;
1272 Standard_Real tole1 = BRep_Tool::Tolerance(E1);
1273 for (k = 2; localok && k < 9; k++) {
0d969553 1274 Standard_Real u = VParaOnEdge1 + k*du1; // check if it works
7fd59977 1275 gp_Pnt P1;
1276 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1277 if (!ConS.IsNull()) {
1278 P1 = ConS->Value(u);
1279 P1.Transform(L.Transformation());
1280 }
1281 else {
1282 gp_Pnt2d aP2d = C1.Value(u);
1283 P1 = HS->Value(aP2d.X(), aP2d.Y());
1284 }
1285 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1286 Standard_Real d1 = Lig.Distance(P1);
1287 if (d1 > maxd1) {
1288 maxd1 = d1;
1289 }
1290 if (d1 > tole1*2.0){
1291 localok = Standard_False;
1292 }
1293 }
0d969553 1294 //-- same for edge2
7fd59977 1295 // Modified by skv - Wed Jul 23 12:22:20 2003 OCC1764 Begin
1296 gp_Dir aTmpDir(P3d2.XYZ().Subtracted(VertexLePlusProche.XYZ()));
1297
1298 Lig.SetDirection(aTmpDir);
1299 // Modified by skv - Wed Jul 23 12:22:23 2003 OCC1764 End
1300 Standard_Real tole2 = BRep_Tool::Tolerance(E2);
1301 for (k = 2; localok && k < 9; k++) {
0d969553 1302 Standard_Real u = VParaOnEdge2 + k*du2; // check if it works
7fd59977 1303 gp_Pnt P2;
1304 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1305 if (!ConS2.IsNull()) {
1306 P2 = ConS2->Value(u);
1307 P2.Transform(L2.Transformation());
1308 }
1309 else {
1310 gp_Pnt2d aP2d = C2.Value(u);
1311 P2 = HS->Value(aP2d.X(), aP2d.Y());
1312 }
1313 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1314 Standard_Real d2 = Lig.Distance(P2);
1315 if (d2 > maxd2) {
1316 maxd2 = d2;
1317 }
1318 if (d2 > tole2*2.0){
1319 localok = Standard_False;
1320 }
1321 }
0797d9d3 1322#ifdef OCCT_DEBUG
7fd59977 1323 if(localok) {
1324 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Bon \n");
1325 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1326 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1327 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1328 fflush(stdout);
1329 }
1330 else {
1331 printf("--- BRepCheck Wire: AutoIntersection Phase2 -> Erreur \n");
1332 printf("--- distance Point Vertex : %10.7g (tol %10.7g)\n",distauvtxleplusproche,tolvtt);
1333 printf("--- Erreur Max sur E1 : %10.7g Tol_Edge:%10.7g\n",maxd1,tole1);
1334 printf("--- Erreur Max sur E2 : %10.7g Tol_Edge:%10.7g\n",maxd2,tole2);
1335 fflush(stdout);
1336 }
1337#endif
1338 } //end of else (construction of the line Lig)
1339 } //end of if (localok == Standard_False && !CommonVertices.IsEmpty())
1340 //
1341 if(localok==Standard_False) {
7fd59977 1342 retE1=E1;
1343 retE2=E2;
1344 if (Update) {
1345 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1346 }
0797d9d3 1347#ifdef OCCT_DEBUG
7fd59977 1348 static Standard_Integer numpoint1=0;
1349 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1350 cout.flush();
1351#endif
1352 delete [] tabDom;
1353 return(BRepCheck_SelfIntersectingWire);
1354 } //-- localok == False
1355 } //end of if(Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1356 } //end of for (Standard_Integer p=1; p <= nbp; p++)
1357 ////
1358 //// **** Segments of intersection **** ////
1359 for (Standard_Integer s = 1; s <= nbs; ++s) {
1360 const IntRes2d_IntersectionSegment& Seg = Inter.Segment(s);
1361 if (Seg.HasFirstPoint() && Seg.HasLastPoint()) {
1362 Standard_Boolean localok;
1363 Standard_Integer k;
1364 IntRes2d_IntersectionPoint PSeg [2];
1365 IntRes2d_Position aPCR1, aPCR2;
1366 //
1367 localok = Standard_False;
1368 PSeg[0] = Seg.FirstPoint();
1369 PSeg[1] = Seg.LastPoint();
1370 // At least one of extremities of the segment must be inside
1371 // the tolerance of a common vertex
1372 for (k = 0; k < 2; ++k) {
1373 IP_ParamOnFirst = PSeg[k].ParamOnFirst();
1374 IP_ParamOnSecond = PSeg[k].ParamOnSecond();
1375 Tr1 = PSeg[k].TransitionOfFirst();
1376 Tr2 = PSeg[k].TransitionOfSecond();
1377 aPCR1=Tr1.PositionOnCurve();
1378 aPCR2=Tr2.PositionOnCurve();
1379 //
1380 if(aPCR1!=IntRes2d_Middle && aPCR2!=IntRes2d_Middle) {
1381 GeomAbs_CurveType aCT1, aCT2;
1382 //ZZ
1383 aCT1=C1.GetType();
1384 aCT2=C2.GetType();
1385 if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1386 // check for the two lines coincidence
1387 Standard_Real aPAR_T, aT11, aT12, aT21, aT22, aT1m, aT2m;
1388 Standard_Real aD2, aTolE1, aTolE2, aTol2, aDot;
1389 gp_Lin2d aL1, aL2;
1390 gp_Pnt2d aP1m;
1391 //
1392 aPAR_T=0.43213918;
1393 //
1394 aTolE1=BRep_Tool::Tolerance(E1);
1395 aTolE2=BRep_Tool::Tolerance(E2);
1396 aTol2=aTolE1+aTolE2;
1397 aTol2=aTol2*aTol2;
1398 //
1399 aL1=C1.Line();
1400 aL2=C2.Line();
1401 //
1402 aT11=PSeg[0].ParamOnFirst();
1403 aT12=PSeg[1].ParamOnFirst();
1404 aT21=PSeg[0].ParamOnSecond();
1405 aT22=PSeg[1].ParamOnSecond();
1406 //
1407 aT1m=(1.-aPAR_T)*aT11 + aPAR_T*aT12;
1408 aP1m=C1.Value(aT1m);
1409 //
1410 aD2=aL2.SquareDistance(aP1m);
1411 if (aD2<aTol2) {
1412 aT2m=ElCLib::Parameter(aL2, aP1m);
1413 if (aT2m>aT21 && aT2m<aT22) {
1414 const gp_Dir2d& aDir1=aL1.Direction();
1415 const gp_Dir2d& aDir2=aL2.Direction();
1416 aDot=aDir1*aDir2;
1417 if (aDot<0.) {
1418 aDot=-aDot;
1419 }
1420 //
1421 if ((1.-aDot)<5.e-11){//0.00001 rad
1422 localok = Standard_False;
1423 break;// from for (k = 0; k < 2; ++k){...
1424 }
1425 }//if (aT2m>aT21 && aT2m<aT22) {
1426 }//if (aD2<aTol2) {
1427 }//if (aCT1==GeomAbs_Line && aCT2==GeomAbs_Line) {
1428 //ZZ
1429 localok = Standard_True;
1430 break;
1431 }
1432 //
1433 Standard_Real f,l, tolvtt;
1434 TopLoc_Location L, L2;
1435 const Handle(Geom_Curve)& ConS = BRep_Tool::Curve(E1,L,f,l);
1436 const Handle(Geom_Curve)& ConS2 = BRep_Tool::Curve(E2,L2,f,l);
1437 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 Begin
1438 if (!ConS.IsNull()) {
1439 P3d = ConS->Value(IP_ParamOnFirst);
1440 P3d.Transform(L.Transformation());
1441 } else {
1442 gp_Pnt2d aP2d = C1.Value(IP_ParamOnFirst);
1443 P3d = HS->Value(aP2d.X(), aP2d.Y());
1444 }
1445 if (!ConS2.IsNull()) {
1446 P3d2 = ConS2->Value(IP_ParamOnSecond);
1447 P3d2.Transform(L2.Transformation());
1448 } else {
1449 gp_Pnt2d aP2d = C2.Value(IP_ParamOnSecond);
1450 P3d2 = HS->Value(aP2d.X(), aP2d.Y());
1451 }
1452 // Modified by Sergey KHROMOV - Mon Apr 15 12:34:22 2002 End
1453 itl.Initialize( CommonVertices );
1454 for (; itl.More(); itl.Next()) {
1455 Standard_Real p3dvttDistanceP3d, p3dvttDistanceP3d2;
1456 gp_Pnt p3dvtt;
1457 //
1458 const TopoDS_Vertex& vtt = TopoDS::Vertex(itl.Value());
1459 p3dvtt = BRep_Tool::Pnt(vtt);
1460 tolvtt = BRep_Tool::Tolerance(vtt);
1461 tolvtt=1.1*tolvtt;
1462 tolvtt=tolvtt*tolvtt;
1463 p3dvttDistanceP3d = p3dvtt.SquareDistance(P3d);
1464 p3dvttDistanceP3d2 = p3dvtt.SquareDistance(P3d2);
1465 if (p3dvttDistanceP3d <= tolvtt && p3dvttDistanceP3d2 <= tolvtt) {
1466 localok = Standard_True;
1467 break;
1468 }
1469 }
1470 if (localok == Standard_True) {
1471 break;
1472 }
1473 } //end of for (k = 0; k < 2; k++)
1474 //
1475 if(localok==Standard_False) {
7fd59977 1476 retE1=E1;
1477 retE2=E2;
1478 if (Update) {
1479 BRepCheck::Add(myMap(myShape),BRepCheck_SelfIntersectingWire);
1480 }
0797d9d3 1481#ifdef OCCT_DEBUG
7fd59977 1482 static Standard_Integer numpoint1=0;
1483 cout<<"point p"<<++numpoint1<<" "<<P3d.X()<<" "<<P3d.Y()<<" "<<P3d.Z()<<endl;
1484 cout.flush();
1485#endif
1486 delete [] tabDom;
1487 return(BRepCheck_SelfIntersectingWire);
1488 } //-- localok == False
1489 } //end of if(Seg.HasFirstPoint() && Seg.HasLastPoint())
1490 } //end of for (Standard_Integer s = 1; s <= nbs; p++)
1491 } //-- Inter.IsDone()
1492 } //end of for( j = i+1; j<=Nbedges; j++)
1493 } //end of for(i = 1; i <= Nbedges; i++)
1494 //
1495 delete [] tabDom;
1496 if (Update) {
1497 BRepCheck::Add(myMap(myShape),BRepCheck_NoError);
1498 }
1499 //
1500 return (BRepCheck_NoError);
1501}
52d45841 1502
1503//=======================================================================
1504//function : SetStatus
1505//purpose :
1506//=======================================================================
1507
1508void BRepCheck_Wire::SetStatus(const BRepCheck_Status theStatus)
1509{
1510 BRepCheck::Add(myMap(myShape),theStatus);
1511}
1512
7fd59977 1513//=======================================================================
1514//function : GeometricControls
1515//purpose :
1516//=======================================================================
1517void BRepCheck_Wire::GeometricControls(const Standard_Boolean B)
1518{
1519 if (myGctrl != B) {
1520 if (B) {
1521 myCdone = Standard_False;
1522 }
1523 myGctrl = B;
1524 }
1525}
1526//=======================================================================
1527//function : GeometricControls
1528//purpose :
1529//=======================================================================
1530Standard_Boolean BRepCheck_Wire::GeometricControls() const
1531{
1532 return myGctrl;
1533}
1534
7fd59977 1535//=======================================================================
1536//function : Propagate
1537//purpose : fill <mapE> with edges connected to <edg> through vertices
1538// contained in <mapVE>
1539//=======================================================================
1540static void Propagate(const TopTools_IndexedDataMapOfShapeListOfShape& mapVE,
22774b62 1541 const TopoDS_Shape& edg,
1542 TopTools_MapOfShape& mapE)
7fd59977 1543{
22774b62 1544 TopTools_ListOfShape currentEdges;
1545 currentEdges.Append(edg);
1546
1547 do
1548 {
1549 TopTools_ListOfShape nextEdges;
1550 TopTools_ListIteratorOfListOfShape itrc(currentEdges);
1551 for (; itrc.More(); itrc.Next())
1552 {
1553 const TopoDS_Shape& Edge = itrc.Value();
a61133c8 1554 if (!mapE.Contains(Edge))
1555 mapE.Add(Edge);
22774b62 1556
1557 TopExp_Explorer ex(Edge, TopAbs_VERTEX);
1558 for (; ex.More(); ex.Next())
1559 {
1560 const TopoDS_Vertex& vtx = TopoDS::Vertex(ex.Current());
1561 Standard_Integer indv = mapVE.FindIndex(vtx);
1562 if (indv != 0)
1563 {
1564 const TopTools_ListOfShape& edges = mapVE(indv);
1565
1566 TopTools_ListIteratorOfListOfShape itl(edges);
1567 for (; itl.More(); itl.Next())
1568 {
1569 const TopoDS_Shape& E = itl.Value();
1570 if (!Edge.IsSame(E) && !mapE.Contains(E))
a61133c8 1571 {
1572 mapE.Add(E);
22774b62 1573 nextEdges.Append(E);
a61133c8 1574 }
22774b62 1575 }
1576 }
7fd59977 1577 }
1578 }
22774b62 1579 currentEdges = nextEdges;
7fd59977 1580 }
22774b62 1581 while (!currentEdges.IsEmpty());
7fd59977 1582}
22774b62 1583
7fd59977 1584//=======================================================================
1585//function : GetOrientation
1586//purpose :
1587//=======================================================================
1588
1589static TopAbs_Orientation GetOrientation(const TopTools_MapOfShape& mapE,
1590 const TopoDS_Edge& edg)
1591{
1592 TopTools_MapIteratorOfMapOfShape itm(mapE);
1593 for ( ; itm.More(); itm.Next()) {
1594 if (itm.Key().IsSame(edg)) {
1595 break;
1596 }
1597 }
1598 return itm.Key().Orientation();
1599}
1600//=======================================================================
1601//function : ChoixUV
3f257c62 1602//purpose : For vertex theVertex given function find an edge along
1603// that we should go further.
7fd59977 1604//=======================================================================
3f257c62 1605void ChoixUV(const TopoDS_Vertex& theVertex,
1606 const TopoDS_Edge& theEdge,
1607 const TopoDS_Face& theFace,
1608 TopTools_ListOfShape& theLOfShape)
1609 {
1610 TopTools_ListIteratorOfListOfShape It( theLOfShape );
7fd59977 1611 while (It.More())
1612 {
3f257c62 1613 if (theEdge.IsSame( It.Value() ))
1614 theLOfShape.Remove( It );
1615 else
1616 It.Next();
7fd59977 1617 }
1618
3f257c62 1619 Standard_Real aTol3d = BRep_Tool::Tolerance(theVertex);
1620
1621 Standard_Integer anIndex = 0, anIndMin = 0;
1622 TopoDS_Edge anEFound;
1623 gp_Pnt2d aPntRef, aPnt;
1624 gp_Vec2d aDerRef, aDer;
1625 Standard_Real aMinAngle, aMaxAngle, anAngle;
1626 Standard_Real a_gpResolution=gp::Resolution();
1627 TopAbs_Orientation aVOrientation, anEdgOrientation;
1628 Standard_Real aParam = 0.0, aFirstParam = 0.0, aLastParam = 0.0, aParPiv = 0.0;
1629 BRepAdaptor_Surface aFaceSurface(theFace,Standard_False); // no restriction
1630
1631 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirstParam, aLastParam);
1632 if (C2d.IsNull())// JAG 10.12.96
7fd59977 1633 return;
3f257c62 1634
1635 aVOrientation = theVertex.Orientation();
1636 anEdgOrientation = theEdge.Orientation();
7fd59977 1637
3f257c62 1638 aParPiv =(aVOrientation==anEdgOrientation) ? aFirstParam : aLastParam;
1639 aMinAngle = RealLast();
1640 aMaxAngle = RealFirst();
7fd59977 1641
3f257c62 1642 CurveDirForParameter(C2d, aParPiv, aPntRef, aDerRef);
1643
1644 if (aVOrientation != anEdgOrientation)
1645 aDerRef.Reverse();
7fd59977 1646
3f257c62 1647 It.Initialize(theLOfShape);
7fd59977 1648
3f257c62 1649 for (; It.More(); It.Next())
1650 {
1651 anIndex++;
1652 const TopoDS_Edge& anE=TopoDS::Edge(It.Value());
1653 C2d = BRep_Tool::CurveOnSurface(anE, theFace, aFirstParam, aLastParam);
1654 if(C2d.IsNull())
7fd59977 1655 continue;
94f71cad 1656 Geom2dAdaptor_Curve aCA(C2d);
7fd59977 1657
3f257c62 1658 aParam =(aVOrientation != anE.Orientation()) ? aFirstParam : aLastParam;
94f71cad 1659 aPnt = aCA.Value(aParam);
3f257c62 1660
1661 if(!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d, Standard_False))
7fd59977 1662 continue;
3f257c62 1663
94f71cad 1664 CurveDirForParameter(aCA, aParam, aPnt, aDer);
3f257c62 1665
1666 if (aVOrientation == anE.Orientation())
1667 aDer.Reverse();
1668
1669 if ((aDerRef.Magnitude() <= a_gpResolution) ||
1670 (aDer.Magnitude() <= a_gpResolution))
1671//Vector length is too small
7fd59977 1672 continue;
3f257c62 1673
1674 anAngle = -aDerRef.Angle( aDer );
1675
1676 if ( anAngle < 0. )
1677 anAngle += 2.*M_PI;
1678
1679 if ( theFace.Orientation() == TopAbs_FORWARD )
1680 {
1681 if ( anAngle < aMinAngle )
1682 {
1683 anIndMin = anIndex;
1684 aMinAngle = anAngle;
1685 }
7fd59977 1686 }
3f257c62 1687 else //theFace.Orientation() != TopAbs_FORWARD
1688 {
1689 if ( anAngle > aMaxAngle )
1690 {
1691 anIndMin = anIndex;
1692 aMaxAngle = anAngle;
1693 }
7fd59977 1694 }
3f257c62 1695 }//end of for
1696
1697// Update edge
1698 if (anIndMin == 0)
1699 if (theLOfShape.Extent() == 1)
1700 {
1701 Standard_Boolean IsFound = Standard_True; //all right
1702 anEFound = TopoDS::Edge(theLOfShape.First());
1703
1704 if(anEFound.IsNull() || BRep_Tool::Degenerated(theEdge) ||
1705 BRep_Tool::Degenerated(anEFound))
1706 IsFound = Standard_False; //bad
1707 else if (!IsDistanceIn2DTolerance(aFaceSurface, aPnt, aPntRef, aTol3d))
1708 IsFound = Standard_False; //bad
1709 else
1710 // clousureness in 3D
1711 {
1712//IsDistanceIn3DTolerance
1713 BRepAdaptor_Curve bcEdg(theEdge, theFace);
1714 BRepAdaptor_Curve bcEvois(anEFound, theFace);
1715 gp_Pnt pEdg = bcEdg.Value(aParPiv);
1716 gp_Pnt pEFound = bcEvois.Value(aParam);
1717
9e20ed57 1718 if(!IsDistanceIn3DTolerance(pEdg, pEFound, aTol3d))
3f257c62 1719 IsFound = Standard_False;
1720 else
1721//angle was not defined but points are close
1722 IsFound = Standard_True; //all right
1723 }
1724
1725 if(!IsFound)
1726 {
1727 theLOfShape.Clear();
1728 }
1729 }//if (theLOfShape.Extent() == 1)
1730 else //if (anIndMin == 0)
1731 {
1732 theLOfShape.Clear();
7fd59977 1733 }
3f257c62 1734 else
1735 {
1736 anIndex = 1;
1737
1738 while (anIndex < anIndMin)
1739 {
1740 theLOfShape.RemoveFirst();
1741 anIndex++;
7fd59977 1742 }
3f257c62 1743
1744 It.Initialize(theLOfShape);
7fd59977 1745 It.Next();
3f257c62 1746
7fd59977 1747 while (It.More())
3f257c62 1748 theLOfShape.Remove(It);
1749 }
1750 }//End of function
1751
1752
7fd59977 1753//=======================================================================
1754//function : CurveDirForParameter
1755//purpose :
1756//=======================================================================
94f71cad 1757void CurveDirForParameter(const Geom2dAdaptor_Curve& aC2d,
1758 const Standard_Real aPrm,
1759 gp_Pnt2d& Pnt,
1760 gp_Vec2d& aVec2d)
7fd59977 1761{
1762 Standard_Real aTol=gp::Resolution();
1763 Standard_Integer i;
1764
94f71cad 1765 aC2d.D1(aPrm, Pnt, aVec2d);
7fd59977 1766 //
1767 if (aVec2d.Magnitude() <= aTol) {
1768 for (i = 2; i <= 100; i++){
94f71cad 1769 aVec2d = aC2d.DN(aPrm, i);
7fd59977 1770 if (aVec2d.Magnitude() > aTol) {
94f71cad 1771 break;
7fd59977 1772 }
1773 }
1774 }
1775}
1776
1777// Modified by Sergey KHROMOV - Wed May 22 10:44:06 2002 OCC325 Begin
1778//=======================================================================
1779//function : GetPnts2d
1780//purpose : this function returns the parametric points of theVertex on theFace.
1781// If theVertex is a start and end vertex of theEdge hasSecondPnt
1782// becomes Standard_True and aPnt2 returns the second parametric point.
1783// Returns Standard_True if paraametric points are successfully found.
1784//=======================================================================
1785
1786static Standard_Boolean GetPnt2d(const TopoDS_Vertex &theVertex,
1787 const TopoDS_Edge &theEdge,
1788 const TopoDS_Face &theFace,
1789 gp_Pnt2d &aPnt)
1790{
1791 Handle(Geom2d_Curve) aPCurve;
1792 Standard_Real aFPar;
1793 Standard_Real aLPar;
1794 Standard_Real aParOnEdge;
1795 TopoDS_Vertex aFirstVtx;
1796 TopoDS_Vertex aLastVtx;
1797
1798 TopExp::Vertices(theEdge, aFirstVtx, aLastVtx);
1799
1800 if (!theVertex.IsSame(aFirstVtx) && !theVertex.IsSame(aLastVtx))
1801 return Standard_False;
1802
1803 aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFPar, aLPar);
1804
1805 if (aPCurve.IsNull())
1806 return Standard_False;
1807
1808 aParOnEdge = BRep_Tool::Parameter(theVertex, theEdge);
1809 aPnt = aPCurve->Value(aParOnEdge);
1810
1811 return Standard_True;
1812}
1813
1814//=======================================================================
1815//function : Closed2dForPeriodicFace
1816//purpose : Checks the distance between first point of the first edge
1817// and last point of the last edge in 2d for periodic face.
1818//=======================================================================
1819static Standard_Boolean IsClosed2dForPeriodicFace
1820 (const TopoDS_Face &theFace,
1821 const gp_Pnt2d &theP1,
1822 const gp_Pnt2d &theP2,
1823 const TopoDS_Vertex &theVertex)
1824{
1825// Check 2d distance for periodic faces with seam edge.
1826// Searching for seam edges
1827 TopTools_ListOfShape aSeamEdges;
1828 TopTools_MapOfShape NotSeams;
1829 TopTools_MapOfShape ClosedEdges;
1830 TopExp_Explorer anExp(theFace, TopAbs_EDGE);
1831
1832 for (;anExp.More(); anExp.Next()) {
1833 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
1834
1835 if (NotSeams.Contains(anEdge))
1836 continue;
1837
1838 if (!IsOriented(anEdge) ||
1839 !BRep_Tool::IsClosed(anEdge, theFace)) {
1840 NotSeams.Add(anEdge);
1841 continue;
1842 }
1843
1844 if (!ClosedEdges.Add(anEdge))
1845 aSeamEdges.Append(anEdge);
1846 }
1847
1848 if (aSeamEdges.Extent() == 0)
1849 return Standard_True;
1850
1851// check if theVertex lies on one of the seam edges
1852 BRepAdaptor_Surface aFaceSurface (theFace, Standard_False);
1853 Standard_Real aTol = BRep_Tool::Tolerance(theVertex);
1854 Standard_Real aUResol = aFaceSurface.UResolution(aTol);
1855 Standard_Real aVResol = aFaceSurface.VResolution(aTol);
1856 Standard_Real aVicinity = Sqrt(aUResol*aUResol + aVResol*aVResol);
1857 Standard_Real aDistP1P2 = theP1.Distance(theP2);
1858
1859
1860 TopTools_ListIteratorOfListOfShape anIter(aSeamEdges);
1861
1862 for (; anIter.More(); anIter.Next()) {
1863 TopoDS_Edge aSeamEdge = TopoDS::Edge(anIter.Value());
1864
1865 anExp.Init(aSeamEdge, TopAbs_VERTEX);
1866 for (; anExp.More(); anExp.Next()) {
1867 const TopoDS_Shape &aVtx = anExp.Current();
1868
1869// We found an edge. Check the distance between two given points
1870// to be lower than the computed tolerance.
1871 if (IsOriented(aVtx) && aVtx.IsSame(theVertex)) {
1872 gp_Pnt2d aPnt1;
1873 gp_Pnt2d aPnt2;
1874 Standard_Real a2dTol;
1875
1876 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt1))
1877 continue;
1878
1879 aSeamEdge = TopoDS::Edge(aSeamEdge.Reversed());
1880
1881 if (!GetPnt2d(theVertex, aSeamEdge, theFace, aPnt2))
1882 continue;
1883
1884 a2dTol = aPnt1.Distance(aPnt2)*1.e-2;
1885 a2dTol = Max(a2dTol, aVicinity);
1886
1887 if (aDistP1P2 > a2dTol)
1888 return Standard_False;
1889 }
1890 }
1891 }
1892
1893 return Standard_True;
1894}
1895// Modified by Sergey KHROMOV - Thu Jun 20 10:58:05 2002 End