1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:o8 abv 19.02.99: CTS18541.stp #18559: coeff 1.0001 added in CheckVertexTol
15 //:p1 abv 22.02.99: protection against edges with no vertices (infinite)
17 //:s1 abv 22.04.99: PRO7226 #489490: protect against Null 3d curve
18 //:s4 abv 26.04.99: sim6049.igs 21677: copy of curve is necessary to get True SP
19 // abv 06.05.99: S4137: adding methods GetTangent2d()
20 #include <ShapeAnalysis_Edge.ixx>
22 #include <Standard_ErrorHandler.hxx>
23 #include <Standard_Failure.hxx>
25 #include <Precision.hxx>
27 #include <GCPnts_AbscissaPoint.hxx>
28 #include <Adaptor3d_Curve.hxx>
29 #include <Adaptor3d_CurveOnSurface.hxx>
30 #include <Geom2dAdaptor_HCurve.hxx>
31 #include <GeomAdaptor_Curve.hxx>
32 #include <GeomAdaptor_HSurface.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <BRepExtrema_DistShapeShape.hxx>
36 #include <BRep_Tool.hxx>
37 #include <BRep_TEdge.hxx>
38 #include <BRep_GCurve.hxx>
39 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
40 #include <BRep_Builder.hxx>
42 #include <Extrema_LocateExtPC.hxx>
44 #include <ShapeExtend.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <Geom_Plane.hxx>
50 //=======================================================================
51 //function : ShapeAnalysis_Edge
53 //=======================================================================
55 ShapeAnalysis_Edge::ShapeAnalysis_Edge()
57 myStatus = 0;//ShapeExtend::EncodeStatus (ShapeExtend_OK);
61 //=======================================================================
64 //=======================================================================
66 Standard_Boolean ShapeAnalysis_Edge::BoundUV (const TopoDS_Edge& edge,
67 const TopoDS_Face& face,
68 gp_Pnt2d& first, gp_Pnt2d& last) const
71 const Handle(Geom_Surface) S = BRep_Tool::Surface(face, L);
72 return BoundUV (edge, S, L, first, last);
76 //=======================================================================
79 //=======================================================================
81 Standard_Boolean ShapeAnalysis_Edge::BoundUV (const TopoDS_Edge& edge,
82 const Handle(Geom_Surface)& surface,
83 const TopLoc_Location& location,
84 gp_Pnt2d& first, gp_Pnt2d& last) const
86 Handle(Geom2d_Curve) c2d;
88 if (!PCurve (edge, surface, location, c2d, uf, ul)) return Standard_False;
89 first = c2d->Value (uf);
90 last = c2d->Value (ul);
95 //=======================================================================
96 //function : HasCurve3d
98 //=======================================================================
100 Standard_Boolean ShapeAnalysis_Edge::HasCurve3d (const TopoDS_Edge& edge) const
102 Standard_Real cf, cl;
103 Handle(Geom_Curve) c3d = BRep_Tool::Curve (edge, cf, cl);
104 return !c3d.IsNull();
108 //=======================================================================
111 //=======================================================================
113 Standard_Boolean ShapeAnalysis_Edge::Curve3d (const TopoDS_Edge& edge,
114 Handle(Geom_Curve)& C3d,
115 Standard_Real& cf, Standard_Real& cl,
116 const Standard_Boolean orient) const
119 C3d = BRep_Tool::Curve (edge, L, cf, cl);
120 if( !C3d.IsNull() && !L.IsIdentity() ) {
121 C3d = Handle(Geom_Curve)::DownCast(C3d->Transformed(L.Transformation()));
122 cf = C3d->TransformedParameter(cf, L.Transformation());
123 cl = C3d->TransformedParameter(cl, L.Transformation());
126 if (edge.Orientation() == TopAbs_REVERSED)
127 {Standard_Real tmp = cf; cf = cl; cl = tmp;}
129 return !C3d.IsNull();
133 //=======================================================================
134 //function : IsClosed3d
136 //=======================================================================
138 Standard_Boolean ShapeAnalysis_Edge::IsClosed3d (const TopoDS_Edge& edge) const
141 Handle(Geom_Curve) c3d = BRep_Tool::Curve (edge,cf,cl);
142 if (c3d.IsNull()) return Standard_False;
143 if (!c3d->IsClosed()) return Standard_False;
144 return FirstVertex (edge).IsSame (LastVertex (edge));
148 //=======================================================================
149 //function : HasPCurve
151 //=======================================================================
153 Standard_Boolean ShapeAnalysis_Edge::HasPCurve (const TopoDS_Edge& edge,
154 const TopoDS_Face& face) const
157 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
158 return HasPCurve (edge, S, L);
162 //=======================================================================
163 //function : HasPCurve
165 //=======================================================================
167 Standard_Boolean ShapeAnalysis_Edge::HasPCurve (const TopoDS_Edge& edge,
168 const Handle(Geom_Surface)& surface,
169 const TopLoc_Location& location) const
171 //try { //szv#4:S4163:12Mar99 waste try
172 Standard_Real cf, cl;
173 Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface (edge, surface, location, cf, cl);
174 return !c2d.IsNull();
176 catch (Standard_Failure) {
178 return Standard_False; */
182 //=======================================================================
185 //=======================================================================
187 Standard_Boolean ShapeAnalysis_Edge::PCurve (const TopoDS_Edge& edge,
188 const TopoDS_Face& face,
189 Handle(Geom2d_Curve)& C2d,
190 Standard_Real& cf, Standard_Real& cl,
191 const Standard_Boolean orient) const
193 //:abv 20.05.02: take into account face orientation
194 // COMMENTED BACK - NEEDS MORE CHANGES IN ALL SHAPEHEALING
195 // C2d = BRep_Tool::CurveOnSurface (edge, face, cf, cl);
196 // if (orient && edge.Orientation() == TopAbs_REVERSED) {
197 // Standard_Real tmp = cf; cf = cl; cl = tmp;
199 // return !C2d.IsNull();
201 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
202 return PCurve (edge, S, L, C2d, cf, cl, orient);
206 //=======================================================================
209 //=======================================================================
211 Standard_Boolean ShapeAnalysis_Edge::PCurve (const TopoDS_Edge& edge,
212 const Handle(Geom_Surface)& surface,
213 const TopLoc_Location& location,
214 Handle(Geom2d_Curve)& C2d,
215 Standard_Real& cf, Standard_Real& cl,
216 const Standard_Boolean orient) const
218 C2d = BRep_Tool::CurveOnSurface (edge, surface, location, cf, cl);
219 if ( orient && edge.Orientation() == TopAbs_REVERSED ) {
220 Standard_Real tmp = cf; cf = cl; cl = tmp;
222 return !C2d.IsNull();
226 //=======================================================================
229 //=======================================================================
231 Standard_Boolean ShapeAnalysis_Edge::IsSeam (const TopoDS_Edge& edge,
232 const TopoDS_Face& face) const
234 return BRep_Tool::IsClosed (edge, face);
238 //=======================================================================
241 //=======================================================================
243 Standard_Boolean ShapeAnalysis_Edge::IsSeam (const TopoDS_Edge& edge,
244 const Handle(Geom_Surface)& surface,
245 const TopLoc_Location& location) const
247 return BRep_Tool::IsClosed (edge, surface, location);
251 //=======================================================================
252 //function : FirstVertex
254 //=======================================================================
256 TopoDS_Vertex ShapeAnalysis_Edge::FirstVertex (const TopoDS_Edge& edge) const
259 if (edge.Orientation() == TopAbs_REVERSED) {
260 V = TopExp::LastVertex(edge);
264 V = TopExp::FirstVertex (edge);
270 //=======================================================================
271 //function : LastVertex
273 //=======================================================================
275 TopoDS_Vertex ShapeAnalysis_Edge::LastVertex (const TopoDS_Edge& edge) const
278 if (edge.Orientation() == TopAbs_REVERSED) {
279 V = TopExp::FirstVertex(edge);
283 V = TopExp::LastVertex (edge);
289 //=======================================================================
292 //=======================================================================
294 Standard_Boolean ShapeAnalysis_Edge::Status (const ShapeExtend_Status Status) const
296 return ShapeExtend::DecodeStatus (myStatus, Status);
300 //=======================================================================
301 //function : GetEndTangent2d
303 //=======================================================================
305 Standard_Boolean ShapeAnalysis_Edge::GetEndTangent2d (const TopoDS_Edge &edge,
306 const TopoDS_Face &face,
307 const Standard_Boolean atend1, /* skl : change "atend" to "atend1" */
310 const Standard_Real dparam) const
313 const Handle(Geom_Surface) S = BRep_Tool::Surface ( face, L );
314 return GetEndTangent2d ( edge, S, L, atend1, pnt, v, dparam );
318 //=======================================================================
319 //function : GetEndTangent2d
321 //=======================================================================
323 Standard_Boolean ShapeAnalysis_Edge::GetEndTangent2d (const TopoDS_Edge &edge,
324 const Handle(Geom_Surface)& S,
325 const TopLoc_Location& L,
326 const Standard_Boolean atend2, /* skl : change "atend" to "atend2" */
329 const Standard_Real dparam) const
331 Standard_Real cf, cl;
332 Handle(Geom2d_Curve) c2d;
333 if ( ! PCurve ( edge, S, L, c2d, cf, cl ) ) {
335 return Standard_False;
337 Standard_Real dpnew = dparam;
339 if(dpnew>Precision::Confusion()) {
341 Standard_Real par1,par2,delta=(cl-cf)*dpnew;
342 if(Abs(delta)<Precision::PConfusion()) {
351 v = pnt.XY() - ptmp.XY();
358 v = ptmp.XY() - pnt.XY();
360 if( v.SquareMagnitude() < Precision::PConfusion()*Precision::PConfusion() ) {
366 if(dpnew<=Precision::Confusion()) {
367 // get non-null tangency searching until 3rd derivative, or as straight btw ends
368 Standard_Real par = ( atend2 ? cl : cf );
369 c2d->D1 ( par, pnt, v );
370 if ( v.SquareMagnitude() < Precision::PConfusion()*Precision::PConfusion() ) {
372 c2d->D2 ( par, pnt, d1, v );
373 if ( v.SquareMagnitude() < Precision::PConfusion()*Precision::PConfusion() ) {
375 c2d->D3 ( par, pnt, d1, d2, v );
376 if ( v.SquareMagnitude() < Precision::PConfusion()*Precision::PConfusion() ) {
378 c2d->D0 ( ( atend2 ? cf : cl ), p2 );
379 v = p2.XY() - pnt.XY();
380 if ( v.SquareMagnitude() < Precision::PConfusion()*Precision::PConfusion() )
381 return Standard_False;
385 if ( edge.Orientation() == TopAbs_REVERSED ) v.Reverse();
388 //if ( edge.Orientation() == TopAbs_REVERSED ) v.Reverse();
389 return Standard_True;
393 //=======================================================================
394 //function : CheckCurve3dWithPCurve
396 //=======================================================================
398 Standard_Boolean ShapeAnalysis_Edge::CheckCurve3dWithPCurve (const TopoDS_Edge& edge,
399 const TopoDS_Face& face)
402 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
403 return CheckCurve3dWithPCurve (edge, S, L);
407 //=======================================================================
408 //function : CheckCurve3dWithPCurve
410 //=======================================================================
412 Standard_Boolean ShapeAnalysis_Edge::CheckCurve3dWithPCurve (const TopoDS_Edge& edge,
413 const Handle(Geom_Surface)& surface,
414 const TopLoc_Location& location)
416 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
418 if(surface->IsKind(STANDARD_TYPE(Geom_Plane)))
419 return Standard_False;
421 Handle (Geom2d_Curve) c2d;
422 Standard_Real f2d, l2d; //szv#4:S4163:12Mar99 moved down f3d, l3d
423 if (!PCurve (edge, surface, location, c2d, f2d ,l2d, Standard_False)) {
424 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
425 return Standard_False;
428 Handle (Geom_Curve) c3d; //szv#4:S4163:12Mar99 moved
429 Standard_Real f3d, l3d; //szv#4:S4163:12Mar99 moved
430 if (!Curve3d (edge, c3d, f3d, l3d, Standard_False)) {
431 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
432 return Standard_False;
435 TopoDS_Vertex aFirstVert = FirstVertex (edge);
436 TopoDS_Vertex aLastVert = LastVertex (edge);
438 if (aFirstVert.IsNull() || aLastVert.IsNull())
439 return Standard_False;
441 Standard_Real preci1 = BRep_Tool::Tolerance (aFirstVert),
442 preci2 = BRep_Tool::Tolerance (aLastVert);
444 gp_Pnt2d p2d1 = c2d->Value (f2d),
445 p2d2 = c2d->Value (l2d);
447 //#39 rln 17.11.98 S4054, annie_surf.igs entity 39
448 return CheckPoints (c3d->Value (f3d)/*.Transformed (location.Transformation())*/,
449 c3d->Value (l3d)/*.Transformed (location.Transformation())*/,
450 surface->Value (p2d1.X(), p2d1.Y()).Transformed (location.Transformation()),
451 surface->Value (p2d2.X(), p2d2.Y()).Transformed (location.Transformation()),
456 //=======================================================================
457 //function : CheckPoints
459 //=======================================================================
461 Standard_Boolean ShapeAnalysis_Edge::CheckPoints (const gp_Pnt& P1A,
465 const Standard_Real preci1,
466 const Standard_Real preci2)
468 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
469 if (P1A.SquareDistance (P2A) <= preci1 * preci1 &&
470 P1B.SquareDistance (P2B) <= preci2 * preci2)
471 return Standard_False;
472 else if (P1A.Distance (P2B) + (P1B.Distance (P2A)) <
473 P1A.Distance (P2A) + (P1B.Distance (P2B)))
474 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
475 return Standard_True;
479 //=======================================================================
480 //function : CheckVerticesWithCurve3d
482 //=======================================================================
484 Standard_Boolean ShapeAnalysis_Edge::CheckVerticesWithCurve3d (const TopoDS_Edge& edge,
485 const Standard_Real preci,
486 const Standard_Integer vtx)
488 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
490 TopoDS_Vertex V1 = FirstVertex (edge);
491 TopoDS_Vertex V2 = LastVertex (edge);
492 gp_Pnt p1v = BRep_Tool::Pnt (V1);
493 gp_Pnt p2v = BRep_Tool::Pnt (V2);
496 Handle(Geom_Curve) c3d;
497 if ( ! Curve3d (edge,c3d,cf,cl) ) {
498 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
499 return Standard_False;
502 // on va faire les checks ...
505 gp_Pnt p13d = c3d->Value(cf);
506 //szv#4:S4163:12Mar99 optimized
507 if (p1v.Distance(p13d) > (preci < 0 ? BRep_Tool::Tolerance (V1) : preci))
508 myStatus |= ShapeExtend_DONE1;
513 gp_Pnt p23d = c3d->Value(cl);
514 //szv#4:S4163:12Mar99 optimized
515 if (p2v.Distance(p23d) > (preci < 0 ? BRep_Tool::Tolerance (V2) : preci))
516 myStatus |= ShapeExtend_DONE2;
519 return Status ( ShapeExtend_DONE );
523 //=======================================================================
524 //function : CheckVerticesWithPCurve
526 //=======================================================================
528 Standard_Boolean ShapeAnalysis_Edge::CheckVerticesWithPCurve (const TopoDS_Edge& edge,
529 const TopoDS_Face& face,
530 const Standard_Real preci,
531 const Standard_Integer vtx)
534 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
535 return CheckVerticesWithPCurve (edge, S, L, preci, vtx); //szv#4:S4163:12Mar99 `vtx,preci` wrong parameters order
539 //=======================================================================
540 //function : CheckVerticesWithPCurve
542 //=======================================================================
544 Standard_Boolean ShapeAnalysis_Edge::CheckVerticesWithPCurve (const TopoDS_Edge& edge,
545 const Handle(Geom_Surface)& surf,
546 const TopLoc_Location& loc,
547 const Standard_Real preci,
548 const Standard_Integer vtx)
550 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
552 TopoDS_Vertex V1 = FirstVertex (edge);
553 TopoDS_Vertex V2 = LastVertex (edge);
554 gp_Pnt p1v = BRep_Tool::Pnt (V1);
555 gp_Pnt p2v = BRep_Tool::Pnt (V2);
557 Standard_Real cf, cl;
558 Handle(Geom2d_Curve) c2d;
559 if ( ! PCurve ( edge, surf, loc, c2d, cf, cl ) ) {
560 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
561 return Standard_False;
564 // on va faire les checks ...
565 if (vtx != 2) { // 1er VTX
566 gp_Pnt2d p1uv = c2d->Value (cf);
567 gp_Pnt p12d = surf->Value (p1uv.X(), p1uv.Y());
568 if (!loc.IsIdentity())
569 p12d.Transform(loc.Transformation());
570 // szv#4:S4163:12Mar99 optimized
571 if ( p1v.Distance(p12d) > (preci < 0 ? BRep_Tool::Tolerance (V1) : preci) )
572 myStatus |= ShapeExtend_DONE1;
575 if (vtx != 1) { // 2me VTX
576 gp_Pnt2d p2uv = c2d->Value (cl);
577 gp_Pnt p22d = surf->Value (p2uv.X(), p2uv.Y());
578 if (!loc.IsIdentity())
579 p22d.Transform(loc.Transformation());
580 // szv#4:S4163:12Mar99 optimized
581 if ( p2v.Distance(p22d) > (preci < 0 ? BRep_Tool::Tolerance (V2) : preci) )
582 myStatus |= ShapeExtend_DONE2;
585 return Status ( ShapeExtend_DONE );
589 //=======================================================================
590 //function : CheckVertexTolerance
592 //=======================================================================
594 static Standard_Integer CheckVertexTolerance(const TopoDS_Edge& edge,
595 const TopoDS_Face& face,
596 const Standard_Boolean checkAll,
597 Standard_Real& toler1,
598 Standard_Real& toler2)
600 Standard_Integer Status = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
602 ShapeAnalysis_Edge sae;
603 TopoDS_Vertex V1 = sae.FirstVertex (edge);
604 TopoDS_Vertex V2 = sae.LastVertex (edge);
605 if ( V1.IsNull() || V2.IsNull() ) { //:p1 abv 22 Feb 99: r76sy.stp
606 Status |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
610 Standard_Real old1 = BRep_Tool::Tolerance (V1);
611 Standard_Real old2 = BRep_Tool::Tolerance (V2);
612 gp_Pnt pnt1 = BRep_Tool::Pnt (V1);
613 gp_Pnt pnt2 = BRep_Tool::Pnt (V2);
616 Handle(Geom_Curve) c3d;
617 if ( ! sae.Curve3d(edge, c3d, a, b, Standard_True)) {
618 if ( ! BRep_Tool::Degenerated ( edge ) )
619 Status |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
620 toler1 = toler2 = 0.;
621 // return Standard_False;
624 toler1 = pnt1.SquareDistance (c3d->Value (a));
625 toler2 = pnt2.SquareDistance (c3d->Value (b));
629 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&edge.TShape());
630 for (BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); itcr.More(); itcr.Next() ) {
631 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
632 if (GC.IsNull() || !GC->IsCurveOnSurface()) continue;
633 Handle(Geom2d_Curve) pcurve;
634 Handle(Geom_Surface) S = GC->Surface();
635 TopLoc_Location L = edge.Location() * GC->Location();
636 sae.PCurve (edge, S, L, pcurve, a, b, Standard_True);
637 gp_Pnt2d p1 = pcurve->Value (a);
638 gp_Pnt2d p2 = pcurve->Value (b);
639 gp_Pnt P1 = S->Value (p1.X(), p1.Y()).Transformed (L.Transformation());
640 gp_Pnt P2 = S->Value (p2.X(), p2.Y()).Transformed (L.Transformation());
641 toler1 = Max (toler1, pnt1.SquareDistance (P1));
642 toler2 = Max (toler2, pnt2.SquareDistance (P2));
645 //:abv 10.06.02: porting C40 -> dev (CC670-12608.stp)
646 // Check with given face is needed for plane surfaces (if no stored pcurves)
647 else if ( ! face.IsNull() ) {
648 Handle(Geom2d_Curve) pcurve;
650 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
651 if ( sae.PCurve(edge, S, L, pcurve, a, b, Standard_True)) {
652 gp_Pnt2d p1 = pcurve->Value (a);
653 gp_Pnt2d p2 = pcurve->Value (b);
654 gp_Pnt P1 = S->Value (p1.X(), p1.Y()).Transformed (L.Transformation());
655 gp_Pnt P2 = S->Value (p2.X(), p2.Y()).Transformed (L.Transformation());
656 toler1 = Max (toler1, pnt1.SquareDistance (P1));
657 toler2 = Max (toler2, pnt2.SquareDistance (P2));
659 else Status |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL3);
662 //:o8 abv 19 Feb 99: CTS18541.stp #18559: coeff 1.0001 added
663 //szv 18 Aug 99: edge tolerance is taken in consideration
664 Standard_Real tole = BRep_Tool::Tolerance (edge);
665 toler1 = Max (1.0000001 * Sqrt (toler1), tole);
666 toler2 = Max (1.0000001 * Sqrt (toler2), tole);
668 Status |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
670 Status |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
676 //=======================================================================
677 //function : CheckVertexTolerance
679 //=======================================================================
681 Standard_Boolean ShapeAnalysis_Edge::CheckVertexTolerance(const TopoDS_Edge& edge,
682 const TopoDS_Face& face,
683 Standard_Real& toler1,
684 Standard_Real& toler2)
686 myStatus = ::CheckVertexTolerance ( edge, face, Standard_False, toler1, toler2 );
687 return Status ( ShapeExtend_DONE );
691 //=======================================================================
692 //function : CheckVertexTolerance
694 //=======================================================================
696 Standard_Boolean ShapeAnalysis_Edge::CheckVertexTolerance(const TopoDS_Edge& edge,
697 Standard_Real& toler1,
698 Standard_Real& toler2)
701 myStatus = ::CheckVertexTolerance ( edge, F, Standard_True, toler1, toler2 );
702 return Status ( ShapeExtend_DONE );
706 //=======================================================================
708 //purpose: For SameParameter: compute it for two curves
709 //note: This function is made from Validate() in BRepCheck_Edge.cxx
710 //=======================================================================
712 Standard_Boolean ShapeAnalysis_Edge::ComputeDeviation (const Adaptor3d_Curve& CRef,
713 const Adaptor3d_Curve& Other,
714 const Standard_Boolean SameParameter,
716 const Standard_Integer NCONTROL)
718 Standard_Boolean OK = Standard_True;
719 Standard_Real dev2 = dev*dev;
721 Standard_Real First = CRef.FirstParameter(), Last = CRef.LastParameter();
722 Standard_Real OFirst = Other.FirstParameter(), OLast = Other.LastParameter(); //szv#4:S4163:12Mar99 moved
724 Standard_Boolean proj = (!SameParameter || First != OFirst || Last != OLast); //szv#4:S4163:12Mar99 optimized
726 Standard_Integer NCtrl = ( NCONTROL < 1 )? 1 : NCONTROL; //szv#4:S4163:12Mar99 anti-exception
729 for (Standard_Integer i = 0; i <= NCtrl; i++) {
730 Standard_Real prm = ((NCtrl-i)*First + i*Last)/NCtrl;
731 gp_Pnt pref = CRef.Value(prm);
732 gp_Pnt pother = Other.Value(prm);
733 Standard_Real dist2 = pref.SquareDistance(pother);
734 if ( dev2 < dist2 ) dev2 = dist2;
739 gp_Pnt pd = CRef.Value(First);
740 gp_Pnt pdo = Other.Value(OFirst);
741 Standard_Real dist2 = pd.SquareDistance(pdo);
742 if ( dev2 < dist2 ) dev = Sqrt ( dev2 = dist2 );
744 pd = CRef.Value(Last);
745 pdo = Other.Value(OLast);
746 dist2 = pd.SquareDistance(pdo);
747 if ( dev2 < dist2 ) dev = Sqrt ( dev2 = dist2 );
749 Extrema_LocateExtPC refd, otherd; //szv#4:S4163:12Mar99 warning
750 refd.Initialize(CRef,First,Last,Precision::PConfusion());
751 otherd.Initialize(Other,OFirst,OLast,Precision::PConfusion());
753 for (Standard_Integer i = 1; i < NCtrl; i++) { //szv#4:S4163:12Mar99 was bug
754 Standard_Real rprm = ((NCtrl-i)*First + i*Last)/NCtrl;
755 gp_Pnt pref = CRef.Value(rprm);
756 Standard_Real oprm = ((NCtrl-i)*OFirst + i*OLast)/NCtrl;
757 gp_Pnt pother = Other.Value(oprm);
759 refd.Perform(pother,rprm);
760 if ( ! refd.IsDone() ) OK = Standard_False;
761 else if ( dev2 < refd.SquareDistance() ) {dev2 = refd.SquareDistance(); dev = sqrt (dev2);}
763 otherd.Perform(pref,oprm);
764 if ( ! otherd.IsDone() ) OK = Standard_False;
765 else if ( dev2 < otherd.SquareDistance() ) {dev2 = otherd.SquareDistance(); dev = sqrt (dev2);}
768 dev *= 1.00001;//ims007 entity 8067 edge 3; 1e-07USA60022 (4255, 4-th edge) SA_Check and BRepCh find distinct points001; // ensure that dev*dev >= dev2
774 //=======================================================================
775 //function : CheckSameParameter
777 //=======================================================================
779 Standard_Boolean ShapeAnalysis_Edge::CheckSameParameter (const TopoDS_Edge& edge,
780 Standard_Real& maxdev,
781 const Standard_Integer NbControl)
783 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
784 if (BRep_Tool::Degenerated (edge)) return Standard_False;
788 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&edge.TShape());
789 Standard_Boolean SameParameter = TE->SameParameter();
791 GeomAdaptor_Curve AC3d;
794 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
795 for ( ; itcr.More(); itcr.Next() ) {
796 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
797 if ( GC.IsNull() || ! GC->IsCurve3D() ) continue;
798 Handle(Geom_Curve) C3d = GC->Curve3D();
799 if ( C3d.IsNull() ) continue; //:s1 abv 22 Apr 99: PRO7226 #489490
800 TopLoc_Location loc = GC->Location();
801 if ( ! loc.IsIdentity() )
802 C3d = Handle(Geom_Curve)::DownCast ( C3d->Transformed ( loc ) );
803 else C3d = Handle(Geom_Curve)::DownCast ( C3d->Copy() ); //:s4 abv 26 Apr 99: sim6049.igs 21677: necessary to get True SP (!!?)
804 Standard_Real First, Last;
805 GC->Range ( First, Last );
806 AC3d.Load ( C3d, First, Last );
810 if ( ! itcr.More() ) {
811 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
812 return Standard_False;
815 // iterate on pcurves
816 itcr.Initialize ( TE->Curves() );
817 for ( ; itcr.More(); itcr.Next() ) {
818 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
819 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
823 Handle(Geom_Surface) Su = GC->Surface();
824 TopLoc_Location loc = GC->Location();
825 if (!loc.IsIdentity())
826 Su = Handle(Geom_Surface)::DownCast ( Su->Transformed ( loc ) );
827 Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(Su);
829 Handle(Geom2d_Curve) PC = GC->PCurve();
830 Handle(Geom2dAdaptor_HCurve) GHPC = new Geom2dAdaptor_HCurve(PC,f,l);
831 //Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
832 Adaptor3d_CurveOnSurface ACS;
835 if ( ! ComputeDeviation ( AC3d, ACS, SameParameter, maxdev, NbControl-1 ) ) {
836 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
839 if ( GC->IsCurveOnClosedSurface() ) {
840 GHPC->ChangeCurve2d().Load ( GC->PCurve2(), f, l ); // same bounds
841 ACS.Load(GAHS); // sans doute inutile
842 ACS.Load(GHPC); // meme remarque...
843 if ( ! ComputeDeviation ( AC3d, ACS, SameParameter, maxdev, NbControl-1 ) ) {
844 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
849 if ( maxdev > TE->Tolerance() )
850 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
851 if ( ! SameParameter )
852 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
854 return Status ( ShapeExtend_DONE );
858 //=======================================================================
859 //function : IsOverlapPartEdges
861 //=======================================================================
863 static Standard_Boolean IsOverlapPartEdges(const TopoDS_Edge& theFirstEdge,
864 const TopoDS_Edge& theSecEdge,
865 const Standard_Real& theTolerance,
866 const Standard_Real& theStep,
867 const Standard_Real& theStartLength,
868 const Standard_Real& theEndLenght)
870 TColStd_SequenceOfInteger aSeqIntervals;
871 BRepAdaptor_Curve aAdCurve1(theFirstEdge);
873 BRepExtrema_DistShapeShape aMinDist;
874 aMinDist.LoadS1(theSecEdge);
876 for(Standard_Real aS = theStartLength; aS <= theEndLenght; aS+=theStep/2) {
879 if(aS <= Precision::Confusion()) {
880 TopoDS_Vertex V1 = TopExp::FirstVertex(theFirstEdge,Standard_True);
881 aPoint = BRep_Tool::Pnt(V1);
884 GCPnts_AbscissaPoint aAbsPoint(Precision::Confusion(),aAdCurve1,aS,aAdCurve1.FirstParameter());
885 if(aAbsPoint.IsDone())
886 aAdCurve1.D0(aAbsPoint.Parameter(),aPoint);
891 aB.MakeVertex(aV,aPoint,Precision::Confusion());
894 if( aMinDist.IsDone() && aMinDist.Value() >= theTolerance)
895 return Standard_False;
897 return Standard_True;
901 //=======================================================================
902 //function : CheckOverlapping
904 //=======================================================================
906 Standard_Boolean ShapeAnalysis_Edge::CheckOverlapping(const TopoDS_Edge& theEdge1,
907 const TopoDS_Edge& theEdge2,
908 Standard_Real& theTolOverlap,
909 const Standard_Real theDomainDist)
911 Standard_Boolean isOverlap = Standard_False;
912 BRepAdaptor_Curve aAdCurve1(theEdge1);
913 Standard_Real aLength1 = GCPnts_AbscissaPoint::Length (aAdCurve1);
914 BRepAdaptor_Curve aAdCurve2(theEdge2);
915 Standard_Real aLength2 = GCPnts_AbscissaPoint::Length (aAdCurve2);
916 TopoDS_Edge aFirstEdge = (aLength1 >= aLength2 ? theEdge2: theEdge1);
917 TopoDS_Edge aSecEdge = (aLength1 >= aLength2 ? theEdge1: theEdge2);
918 Standard_Real aLength = Min(aLength1,aLength2);
920 //check overalpping between edges on whole edges
921 Standard_Real aStep = Min(aLength1,aLength2)/2;
922 isOverlap = IsOverlapPartEdges(aFirstEdge,aSecEdge,theTolOverlap,aStep,0.,Min(aLength1,aLength2));
925 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3);
928 if(theDomainDist ==0.0)
931 //check overalpping between edges on segment with length less than theDomainDist
933 Standard_Real aDomainTol = (theDomainDist > Min( aLength1,aLength2) ? Min( aLength1,aLength2) :theDomainDist);
934 BRepExtrema_DistShapeShape aMinDist(aFirstEdge,aSecEdge,theTolOverlap);
935 Standard_Real aresTol = theTolOverlap;
936 if(aMinDist.IsDone()) {
937 aresTol = aMinDist.Value();
938 if(aresTol >= theTolOverlap) return Standard_False;
939 Standard_Integer NbSol = aMinDist.NbSolution();
940 for(Standard_Integer i =1; i<= NbSol && !isOverlap; i++) {
941 BRepExtrema_SupportType aType1 = aMinDist.SupportTypeShape1(i);
942 Standard_Real aEndLength, aStartLength, aLengthP;
943 if(aType1 == BRepExtrema_IsVertex) {
944 TopoDS_Shape aSupportShape1 = aMinDist.SupportOnShape1(i);
945 TopoDS_Vertex aV1,aV2;
946 TopExp::Vertices (aFirstEdge, aV1, aV2, Standard_True);
947 if( aV1.IsSame(aSupportShape1))
952 else if(aType1 == BRepExtrema_IsOnEdge) {
953 Standard_Real aParam1, aFirst, aLast;
954 aMinDist.ParOnEdgeS1 ( i, aParam1 );
955 BRep_Tool::Range(aFirstEdge,aFirst,aLast);
956 BRepAdaptor_Curve anAdaptor(aFirstEdge);
957 aLengthP = GCPnts_AbscissaPoint::Length(anAdaptor,aFirst,aParam1);
960 aStartLength = aLengthP - aDomainTol/2;
961 if( aStartLength <0.0) {
963 aEndLength = aDomainTol;
965 aEndLength = aLengthP + aDomainTol/2;
966 if(aEndLength > aLength) {
967 aEndLength = aLength;
968 aStartLength = aEndLength - aDomainTol;
970 aStep = (aEndLength - aStartLength)/5;
971 isOverlap = (IsOverlapPartEdges(aFirstEdge,aSecEdge,theTolOverlap,aStep,aStartLength,aEndLength));
975 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4);
977 theTolOverlap = aresTol;