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