1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPTools_AlgoTools.ixx>
18 #include <gp_Pnt2d.hxx>
20 #include <Adaptor3d_HCurve.hxx>
21 #include <Adaptor3d_CurveOnSurface.hxx>
22 #include <Adaptor3d_HCurveOnSurface.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Geom_Surface.hxx>
26 #include <Geom_Plane.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <GeomAdaptor_Surface.hxx>
31 #include <GeomAdaptor_Curve.hxx>
32 #include <GeomAdaptor_HCurve.hxx>
33 #include <GeomAdaptor_HSurface.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <Geom2dInt_GInter.hxx>
37 #include <Geom2dAdaptor_Curve.hxx>
38 #include <Geom2dAdaptor_HCurve.hxx>
39 #include <Geom2dAdaptor.hxx>
41 #include <GeomProjLib.hxx>
43 #include <ProjLib_ProjectedCurve.hxx>
44 #include <Extrema_LocateExtPC.hxx>
46 #include <IntRes2d_Domain.hxx>
47 #include <IntRes2d_IntersectionPoint.hxx>
49 #include <TopLoc_Location.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Iterator.hxx>
56 #include <TopoDS_Wire.hxx>
58 #include <BRep_TVertex.hxx>
59 #include <BRep_TEdge.hxx>
60 #include <BRep_TFace.hxx>
61 #include <BRep_Tool.hxx>
62 #include <BRep_GCurve.hxx>
63 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
64 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
65 #include <BRep_CurveRepresentation.hxx>
66 #include <BRep_PointRepresentation.hxx>
67 #include <BRep_Builder.hxx>
69 #include <BRepAdaptor_Surface.hxx>
71 #include <BRepTools_WireExplorer.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopTools_IndexedMapOfShape.hxx>
76 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
77 #include <TopTools_ListOfShape.hxx>
78 #include <TopTools_ListIteratorOfListOfShape.hxx>
80 #include <IntTools_Tools.hxx>
82 #include <BOPCol_NCVector.hxx>
83 #include <BOPCol_Parallel.hxx>
84 #include <BRepLib_CheckCurveOnSurface.hxx>
87 void CheckEdge (const TopoDS_Edge& E,
88 const Standard_Real aMaxTol);
90 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
92 const Standard_Real aMaxTol);
94 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
95 const Adaptor3d_Curve& Other,
96 const Standard_Real Tol,
97 const Standard_Boolean SameParameter,
98 Standard_Real& aNewTolerance);
101 void CorrectVertexTolerance(const TopoDS_Edge& aE);
104 void CorrectWires(const TopoDS_Face& aF);
109 void UpdateEdges(const TopoDS_Face& aF);
112 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
113 const TopoDS_Face& aF,
114 const GeomAdaptor_Surface& aS,
115 const TopoDS_Edge& aE1,
116 const TopoDS_Edge& aE2);
120 //=======================================================================
121 //class : BOPTools_CPC
123 //=======================================================================
133 void SetEdge(const TopoDS_Edge& aE) {
137 const TopoDS_Edge& Edge()const {
141 void SetMaxTol(const Standard_Real aMaxTol) {
145 Standard_Real MaxTol()const {
150 CheckEdge(myEdge, myMaxTol);
154 Standard_Real myMaxTol;
158 //=======================================================================
159 typedef BOPCol_NCVector<BOPTools_CPC> BOPTools_VectorOfCPC;
161 typedef BOPCol_Functor
163 BOPTools_VectorOfCPC> BOPTools_CPCFunctor;
166 <BOPTools_CPCFunctor,
167 BOPTools_VectorOfCPC> BOPTools_CPCCnt;
169 //=======================================================================
170 //class : BOPTools_CWT
172 //=======================================================================
181 void SetFace(const TopoDS_Face& aF) {
186 CorrectWires(myFace);
192 //=======================================================================
193 typedef BOPCol_NCVector<BOPTools_CWT> BOPTools_VectorOfCWT;
195 typedef BOPCol_Functor
197 BOPTools_VectorOfCWT> BOPTools_CWTFunctor;
200 <BOPTools_CWTFunctor,
201 BOPTools_VectorOfCWT> BOPTools_CWTCnt;
203 //=======================================================================
204 //class : BOPTools_CDT
206 //=======================================================================
216 void SetEdge(const TopoDS_Edge& aE) {
220 void SetFace(const TopoDS_Face& aF) {
224 void SetMaxTol(const Standard_Real aMaxTol) {
229 CorrectEdgeTolerance (myEdge, myFace, myMaxTol);
233 Standard_Real myMaxTol;
237 //=======================================================================
238 typedef BOPCol_NCVector<BOPTools_CDT> BOPTools_VectorOfCDT;
240 typedef BOPCol_Functor
242 BOPTools_VectorOfCDT> BOPTools_CDTFunctor;
245 <BOPTools_CDTFunctor,
246 BOPTools_VectorOfCDT> BOPTools_CDTCnt;
248 //=======================================================================
249 //class : BOPTools_CVT
251 //=======================================================================
260 void SetEdge(const TopoDS_Edge& aE) {
265 CorrectVertexTolerance(myEdge);
272 //=======================================================================
273 typedef BOPCol_NCVector<BOPTools_CVT> BOPTools_VectorOfCVT;
275 typedef BOPCol_Functor
277 BOPTools_VectorOfCVT> BOPTools_CVTFunctor;
280 <BOPTools_CVTFunctor,
281 BOPTools_VectorOfCVT> BOPTools_CVTCnt;
283 //=======================================================================
284 //class : BOPTools_CET
286 //=======================================================================
295 void SetFace(const TopoDS_Face& aF) {
306 //=======================================================================
307 typedef BOPCol_NCVector<BOPTools_CET> BOPTools_VectorOfCET;
309 typedef BOPCol_Functor
311 BOPTools_VectorOfCET> BOPTools_CETFunctor;
314 <BOPTools_CETFunctor,
315 BOPTools_VectorOfCET> BOPTools_CETCnt;
318 //=======================================================================
320 //=======================================================================
321 // Function : CorrectTolerances
323 //=======================================================================
324 void BOPTools_AlgoTools::CorrectTolerances
325 (const TopoDS_Shape& aShape,
326 const Standard_Real aMaxTol,
327 const Standard_Boolean bRunParallel)
329 BOPTools_AlgoTools::CorrectPointOnCurve(aShape, aMaxTol, bRunParallel);
330 BOPTools_AlgoTools::CorrectCurveOnSurface(aShape, aMaxTol, bRunParallel);
333 //=======================================================================
334 // Function : CorrectPointOnCurve
336 //=======================================================================
337 void BOPTools_AlgoTools::CorrectPointOnCurve
338 (const TopoDS_Shape& aS,
339 const Standard_Real aMaxTol,
340 const Standard_Boolean bRunParallel)
342 TopExp_Explorer aExp;
343 BOPTools_VectorOfCPC aVCPC;
345 aExp.Init(aS, TopAbs_EDGE);
346 for(; aExp.More(); aExp.Next()) {
347 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
348 BOPTools_CPC& aCPC=aVCPC.Append1();
350 aCPC.SetMaxTol(aMaxTol);
353 //======================================================
354 BOPTools_CPCCnt::Perform(bRunParallel, aVCPC);
355 //======================================================
357 //=======================================================================
358 // Function : CorrectCurveOnSurface
360 //=======================================================================
361 void BOPTools_AlgoTools::CorrectCurveOnSurface
362 (const TopoDS_Shape& aS,
363 const Standard_Real aMaxTol,
364 const Standard_Boolean bRunParallel)
366 TopExp_Explorer aExpF, aExpE;
367 BOPTools_VectorOfCWT aVCWT;
368 BOPTools_VectorOfCDT aVCDT;
370 aExpF.Init(aS, TopAbs_FACE);
371 for (; aExpF.More(); aExpF.Next()) {
372 const TopoDS_Face& aF=*((TopoDS_Face*)&aExpF.Current());
374 BOPTools_CWT& aCWT=aVCWT.Append1();
377 aExpE.Init(aF, TopAbs_EDGE);
378 for (; aExpE.More(); aExpE.Next()) {
379 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExpE.Current());
381 BOPTools_CDT& aCDT=aVCDT.Append1();
384 aCDT.SetMaxTol(aMaxTol);
388 //======================================================
389 BOPTools_CWTCnt::Perform(bRunParallel, aVCWT);
390 //======================================================
391 BOPTools_CDTCnt::Perform(bRunParallel, aVCDT);
392 //======================================================
394 //=======================================================================
395 // Function : CorrectShapeTolerances
397 //=======================================================================
398 void BOPTools_AlgoTools::CorrectShapeTolerances
399 (const TopoDS_Shape& aShape,
400 const Standard_Boolean bRunParallel)
402 TopExp_Explorer aExp;
403 BOPTools_VectorOfCVT aVCVT;
404 BOPTools_VectorOfCET aVCET;
406 aExp.Init(aShape, TopAbs_EDGE);
407 for (; aExp.More(); aExp.Next()) {
408 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExp.Current();
409 BOPTools_CVT& aCVT=aVCVT.Append1();
413 //======================================================
414 BOPTools_CVTCnt::Perform(bRunParallel, aVCVT);
415 //======================================================
417 aExp.Init(aShape, TopAbs_FACE);
418 for (; aExp.More(); aExp.Next()) {
419 const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current();
420 BOPTools_CET& aCET=aVCET.Append1();
424 //======================================================
425 BOPTools_CETCnt::Perform(bRunParallel, aVCET);
426 //======================================================
429 //=======================================================================
430 // Function : CheckEdge
431 // purpose : Correct tolerances for Vertices on Edge
432 //=======================================================================
433 void CheckEdge (const TopoDS_Edge& Ed,
434 const Standard_Real aMaxTol)
436 Standard_Real aTolE, aTol, aD2, aNewTolerance, dd;
441 TopoDS_Iterator aItS;
443 TopAbs_Orientation aOrV;
444 BRep_ListIteratorOfListOfPointRepresentation aItPR;
445 BRep_ListIteratorOfListOfCurveRepresentation aItCR;
448 aE.Orientation(TopAbs_FORWARD);
449 aTolE=BRep_Tool::Tolerance(aE);
451 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&aE.TShape());
454 for (; aItS.More(); aItS.Next()) {
455 aV= TopoDS::Vertex(aItS.Value());
457 Handle(BRep_TVertex)& TV=*((Handle(BRep_TVertex)*)&aV.TShape());
458 const gp_Pnt& aPV = TV->Pnt();
460 aTol=BRep_Tool::Tolerance(aV);
461 aTol=Max(aTol, aTolE);
465 const TopLoc_Location& Eloc = aE.Location();
467 aItCR.Initialize(TE->Curves());
468 while (aItCR.More()) {
469 const Handle(BRep_CurveRepresentation)& aCR = aItCR.Value();
470 const TopLoc_Location& loc = aCR->Location();
471 L = (Eloc * loc).Predivided(aV.Location());
473 if (aCR->IsCurve3D()) {
474 const Handle(Geom_Curve)& aC = aCR->Curve3D();
476 aItPR.Initialize(TV->Points());
477 while (aItPR.More()) {
478 const Handle(BRep_PointRepresentation)& aPR=aItPR.Value();
479 if (aPR->IsPointOnCurve(aC, L)) {
480 aPC = aC->Value(aPR->Parameter());
481 aPC.Transform(L.Transformation());
482 aD2=aPV.SquareDistance(aPC);
484 aNewTolerance=sqrt(aD2)+dd;
485 if (aNewTolerance<aMaxTol)
486 TV->UpdateTolerance(aNewTolerance);
492 aOrV=aV.Orientation();
493 if (aOrV==TopAbs_FORWARD || aOrV==TopAbs_REVERSED) {
494 Handle(BRep_GCurve) aGC (Handle(BRep_GCurve)::DownCast (aCR));
496 if (aOrV==TopAbs_FORWARD) {
497 aPC=aC->Value(aGC->First());
500 aPC=aC->Value(aGC->Last());
502 aPC.Transform(L.Transformation());
504 aD2=aPV.SquareDistance(aPC);
506 aNewTolerance=sqrt(aD2)+dd;
507 if (aNewTolerance<aMaxTol)
508 TV->UpdateTolerance(aNewTolerance);
514 }// while (itcr.More()) {
515 } // for (; aVExp.More(); aVExp.Next()) {
517 //=======================================================================
518 // Function : CorrectWires
520 //=======================================================================
521 void CorrectWires(const TopoDS_Face& aFx)
523 Standard_Boolean bIsPeriodic;
524 Standard_Integer i, aNbV;
525 Standard_Real aTol, aTol2, aD2, aD2max, aT1, aT2, aT;
529 TopoDS_Vertex aV11, aV12, aV21, aV22;;
530 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
531 TopTools_ListIteratorOfListOfShape aIt, aIt1;
534 aF.Orientation(TopAbs_FORWARD);
535 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aFx);
536 GeomAdaptor_Surface aGAS (aS);
538 bIsPeriodic=(aGAS.IsUPeriodic() || aGAS.IsVPeriodic());
540 TopExp::MapShapesAndAncestors(aF,
545 for (i=1; i<=aNbV; ++i) {
546 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMVE.FindKey(i));
547 aPV=BRep_Tool::Pnt(aV);
548 aTol=BRep_Tool::Tolerance(aV);
552 const TopTools_ListOfShape& aLE=aMVE.FindFromIndex(i);
554 for (; aIt.More(); aIt.Next()) {
555 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aIt.Value());
556 const Handle(Geom2d_Curve)& aC2D=
557 BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
558 aT=BRep_Tool::Parameter(aV, aE);
561 aGAS.D0(aP2D.X(), aP2D.Y(), aP);
562 aD2=aPV.SquareDistance(aP);
566 //check self interference
575 TopExp::Vertices(aE, aV11, aV12);
579 for (; aIt1.More(); aIt1.Next()) {
580 const TopoDS_Edge& aE1=*(TopoDS_Edge*)(&aIt1.Value());
582 //do not perform check for edges that have two common vertices
583 TopExp::Vertices(aE1, aV21, aV22);
584 if ((aV11.IsSame(aV21) && aV12.IsSame(aV22)) ||
585 (aV12.IsSame(aV21) && aV11.IsSame(aV22))) {
589 aD2=IntersectCurves2d(aPV, aF, aGAS, aE, aE1);
593 }// for (; aIt1.More(); aIt1.Next()) {
594 }// for (; aIt.More(); aIt.Next()) {
599 aBB.UpdateVertex(aV, aTol);
601 }// for (i=1; i<=aNbV; ++i) {
603 //=======================================================================
604 // Function : IntersectCurves2d
605 // purpose : Intersect 2d curves of edges
606 //=======================================================================
607 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
608 const TopoDS_Face& aF,
609 const GeomAdaptor_Surface& aGAS,
610 const TopoDS_Edge& aE1,
611 const TopoDS_Edge& aE2)
613 Standard_Real aDist, aD, aT11, aT12, aT21, aT22, aTol2d, aT1, aT2;
614 Standard_Integer j, aNbPnt;
615 Geom2dInt_GInter aInter;
620 aTol2d = 1.e-10;//Precision::Confusion();
622 const Handle(Geom2d_Curve)& aC2D1=
623 BRep_Tool::CurveOnSurface(aE1, aF, aT11, aT12);
624 const Handle(Geom2d_Curve)& aC2D2=
625 BRep_Tool::CurveOnSurface(aE2, aF, aT21, aT22);
627 Geom2dAdaptor_Curve aGAC1(aC2D1), aGAC2(aC2D2);
628 IntRes2d_Domain aDom1(aC2D1->Value(aT11), aT11, aTol2d,
629 aC2D1->Value(aT12), aT12, aTol2d);
630 IntRes2d_Domain aDom2(aC2D2->Value(aT21), aT21, aTol2d,
631 aC2D2->Value(aT22), aT22, aTol2d);
633 aInter.Perform(aGAC1, aDom1, aGAC2, aDom2, aTol2d, aTol2d);
634 if (aInter.IsDone()) {
635 if (aInter.NbSegments()) {
638 aNbPnt = aInter.NbPoints();
640 aDist = -Precision::Infinite();
641 for (j = 1; j <= aNbPnt; ++j) {
642 const IntRes2d_IntersectionPoint& aPoint = aInter.Point(j);
644 aT1 = aPoint.ParamOnFirst();
645 aT2 = aPoint.ParamOnSecond();
647 if ((aT1 < aT11 || aT1 > aT12) ||
648 (aT2 < aT21 || aT2 > aT22)) {
652 aP2D = aPoint.Value();
653 aGAS.D0(aP2D.X(), aP2D.Y(), aP);
654 aD=aPV.SquareDistance(aP);
663 //=======================================================================
664 // Function : CorrectEdgeTolerance
665 // purpose : Correct tolerances for Edge
666 //=======================================================================
667 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
668 const TopoDS_Face& S,
669 const Standard_Real aMaxTol)
672 // 1. Minimum of conditions to Perform
673 Handle (BRep_CurveRepresentation) myCref;
674 Handle (Adaptor3d_HCurve) myHCurve;
678 Handle(BRep_TEdge)& TEx = *((Handle(BRep_TEdge)*)&myShape.TShape());
679 BRep_ListIteratorOfListOfCurveRepresentation itcrx(TEx->Curves());
680 Standard_Boolean Degenerated, SameParameterx, SameRangex;
682 Standard_Integer unique = 0;
684 Degenerated = TEx->Degenerated();
685 SameParameterx = TEx->SameParameter();
686 SameRangex = TEx->SameRange();
688 if (!SameRangex && SameParameterx) {
692 Handle(Geom_Curve) C3d;
693 while (itcrx.More()) {
694 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
695 if (cr->IsCurve3D()) {
697 if (myCref.IsNull() && !cr->Curve3D().IsNull()) {
705 return;//...No3DCurve
708 return;//...Multiple3DCurve;
711 if (myCref.IsNull() && !Degenerated) {
712 itcrx.Initialize(TEx->Curves());
713 while (itcrx.More()) {
714 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
715 if (cr->IsCurveOnSurface()) {
723 else if (!myCref.IsNull() && Degenerated){
724 return ;//...InvalidDegeneratedFlag;
727 if (!myCref.IsNull()) {
728 Handle(BRep_GCurve) GCref (Handle(BRep_GCurve)::DownCast (myCref));
729 Standard_Real First,Last;
730 GCref->Range(First,Last);
733 return ;//InvalidRange;
737 if (myCref->IsCurve3D()) {
738 Handle(Geom_Curve) C3dx = Handle(Geom_Curve)::DownCast
739 (myCref->Curve3D()->Transformed
740 (myCref->Location().Transformation()));
741 GeomAdaptor_Curve GAC3d(C3dx, First, Last);
742 myHCurve = new GeomAdaptor_HCurve(GAC3d);
744 else { // curve on surface
745 Handle(Geom_Surface) Sref = myCref->Surface();
746 Sref = Handle(Geom_Surface)::
747 DownCast(Sref->Transformed(myCref->Location().Transformation()));
748 const Handle(Geom2d_Curve)& PCref = myCref->PCurve();
749 Handle(GeomAdaptor_HSurface) GAHSref =
750 new GeomAdaptor_HSurface(Sref);
751 Handle(Geom2dAdaptor_HCurve) GHPCref =
752 new Geom2dAdaptor_HCurve(PCref, First, Last);
753 Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref);
754 myHCurve = new Adaptor3d_HCurveOnSurface(ACSref);
759 //===============================================
760 // 2. Tolerances in InContext
764 Standard_Boolean ok=Standard_True;;
766 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape());
767 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape));
768 Standard_Real aNewTol=Tol;
770 Standard_Boolean SameParameter = TE->SameParameter();
771 Standard_Boolean SameRange = TE->SameRange();
772 Standard_Real First = myHCurve->FirstParameter();
773 Standard_Real Last = myHCurve->LastParameter();
774 Standard_Real Delta =1.e-12;
776 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
777 const TopLoc_Location& Floc = S.Location();
778 const TopLoc_Location& TFloc = TF->Location();
779 const Handle(Geom_Surface)& Su = TF->Surface();
780 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
781 Standard_Boolean pcurvefound = Standard_False;
783 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
784 while (itcr.More()) {
785 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
786 if (cr != myCref && cr->IsCurveOnSurface(Su,L)) {
787 pcurvefound = Standard_True;
788 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
791 if (SameRange && (f != First || l != Last)) {
792 return ;//BRepCheck_InvalidSameRangeFlag;
795 Handle(Geom_Surface) Sb = cr->Surface();
796 Sb = Handle(Geom_Surface)::
797 DownCast (Su->Transformed(L.Transformation()));
798 Handle(Geom2d_Curve) PC = cr->PCurve();
799 Handle(GeomAdaptor_HSurface) GAHS =
800 new GeomAdaptor_HSurface(Sb);
801 Handle(Geom2dAdaptor_HCurve) GHPC =
802 new Geom2dAdaptor_HCurve(PC,f,l);
803 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
804 ok = Validate(myHCurve->Curve(), ACS,
805 Tol, SameParameter, aNewTol);
807 if (aNewTol<aMaxTol) {
808 TE->UpdateTolerance(aNewTol+Delta);
810 CorrectVertexTolerance(myShape);
814 if (cr->IsCurveOnClosedSurface()) {
815 //checkclosed = Standard_True;
816 GHPC->ChangeCurve2d().Load(cr->PCurve2(),f,l); // same bounds
817 ACS.Load(GAHS); // sans doute inutile
818 ACS.Load(GHPC); // meme remarque...
819 ok = Validate(myHCurve->Curve(),ACS,Tol,SameParameter, aNewTol);
821 if (aNewTol<aMaxTol) {
822 TE->UpdateTolerance(aNewTol+Delta);
823 CorrectVertexTolerance(myShape);
832 Handle(Geom_Plane) P;
833 Handle(Standard_Type) styp = Su->DynamicType();
834 if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
835 P = Handle(Geom_Plane)::
836 DownCast(Handle(Geom_RectangularTrimmedSurface)::
837 DownCast(Su)->BasisSurface());
840 P = Handle(Geom_Plane)::DownCast(Su);
842 if (P.IsNull()) { // not a plane
846 else {// on fait la projection a la volee, comme BRep_Tool
847 P = Handle(Geom_Plane)::
848 DownCast(P->Transformed(L.Transformation()));
849 //on projette Cref sur ce plan
850 Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(P);
852 // Dub - Normalement myHCurve est une GeomAdaptor_HCurve
853 GeomAdaptor_Curve& Gac =
854 Handle(GeomAdaptor_HCurve)::DownCast(myHCurve)->ChangeCurve();
855 Handle(Geom_Curve) C3dx = Gac.Curve();
856 Handle(Geom_Curve) ProjOnPlane =
857 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3dx,First,Last),
859 P->Position().Direction(),
862 Handle(GeomAdaptor_HCurve) aHCurve =
863 new GeomAdaptor_HCurve(ProjOnPlane);
865 ProjLib_ProjectedCurve proj(GAHS,aHCurve);
866 Handle(Geom2d_Curve) PC = Geom2dAdaptor::MakeCurve(proj);
867 Handle(Geom2dAdaptor_HCurve) GHPC =
868 new Geom2dAdaptor_HCurve(PC,
869 myHCurve->FirstParameter(),
870 myHCurve->LastParameter());
872 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
874 Standard_Boolean okx = Validate(myHCurve->Curve(),ACS,
875 Tol,Standard_True, aNewTol);
877 if (aNewTol<aMaxTol) {
878 TE->UpdateTolerance(aNewTol+Delta);
879 CorrectVertexTolerance(myShape);
883 }//end of if (!pcurvefound) {
884 } // end of 2. Tolerances in InContext
886 //=======================================================================
887 //function : CorrectVertexTolerance
889 //=======================================================================
890 void CorrectVertexTolerance(const TopoDS_Edge& aE)
892 Standard_Real aTolE, aTolV;
895 aTolE=BRep_Tool::Tolerance(aE);
897 for(; aIt.More(); aIt.Next()) {
898 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aIt.Value());
899 aTolV=BRep_Tool::Tolerance(aV);
901 Handle(BRep_TVertex)& aTV= *((Handle(BRep_TVertex)*)&aV.TShape());
902 aTV->UpdateTolerance(aTolE);
906 //=======================================================================
907 //function : Validate
909 //=======================================================================
910 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
911 const Adaptor3d_Curve& Other,
912 const Standard_Real Tol,
913 const Standard_Boolean SameParameter,
914 Standard_Real& aNewTolerance)
916 Standard_Real First, Last, MaxDistance, aD, Tol2;
918 First = CRef.FirstParameter();
919 Last = CRef.LastParameter();
923 Standard_Integer NCONTROL=23;
924 Standard_Integer i, aNC1=NCONTROL-1;
926 Standard_Boolean aFlag=Standard_False;
927 Standard_Boolean proj = (!SameParameter ||
928 First != Other.FirstParameter() ||
929 Last != Other.LastParameter());
933 for (i = 0; i < NCONTROL; i++) {
934 Standard_Real prm = ((aNC1-i)*First + i*Last)/aNC1;
935 gp_Pnt pref = CRef.Value(prm);
936 gp_Pnt pother = Other.Value(prm);
938 aD=pref.SquareDistance(pother);
941 if (aD>MaxDistance) {
949 aNewTolerance=sqrt(MaxDistance);
957 Extrema_LocateExtPC refd,otherd;
958 Standard_Real OFirst, OLast;
959 OFirst = Other.FirstParameter();
960 OLast = Other.LastParameter();
962 gp_Pnt pd = CRef.Value(First);
963 gp_Pnt pdo = Other.Value(OFirst);
965 aD = pd.SquareDistance(pdo);
967 if (aD>MaxDistance) {
973 pd = CRef.Value(Last);
974 pdo = Other.Value(OLast);
975 aD = pd.SquareDistance(pdo);
976 if (aD > Tol2 && aD > MaxDistance) {
981 refd.Initialize(CRef, First, Last, CRef.Resolution(Tol));
982 otherd.Initialize(Other, OFirst, OLast, Other.Resolution(Tol));
984 for (i = 2; i< aNC1; i++) {
985 Standard_Real rprm = ((aNC1-i)*First + i*Last)/aNC1;
986 gp_Pnt pref = CRef.Value(rprm);
988 Standard_Real oprm = ((aNC1-i)*OFirst + i*OLast)/aNC1;
989 gp_Pnt pother = Other.Value(oprm);
991 refd.Perform(pother,rprm);
992 if (!refd.IsDone() || refd.SquareDistance() > Tol2) {
994 aD=refd.SquareDistance();
995 if (aD > Tol2 && aD>MaxDistance) {
1002 otherd.Perform(pref,oprm);
1003 if (!otherd.IsDone() || otherd.SquareDistance() > Tol2) {
1005 if (otherd.IsDone()) {
1006 aD=otherd.SquareDistance();
1007 if (aD > Tol2 && aD>MaxDistance) {
1008 aFlag=Standard_True;
1016 aD=sqrt (MaxDistance);
1020 //=======================================================================
1021 // Function : UpdateEdges
1023 //=======================================================================
1024 void UpdateEdges(const TopoDS_Face& aF)
1026 Standard_Real aTolF, aTolE, aTolV;
1027 TopoDS_Iterator aItF, aItW, aItE;
1030 aTolE=aTolF= BRep_Tool::Tolerance(aF);
1031 aItF.Initialize(aF);
1032 for (; aItF.More(); aItF.Next()) {
1033 const TopoDS_Shape& aS = aItF.Value();
1034 if (aS.ShapeType()==TopAbs_WIRE) {
1035 aItW.Initialize(aS);
1036 for (; aItW.More(); aItW.Next()) {
1037 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aItW.Value());
1038 aTolE = BRep_Tool::Tolerance(aE);
1039 if (aTolE < aTolF) {
1040 aBB.UpdateEdge(aE, aTolF);
1043 //UpdateVertices(aE);
1047 const TopoDS_Vertex& aV=*(TopoDS_Vertex*)&aItF.Value();
1048 aTolV = BRep_Tool::Tolerance(aV);
1049 if (aTolV < aTolE) {
1050 aBB.UpdateVertex(aV, aTolF);
1055 //=======================================================================
1056 // Function : ComputeTolerance
1058 //=======================================================================
1059 Standard_Boolean BOPTools_AlgoTools::ComputeTolerance
1060 (const TopoDS_Face& theFace,
1061 const TopoDS_Edge& theEdge,
1062 Standard_Real& theMaxDist,
1063 Standard_Real& theMaxPar)
1065 BRepLib_CheckCurveOnSurface aCS;
1067 aCS.Init(theEdge, theFace);
1069 if (!aCS.IsDone()) {
1070 return Standard_False;
1073 theMaxDist = aCS.MaxDistance();
1074 theMaxPar = aCS.MaxParameter();
1076 return Standard_True;