0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / ShapeAnalysis / ShapeAnalysis_Wire.cxx
CommitLineData
b311480e 1// Created on: 2000-01-20
2// Created by: data exchange team
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16//:pdn 11.12.98: FixDegenerated improved
17//:pdn 05.01.99: renaming method CheckLittle to CheckSmall
18//:l0 abv 10.01.99: CATIA01 #1727: fix intersecting edges always if edge is lacking
19//:n2 abv 22.01.99: ma-test5.igs: IGES read (pref3d): remove degen edge with no pcurve
20//:o4 abv 17.02.99: r0301_db.stp #53082: adding parameter isClosed to CheckOrder
21// rln 03.03.99 S4135: using updated ShapeAnalysis_Surface for checking of singularities
22//:p9 abv 11.03.99: PRO7226 #489490: fix :i9 moved to allow fixing a set of degenerated edges
23//#77 rln 11.03.99: S4135: using singularity which has minimum gap between singular point and input 3D point
24//#84 rln 18.03.99: inserting degenerated edge between ends of pcurves
25//pdn 12.03.99 S4135 check degenerated applies minimal tolerance first.
26//pdn 16.03.99 S4135 adding check of non adjacent edjes.
27//#83 rln 19.03.99: processing segments in intersection as in BRepCheck
28//%15 pdn 15.03.99 checking of small area wire added
29//#2 smh 26.03.99 S4163 Zero divide
30//#4 szv S4163 optimizing
31//:r6 abv 08.04.99: protect FixIE against working out of curve range
32//:s1 abv 22.04.99: PRO7226 #489490: ensure fixing of degenerated edge
33//#9 smh 14.12.99 BUC60615 Using tolerance of verteces during checking degenerated edge.
34
42cf5bc1 35#include <Adaptor3d_CurveOnSurface.hxx>
36#include <Bnd_Array1OfBox2d.hxx>
37#include <Bnd_Box2d.hxx>
38#include <BndLib_Add2dCurve.hxx>
39#include <BRep_Builder.hxx>
40#include <BRep_Tool.hxx>
41#include <BRepBuilderAPI_MakeFace.hxx>
42#include <BRepGProp.hxx>
43#include <BRepTools.hxx>
44#include <GCPnts_AbscissaPoint.hxx>
7fd59977 45#include <Geom2d_Curve.hxx>
7fd59977 46#include <Geom2dAdaptor_Curve.hxx>
42cf5bc1 47#include <Geom2dAdaptor_HCurve.hxx>
7fd59977 48#include <Geom2dInt_GInter.hxx>
42cf5bc1 49#include <Geom_Curve.hxx>
50#include <Geom_Plane.hxx>
51#include <Geom_Surface.hxx>
52#include <GeomAdaptor_Curve.hxx>
53#include <GeomAdaptor_HSurface.hxx>
54#include <gp_Pnt2d.hxx>
56a9db93 55#include <GProp_GProps.hxx>
7fd59977 56#include <IntRes2d_Domain.hxx>
7fd59977 57#include <IntRes2d_IntersectionPoint.hxx>
58#include <IntRes2d_IntersectionSegment.hxx>
42cf5bc1 59#include <IntRes2d_Transition.hxx>
60#include <Precision.hxx>
7fd59977 61#include <ShapeAnalysis.hxx>
62#include <ShapeAnalysis_Curve.hxx>
63#include <ShapeAnalysis_Edge.hxx>
7fd59977 64#include <ShapeAnalysis_Surface.hxx>
fbf3becf 65#include <ShapeAnalysis_TransferParametersProj.hxx>
42cf5bc1 66#include <ShapeAnalysis_Wire.hxx>
67#include <ShapeAnalysis_WireOrder.hxx>
fbf3becf 68#include <ShapeBuild_Edge.hxx>
42cf5bc1 69#include <ShapeExtend.hxx>
70#include <ShapeExtend_WireData.hxx>
71#include <Standard_Type.hxx>
72#include <TColgp_Array1OfPnt.hxx>
73#include <TColgp_SequenceOfPnt.hxx>
74#include <TColStd_Array1OfReal.hxx>
75#include <TopExp.hxx>
76#include <TopLoc_Location.hxx>
77#include <TopoDS.hxx>
78#include <TopoDS_Edge.hxx>
79#include <TopoDS_Face.hxx>
7fd59977 80#include <TopoDS_Iterator.hxx>
42cf5bc1 81#include <TopoDS_Shape.hxx>
82#include <TopoDS_Vertex.hxx>
83#include <TopoDS_Wire.hxx>
7fd59977 84#include <TopTools_DataMapOfShapeListOfShape.hxx>
42cf5bc1 85#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
7fd59977 86#include <TopTools_IndexedMapOfShape.hxx>
87#include <TopTools_ListIteratorOfListOfShape.hxx>
42cf5bc1 88#include <TopTools_ListOfShape.hxx>
7fd59977 89
92efcf78 90IMPLEMENT_STANDARD_RTTIEXT(ShapeAnalysis_Wire,MMgt_TShared)
91
42cf5bc1 92//szvsh addition
7fd59977 93//=======================================================================
94//function : ShapeAnalysis_Wire
95//purpose :
96//=======================================================================
7fd59977 97ShapeAnalysis_Wire::ShapeAnalysis_Wire()
98{
99 ClearStatuses();
100 myPrecision = ::Precision::Confusion();
101}
102
103//=======================================================================
104//function : ShapeAnalysis_Wire
105//purpose :
106//=======================================================================
107
108ShapeAnalysis_Wire::ShapeAnalysis_Wire (const TopoDS_Wire& wire,
109 const TopoDS_Face& face,
110 const Standard_Real precision)
111{
112 Init (wire, face, precision);
113}
114
115//=======================================================================
116//function : ShapeAnalysis_Wire
117//purpose :
118//=======================================================================
119
120ShapeAnalysis_Wire::ShapeAnalysis_Wire (const Handle(ShapeExtend_WireData)& sbwd,
121 const TopoDS_Face& face,
122 const Standard_Real precision)
123{
124 Init (sbwd, face, precision);
125}
126
127//=======================================================================
128//function : Init
129//purpose :
130//=======================================================================
131
132void ShapeAnalysis_Wire::Init (const TopoDS_Wire& wire,
133 const TopoDS_Face& face, const Standard_Real precision)
134{
135 Init (new ShapeExtend_WireData (wire), face, precision);
136}
137
138//=======================================================================
139//function : Init
140//purpose :
141//=======================================================================
142
143void ShapeAnalysis_Wire::Init (const Handle(ShapeExtend_WireData)& sbwd,
144 const TopoDS_Face& face, const Standard_Real precision)
145{
146 Load (sbwd);
147 SetFace (face);
148 SetPrecision (precision);
149}
150
151//=======================================================================
152//function : Load
153//purpose :
154//=======================================================================
155
156void ShapeAnalysis_Wire::Load (const TopoDS_Wire& wire)
157{
158 ClearStatuses();
159 myWire = new ShapeExtend_WireData (wire);
160}
161
162//=======================================================================
163//function : Load
164//purpose :
165//=======================================================================
166
167void ShapeAnalysis_Wire::Load (const Handle(ShapeExtend_WireData)& sbwd)
168{
169 ClearStatuses();
170 myWire = sbwd;
171}
172
173//=======================================================================
174//function : SetFace
175//purpose :
176//=======================================================================
177
178void ShapeAnalysis_Wire::SetFace(const TopoDS_Face& face)
179{
180 myFace = face;
181 if(!face.IsNull())
182 mySurf = new ShapeAnalysis_Surface ( BRep_Tool::Surface ( myFace ) );
183}
184
185//=======================================================================
186//function : SetSurface
187//purpose :
188//=======================================================================
189
190void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface)
191{
192 SetSurface ( surface, TopLoc_Location() );
193}
194
195//=======================================================================
196//function : SetSurface
197//purpose :
198//=======================================================================
199
200void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface,
201 const TopLoc_Location& location)
202{
203 BRep_Builder B;
204 TopoDS_Face face;
205 B.MakeFace ( face, surface, location, ::Precision::Confusion() );
206 SetFace ( face );
207}
208
209//=======================================================================
210//function : SetPrecision
211//purpose :
212//=======================================================================
213
214 void ShapeAnalysis_Wire::SetPrecision(const Standard_Real precision)
215{
216 myPrecision = precision;
217}
218
219//=======================================================================
220//function : ClearStatuses
221//purpose :
222//=======================================================================
223
224 void ShapeAnalysis_Wire::ClearStatuses()
225{
226 myStatusOrder = myStatusConnected =
227 myStatusEdgeCurves = myStatusDegenerated =
228 myStatusClosed = myStatusLacking =
229 myStatusSelfIntersection = myStatusSmall =
230 myStatusGaps3d = myStatusGaps2d =
231 myStatusCurveGaps = myStatusLoop = myStatus = 0;
232
233 myMin3d = myMin2d = myMax3d = myMax2d = 0.;
234}
235
236//=======================================================================
237//function : Perform
238//purpose :
239//=======================================================================
240
241 Standard_Boolean ShapeAnalysis_Wire::Perform()
242{
243 Standard_Boolean result = Standard_False;
244 result |= CheckOrder();
245 result |= CheckSmall();
246 result |= CheckConnected();
247 result |= CheckEdgeCurves();
248 result |= CheckDegenerated();
249 result |= CheckSelfIntersection();
250 result |= CheckLacking();
251 result |= CheckClosed();
252 return result;
253}
254
255//=======================================================================
256//function : CheckOrder
257//purpose :
258//=======================================================================
259
260 Standard_Boolean ShapeAnalysis_Wire::CheckOrder (const Standard_Boolean isClosed,
261 const Standard_Boolean mode3d)
262{
263 ShapeAnalysis_WireOrder sawo;
264 CheckOrder (sawo, isClosed, mode3d);
265 myStatusOrder = myStatus;
266 return StatusOrder (ShapeExtend_DONE);
267}
268
269//=======================================================================
270//function : CheckSmall
271//purpose :
272//=======================================================================
273
274 Standard_Boolean ShapeAnalysis_Wire::CheckSmall(const Standard_Real precsmall)
275{
276 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
277 CheckSmall (i, precsmall);
278 myStatusSmall |= myStatus;
279 }
280 return StatusSmall (ShapeExtend_DONE);
281}
282
283//=======================================================================
284//function : CheckConnected
285//purpose :
286//=======================================================================
287
288 Standard_Boolean ShapeAnalysis_Wire::CheckConnected(const Standard_Real prec)
289{
290 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
291 CheckConnected ( i, prec );
292 myStatusConnected |= myStatus;
293 }
294 return StatusConnected (ShapeExtend_DONE);
295}
296
297//=======================================================================
298//function : CheckEdgeCurves
299//purpose :
300//=======================================================================
301
302 Standard_Boolean ShapeAnalysis_Wire::CheckEdgeCurves()
303{
304 myStatusEdgeCurves = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
305 if ( ! IsReady() ) return Standard_False;
306
307 Standard_Integer i, nb = myWire->NbEdges();
308 ShapeAnalysis_Edge SAE;
309
310 for (i = 1; i <= nb; i++) {
311 TopoDS_Edge E = myWire->Edge (i);
312
313 SAE.CheckCurve3dWithPCurve (E, myFace);
314 if (SAE.Status (ShapeExtend_DONE))
315 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
316 if (SAE.Status ( ShapeExtend_FAIL))
317 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
318
319 SAE.CheckVerticesWithPCurve (E, myFace);
320 if (SAE.Status (ShapeExtend_DONE))
321 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
322 if (SAE.Status ( ShapeExtend_FAIL))
323 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
324
325 SAE.CheckVerticesWithCurve3d (E);
326 if (SAE.Status (ShapeExtend_DONE))
327 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
328 if (SAE.Status ( ShapeExtend_FAIL))
329 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
330
331 CheckSeam (i);
332 if (LastCheckStatus (ShapeExtend_DONE))
333 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
334 if (LastCheckStatus (ShapeExtend_FAIL))
335 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL4);
336
337 CheckGap3d (i);
338 if (LastCheckStatus (ShapeExtend_DONE))
339 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
340 if (LastCheckStatus (ShapeExtend_FAIL))
341 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL5);
342
343 CheckGap2d (i);
344 if (LastCheckStatus (ShapeExtend_DONE))
345 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
346 if (LastCheckStatus (ShapeExtend_FAIL))
347 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL6);
348
349 Standard_Real maxdev = 0.0;
350 SAE.CheckSameParameter (myWire->Edge (i), maxdev);
351 if (SAE.Status (ShapeExtend_DONE))
352 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_DONE7);
353 if (SAE.Status ( ShapeExtend_FAIL))
354 myStatusEdgeCurves |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL7);
355 }
356 return StatusEdgeCurves (ShapeExtend_DONE);
357}
358
359//=======================================================================
360//function : CheckDegenerated
361//purpose :
362//=======================================================================
363
364 Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated()
365{
366 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
367 CheckDegenerated (i);
368 myStatusDegenerated |= myStatus;
369 }
370 return StatusDegenerated (ShapeExtend_DONE);
371}
372
373//=======================================================================
374//function : CheckSelfIntersection
375//purpose :
376//=======================================================================
377
378 Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersection()
379{
380 myStatusSelfIntersection = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
381 if (!IsReady()) return Standard_False;
382 Standard_Integer i, nb = myWire->NbEdges();
383 for (i = 1; i <= nb; i++) {
384 CheckSelfIntersectingEdge (i);
385 if (LastCheckStatus (ShapeExtend_DONE))
386 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
387 if (LastCheckStatus (ShapeExtend_FAIL))
388 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
389
390 CheckIntersectingEdges (i);
391 if (LastCheckStatus (ShapeExtend_DONE))
392 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
393 if (LastCheckStatus (ShapeExtend_FAIL))
394 myStatusSelfIntersection |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
395 }
396
397 Bnd_Array1OfBox2d boxes(1,nb);
398 TopLoc_Location L;
399 const Handle(Geom_Surface)& S = BRep_Tool::Surface(Face(), L);
400 Handle(Geom2d_Curve) c2d;
401 Standard_Real cf,cl;
402 ShapeAnalysis_Edge sae;
403 Handle(ShapeExtend_WireData) sbwd = WireData();
404 for(i = 1; i <= nb; i++){
405 TopoDS_Edge E = sbwd->Edge (i);
406 if(sae.PCurve (E,S,L,c2d,cf,cl,Standard_False)) {
407 Bnd_Box2d box;
408 Geom2dAdaptor_Curve gac(c2d,cf,cl);
409 BndLib_Add2dCurve::Add(gac,::Precision::Confusion(),box);
410 boxes(i) = box;
411 }
412 }
413
414 Standard_Boolean isFail = Standard_False, isDone = Standard_False;
415 for(Standard_Integer num1 = 1; num1 < nb-1; num1++) {
ef57920a
V
416 Standard_Integer fin = nb;
417 if (CheckClosed(Precision::Confusion()) && 1 == num1)
418 fin = nb-1;
7fd59977 419 for(Standard_Integer num2 = num1+2; num2 <= fin; num2++)
420 if(!boxes(num1).IsOut(boxes(num2))){
421 CheckIntersectingEdges(num1, num2);
422 isFail |= LastCheckStatus ( ShapeExtend_FAIL1 );
423 isDone |= LastCheckStatus ( ShapeExtend_DONE1 );
424 }
425 }
426 if(isFail)
427 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
428 if(isDone)
429 myStatusSelfIntersection |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
430
431 return StatusSelfIntersection (ShapeExtend_DONE);
432}
433
434//=======================================================================
435//function : CheckLacking
436//purpose :
437//=======================================================================
438
439 Standard_Boolean ShapeAnalysis_Wire::CheckLacking()
440{
441 if (!IsReady() || NbEdges() < 2) return Standard_False;
442 for (Standard_Integer i = 1; i <= myWire->NbEdges(); i++) {
443 CheckLacking (i);
444 myStatusLacking |= myStatus;
445 }
446 return StatusLacking (ShapeExtend_DONE);
447}
448
449//=======================================================================
450//function : CheckClosed
451//purpose :
452//=======================================================================
453
454 Standard_Boolean ShapeAnalysis_Wire::CheckClosed(const Standard_Real prec)
455{
456 myStatusClosed = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
457 if (!IsReady() || NbEdges() < 1) return Standard_False;
458
459 CheckConnected (1, prec);
460 if ( LastCheckStatus ( ShapeExtend_DONE ) )
461 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
462 if ( LastCheckStatus ( ShapeExtend_FAIL ) )
463 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
464
465 CheckDegenerated ( 1 );
466 if ( LastCheckStatus ( ShapeExtend_DONE ) )
467 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
468 if ( LastCheckStatus ( ShapeExtend_FAIL ) )
469 myStatusClosed |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
470
471 return StatusClosed ( ShapeExtend_DONE );
472}
473
474//=======================================================================
475//function : CheckGaps3d
476//purpose :
477//=======================================================================
478
479 Standard_Boolean ShapeAnalysis_Wire::CheckGaps3d ()
480{
481 myStatusGaps3d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
482 if (!IsLoaded() || NbEdges() < 1) return Standard_False; //gka IsLoaded
483
484 Standard_Real dist, maxdist = 0.;
485
486 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
487 CheckGap3d(i);
488 myStatusGaps3d |= myStatus;
489 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
490 dist = MinDistance3d();
491 if (maxdist<dist) maxdist = dist;
492 }
493 }
494 myMin3d = myMax3d = maxdist;
495
496 return StatusGaps3d ( ShapeExtend_DONE );
497}
498
499//=======================================================================
500//function : CheckGaps2d
501//purpose :
502//=======================================================================
503
504 Standard_Boolean ShapeAnalysis_Wire::CheckGaps2d ()
505{
506 myStatusGaps2d = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
507 if (!IsReady() || NbEdges() < 1) return Standard_False;
508
509 Standard_Real dist, maxdist = 0.;
510
511 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
512 CheckGap2d(i);
513 myStatusGaps2d |= myStatus;
514 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
515 dist = MinDistance2d();
516 if (maxdist<dist) maxdist = dist;
517 }
518 }
519 myMin2d = myMax2d = maxdist;
520
521 return StatusGaps2d ( ShapeExtend_DONE );
522}
523
524//=======================================================================
525//function : CheckCurveGaps
526//purpose :
527//=======================================================================
528
529 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGaps ()
530{
531 myStatusCurveGaps = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
532 if (!IsReady() || NbEdges() < 1) return Standard_False;
533
534 Standard_Real dist, maxdist = 0.;
535
536 for (Standard_Integer i = 1; i <= NbEdges(); i++) {
537 CheckCurveGap(i);
538 myStatusCurveGaps |= myStatus;
539 if (!LastCheckStatus(ShapeExtend_FAIL1)) {
540 dist = MinDistance3d();
541 if (maxdist<dist) maxdist = dist;
542 }
543 }
544 myMin3d = myMax3d = maxdist;
545
546 return StatusCurveGaps ( ShapeExtend_DONE );
547}
548
549//=======================================================================
550//function : CheckOrder
551//purpose :
552//=======================================================================
553
554Standard_Boolean ShapeAnalysis_Wire::CheckOrder(ShapeAnalysis_WireOrder& sawo,
555 const Standard_Boolean isClosed,
556 const Standard_Boolean mode3d)
557{
558 if ( ! mode3d && myFace.IsNull() ) {
559 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
560 return Standard_False;
561 }
562
563 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
564 sawo.SetMode ( mode3d, ( mode3d ? myPrecision : ::Precision::PConfusion() ) );
565 Standard_Integer i, nb = myWire->NbEdges();
566 ShapeAnalysis_Edge EA;
567 for (i = 1; i <= nb; i ++) {
568 TopoDS_Edge E = myWire->Edge(i);
569 if ( mode3d ) {
570 TopoDS_Vertex V1 = EA.FirstVertex (E);
571 TopoDS_Vertex V2 = EA.LastVertex (E);
42e4630c 572 if (V1.IsNull() || V2.IsNull())
573 {
574 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
575 return Standard_False;
576 }
7fd59977 577 gp_Pnt p1 = BRep_Tool::Pnt (V1);
578 gp_Pnt p2 = BRep_Tool::Pnt (V2);
579 sawo.Add (p1.XYZ(),p2.XYZ());
580 }
581 else {
582 Standard_Real f,l;
583 Handle(Geom2d_Curve) c2d;
584 TopoDS_Shape tmpF = myFace.Oriented(TopAbs_FORWARD);
585 if ( ! EA.PCurve(E,TopoDS::Face(tmpF),c2d,f,l) ) {
586 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
587 return Standard_False;
588 }
589 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
590 }
591 }
592 sawo.Perform(isClosed);
593 Standard_Integer stat = sawo.Status();
594 switch (stat) {
595 case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); break;
596 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break;
597 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
598 case -1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
599 case -2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
673693f1 600 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE5); break;//only shifted
7fd59977 601 case -10: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); break;
602 }
603 return LastCheckStatus (ShapeExtend_DONE);
604}
605
606//=======================================================================
607//function : CheckConnected
608//purpose :
609//=======================================================================
610
611Standard_Boolean ShapeAnalysis_Wire::CheckConnected (const Standard_Integer num,
612 const Standard_Real prec)
613{
614 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
615 if ( ! IsLoaded() || NbEdges() < 1 ) return Standard_False;
616
617 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
618 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
619// if (n1 == n2) return 0;
620
621 TopoDS_Edge E1 = WireData()->Edge ( n1 );
622 TopoDS_Edge E2 = WireData()->Edge ( n2 );
623
624 ShapeAnalysis_Edge sae;
625 TopoDS_Vertex V1 = sae.LastVertex (E1);
626 TopoDS_Vertex V2 = sae.FirstVertex (E2);
42e4630c 627 if (V1.IsNull() || V2.IsNull())
628 {
629 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
630 return Standard_False;
631 }
7fd59977 632 if (V1.IsSame(V2)) return Standard_False;
633
634 gp_Pnt p1 = BRep_Tool::Pnt (V1);
635 gp_Pnt p2 = BRep_Tool::Pnt (V2);
636 myMin3d = p1.Distance(p2);
637 if ( myMin3d <= gp::Resolution() ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
638 else if ( myMin3d <= myPrecision ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
639 else if ( myMin3d <= prec ) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
640 else {
641 // et en inversant la derniere edge ?
642 if ( n1 == n2 ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
643 else {
644 V2 = sae.LastVertex (E2);
645 p2 = BRep_Tool::Pnt (V2);
646 Standard_Real dist = p1.Distance(p2);
647 if ( dist > myPrecision ) myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
648 else {
649 myMin3d = dist;
650 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
651 }
652 }
653 return Standard_False;
654 }
655 return Standard_True;
656}
657
658//=======================================================================
659//function : CheckSmall
660//purpose :
661//=======================================================================
662
663Standard_Boolean ShapeAnalysis_Wire::CheckSmall (const Standard_Integer num,
664 const Standard_Real precsmall)
665{
666 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
667 if ( ! IsLoaded() || NbEdges() <= 1 ) return Standard_False;
668
669 //Standard_Integer n = ( num ? num : NbEdges() ); //szv#4:S4163:12Mar99 not needed
670 TopoDS_Edge E = myWire->Edge ( num ? num : NbEdges() );
671 ShapeAnalysis_Edge sae;
672
673 if ( BRep_Tool::Degenerated ( E ) ) {
674 //:n2 abv 22 Jan 99: ma-test5.igs -> IGES (brep) -> read (pref3d):
675 // degen edge with no pcurve should be removed
676 if ( ! myFace.IsNull() && sae.HasPCurve ( E, Face() ) ) return Standard_False;
677 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
678 }
679
680 TopoDS_Vertex V1 = sae.FirstVertex (E);
681 TopoDS_Vertex V2 = sae.LastVertex (E);
29582444 682 if (V1.IsNull() || V2.IsNull())
683 {
684 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
685 return Standard_False;
686 }
7fd59977 687 gp_Pnt p1 = BRep_Tool::Pnt (V1);
688 gp_Pnt p2 = BRep_Tool::Pnt (V2);
689 Standard_Real dist = p1.Distance(p2);
690 Standard_Real prec = precsmall;//Min ( myPrecision, precsmall );
691 //Standard_Real prec = Min(BRep_Tool::Tolerance(V1),BRep_Tool::Tolerance(V2)); //skl
692 if (dist > prec) return Standard_False; // pas nulle
693
694 // La courbe 3D a present : est-elle FERMEE ou DE LONGUEUR NULLE ... ???
695 // Pour cela on prend le point milieu (y a-t-il mieux)
696 // Si pas de C3D, on essaie la C2D ...
697
698 gp_Pnt Pm;
699 Standard_Real cf,cl;
700 Handle(Geom_Curve) c3d;
701 if ( sae.Curve3d (E,c3d,cf,cl,Standard_False) ) Pm = c3d->Value ( (cf+cl)/2. );
702 else {
703 Handle(Geom2d_Curve) c2d;
704 if ( ! myFace.IsNull() && sae.PCurve (E,myFace,c2d,cf,cl,Standard_False)) {
705 gp_Pnt2d p2m = c2d->Value ( (cf+cl)/2. );
706 Pm = mySurf->Value (p2m);
707 }
708 else {
709 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
710 Pm = p1;
711//:n2 return Standard_False;
712 }
713 }
714 if ( Pm.Distance(p1) > prec || Pm.Distance(p2) > prec ) return Standard_False;
715
716 myStatus |= ShapeExtend::EncodeStatus ( V1.IsSame(V2) ? ShapeExtend_DONE1 : ShapeExtend_DONE2 );
717 return Standard_True;
718}
719
720//=======================================================================
721//function : CheckSeam
722//purpose :
723//=======================================================================
724
725 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num,
726 Handle(Geom2d_Curve)& C1,
727 Handle(Geom2d_Curve)& C2,
728 Standard_Real& cf,
729 Standard_Real& cl)
730{
731 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
732 if (!IsReady()) return Standard_False;
733 Standard_Integer n = num; if (n == 0) n = NbEdges();
734 TopoDS_Edge E = myWire->Edge (n);
735 if ( ! ShapeAnalysis_Edge().IsSeam ( E, myFace ) ) return Standard_False;
736 // Extract the Two PCurves of the Seam
737 TopoDS_Face ForwardFace = myFace; ForwardFace.Orientation (TopAbs_FORWARD);
738 //szv#4:S4163:12Mar99 SGI warns
739 TopoDS_Shape EF = E.Oriented(TopAbs_FORWARD);
740 TopoDS_Shape ER = E.Oriented(TopAbs_REVERSED);
741 C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(EF), ForwardFace, cf, cl);
742 C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(ER), ForwardFace, cf, cl);
743 if (C1.IsNull() || C2.IsNull()) return Standard_False;
744
745// SelectForward est destine a devenir un outil distinct
746
747 Standard_Integer theCurveIndice = ShapeAnalysis_Curve().SelectForwardSeam (C1,C2);
748 if ( theCurveIndice != 2 ) return Standard_False;
749
750 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
751 return Standard_True;
752}
753
754//=======================================================================
755//function : CheckSeam
756//purpose :
757//=======================================================================
758
759 Standard_Boolean ShapeAnalysis_Wire::CheckSeam(const Standard_Integer num)
760{
761 Handle(Geom2d_Curve) C1, C2;
762 Standard_Real cf, cl;
763 return CheckSeam (num, C1, C2, cf, cl);
764}
765
766//=======================================================================
767//function : CheckDegenerated
768//purpose :
769//=======================================================================
770
771Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num,
772 gp_Pnt2d& p2d1, gp_Pnt2d& p2d2)
773{
774 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
775 if ( ! IsReady() || NbEdges() < 1 ) return Standard_False;
776
777 Standard_Integer n2 = (num > 0)? num : NbEdges();
778 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
779 Standard_Integer n3 = (n2 < NbEdges())? n2+1 : 1;
780 TopoDS_Edge E1 = myWire->Edge ( n1 );
781 TopoDS_Edge E2 = myWire->Edge ( n2 );
782 TopoDS_Edge E3 = myWire->Edge ( n3 );
783
784 ShapeAnalysis_Edge sae;
785
786 // skip if edge is already marked as degenerated and has pcurve
787 if ( BRep_Tool::Degenerated ( E2 ) && sae.HasPCurve ( E2, Face() ) ) {
788 // skl 30.12.2004 for OCC7630 - we have to check pcurve
789 if( sae.HasPCurve(E1,Face()) && sae.HasPCurve(E3,Face()) ) {
790 Handle(Geom2d_Curve) c2d;
791 Standard_Real fp,lp;
792 sae.PCurve ( E2, myFace, c2d, fp, lp, Standard_True );
793 gp_Pnt2d p21 = c2d->Value(fp);
794 gp_Pnt2d p22 = c2d->Value(lp);
795 sae.PCurve ( E1, myFace, c2d, fp, lp, Standard_True );
796 gp_Pnt2d p12 = c2d->Value(lp);
797 sae.PCurve ( E3, myFace, c2d, fp, lp, Standard_True );
798 gp_Pnt2d p31 = c2d->Value(fp);
799 if( fabs(p12.Distance(p31)-p21.Distance(p22)) > 2*Precision::PConfusion() ) {
800 // pcurve is bad => we can remove this edge in ShapeFix
801 // if set needed status
802 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
803 }
804 }
805 return Standard_False;
806 }
807
808 //pdn allows to insert two sequences of degenerated edges (on separate bounds of surfaces)
809 if ( n1 != n2 && BRep_Tool::Degenerated ( E1 ) &&
810 ! sae.HasPCurve ( E1, Face() ) ) {
811 //:abv 13.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
812 if ( BRep_Tool::Degenerated ( E2 ) )
813 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
814 return Standard_False;
815 }
816//:i8 if ( BRep_Tool::Degenerated ( E1 ) ||
817//:i8 BRep_Tool::Degenerated ( E2 ) ) return Standard_False; // deja OK
818
819 TopoDS_Vertex Vp = sae.FirstVertex (E1); //:i9
820 TopoDS_Vertex V0 = sae.LastVertex (E1);
821 TopoDS_Vertex V1 = sae.FirstVertex (E2);
822 TopoDS_Vertex V2 = sae.LastVertex (E2);
46aed280 823
824 if (Vp.IsNull() || V0.IsNull() || V1.IsNull() || V2.IsNull())
825 return Standard_False;
826
7fd59977 827 gp_Pnt pp = BRep_Tool::Pnt (Vp); //:i9
828 gp_Pnt p0 = BRep_Tool::Pnt (V0);
829 gp_Pnt p1 = BRep_Tool::Pnt (V1);
830 gp_Pnt p2 = BRep_Tool::Pnt (V2);
831 Standard_Real par1, par2;
832 Standard_Boolean lack = Standard_False;
833 Standard_Boolean dgnr = Standard_False;
834 //pdn 12.03.99 minimal value processing first
835 Standard_Real precFirst = Min(myPrecision,BRep_Tool::Tolerance(V1));
836 Standard_Real precFin = Max(myPrecision,BRep_Tool::Tolerance(V1));
837 Standard_Real precVtx = (myPrecision<BRep_Tool::Tolerance(V1) ? 2*precFin : precFin);
838 // forward : si Edge <num> FWD/REV. Si LACK, toujours True
839 Standard_Boolean forward = ( E2.Orientation() == TopAbs_FORWARD );
840 // FIX FEV 1998 : recompute singularity according precision
841
842 if (p1.Distance(p2) <= precFirst) { // edge DGNR
843 dgnr = mySurf->DegeneratedValues ( p1, precVtx, p2d1, p2d2, par1, par2, forward ); //smh#9
844 if ( dgnr ) { // abv 24 Feb 00: trj3_as1-ac-214.stp #6065: avoid making closed edge degenerated
845 Standard_Real a, b;
846 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E2, a, b );
847 if ( ! C3d.IsNull() ) {
848 gp_Pnt p = C3d->Value ( 0.5 * ( a + b ) );
849 if ( p.SquareDistance ( p1 ) > precVtx * precVtx ) dgnr = Standard_False;
850 }
851 }
852 }
853 if ( ! dgnr ) {
854 //:i9 abv 23 Sep 98: CTS20315-2 #63231: check that previous edge is not degenerated
855 if ( n1 != n2 && p1.Distance(pp) <= precFirst &&
856 mySurf->IsDegenerated ( pp, precFirst ) &&
857 ! BRep_Tool::Degenerated ( E1 ) ) return Standard_False;
858 //rln S4135 ShapeAnalysis_Surface new algorithms for singularities
859 //:45 by abv 16 Dec 97: BUC60035 2659: precision increased to vertex tolerance
860 //Standard_Real prec = Max ( myPrecision, BRep_Tool::Tolerance(V1) );
861 //:51 abv 22 Dec 97: recompute singularities if necessary
862 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( 2 * prec ); //:51 //:74 abv 15 Jan 97: *2
863
864 if ( p0.Distance ( p1 ) <= precFin ) {// ou DGNR manquante ?
865 //rln S4135 singularity with precision = 2 * prec, but distance <= prec
866 //lack = mySurf->DegeneratedValues ( p1, prec, p2d1, p2d2, par1, par2, forward);
867 Standard_Real tmpPreci;
868 gp_Pnt tmpP3d;
869 Standard_Boolean tmpUIsoDeg;
870 //#77 rln S4135: using singularity which has minimum gap between singular point and input 3D point
871 Standard_Integer indMin = -1;
872 Standard_Real gapMin2 = RealLast();
873 for (Standard_Integer i = 1; i <= mySurf->NbSingularities (precVtx); i++) {
874 mySurf->Singularity (i, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
875 Standard_Real gap2 = p1.SquareDistance (tmpP3d);
876 if (gap2 <= precVtx * precVtx)
877 if (gapMin2 > gap2) {
878 gapMin2 = gap2;
879 indMin = i;
880 }
881 }
882 if (indMin >= 1) {
883 mySurf->Singularity (indMin, tmpPreci, tmpP3d, p2d1, p2d2, par1, par2, tmpUIsoDeg);
884 lack = Standard_True;
885 }
886 }
887
888 //rln S4135 if ( prec > myPrecision ) mySurf->ComputeSingularities ( myPrecision ); //:51
889 }
890
891 // voila, on a soit dgnr soit lack
892 if ( ! lack && ! dgnr ) {
893 //:abv 29.08.01: if singularity not detected but edge is marked
894 // as degenerated, report fail
895 if ( BRep_Tool::Degenerated ( E2 ) && ! sae.HasPCurve ( E2, Face() ) )
896 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
897 return Standard_False;
898 }
899
900 // OK, degenerated case detected; we will find its start and end in 2d
901
902 if ( lack ) forward = Standard_True;
903
904 //:24 by abv 28 Nov 97:
905 // make degenerative pcurve parametrized exactly from end of pcurve of the
906 // previous edge to the start of the next one
907 if ( lack || n1 != n2 ) { //:i8 abv 18 Sep 98: ProSTEP TR9 r0501-ug.stp #182180: single degedge is a wire at apex of a cone
908 Standard_Real a, b;
909 Handle(Geom2d_Curve) c2d;
910 if ( sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
911 p2d1 = c2d->Value ( b );
912 //#84 rln gp_Pnt2d p2d = c2d->Value ( b );
913 //#84 rln par1 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
914 }
915 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
916 //pdn pcurves (fixing regression in f0 in degenerated case)
917 if ( sae.PCurve ( ( dgnr ? E3 : E2 ), myFace, c2d, a, b, Standard_True ) ) {
918 p2d2 = c2d->Value ( a );
919 //#84 rln gp_Pnt2d p2d = c2d->Value ( a );
920 //#84 rln par2 = ( p2d.XY() - aP2d.XY() ) * theDir2d.XY();
921 }
922 else myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
923 }
924/*
925 if ( par2 < par1 ) {
926 par1 = -par1;
927 par2 = -par2;
928 theDir2d.Reverse();
929 }
930*/
931
932 //#84 rln 18.03.99 if pcurve is not degenerate anymore, the fix is postponned
933 //to ShapeFix_Wire::FixLacking
934 if ( ! mySurf->IsDegenerated ( p2d1, p2d2, precVtx, 10. ) ) { //:s1 abv 22 Apr 99: PRO7226 #489490 //smh#9
935 //:abv 24.05.02: OCC320 - fail (to remove edge) if two consequtive degenerated edges w/o pcurves
936 if ( BRep_Tool::Degenerated ( E2 ) )
937 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
938 return Standard_False;
939 }
940
941 //added by rln 18/12/97 CSR# CTS18544 entity 13638
942 //the situation when degenerated edge already exists but flag is not set
943 //(i.e. the parametric space is closed)
944 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
945 Standard_Real max = Max ( Ads.UResolution(myPrecision),
946 Ads.VResolution(myPrecision) );
947 if ( p2d1.Distance (p2d2) /*Abs (par1 - par2)*/ <= max + gp::Resolution() ) return Standard_False;
948
949 //#84 rln p2d1 = aP2d.XY() + par1 * theDir2d.XY();
950 //#84 rln p2d2 = aP2d.XY() + par2 * theDir2d.XY();
951 myStatus = ShapeExtend::EncodeStatus ( dgnr ? ShapeExtend_DONE2 : ShapeExtend_DONE1 );
952 return Standard_True;
953}
954
955//=======================================================================
956//function : CheckDegenerated
957//purpose :
958//=======================================================================
959
960Standard_Boolean ShapeAnalysis_Wire::CheckDegenerated (const Standard_Integer num)
961{
962 gp_Pnt2d p2d1, p2d2;
963 return CheckDegenerated ( num, p2d1, p2d2 );
964}
965
966//=======================================================================
967//function : CheckGap3d
968//purpose :
969//=======================================================================
970
971 Standard_Boolean ShapeAnalysis_Wire::CheckGap3d(const Standard_Integer num)
972{
973 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
974 //szv#4:S4163:12Mar99 optimized
975 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
976 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
977 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
978 TopoDS_Edge E1 = myWire->Edge(n1);
979 TopoDS_Edge E2 = myWire->Edge(n2);
980 Standard_Real uf1,ul1,uf2,ul2;
981 Handle(Geom_Curve) C1,C2;
982 ShapeAnalysis_Edge SAE;
983 if (!SAE.Curve3d (E1,C1,uf1,ul1) || !SAE.Curve3d (E2,C2,uf2,ul2)) {
984 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
985 return Standard_False;
986 }
987 gp_Pnt p1 = C1->Value (ul1);
988 gp_Pnt p2 = C2->Value (uf2);
989 myMin3d = myMax3d = p1.Distance (p2);
990 if (myMin3d > myPrecision)
991 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
992 return LastCheckStatus (ShapeExtend_DONE);
993}
994
995//=======================================================================
996//function : CheckGap2d
997//purpose :
998//=======================================================================
999
1000 Standard_Boolean ShapeAnalysis_Wire::CheckGap2d(const Standard_Integer num)
1001{
1002 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1003 //szv#4:S4163:12Mar99 optimized
1004 if ( !IsReady() || NbEdges() < 1 ) return Standard_False; //szvsh was nbedges < 2
1005 Standard_Integer n2 = ( num >0 ? num : NbEdges() );
1006 Standard_Integer n1 = ( n2 >1 ? n2-1 : NbEdges() );
1007 TopoDS_Edge E1 = myWire->Edge(n1);
1008 TopoDS_Edge E2 = myWire->Edge(n2);
1009 Standard_Real uf1,ul1,uf2,ul2;
1010 Handle(Geom2d_Curve) C1,C2;
1011 ShapeAnalysis_Edge SAE;
1012 if (!SAE.PCurve (E1,myFace,C1,uf1,ul1) || !SAE.PCurve (E2,myFace,C2,uf2,ul2)) {
1013 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1014 return Standard_False;
1015 }
1016 gp_Pnt2d p1 = C1->Value (ul1);
1017 gp_Pnt2d p2 = C2->Value (uf2);
1018 myMin2d = myMax2d = p1.Distance (p2);
1019 GeomAdaptor_Surface& SA = mySurf->Adaptor3d()->ChangeSurface();
1020 if (myMin2d > (Max (SA.UResolution (myPrecision), SA.VResolution (myPrecision)) + Precision::PConfusion()))
1021 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1022 return LastCheckStatus (ShapeExtend_DONE);
1023}
1024
1025//=======================================================================
1026//function : CheckCurveGap
1027//purpose :
1028//=======================================================================
1029
1030 Standard_Boolean ShapeAnalysis_Wire::CheckCurveGap(const Standard_Integer num)
1031{
1032 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1033 if ( !IsLoaded() || NbEdges() < 1 ) return Standard_False;
1034 Standard_Integer n = ( num >0 ? num : NbEdges() );
1035 TopoDS_Edge E = myWire->Edge(n);
1036 Standard_Real cuf,cul,pcuf,pcul;
1037 Handle(Geom_Curve) c;
1038 ShapeAnalysis_Edge SAE;
1039 if (!SAE.Curve3d (E,c,cuf,cul,Standard_False)) {
1040 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1041 return Standard_False;
1042 }
1043 Handle(Geom2d_Curve) pc;
1044 if (!SAE.PCurve (E,myFace,pc,pcuf,pcul,Standard_False)) {
1045 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1046 return Standard_False;
1047 }
1048 Handle(Geom2dAdaptor_HCurve) AC = new Geom2dAdaptor_HCurve(pc,pcuf,pcul);
1049 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(mySurf->Surface());
1050 Adaptor3d_CurveOnSurface ACS(AC,AS);
1051 gp_Pnt cpnt, pcpnt;
1052 Standard_Integer nbp = 45;
1053 Standard_Real dist, maxdist=0.;
1054 for (Standard_Integer i=0; i<nbp; i++) {
1055 cpnt = c->Value(cuf + i*(cul-cuf)/(nbp-1));
1056 pcpnt = ACS.Value(pcuf + i*(pcul-pcuf)/(nbp-1));
1057 dist = cpnt.SquareDistance(pcpnt);
1058 if (maxdist<dist) maxdist = dist;
1059 }
1060 myMin3d = myMax3d = Sqrt(maxdist);
1061 if (myMin3d > myPrecision)
1062 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1063 return LastCheckStatus (ShapeExtend_DONE);
1064}
1065
1066//=======================================================================
1067//function : CheckSelfIntersectingEdge
1068//purpose :
1069//=======================================================================
1070
1071// auxiliary function
1072//:h0 abv 29 May 98: PRO10105 1949: like in BRepCheck, point is to be taken
1073// from 3d curve (but only if edge is SameParameter)
1074static gp_Pnt GetPointOnEdge ( const TopoDS_Edge &edge,
1075 const Handle(ShapeAnalysis_Surface) &surf,
94f71cad 1076 const Geom2dAdaptor_Curve &Crv2d,
7fd59977 1077 const Standard_Real param )
1078{
1079 if ( BRep_Tool::SameParameter ( edge ) ) {
1080 Standard_Real f,l;
1081 TopLoc_Location L;
1082 const Handle(Geom_Curve) ConS = BRep_Tool::Curve ( edge, L, f, l );
1083 if ( ! ConS.IsNull() )
1084 return ConS->Value ( param ).Transformed ( L.Transformation() );
1085 }
94f71cad 1086 gp_Pnt2d aP2d = Crv2d.Value(param);
1087 return surf->Adaptor3d()->Value(aP2d.X(), aP2d.Y());
7fd59977 1088}
1089
1090//=======================================================================
1091//function : CheckSelfIntersectingEdge
1092//purpose :
1093//=======================================================================
1094
1095Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num,
1096 IntRes2d_SequenceOfIntersectionPoint& points2d,
1097 TColgp_SequenceOfPnt& points3d)
1098{
1099 points2d.Clear();
1100 points3d.Clear();
1101 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1102 if ( ! IsReady() ) return Standard_False;
1103
1104 TopoDS_Edge edge = WireData()->Edge ( num >0 ? num : NbEdges() );
1105 ShapeAnalysis_Edge sae;
1106
1107 Standard_Real a, b;
1108 Handle(Geom2d_Curve) Crv;
1109 if ( ! sae.PCurve ( edge, myFace, Crv, a, b, Standard_False ) ) {
1110 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1111 return Standard_False;
1112 }
1113 if ( Abs ( a - b ) <= ::Precision::PConfusion() ) return Standard_False;
1114
1115 Standard_Real tolint = 1.0e-10;
1116 //szv#4:S4163:12Mar99 warning
1117 IntRes2d_Domain domain ( Crv->Value ( a ), a, tolint, Crv->Value ( b ), b, tolint );
1118 Geom2dAdaptor_Curve AC ( Crv );
1119 Geom2dInt_GInter Inter ( AC, domain, tolint, tolint );
1120
1121 if ( ! Inter.IsDone() ) return Standard_False;
1122
1123 TopoDS_Vertex V1 = sae.FirstVertex ( edge );
1124 TopoDS_Vertex V2 = sae.LastVertex ( edge );
1125 if ( V1.IsNull() || V2.IsNull() ) {
1126 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1127 return Standard_False;
1128 }
1129 Standard_Real tol1 = BRep_Tool::Tolerance ( V1 );
1130 Standard_Real tol2 = BRep_Tool::Tolerance ( V2 );
1131
1132 gp_Pnt pnt1 = BRep_Tool::Pnt ( V1 );
1133 gp_Pnt pnt2 = BRep_Tool::Pnt ( V2 );
1134
1135 for ( Standard_Integer i=1; i <= Inter.NbPoints(); i++ ) {
1136 const IntRes2d_IntersectionPoint &IP = Inter.Point ( i );
1137 const IntRes2d_Transition &Tr1 = IP.TransitionOfFirst();
1138 const IntRes2d_Transition &Tr2 = IP.TransitionOfSecond();
1139 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1140 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
94f71cad 1141 gp_Pnt pint = GetPointOnEdge ( edge, mySurf, AC, IP.ParamOnFirst() );
7fd59977 1142 Standard_Real dist21 = pnt1.SquareDistance ( pint );
1143 Standard_Real dist22 = pnt2.SquareDistance ( pint );
1144 if ( dist21 > tol1 * tol1 && dist22 > tol2 * tol2 ) {
1145 points2d.Append ( IP );
1146 points3d.Append ( pint );
1147 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1148 }
1149 }
1150
1151 return LastCheckStatus ( ShapeExtend_DONE );
1152}
1153
1154//=======================================================================
1155//function : CheckSelfIntersectingEdge
1156//purpose :
1157//=======================================================================
1158
1159Standard_Boolean ShapeAnalysis_Wire::CheckSelfIntersectingEdge (const Standard_Integer num)
1160{
1161 IntRes2d_SequenceOfIntersectionPoint points2d;
1162 TColgp_SequenceOfPnt points3d;
1163 return CheckSelfIntersectingEdge ( num, points2d, points3d );
1164}
1165
1166//=======================================================================
1167//function : CheckIntersectingEdges
1168//purpose : Test if two consequent edges are intersecting
1169// It is made in accordance with the following check in BRepCheck:
1170// - in BRepCheck_Wire::Orientation(), test for self-intersection
1171//=======================================================================
1172
1173Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num,
1174 IntRes2d_SequenceOfIntersectionPoint& points2d,
1175 TColgp_SequenceOfPnt& points3d,
1176 TColStd_SequenceOfReal& errors)
1177{
1178 points2d.Clear();
1179 points3d.Clear();
1180 errors.Clear();
1181 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1182 if ( ! IsReady() || NbEdges() <2 ) return Standard_False;
1183
1184 //szv#4:S4163:12Mar99 optimized
1185 Standard_Integer n2 = (num > 0)? num : NbEdges();
1186 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1187 TopoDS_Edge edge1 = myWire->Edge ( n1 );
1188 TopoDS_Edge edge2 = myWire->Edge ( n2 );
1189
1190 ShapeAnalysis_Edge sae;
1191 TopoDS_Vertex V1 = sae.LastVertex ( edge1 );
1192 TopoDS_Vertex V2 = sae.FirstVertex ( edge2 );
1193 if ( V1.IsNull() || V2.IsNull() ) {
1194 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1195 return Standard_False;
1196 }
1197 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1198 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1199 return Standard_False;
1200 }
1201
1202 TopoDS_Vertex Vp = sae.FirstVertex ( edge1 );
1203 TopoDS_Vertex Vn = sae.LastVertex ( edge2 );
1204
1205 Standard_Real a1, b1, a2, b2;
1206 Handle(Geom2d_Curve) Crv1, Crv2;
1207 if ( ! sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False ) ) {
1208 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1209 return Standard_False;
1210 }
1211 if ( ! sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False ) ) {
1212 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1213 return Standard_False;
1214 }
1215 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1216 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False; //:f7 abv 6 May 98: BUC50070 on #42276
1217
1218 Standard_Boolean isForward1 = ( edge1.Orientation() == TopAbs_FORWARD );
1219 Standard_Boolean isForward2 = ( edge2.Orientation() == TopAbs_FORWARD );
1220
1221 Standard_Real tol0 = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1222 Standard_Real tol = tol0;
1223
1224 gp_Pnt pnt = BRep_Tool::Pnt ( V1 );
1225
1226// Standard_Boolean Status = Standard_False;
1227
1228 Standard_Real tolint = 1.0e-10;
1229
1230 //szv#4:S4163:12Mar99 warning
7fd59977 1231 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
94f71cad 1232 IntRes2d_Domain d1 ( C1.Value ( a1 ), a1, tolint,
1233 C1.Value ( b1 ), b1, tolint );
1234 IntRes2d_Domain d2 ( C2.Value ( a2 ), a2, tolint,
1235 C2.Value ( b2 ), b2, tolint );
7fd59977 1236
1237 //:64 abv 25 Dec 97: Attention!
1238 // Since Intersection algorithm is not symmetrical, for consistency with BRepCheck
1239 // edge with lower order number shoud be intersecting with edge with higher one
1240 // i.e., for intersection of last and first edges, they should go in reversed order
1241 // Example: entity #38285 from bug CSR #CTS17806
1242 // NOTE: Tr1 and Tr2 are not reordered because they are used in the same manner
1243 Geom2dInt_GInter Inter;
1244 if ( num ==1 ) Inter.Perform ( C2, d2, C1, d1, tolint, tolint );
1245 else Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1246 if ( ! Inter.IsDone() ) return Standard_False;
1247
1248 //:86 abv 22 Jan 98: fix self-intersection even if tolerance of vertex is enough
1249 // to annihilate it. This is done to prevent wrong effects if vertex tolerance
1250 // will be decreased (e.g., in FixLacking)
1251 Standard_Real tole = Max ( ( BRep_Tool::SameParameter ( edge1 ) ?
1252 BRep_Tool::Tolerance ( edge1 ) : tol0 ),
1253 ( BRep_Tool::SameParameter ( edge2 ) ?
1254 BRep_Tool::Tolerance ( edge2 ) : tol0 ) );
1255 Standard_Real tolt = Min ( tol, Max ( tole, myPrecision ) );
1256 //Standard_Real prevRange1 = RealLast(), prevRange2 = RealLast(); //SK
1257 Standard_Integer isLacking = -1; //:l0 abv: CATIA01 #1727: protect against adding lacking
1258 //#83 rln 19.03.99 sim2.igs, entity 4292
1259 //processing also segments as in BRepCheck
1260 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1261 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1262 IntRes2d_IntersectionPoint IP;
1263 IntRes2d_Transition Tr1, Tr2;
1264 if (i <= NbPoints)
1265 IP = Inter.Point ( i );
1266 else {
1267 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1268 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1269 IP = Seg.FirstPoint();
1270 Tr1 = IP.TransitionOfFirst();
1271 Tr2 = IP.TransitionOfSecond();
1272 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1273 IP = Seg.LastPoint();
1274 }
1275 Tr1 = IP.TransitionOfFirst();
1276 Tr2 = IP.TransitionOfSecond();
1277
1278 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1279 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1280 Standard_Real param1, param2;
1281 param1 = ( num ==1 ? IP.ParamOnSecond() : IP.ParamOnFirst() );
1282 param2 = ( num ==1 ? IP.ParamOnFirst() : IP.ParamOnSecond() );
1283
1284 //:r6 abv 8 Apr 99: r_47-sd.stp #173850: protect against working out of curve range
1285 if ( a1-param1 > ::Precision::PConfusion() ||
1286 param1-b1 > ::Precision::PConfusion() ||
1287 a2-param2 > ::Precision::PConfusion() ||
1288 param2-b2 > ::Precision::PConfusion() ) continue;
1289
1290 //:82 abv 21 Jan 98: point of intersection on Crv1 and Crv2 is different
94f71cad 1291 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, C1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1292 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, C2, param2 ); //:h0: thesurf.Value ( Crv2->Value ( param2 ) );
7fd59977 1293 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1294 Standard_Real di1 = pi1.SquareDistance ( pnt );
1295 Standard_Real di2 = pi2.SquareDistance ( pnt );
1296 Standard_Real dist2 = Max ( di1, di2 );
1297
1298 //rln 03/02/98: CSR#BUC50004 entity 56 (to avoid later inserting lacking edge)
1299 if ( isLacking <0 ) { //:l0
1300 gp_Pnt2d end1 = Crv1->Value ( isForward1 ? b1 : a1 );
1301 gp_Pnt2d end2 = Crv2->Value ( isForward2 ? a2 : b2 );
1302//:l0 Standard_Real distab2 = mySurf->Value ( end1 ).SquareDistance ( mySurf->Value ( end2 ) );
1303 //:l0: test like in BRepCheck
1304 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1305 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1306 isLacking = ( end1.SquareDistance(end2) >= tol2d * tol2d );
1307 }
1308
1309 if ( ( dist2 > tolt * tolt || //:86: tol -> tolt
1310 isLacking ) && //:l0
1311//:l0 distab2 > BRep_Tool::Tolerance ( edge1 ) + BRep_Tool::Tolerance ( edge2 ) ) && //rln
1312 ( ! BRepTools::Compare ( Vp, Vn ) || //:63
1313 dist2 < pint.SquareDistance ( BRep_Tool::Pnt ( Vp ) ) ) ) { //:63
1314 points2d.Append ( IP );
1315 points3d.Append ( pint );
1316 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1317 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1318 }
1319 }
1320
1321 return LastCheckStatus ( ShapeExtend_DONE );
1322}
1323
1324//=======================================================================
1325//function : CheckIntersectingEdges
1326//purpose :
1327//=======================================================================
1328
1329Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num)
1330{
1331 IntRes2d_SequenceOfIntersectionPoint points2d;
1332 TColgp_SequenceOfPnt points3d;
1333 TColStd_SequenceOfReal errors;
1334 return CheckIntersectingEdges ( num, points2d, points3d, errors );
1335}
1336
1337//=======================================================================
1338//function : CheckIntersectingEdges
1339//purpose :
1340//=======================================================================
1341
1342Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges(const Standard_Integer num1,
1343 const Standard_Integer num2,
1344 IntRes2d_SequenceOfIntersectionPoint& points2d,
1345 TColgp_SequenceOfPnt& points3d,
1346 TColStd_SequenceOfReal& errors)
1347{
1348 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1349 if ( ! IsReady() ) return Standard_False;
1350 Handle(ShapeExtend_WireData) sbwd = WireData();
1351 Standard_Integer n2 = ( num2 >0 ? num2 : sbwd->NbEdges() );
1352 Standard_Integer n1 = ( num1 >0 ? num1 : sbwd->NbEdges() );
1353
1354 TopoDS_Edge edge1 = sbwd->Edge ( n1 );
1355 TopoDS_Edge edge2 = sbwd->Edge ( n2 );
1356
1357 ShapeAnalysis_Edge sae;
1358 Standard_Real a1, b1, a2, b2;
1359 Handle(Geom2d_Curve) Crv1, Crv2;
1360 if(!sae.PCurve ( edge1, myFace, Crv1, a1, b1, Standard_False )){
1361 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1362 return Standard_False;
1363 }
1364
1365 if(!sae.PCurve ( edge2, myFace, Crv2, a2, b2, Standard_False )){
1366 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1367 return Standard_False;
1368 }
1369
1370 if ( Abs ( a1 - b1 ) <= ::Precision::PConfusion() ||
1371 Abs ( a2 - b2 ) <= ::Precision::PConfusion() ) return Standard_False;
1372
1373 points2d.Clear();
1374 points3d.Clear();
1375 errors.Clear();
1376 TColgp_Array1OfPnt vertexPoints(1,4);
1377 TColStd_Array1OfReal vertexTolers(1,4);
1378 vertexPoints(1) = BRep_Tool::Pnt(sae.FirstVertex(edge1));
1379 vertexTolers(1) = BRep_Tool::Tolerance(sae.FirstVertex(edge1));
1380 vertexPoints(2) = BRep_Tool::Pnt(sae.LastVertex(edge1));
1381 vertexTolers(2) = BRep_Tool::Tolerance(sae.LastVertex(edge1));
1382 vertexPoints(3) = BRep_Tool::Pnt(sae.FirstVertex(edge2));
1383 vertexTolers(3) = BRep_Tool::Tolerance(sae.FirstVertex(edge2));
1384 vertexPoints(4) = BRep_Tool::Pnt(sae.LastVertex(edge2));
1385 vertexTolers(4) = BRep_Tool::Tolerance(sae.LastVertex(edge2));
1386
1387 Standard_Real tolint = 1.0e-10;
1388
1389 IntRes2d_Domain d1 ( Crv1->Value ( a1 ), a1, tolint,
1390 Crv1->Value ( b1 ), b1, tolint );
1391 IntRes2d_Domain d2 ( Crv2->Value ( a2 ), a2, tolint,
1392 Crv2->Value ( b2 ), b2, tolint );
1393 Geom2dAdaptor_Curve C1 ( Crv1 ), C2 ( Crv2 );
1394
1395 Geom2dInt_GInter Inter;
1396 Inter.Perform ( C1, d1, C2, d2, tolint, tolint );
1397 if ( ! Inter.IsDone() ) return Standard_False;
1398
1399 //#83 rln 19.03.99 sim2.igs, entity 4292
1400 //processing also segments as in BRepCheck
1401 Standard_Integer NbPoints = Inter.NbPoints(), NbSegments = Inter.NbSegments();
1402 for ( Standard_Integer i=1; i <= NbPoints + NbSegments; i++ ) {
1403 IntRes2d_IntersectionPoint IP;
1404 IntRes2d_Transition Tr1, Tr2;
1405 if (i <= NbPoints)
1406 IP = Inter.Point ( i );
1407 else {
1408 const IntRes2d_IntersectionSegment &Seg = Inter.Segment ( i - NbPoints );
1409 if (!Seg.HasFirstPoint() || !Seg.HasLastPoint()) continue;
1410 IP = Seg.FirstPoint();
1411 Tr1 = IP.TransitionOfFirst();
1412 Tr2 = IP.TransitionOfSecond();
1413 if (Tr1.PositionOnCurve() == IntRes2d_Middle || Tr2.PositionOnCurve() == IntRes2d_Middle)
1414 IP = Seg.LastPoint();
1415 }
1416 Tr1 = IP.TransitionOfFirst();
1417 Tr2 = IP.TransitionOfSecond();
1418 if ( Tr1.PositionOnCurve() != IntRes2d_Middle &&
1419 Tr2.PositionOnCurve() != IntRes2d_Middle ) continue;
1420 Standard_Real param1 = IP.ParamOnFirst();
1421 Standard_Real param2 = IP.ParamOnSecond();
94f71cad 1422 gp_Pnt pi1 = GetPointOnEdge ( edge1, mySurf, C1, param1 ); //:h0: thesurf.Value ( Crv1->Value ( param1 ) );
1423 gp_Pnt pi2 = GetPointOnEdge ( edge2, mySurf, C2, param2 );
16a1f265 1424 Standard_Boolean OK1 = Standard_False;
1425 Standard_Boolean OK2 = Standard_False;
1426
1427 for(Standard_Integer j=1; (j<=2)&&!OK1; j++) {
7fd59977 1428 Standard_Real di1 = pi1.SquareDistance (vertexPoints(j));
16a1f265 1429 if(di1 < vertexTolers(j) * vertexTolers(j))
1430 OK1 = Standard_True;
1431 }
1432
1433 for(Standard_Integer j=3; (j<=4)&&!OK2; j++) {
7fd59977 1434 Standard_Real di2 = pi2.SquareDistance (vertexPoints(j));
16a1f265 1435 if(di2 < vertexTolers(j) * vertexTolers(j))
1436 OK2 = Standard_True;
7fd59977 1437 }
16a1f265 1438
1439 if(!OK1 || !OK2) {
7fd59977 1440 gp_Pnt pint = 0.5 * ( pi1.XYZ() + pi2.XYZ() );
1441 points2d.Append ( IP );
1442 points3d.Append ( pint );
1443 errors.Append ( 0.5 * pi1.Distance ( pi2 ) );
1444 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1445 }
1446 }
1447 return LastCheckStatus ( ShapeExtend_DONE );
1448}
1449
1450//=======================================================================
1451//function : CheckIntersectingEdges
1452//purpose :
1453//=======================================================================
1454
1455Standard_Boolean ShapeAnalysis_Wire::CheckIntersectingEdges (const Standard_Integer num1,
1456 const Standard_Integer num2)
1457{
1458 IntRes2d_SequenceOfIntersectionPoint points2d;
1459 TColgp_SequenceOfPnt points3d;
1460 TColStd_SequenceOfReal errors;
1461 return CheckIntersectingEdges(num1, num2, points2d, points3d, errors);
1462}
1463
1464//=======================================================================
1465//function : CheckLacking
1466//purpose : Test if two edges are disconnected in 2d according to the
1467// Adaptor_Surface::Resolution
1468//=======================================================================
1469
1470Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1471 const Standard_Real Tolerance,
1472 gp_Pnt2d &p2d1, gp_Pnt2d &p2d2)
1473{
1474 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1475 if ( ! IsReady() ) return Standard_False;
1476
1477 //szv#4:S4163:12Mar99 optimized
1478 Standard_Integer n2 = (num > 0)? num : NbEdges();
1479 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1480 TopoDS_Edge E1 = myWire->Edge ( n1 );
1481 TopoDS_Edge E2 = myWire->Edge ( n2 );
1482
1483 ShapeAnalysis_Edge sae;
1484 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1485 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1486 // CKY 4 MAR 1998 : protection against null vertex
1487 if ( V1.IsNull() || V2.IsNull() ) {
1488 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1489 return Standard_False;
1490 }
1491 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1492 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1493 return Standard_False;
1494 }
1495
1496 Standard_Real a, b;
1497 gp_Vec2d v1, v2, v12;
1498 Handle(Geom2d_Curve) c2d;
1499 if ( ! sae.PCurve ( E1, myFace, c2d, a, b, Standard_True ) ) {
1500 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1501 return Standard_False;
1502 }
94f71cad 1503 Geom2dAdaptor_Curve anAdapt(c2d);
1504 anAdapt.D1(b, p2d1, v1);
7fd59977 1505 if ( E1.Orientation() == TopAbs_REVERSED ) v1.Reverse();
1506 if ( ! sae.PCurve ( E2, myFace, c2d, a, b, Standard_True ) ) {
1507 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1508 return Standard_False;
1509 }
94f71cad 1510 anAdapt.Load(c2d);
1511 anAdapt.D1(a, p2d2, v2);
7fd59977 1512 if ( E2.Orientation() == TopAbs_REVERSED ) v2.Reverse();
1513 v12 = p2d2.XY() - p2d1.XY();
1514 myMax2d = v12.SquareMagnitude();
1515
1516 // test like in BRepCheck
1517 Standard_Real tol = Max ( BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ) );
1518 tol = ( Tolerance > gp::Resolution() && Tolerance < tol ? Tolerance : tol );
1519 GeomAdaptor_Surface& Ads = mySurf->Adaptor3d()->ChangeSurface();
1520 Standard_Real tol2d = 2 * Max ( Ads.UResolution(tol), Ads.VResolution(tol) );
1521 if ( // tol2d < gp::Resolution() || //#2 smh 26.03.99 S4163 Zero divide
1522 myMax2d < tol2d * tol2d ) return Standard_False;
1523
1524 myMax2d = Sqrt ( myMax2d );
1525 myMax3d = tol * myMax2d / Max ( tol2d, gp::Resolution() );
1526 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
1527
1528 if ( myMax2d < Precision::PConfusion() || //:abv 03.06.02 CTS21866.stp
c6541a0c
D
1529 ( v1.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v1 ) ) > 0.9 * M_PI ) ||
1530 ( v2.SquareMagnitude() > gp::Resolution() && Abs ( v12.Angle ( v2 ) ) > 0.9 * M_PI ) )
7fd59977 1531 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
1532 return Standard_True;
1533}
1534
1535//=======================================================================
1536//function : CheckLacking
1537//purpose :
1538//
1539//=======================================================================
1540
1541Standard_Boolean ShapeAnalysis_Wire::CheckLacking (const Standard_Integer num,
1542 const Standard_Real Tolerance)
1543{
1544 gp_Pnt2d p1, p2;
1545 return CheckLacking (num, Tolerance, p1, p2);
1546}
1547
1548//=======================================================================
1549//function : CheckOuterBound
1550//purpose :
1551//=======================================================================
1552
1553 Standard_Boolean ShapeAnalysis_Wire::CheckOuterBound(const Standard_Boolean APIMake)
1554{
1555 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1556 if ( ! IsReady() ) return Standard_False;
1557
1558 TopoDS_Wire wire;
1559 if (APIMake) wire = myWire->WireAPIMake();
1560 else wire = myWire->Wire();
1561
1562 TopoDS_Shape sh = myFace.EmptyCopied(); //szv#4:S4163:12Mar99 SGI warns
1563 TopoDS_Face face = TopoDS::Face(sh);
1564 BRep_Builder B;
1565 B.Add (face, wire);
1566 if (ShapeAnalysis::IsOuterBound (face)) return Standard_False;
1567 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1568 return Standard_True;
1569}
1570
1571//=======================================================================
1572//function : CheckNotchedEdges
1573//purpose :
1574//=======================================================================
1575
1576static Standard_Real ProjectInside(const Adaptor3d_CurveOnSurface AD,
1577 const gp_Pnt pnt,
1578 const Standard_Real preci,
1579 gp_Pnt& proj,
1580 Standard_Real& param,
1581 const Standard_Boolean adjustToEnds = Standard_True)
1582{
1583 ShapeAnalysis_Curve sac;
1584 Standard_Real dist = sac.Project(AD,pnt,preci,proj,param,adjustToEnds);
1585 Standard_Real uFirst = AD.FirstParameter();
1586 Standard_Real uLast = AD.LastParameter();
1587 if(param<uFirst) {
1588 param = uFirst;
1589 proj = AD.Value(uFirst);
1590 return proj.Distance(pnt);
1591 }
1592
1593 if(param>uLast) {
1594 param = uLast;
1595 proj = AD.Value(uLast);
1596 return proj.Distance(pnt);
1597 }
1598 return dist;
1599}
1600
1601Standard_Boolean ShapeAnalysis_Wire::CheckNotchedEdges(const Standard_Integer num,
1602 Standard_Integer& shortNum,
1603 Standard_Real& param,
1604 const Standard_Real Tolerance)
1605{
1606 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
1607 if ( ! IsReady() ) return Standard_False;
1608
1609 Standard_Integer n2 = (num > 0)? num : NbEdges();
1610 Standard_Integer n1 = (n2 > 1)? n2-1 : NbEdges();
1611 TopoDS_Edge E1 = myWire->Edge ( n1 );
1612 TopoDS_Edge E2 = myWire->Edge ( n2 );
1613
1614 if(BRep_Tool::Degenerated(E1)||BRep_Tool::Degenerated(E2))
1615 return Standard_False;
1616
1617 ShapeAnalysis_Edge sae;
1618 TopoDS_Vertex V1 = sae.LastVertex ( E1 );
1619 TopoDS_Vertex V2 = sae.FirstVertex ( E2 );
1620
1621 if ( V1.IsNull() || V2.IsNull() ) {
1622 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1623 return Standard_False;
1624 }
1625 if ( ! BRepTools::Compare ( V1, V2 ) ) {
1626 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1627 return Standard_False;
1628 }
1629
1630 Standard_Real a1, b1, a2, b2;
1631 gp_Pnt2d p2d1, p2d2;
1632 gp_Vec2d v1, v2;
1633 Handle(Geom2d_Curve) c2d1, c2d2;
1634 if ( ! sae.PCurve ( E1, myFace, c2d1, a1, b1, Standard_False ) ) {
1635 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1636 return Standard_False;
1637 }
1638
1639 if(E1.Orientation()==TopAbs_REVERSED)
1640 c2d1->D1 ( a1, p2d1, v1 );
1641 else {
1642 c2d1->D1 ( b1, p2d1, v1 );
1643 v1.Reverse();
1644 }
1645
1646 if ( ! sae.PCurve ( E2, myFace, c2d2, a2, b2, Standard_False ) ) {
1647 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
1648 return Standard_False;
1649 }
1650 if(E2.Orientation()==TopAbs_REVERSED) {
1651 c2d2->D1 ( b2, p2d2, v2 );
1652 v2.Reverse();
1653 }
1654 else
1655 c2d2->D1 ( a2, p2d2, v2 );
1656
1657 if ( v2.Magnitude() < gp::Resolution() || v1.Magnitude() < gp::Resolution())
1658 return Standard_False;
1659
1660 if ( Abs ( v2.Angle ( v1 ) ) > 0.1 || p2d1.Distance(p2d2) > Tolerance)
1661 return Standard_False;
1662
1663 Handle(Geom2dAdaptor_HCurve) AC2d1 = new Geom2dAdaptor_HCurve(c2d1,a1,b1);
1664 Handle(GeomAdaptor_HSurface) AdS1 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1665 Adaptor3d_CurveOnSurface Ad1(AC2d1,AdS1);
1666
1667 Handle(Geom2dAdaptor_HCurve) AC2d2 = new Geom2dAdaptor_HCurve(c2d2,a2,b2);
1668 Handle(GeomAdaptor_HSurface) AdS2 = new GeomAdaptor_HSurface(new Geom_Plane(gp_Pln()));
1669 Adaptor3d_CurveOnSurface Ad2(AC2d2,AdS2);
1670
1671 Adaptor3d_CurveOnSurface longAD, shortAD;
1672 Standard_Real lenP, firstP;
1673
1674 ShapeAnalysis_Curve sac;
1675
1676 gp_Pnt Proj1, Proj2;
bbf32d01 1677 Standard_Real param1 = 0., param2 = 0.;
7fd59977 1678 p2d2=c2d2->Value(E2.Orientation()==TopAbs_FORWARD ? b2 : a2);
1679 p2d1=c2d1->Value(E1.Orientation()==TopAbs_FORWARD ? a1 : b1);
1680 Standard_Real dist1 = ProjectInside(Ad1,gp_Pnt(p2d2.X(),p2d2.Y(),0),Tolerance,Proj1,param1,Standard_False);
1681 Standard_Real dist2 = ProjectInside(Ad2,gp_Pnt(p2d1.X(),p2d1.Y(),0),Tolerance,Proj2,param2,Standard_False);
1682
1683 if ( dist1 > Tolerance && dist2 > Tolerance)
1684 return Standard_False;
1685
1686 if (dist1 < dist2 ) {
1687 shortAD = Ad2;
1688 longAD = Ad1;
1689 lenP = b2 - a2;
1690 firstP = a2;
1691 shortNum=n2;
1692 param=param1;
1693
1694 }
1695 else {
1696 shortAD = Ad1;
1697 longAD = Ad2;
1698 lenP = b1 - a1;
1699 firstP = a1;
1700 shortNum=n1;
1701 param=param2;
1702 }
1703
1704 Standard_Real step = lenP/23;
1705 for (Standard_Integer i = 1; i < 23; i++,firstP+=step) {
1706 Standard_Real d1 = sac.Project(longAD,shortAD.Value(firstP),Tolerance,Proj1,param1);
1707 if (d1 > Tolerance) {
1708 return Standard_False;
1709 }
1710 }
1711
1712 return Standard_True;
1713}
1714
1715//=======================================================================
1716//function : CheckSmallArea
1717//purpose :
1718//=======================================================================
8b1e055f 1719Standard_Boolean ShapeAnalysis_Wire::CheckSmallArea(const TopoDS_Wire& theWire)
7fd59977 1720{
1721 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
56a9db93 1722 const Standard_Integer aNbControl = 23;
1723 const Standard_Integer NbEdges = myWire->NbEdges();
1724 if ( !IsReady() || NbEdges < 1 )
1725 return Standard_False;
7fd59977 1726 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
56a9db93 1727
1728 Standard_Real aF, aL, aLength(0.0);
1729 const Standard_Real anInv = 1.0 / static_cast<Standard_Real>(aNbControl - 1);
1730 gp_XY aCenter2d(0., 0.);
1731
1732 // try to find mid point for closed contour
1733 Handle(Geom2d_Curve) aCurve2d;
1734 for (Standard_Integer j = 1; j <= NbEdges; ++j)
1735 {
1736 const ShapeAnalysis_Edge anAnalyzer;
1737 if (!anAnalyzer.PCurve(myWire->Edge(j),myFace,aCurve2d,aF,aL))
1738 {
7fd59977 1739 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1740 return Standard_False;
1741 }
56a9db93 1742
1743 for (Standard_Integer i = 1; i < aNbControl; ++i)
1744 {
1745 const Standard_Real aV = anInv * ((aNbControl - 1 - i) * aF+ i * aL);
1746 aCenter2d += aCurve2d->Value(aV).XY();
1747 }
1748 }
1749 aCenter2d *= 1.0 / static_cast<Standard_Real>(NbEdges * (aNbControl - 1));
1750
1751 // check approximated area in 3D
1752 gp_Pnt aPnt3d;
1753 gp_XYZ aPrev3d, aCross(0., 0., 0.);
1754 gp_XYZ aCenter(mySurf->Value(aCenter2d.X(), aCenter2d.Y()).XYZ());
1755
1756 Handle(Geom_Curve) aCurve3d;
1757 for (Standard_Integer j = 1; j <= NbEdges; ++j)
1758 {
1759 const ShapeAnalysis_Edge anAnalizer;
1760 if (!anAnalizer.Curve3d(myWire->Edge(j), aCurve3d, aF, aL))
1761 {
1762 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1763 return Standard_False;
7fd59977 1764 }
f4dee9bb 1765 if (Precision::IsInfinite(aF) || Precision::IsInfinite(aL))
1766 {
1767 continue;
1768 }
56a9db93 1769
1770 Standard_Integer aBegin = 0;
1771 if (j == 1)
1772 {
1773 aBegin = 1;
1774 aPnt3d = aCurve3d->Value(aF);
1775 aPrev3d = aPnt3d.XYZ() - aCenter;
1776 }
1777 for (Standard_Integer i = aBegin; i < aNbControl; ++i)
1778 {
1779 const Standard_Real anU =
1780 anInv * ( (aNbControl - 1 - i) * aF + i * aL );
1781 const gp_Pnt aPnt = aCurve3d->Value(anU);
1782 const gp_XYZ& aCurrent = aPnt.XYZ();
1783 const gp_XYZ aVec = aCurrent - aCenter;
1784
1785 aCross += aPrev3d ^ aVec;
1786 aLength += aPnt3d.Distance(aPnt);
1787
1788 aPnt3d = aPnt;
1789 aPrev3d = aVec;
7fd59977 1790 }
1791 }
56a9db93 1792
1793 Standard_Real aTolerance = aLength * myPrecision;
1794 if ( aCross.Modulus() < aTolerance )
1795 {
1796 // check real area in 3D
1797 GProp_GProps aProps;
1798 GProp_GProps aLProps;
8b1e055f 1799 TopoDS_Face aFace = TopoDS::Face(myFace.EmptyCopied());
1800 BRep_Builder().Add(aFace, theWire);
1801 BRepGProp::SurfaceProperties(aFace, aProps);
1802 BRepGProp::LinearProperties(aFace, aLProps);
56a9db93 1803
1804 Standard_Real aNewTolerance = aLProps.Mass() * myPrecision;
8b1e055f 1805 if ( Abs(aProps.Mass()) < 0.5 * aNewTolerance )
56a9db93 1806 {
1807 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1808 return Standard_True;
1809 }
7fd59977 1810 }
56a9db93 1811
7fd59977 1812 return Standard_False;
1813}
1814
1815//=======================================================================
1816//function : CheckShapeConnect
1817//purpose :
1818//=======================================================================
1819
1820 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(const TopoDS_Shape& shape,const Standard_Real prec)
1821{
1822 Standard_Real tailhead, tailtail, headhead, headtail;
1823 return CheckShapeConnect (tailhead, tailtail, headtail, headhead, shape, prec);
1824}
1825
1826//=======================================================================
1827//function : CheckShapeConnect
1828//purpose :
1829//=======================================================================
1830
1831 Standard_Boolean ShapeAnalysis_Wire::CheckShapeConnect(Standard_Real& tailhead, Standard_Real& tailtail,
1832 Standard_Real& headtail, Standard_Real& headhead,
1833 const TopoDS_Shape& shape, const Standard_Real prec)
1834{
1835 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
1836 if (!IsLoaded () || shape.IsNull()) return Standard_False;
1837 TopoDS_Vertex V1,V2;
1838 TopoDS_Edge E; TopoDS_Wire W;
1839 ShapeAnalysis_Edge SAE;
1840 if (shape.ShapeType() == TopAbs_EDGE) {
1841 E = TopoDS::Edge (shape);
1842 V1 = SAE.FirstVertex (E); V2 = SAE.LastVertex (E);
1843 } else if (shape.ShapeType() == TopAbs_WIRE) {
1844 W = TopoDS::Wire (shape);
1845 ShapeAnalysis::FindBounds (W,V1,V2);
1846 }
1847 else return Standard_False;
1848 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1849// on va comparer les points avec ceux de thevfirst et thevlast
1850 gp_Pnt p1 = BRep_Tool::Pnt(V1);
1851 gp_Pnt p2 = BRep_Tool::Pnt(V2);
1852
1853 TopoDS_Vertex vfirst = SAE.FirstVertex (myWire->Edge (1)),
1854 vlast = SAE.LastVertex (myWire->Edge (NbEdges()));
1855 gp_Pnt pf = BRep_Tool::Pnt(vfirst);
1856 gp_Pnt pl = BRep_Tool::Pnt(vlast);
1857
1858 tailhead = p1.Distance(pl);
1859 tailtail = p2.Distance(pl);
1860 headhead = p1.Distance(pf);
1861 headtail = p2.Distance(pf);
1862 Standard_Real dm1 = tailhead, dm2 = headtail;
1863 Standard_Integer res1 = 0, res2 = 0;
1864
1865 if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
1866 if (headtail > headhead) {res2 = 1; dm2 = headhead;}
1867 Standard_Integer result = res1;
1868 myMin3d = Min (dm1, dm2);
1869 myMax3d = Max (dm1, dm2);
1870 if (dm1 > dm2) {dm1 = dm2; result = res2 + 2;}
1871 switch (result) {
1872 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
1873 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
1874 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
1875 }
1876 if (!res1) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE5);
1877 if (!res2) myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE6);
1878
1879 if (myMin3d > Max (myPrecision, prec))
1880 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1881 return LastCheckStatus (ShapeExtend_DONE);
1882}
1883
1884//=======================================================================
1885//function : CheckLoop
1886//purpose :
1887//=======================================================================
1888Standard_Boolean isMultiVertex(const TopTools_ListOfShape& alshape,
1889 const TopTools_MapOfShape& aMapSmallEdges,
1890 const TopTools_MapOfShape& aMapSeemEdges)
1891{
1892 TopTools_ListIteratorOfListOfShape lIt1(alshape);
1893 Standard_Integer nbNotAccount =0;
1894
1895 for( ; lIt1.More() ; lIt1.Next())
1896 {
1897 if(aMapSmallEdges.Contains(lIt1.Value()))
1898 nbNotAccount++;
1899 else if(aMapSeemEdges.Contains(lIt1.Value()))
1900 nbNotAccount++;
1901 }
1902 return ((alshape.Extent() -nbNotAccount) >2);
1903}
1904 Standard_Boolean ShapeAnalysis_Wire::CheckLoop(TopTools_IndexedMapOfShape& aMapLoopVertices,
1905 TopTools_DataMapOfShapeListOfShape& aMapVertexEdges,
1906 TopTools_MapOfShape& aMapSmallEdges,
1907 TopTools_MapOfShape& aMapSeemEdges)
1908{
1909 myStatus = ShapeExtend::EncodeStatus(ShapeExtend_OK);
1910 if (!IsLoaded() || NbEdges() < 2) return Standard_False;
1911 Standard_Real aSavPreci = Precision();
1912 SetPrecision(Precision::Infinite());
1913 Standard_Integer i =1;
1914
1915 for( ; i <= myWire->NbEdges(); i++) {
1916 TopoDS_Edge aedge = myWire->Edge(i);
1917 TopoDS_Vertex aV1,aV2;
1918 TopExp::Vertices(aedge,aV1,aV2);
29582444 1919 if (aV1.IsNull() || aV2.IsNull())
1920 {
1921 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
1922 return Standard_False;
1923 }
7fd59977 1924 Standard_Boolean isSame = aV1.IsSame(aV2);
1925 if(myWire->IsSeam(i))
1926 aMapSeemEdges.Add(aedge); ///continue;
1927 else if(BRep_Tool::Degenerated(aedge))
1928 aMapSmallEdges.Add(aedge);
1929 else if(isSame && CheckSmall(i,BRep_Tool::Tolerance(aV1)))
1930 aMapSmallEdges.Add(aedge);
1931
1932 if(!aMapVertexEdges.IsBound(aV1)) {
1933 TopTools_ListOfShape alshape;
1934 aMapVertexEdges.Bind(aV1,alshape);
1935 }
1936 if(!aMapVertexEdges.IsBound(aV2)) {
1937 TopTools_ListOfShape alshape;
1938 aMapVertexEdges.Bind(aV2,alshape);
1939 }
1940 if(isSame)
1941 {
1942 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1943 alshape.Append(aedge);
1944 alshape.Append(aedge);
1945 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1946 aMapLoopVertices.Add(aV1);
1947 }
1948 else {
1949 TopTools_ListOfShape& alshape = aMapVertexEdges.ChangeFind(aV1);
1950 alshape.Append(aedge);
1951 if(alshape.Extent() >2 && isMultiVertex( alshape,aMapSmallEdges,aMapSeemEdges))
1952 aMapLoopVertices.Add(aV1);
1953 TopTools_ListOfShape& alshape2 = aMapVertexEdges.ChangeFind(aV2);
1954 alshape2.Append(aedge);
1955 if(alshape2.Extent() >2 && isMultiVertex( alshape2,aMapSmallEdges,aMapSeemEdges))
1956 aMapLoopVertices.Add(aV2);
1957 }
1958 }
1959 SetPrecision(aSavPreci);
1960 if(aMapLoopVertices.Extent())
1961 {
1962 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
1963 myStatusLoop |= myStatus;
1964 return Standard_True;
1965 }
1966 return Standard_False;
1967}
fbf3becf 1968
1969//=======================================================================
1970//function : Project
1971//purpose :
1972//=======================================================================
1973static Standard_Real Project(
1974 const Handle(Geom_Curve)& theCurve,
1975 const Standard_Real theFirstParameter,
1976 const Standard_Real theLastParameter,
1977 const gp_Pnt& thePoint,
1978 const Standard_Real thePrecision,
1979 Standard_Real& theParameter,
1980 gp_Pnt& theProjection)
1981{
1982 const Standard_Real aDist = ShapeAnalysis_Curve().Project(theCurve, thePoint,
1983 thePrecision, theProjection, theParameter, theFirstParameter,
1984 theLastParameter);
1985 if (theParameter >= theFirstParameter && theParameter <= theLastParameter)
1986 {
1987 return aDist;
1988 }
1989
1990 const Standard_Real aParams[] = {theFirstParameter, theLastParameter};
1991 const gp_Pnt aPrjs[] =
1992 {theCurve->Value(aParams[0]), theCurve->Value(aParams[1])};
1993 const Standard_Real aDists[] =
1994 {thePoint.Distance(aPrjs[0]), thePoint.Distance(aPrjs[1])};
1995 const Standard_Integer aPI = (aDists[0] <= aDists[1]) ? 0 : 1;
1996 theParameter = aParams[aPI];
1997 theProjection = aPrjs[aPI];
1998 return aDists[aPI];
1999}
2000
2001//=======================================================================
2002//function : CheckTail
2003//purpose :
2004//=======================================================================
2005Standard_Boolean ShapeAnalysis_Wire::CheckTail(
2006 const TopoDS_Edge& theEdge1,
2007 const TopoDS_Edge& theEdge2,
2008 const Standard_Real theMaxSine,
2009 const Standard_Real theMaxWidth,
2010 const Standard_Real theMaxTolerance,
2011 TopoDS_Edge& theEdge11,
2012 TopoDS_Edge& theEdge12,
2013 TopoDS_Edge& theEdge21,
2014 TopoDS_Edge& theEdge22)
2015{
2016 const TopoDS_Edge aEs[] = {theEdge1, theEdge2};
2017 if (!IsReady() || BRep_Tool::Degenerated(aEs[0]) ||
2018 BRep_Tool::Degenerated(aEs[1]))
2019 {
2020 return Standard_False;
2021 }
2022
2023 // Check the distance between the edge common ends.
2024 const Standard_Real aTol2 = theMaxWidth + 0.5 * Precision::Confusion();
2025 const Standard_Real aTol3 = theMaxWidth + Precision::Confusion();
2026 const Standard_Real aTol4 = theMaxWidth + 1.5 * Precision::Confusion();
2027 const Standard_Real aSqTol2 = aTol2 * aTol2;
2028 const Standard_Real aSqTol3 = aTol3 * aTol3;
2029 Handle(Geom_Curve) aCs[2];
2030 Standard_Real aLs[2][2];
2031 Standard_Integer aVIs[2];
2032 gp_Pnt aVPs[2];
2033 {
2034 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2035 {
2036 if (!ShapeAnalysis_Edge().Curve3d(
2037 aEs[aEI], aCs[aEI], aLs[aEI][0], aLs[aEI][1], Standard_False))
2038 {
2039 return Standard_False;
2040 }
2041
2042 aVIs[aEI] = (aEs[aEI].Orientation() == TopAbs_REVERSED) ? aEI : 1 - aEI;
2043 aVPs[aEI] = aCs[aEI]->Value(aLs[aEI][aVIs[aEI]]);
2044 }
2045 if (aVPs[0].SquareDistance(aVPs[1]) > aSqTol2)
2046 {
2047 return Standard_False;
2048 }
2049 }
2050
2051 // Check the angle between the edges.
2052 if (theMaxSine >= 0)
2053 {
2054 const Standard_Real aSqMaxSine = theMaxSine * theMaxSine;
2055 gp_XYZ aDs[2];
2056 Standard_Integer aReverse = 0;
2057 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2058 {
2059 GeomAdaptor_Curve aCA(aCs[aEI]);
2060 if (GCPnts_AbscissaPoint::Length(aCA, aLs[aEI][0], aLs[aEI][1],
2061 0.25 * Precision::Confusion()) < 0.5 * Precision::Confusion())
2062 {
2063 return Standard_False;
2064 }
2065
2066 GCPnts_AbscissaPoint aAP(0.25 * Precision::Confusion(), aCA,
2067 0.5 * Precision::Confusion() * (1 - 2 * aVIs[aEI]),
2068 aLs[aEI][aVIs[aEI]]);
2069 if (!aAP.IsDone())
2070 {
2071 return Standard_False;
2072 }
2073
2074 gp_XYZ aPs[2];
2075 aPs[aVIs[aEI]] = aVPs[aEI].XYZ();
2076 aPs[1 - aVIs[aEI]] = aCs[aEI]->Value(aAP.Parameter()).XYZ();
2077 aDs[aEI] = aPs[1] - aPs[0];
2078 const Standard_Real aDN = aDs[aEI].Modulus();
2079 if (aDN < 0.1 * Precision::Confusion())
2080 {
2081 return Standard_False;
2082 }
2083
2084 aDs[aEI] *= 1 / aDN;
2085 aReverse ^= aVIs[aEI];
2086 }
2087 if (aReverse)
2088 {
2089 aDs[0].Reverse();
2090 }
2091 if (aDs[0] * aDs[1] < 0 || aDs[0].CrossSquareMagnitude(aDs[1]) > aSqMaxSine)
2092 {
2093 return Standard_False;
2094 }
2095 }
2096
2097 // Calculate the tail bounds.
2098 gp_Pnt aPs[2], aPrjs[2];
2099 Standard_Real aParams1[2], aParams2[2];
2100 Standard_Real aDists[2];
2101 Standard_Boolean isWholes[] = {Standard_True, Standard_True};
2102 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2103 {
2104 Standard_Real aParam1 = aLs[aEI][aVIs[aEI]];
2105 aParams1[aEI] = aLs[aEI][1 - aVIs[aEI]];
2106 aCs[aEI]->D0(aParams1[aEI], aPs[aEI]);
2107 aDists[aEI] = Project(aCs[1 - aEI], aLs[1 - aEI][0], aLs[1 - aEI][1],
2108 aPs[aEI], 0.25 * Precision::Confusion(), aParams2[aEI], aPrjs[aEI]);
2109 if (aDists[aEI] <= aTol2)
2110 {
2111 continue;
2112 }
2113
2114 isWholes[aEI] = Standard_False;
2115 for (;;)
2116 {
2117 const Standard_Real aParam = (aParam1 + aParams1[aEI]) * 0.5;
2118 aCs[aEI]->D0(aParam, aPs[aEI]);
2119 const Standard_Real aDist = Project(aCs[1 - aEI], aLs[1 - aEI][0],
2120 aLs[1 - aEI][1], aPs[aEI], 0.25 * Precision::Confusion(), aParams2[aEI],
2121 aPrjs[aEI]);
2122 if (aDist <= aTol2)
2123 {
2124 aParam1 = aParam;
2125 }
2126 else
2127 {
2128 aParams1[aEI] = aParam;
2129 if (aDist <= aTol3)
2130 {
2131 break;
2132 }
2133 }
2134 }
2135 }
2136
2137 // Check the tail bounds.
2138 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2139 {
2140 const Standard_Real aParam1 = aLs[aEI][aVIs[aEI]];
2141 const Standard_Real aParam2 = aParams1[aEI];
2142 const Standard_Real aStepL = (aParam2 - aParam1) / 23;
2143 for (Standard_Integer aStepN = 1; aStepN < 23; ++aStepN)
2144 {
2145 Standard_Real aParam = aParam1 + aStepN * aStepL;
2146 gp_Pnt aP = aCs[aEI]->Value(aParam), aPrj;
2147 if (Project(aCs[1 - aEI], aLs[1 - aEI][0], aLs[1 - aEI][1], aP,
2148 0.25 * Precision::Confusion(), aParam, aPrj) > aTol4)
2149 {
2150 return Standard_False;
2151 }
2152 }
2153 }
2154
2155 // Check whether both edges must be removed.
2156 if (isWholes[0] && isWholes[1] && aPs[0].SquareDistance(aPs[1]) <= aSqTol3)
2157 {
2158 theEdge11 = theEdge1;
2159 theEdge21 = theEdge2;
2160 return Standard_True;
2161 }
2162
2163 // Cut and remove the edges.
2164 Standard_Integer aFI = 0;
2165 if (isWholes[0] || isWholes[1])
2166 {
2167 // Determine an edge to remove and the other one to cut.
2168 aFI = isWholes[0] ? 0 : 1;
2169 if (aDists[1 - aFI] < aDists[aFI] && isWholes[1 - aFI])
2170 {
2171 aFI = 1 - aFI;
2172 }
2173 }
2174 Standard_Real aParams[2];
2175 aParams[aFI] = aParams1[aFI];
2176 aParams[1 - aFI] = aParams2[aFI];
2177
2178 // Correct the cut for the parametrization tolerance.
2179 TopoDS_Edge* aEParts[][2] =
2180 {{&theEdge11, &theEdge12}, {&theEdge21, &theEdge22}};
2181 Standard_Integer aResults[] = {1, 1};
2182 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2183 {
2184 if (Abs(aParams[aEI] - aLs[aEI][1 - aVIs[aEI]]) <= Precision::PConfusion())
2185 {
2186 aResults[aEI] = 2;
2187 *aEParts[aEI][0] = aEs[aEI];
2188 }
2189 else if (Abs(aParams[aEI] - aLs[aEI][aVIs[aEI]]) <= Precision::PConfusion())
2190 {
2191 aResults[aEI] = 0;
2192 }
2193 }
2194
2195 // Correct the cut for the distance tolerance.
2196 for (Standard_Integer aEI = 0; aEI < 2; ++aEI)
2197 {
2198 if (aResults[aEI] != 1)
2199 {
2200 continue;
2201 }
2202
2203 // Create the parts of the edge.
2204 TopoDS_Edge aFE = TopoDS::Edge(aEs[aEI].Oriented(TopAbs_FORWARD));
2205 ShapeAnalysis_TransferParametersProj aSATPP(aFE, TopoDS_Face());
2206 aSATPP.SetMaxTolerance(theMaxTolerance);
2207 TopoDS_Vertex aSplitV;
2208 BRep_Builder().MakeVertex(
2209 aSplitV, aCs[aEI]->Value(aParams[aEI]), Precision::Confusion());
2210 TopoDS_Edge aEParts2[] = {
2211 ShapeBuild_Edge().CopyReplaceVertices(aFE, TopoDS_Vertex(),
2212 TopoDS::Vertex(aSplitV.Oriented(TopAbs_REVERSED))),
2213 ShapeBuild_Edge().CopyReplaceVertices(aFE, aSplitV, TopoDS_Vertex())};
2214 ShapeBuild_Edge().CopyPCurves(aEParts2[0], aFE);
2215 ShapeBuild_Edge().CopyPCurves(aEParts2[1], aFE);
2216 BRep_Builder().SameRange(aEParts2[0], Standard_False);
2217 BRep_Builder().SameRange(aEParts2[1], Standard_False);
2218 BRep_Builder().SameParameter(aEParts2[0], Standard_False);
2219 BRep_Builder().SameParameter(aEParts2[1], Standard_False);
2220 aSATPP.TransferRange(
2221 aEParts2[0], aLs[aEI][0], aParams[aEI], Standard_False);
2222 aSATPP.TransferRange(
2223 aEParts2[1], aParams[aEI], aLs[aEI][1], Standard_False);
2224 GProp_GProps aLinProps;
2225 BRepGProp::LinearProperties(aEParts2[1 - aVIs[aEI]], aLinProps);
2226 if (aLinProps.Mass() <= Precision::Confusion())
2227 {
2228 aResults[aEI] = 2;
2229 *aEParts[aEI][0] = aEs[aEI];
2230 }
2231 else
2232 {
2233 BRepGProp::LinearProperties(aEParts2[aVIs[aEI]], aLinProps);
2234 if (aLinProps.Mass() <= Precision::Confusion())
2235 {
2236 aResults[aEI] = 0;
2237 }
2238 else
2239 {
2240 *aEParts[aEI][0] = aEParts2[0];
2241 *aEParts[aEI][1] = aEParts2[1];
2242 }
2243 }
2244 }
2245
2246 return aResults[0] + aResults[1] != 0;
2247}