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 <BOPCol_NCVector.hxx>
81 #include <BOPCol_TBB.hxx>
84 void CheckEdge (const TopoDS_Edge& E,
85 const Standard_Real aMaxTol);
87 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
89 const Standard_Real aMaxTol);
91 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
92 const Adaptor3d_Curve& Other,
93 const Standard_Real Tol,
94 const Standard_Boolean SameParameter,
95 Standard_Real& aNewTolerance);
98 void CorrectVertexTolerance(const TopoDS_Edge& aE);
101 void CorrectWires(const TopoDS_Face& aF);
106 void UpdateEdges(const TopoDS_Face& aF);
109 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
110 const TopoDS_Face& aF,
111 const Handle(Geom_Surface)& aS,
112 const TopoDS_Edge& aE1,
113 const TopoDS_Edge& aE2);
117 //=======================================================================
118 //class : BOPTools_CPC
120 //=======================================================================
130 void SetEdge(const TopoDS_Edge& aE) {
134 const TopoDS_Edge& Edge()const {
138 void SetMaxTol(const Standard_Real aMaxTol) {
142 Standard_Real MaxTol()const {
147 CheckEdge(myEdge, myMaxTol);
151 Standard_Real myMaxTol;
155 //=======================================================================
156 typedef BOPCol_NCVector<BOPTools_CPC> BOPTools_VectorOfCPC;
158 typedef BOPCol_TBBFunctor
160 BOPTools_VectorOfCPC> BOPTools_CPCFunctor;
162 typedef BOPCol_TBBCnt
163 <BOPTools_CPCFunctor,
164 BOPTools_VectorOfCPC> BOPTools_CPCCnt;
166 //=======================================================================
167 //class : BOPTools_CWT
169 //=======================================================================
178 void SetFace(const TopoDS_Face& aF) {
183 CorrectWires(myFace);
189 //=======================================================================
190 typedef BOPCol_NCVector<BOPTools_CWT> BOPTools_VectorOfCWT;
192 typedef BOPCol_TBBFunctor
194 BOPTools_VectorOfCWT> BOPTools_CWTFunctor;
196 typedef BOPCol_TBBCnt
197 <BOPTools_CWTFunctor,
198 BOPTools_VectorOfCWT> BOPTools_CWTCnt;
200 //=======================================================================
201 //class : BOPTools_CDT
203 //=======================================================================
213 void SetEdge(const TopoDS_Edge& aE) {
217 void SetFace(const TopoDS_Face& aF) {
221 void SetMaxTol(const Standard_Real aMaxTol) {
226 CorrectEdgeTolerance (myEdge, myFace, myMaxTol);
230 Standard_Real myMaxTol;
234 //=======================================================================
235 typedef BOPCol_NCVector<BOPTools_CDT> BOPTools_VectorOfCDT;
237 typedef BOPCol_TBBFunctor
239 BOPTools_VectorOfCDT> BOPTools_CDTFunctor;
241 typedef BOPCol_TBBCnt
242 <BOPTools_CDTFunctor,
243 BOPTools_VectorOfCDT> BOPTools_CDTCnt;
245 //=======================================================================
246 //class : BOPTools_CVT
248 //=======================================================================
257 void SetEdge(const TopoDS_Edge& aE) {
262 CorrectVertexTolerance(myEdge);
269 //=======================================================================
270 typedef BOPCol_NCVector<BOPTools_CVT> BOPTools_VectorOfCVT;
272 typedef BOPCol_TBBFunctor
274 BOPTools_VectorOfCVT> BOPTools_CVTFunctor;
276 typedef BOPCol_TBBCnt
277 <BOPTools_CVTFunctor,
278 BOPTools_VectorOfCVT> BOPTools_CVTCnt;
280 //=======================================================================
281 //class : BOPTools_CET
283 //=======================================================================
292 void SetFace(const TopoDS_Face& aF) {
303 //=======================================================================
304 typedef BOPCol_NCVector<BOPTools_CET> BOPTools_VectorOfCET;
306 typedef BOPCol_TBBFunctor
308 BOPTools_VectorOfCET> BOPTools_CETFunctor;
310 typedef BOPCol_TBBCnt
311 <BOPTools_CETFunctor,
312 BOPTools_VectorOfCET> BOPTools_CETCnt;
314 //=======================================================================
315 // Function : CorrectTolerances
317 //=======================================================================
318 void BOPTools_AlgoTools::CorrectTolerances
319 (const TopoDS_Shape& aShape,
320 const Standard_Real aMaxTol,
321 const Standard_Boolean bRunParallel)
323 BOPTools_AlgoTools::CorrectPointOnCurve(aShape, aMaxTol, bRunParallel);
324 BOPTools_AlgoTools::CorrectCurveOnSurface(aShape, aMaxTol, bRunParallel);
327 //=======================================================================
328 // Function : CorrectPointOnCurve
330 //=======================================================================
331 void BOPTools_AlgoTools::CorrectPointOnCurve
332 (const TopoDS_Shape& aS,
333 const Standard_Real aMaxTol,
334 const Standard_Boolean bRunParallel)
336 TopExp_Explorer aExp;
337 BOPTools_VectorOfCPC aVCPC;
339 aExp.Init(aS, TopAbs_EDGE);
340 for(; aExp.More(); aExp.Next()) {
341 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
342 BOPTools_CPC& aCPC=aVCPC.Append1();
344 aCPC.SetMaxTol(aMaxTol);
347 //======================================================
348 BOPTools_CPCCnt::Perform(bRunParallel, aVCPC);
349 //======================================================
351 //=======================================================================
352 // Function : CorrectCurveOnSurface
354 //=======================================================================
355 void BOPTools_AlgoTools::CorrectCurveOnSurface
356 (const TopoDS_Shape& aS,
357 const Standard_Real aMaxTol,
358 const Standard_Boolean bRunParallel)
360 TopExp_Explorer aExpF, aExpE;
361 BOPTools_VectorOfCWT aVCWT;
362 BOPTools_VectorOfCDT aVCDT;
364 aExpF.Init(aS, TopAbs_FACE);
365 for (; aExpF.More(); aExpF.Next()) {
366 const TopoDS_Face& aF=*((TopoDS_Face*)&aExpF.Current());
368 BOPTools_CWT& aCWT=aVCWT.Append1();
371 aExpE.Init(aF, TopAbs_EDGE);
372 for (; aExpE.More(); aExpE.Next()) {
373 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExpE.Current());
375 BOPTools_CDT& aCDT=aVCDT.Append1();
378 aCDT.SetMaxTol(aMaxTol);
382 //======================================================
383 BOPTools_CWTCnt::Perform(bRunParallel, aVCWT);
384 //======================================================
385 BOPTools_CDTCnt::Perform(bRunParallel, aVCDT);
386 //======================================================
388 //=======================================================================
389 // Function : CorrectShapeTolerances
391 //=======================================================================
392 void BOPTools_AlgoTools::CorrectShapeTolerances
393 (const TopoDS_Shape& aShape,
394 const Standard_Boolean bRunParallel)
396 TopExp_Explorer aExp;
397 BOPTools_VectorOfCVT aVCVT;
398 BOPTools_VectorOfCET aVCET;
400 aExp.Init(aShape, TopAbs_EDGE);
401 for (; aExp.More(); aExp.Next()) {
402 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExp.Current();
403 BOPTools_CVT& aCVT=aVCVT.Append1();
407 //======================================================
408 BOPTools_CVTCnt::Perform(bRunParallel, aVCVT);
409 //======================================================
411 aExp.Init(aShape, TopAbs_FACE);
412 for (; aExp.More(); aExp.Next()) {
413 const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current();
414 BOPTools_CET& aCET=aVCET.Append1();
418 //======================================================
419 BOPTools_CETCnt::Perform(bRunParallel, aVCET);
420 //======================================================
423 //=======================================================================
424 // Function : CheckEdge
425 // purpose : Correct tolerances for Vertices on Edge
426 //=======================================================================
427 void CheckEdge (const TopoDS_Edge& Ed,
428 const Standard_Real aMaxTol)
430 Standard_Real aTolE, aTol, aD2, aNewTolerance, dd;
435 TopoDS_Iterator aItS;
437 TopAbs_Orientation aOrV;
438 BRep_ListIteratorOfListOfPointRepresentation aItPR;
439 BRep_ListIteratorOfListOfCurveRepresentation aItCR;
442 aE.Orientation(TopAbs_FORWARD);
443 aTolE=BRep_Tool::Tolerance(aE);
445 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&aE.TShape());
448 for (; aItS.More(); aItS.Next()) {
449 aV= TopoDS::Vertex(aItS.Value());
451 Handle(BRep_TVertex)& TV=*((Handle(BRep_TVertex)*)&aV.TShape());
452 const gp_Pnt& aPV = TV->Pnt();
454 aTol=BRep_Tool::Tolerance(aV);
455 aTol=Max(aTol, aTolE);
459 const TopLoc_Location& Eloc = aE.Location();
461 aItCR.Initialize(TE->Curves());
462 while (aItCR.More()) {
463 const Handle(BRep_CurveRepresentation)& aCR = aItCR.Value();
464 const TopLoc_Location& loc = aCR->Location();
465 L = (Eloc * loc).Predivided(aV.Location());
467 if (aCR->IsCurve3D()) {
468 const Handle(Geom_Curve)& aC = aCR->Curve3D();
470 aItPR.Initialize(TV->Points());
471 while (aItPR.More()) {
472 const Handle(BRep_PointRepresentation)& aPR=aItPR.Value();
473 if (aPR->IsPointOnCurve(aC, L)) {
474 aPC = aC->Value(aPR->Parameter());
475 aPC.Transform(L.Transformation());
476 aD2=aPV.SquareDistance(aPC);
478 aNewTolerance=sqrt(aD2)+dd;
479 if (aNewTolerance<aMaxTol)
480 TV->UpdateTolerance(aNewTolerance);
486 aOrV=aV.Orientation();
487 if (aOrV==TopAbs_FORWARD || aOrV==TopAbs_REVERSED) {
488 const Handle(BRep_GCurve)& aGC=*((Handle(BRep_GCurve)*)&aCR);
490 if (aOrV==TopAbs_FORWARD) {
491 aPC=aC->Value(aGC->First());
494 aPC=aC->Value(aGC->Last());
496 aPC.Transform(L.Transformation());
498 aD2=aPV.SquareDistance(aPC);
500 aNewTolerance=sqrt(aD2)+dd;
501 if (aNewTolerance<aMaxTol)
502 TV->UpdateTolerance(aNewTolerance);
508 }// while (itcr.More()) {
509 } // for (; aVExp.More(); aVExp.Next()) {
511 //=======================================================================
512 // Function : CorrectWires
514 //=======================================================================
515 void CorrectWires(const TopoDS_Face& aFx)
517 Standard_Boolean bIsPeriodic;
518 Standard_Integer i, aNbV;
519 Standard_Real aTol, aTol2, aD2, aD2max, aT1, aT2, aT;
523 TopoDS_Vertex aV11, aV12, aV21, aV22;;
524 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
525 TopTools_ListIteratorOfListOfShape aIt, aIt1;
528 aF.Orientation(TopAbs_FORWARD);
529 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aFx);
530 GeomAdaptor_Surface aGAS (aS);
532 bIsPeriodic=(aGAS.IsUPeriodic() || aGAS.IsVPeriodic());
534 TopExp::MapShapesAndAncestors(aF,
539 for (i=1; i<=aNbV; ++i) {
540 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMVE.FindKey(i));
541 aPV=BRep_Tool::Pnt(aV);
542 aTol=BRep_Tool::Tolerance(aV);
546 const TopTools_ListOfShape& aLE=aMVE.FindFromIndex(i);
548 for (; aIt.More(); aIt.Next()) {
549 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aIt.Value());
550 const Handle(Geom2d_Curve)& aC2D=
551 BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
552 aT=BRep_Tool::Parameter(aV, aE);
555 aS->D0(aP2D.X(), aP2D.Y(), aP);
556 aD2=aPV.SquareDistance(aP);
560 //check self interference
569 TopExp::Vertices(aE, aV11, aV12);
573 for (; aIt1.More(); aIt1.Next()) {
574 const TopoDS_Edge& aE1=*(TopoDS_Edge*)(&aIt1.Value());
576 //do not perform check for edges that have two common vertices
577 TopExp::Vertices(aE1, aV21, aV22);
578 if ((aV11.IsSame(aV21) && aV12.IsSame(aV22)) ||
579 (aV12.IsSame(aV21) && aV11.IsSame(aV22))) {
583 aD2=IntersectCurves2d(aPV, aF, aS, aE, aE1);
587 }// for (; aIt1.More(); aIt1.Next()) {
588 }// for (; aIt.More(); aIt.Next()) {
593 aBB.UpdateVertex(aV, aTol);
595 }// for (i=1; i<=aNbV; ++i) {
597 //=======================================================================
598 // Function : IntersectCurves2d
599 // purpose : Intersect 2d curves of edges
600 //=======================================================================
601 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
602 const TopoDS_Face& aF,
603 const Handle(Geom_Surface)& aS,
604 const TopoDS_Edge& aE1,
605 const TopoDS_Edge& aE2)
607 Standard_Real aDist, aD, aT11, aT12, aT21, aT22, aTol2d;
608 Standard_Integer j, aNbPnt;
609 Geom2dInt_GInter aInter;
614 aTol2d = Precision::Confusion();
616 const Handle(Geom2d_Curve)& aC2D1=
617 BRep_Tool::CurveOnSurface(aE1, aF, aT11, aT12);
618 const Handle(Geom2d_Curve)& aC2D2=
619 BRep_Tool::CurveOnSurface(aE2, aF, aT21, aT22);
621 Geom2dAdaptor_Curve aGAC1(aC2D1), aGAC2(aC2D2);
622 IntRes2d_Domain aDom1(aC2D1->Value(aT11), aT11, aTol2d,
623 aC2D1->Value(aT12), aT12, aTol2d);
624 IntRes2d_Domain aDom2(aC2D2->Value(aT21), aT21, aTol2d,
625 aC2D2->Value(aT22), aT22, aTol2d);
627 aInter.Perform(aGAC1, aDom1, aGAC2, aDom2, aTol2d, aTol2d);
628 if (aInter.IsDone()) {
629 if (aInter.NbSegments()) {
632 aNbPnt = aInter.NbPoints();
634 aDist = Precision::Infinite();
635 for (j = 1; j <= aNbPnt; ++j) {
636 aP2D = aInter.Point(j).Value();
637 aS->D0(aP2D.X(), aP2D.Y(), aP);
638 aD=aPV.SquareDistance(aP);
647 //=======================================================================
648 // Function : CorrectEdgeTolerance
649 // purpose : Correct tolerances for Edge
650 //=======================================================================
651 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
652 const TopoDS_Face& S,
653 const Standard_Real aMaxTol)
656 // 1. Minimum of conditions to Perform
657 Handle (BRep_CurveRepresentation) myCref;
658 Handle (Adaptor3d_HCurve) myHCurve;
662 Handle(BRep_TEdge)& TEx = *((Handle(BRep_TEdge)*)&myShape.TShape());
663 BRep_ListIteratorOfListOfCurveRepresentation itcrx(TEx->Curves());
664 Standard_Boolean Degenerated, SameParameterx, SameRangex;
666 Standard_Integer unique = 0;
668 Degenerated = TEx->Degenerated();
669 SameParameterx = TEx->SameParameter();
670 SameRangex = TEx->SameRange();
672 if (!SameRangex && SameParameterx) {
676 Handle(Geom_Curve) C3d;
677 while (itcrx.More()) {
678 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
679 if (cr->IsCurve3D()) {
681 if (myCref.IsNull() && !cr->Curve3D().IsNull()) {
689 return;//...No3DCurve
692 return;//...Multiple3DCurve;
695 if (myCref.IsNull() && !Degenerated) {
696 itcrx.Initialize(TEx->Curves());
697 while (itcrx.More()) {
698 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
699 if (cr->IsCurveOnSurface()) {
707 else if (!myCref.IsNull() && Degenerated){
708 return ;//...InvalidDegeneratedFlag;
711 if (!myCref.IsNull()) {
712 const Handle(BRep_GCurve)& GCref =
713 *((Handle(BRep_GCurve)*)&myCref);
714 Standard_Real First,Last;
715 GCref->Range(First,Last);
718 return ;//InvalidRange;
722 if (myCref->IsCurve3D()) {
723 Handle(Geom_Curve) C3dx = Handle(Geom_Curve)::DownCast
724 (myCref->Curve3D()->Transformed
725 (myCref->Location().Transformation()));
726 GeomAdaptor_Curve GAC3d(C3dx, First, Last);
727 myHCurve = new GeomAdaptor_HCurve(GAC3d);
729 else { // curve on surface
730 Handle(Geom_Surface) Sref = myCref->Surface();
731 Sref = Handle(Geom_Surface)::
732 DownCast(Sref->Transformed(myCref->Location().Transformation()));
733 const Handle(Geom2d_Curve)& PCref = myCref->PCurve();
734 Handle(GeomAdaptor_HSurface) GAHSref =
735 new GeomAdaptor_HSurface(Sref);
736 Handle(Geom2dAdaptor_HCurve) GHPCref =
737 new Geom2dAdaptor_HCurve(PCref, First, Last);
738 Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref);
739 myHCurve = new Adaptor3d_HCurveOnSurface(ACSref);
744 //===============================================
745 // 2. Tolerances in InContext
749 Standard_Boolean ok=Standard_True;;
751 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape());
752 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape));
753 Standard_Real aNewTol=Tol;
755 Standard_Boolean SameParameter = TE->SameParameter();
756 Standard_Boolean SameRange = TE->SameRange();
757 Standard_Real First = myHCurve->FirstParameter();
758 Standard_Real Last = myHCurve->LastParameter();
759 Standard_Real Delta =1.e-12;
761 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
762 const TopLoc_Location& Floc = S.Location();
763 const TopLoc_Location& TFloc = TF->Location();
764 const Handle(Geom_Surface)& Su = TF->Surface();
765 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
766 Standard_Boolean pcurvefound = Standard_False;
768 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
769 while (itcr.More()) {
770 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
771 if (cr != myCref && cr->IsCurveOnSurface(Su,L)) {
772 pcurvefound = Standard_True;
773 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
776 if (SameRange && (f != First || l != Last)) {
777 return ;//BRepCheck_InvalidSameRangeFlag;
780 Handle(Geom_Surface) Sb = cr->Surface();
781 Sb = Handle(Geom_Surface)::
782 DownCast (Su->Transformed(L.Transformation()));
783 Handle(Geom2d_Curve) PC = cr->PCurve();
784 Handle(GeomAdaptor_HSurface) GAHS =
785 new GeomAdaptor_HSurface(Sb);
786 Handle(Geom2dAdaptor_HCurve) GHPC =
787 new Geom2dAdaptor_HCurve(PC,f,l);
788 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
789 ok = Validate(myHCurve->Curve(), ACS,
790 Tol, SameParameter, aNewTol);
792 if (aNewTol<aMaxTol) {
793 TE->UpdateTolerance(aNewTol+Delta);
795 CorrectVertexTolerance(myShape);
799 if (cr->IsCurveOnClosedSurface()) {
800 //checkclosed = Standard_True;
801 GHPC->ChangeCurve2d().Load(cr->PCurve2(),f,l); // same bounds
802 ACS.Load(GAHS); // sans doute inutile
803 ACS.Load(GHPC); // meme remarque...
804 ok = Validate(myHCurve->Curve(),ACS,Tol,SameParameter, aNewTol);
806 if (aNewTol<aMaxTol) {
807 TE->UpdateTolerance(aNewTol+Delta);
808 CorrectVertexTolerance(myShape);
817 Handle(Geom_Plane) P;
818 Handle(Standard_Type) styp = Su->DynamicType();
819 if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
820 P = Handle(Geom_Plane)::
821 DownCast(Handle(Geom_RectangularTrimmedSurface)::
822 DownCast(Su)->BasisSurface());
825 P = Handle(Geom_Plane)::DownCast(Su);
827 if (P.IsNull()) { // not a plane
831 else {// on fait la projection a la volee, comme BRep_Tool
832 P = Handle(Geom_Plane)::
833 DownCast(P->Transformed(L.Transformation()));
834 //on projette Cref sur ce plan
835 Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(P);
837 // Dub - Normalement myHCurve est une GeomAdaptor_HCurve
838 GeomAdaptor_Curve& Gac =
839 Handle(GeomAdaptor_HCurve)::DownCast(myHCurve)->ChangeCurve();
840 Handle(Geom_Curve) C3dx = Gac.Curve();
841 Handle(Geom_Curve) ProjOnPlane =
842 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3dx,First,Last),
844 P->Position().Direction(),
847 Handle(GeomAdaptor_HCurve) aHCurve =
848 new GeomAdaptor_HCurve(ProjOnPlane);
850 ProjLib_ProjectedCurve proj(GAHS,aHCurve);
851 Handle(Geom2d_Curve) PC = Geom2dAdaptor::MakeCurve(proj);
852 Handle(Geom2dAdaptor_HCurve) GHPC =
853 new Geom2dAdaptor_HCurve(PC,
854 myHCurve->FirstParameter(),
855 myHCurve->LastParameter());
857 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
859 Standard_Boolean okx = Validate(myHCurve->Curve(),ACS,
860 Tol,Standard_True, aNewTol);
862 if (aNewTol<aMaxTol) {
863 TE->UpdateTolerance(aNewTol+Delta);
864 CorrectVertexTolerance(myShape);
868 }//end of if (!pcurvefound) {
869 } // end of 2. Tolerances in InContext
871 //=======================================================================
872 //function : CorrectVertexTolerance
874 //=======================================================================
875 void CorrectVertexTolerance(const TopoDS_Edge& aE)
877 Standard_Real aTolE, aTolV;
880 aTolE=BRep_Tool::Tolerance(aE);
882 for(; aIt.More(); aIt.Next()) {
883 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aIt.Value());
884 aTolV=BRep_Tool::Tolerance(aV);
886 Handle(BRep_TVertex)& aTV= *((Handle(BRep_TVertex)*)&aV.TShape());
887 aTV->UpdateTolerance(aTolE);
891 //=======================================================================
892 //function : Validate
894 //=======================================================================
895 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
896 const Adaptor3d_Curve& Other,
897 const Standard_Real Tol,
898 const Standard_Boolean SameParameter,
899 Standard_Real& aNewTolerance)
901 Standard_Real First, Last, MaxDistance, aD, Tol2;
903 First = CRef.FirstParameter();
904 Last = CRef.LastParameter();
908 Standard_Integer NCONTROL=23;
909 Standard_Integer i, aNC1=NCONTROL-1;
911 Standard_Boolean aFlag=Standard_False;
912 Standard_Boolean proj = (!SameParameter ||
913 First != Other.FirstParameter() ||
914 Last != Other.LastParameter());
918 for (i = 0; i < NCONTROL; i++) {
919 Standard_Real prm = ((aNC1-i)*First + i*Last)/aNC1;
920 gp_Pnt pref = CRef.Value(prm);
921 gp_Pnt pother = Other.Value(prm);
923 aD=pref.SquareDistance(pother);
926 if (aD>MaxDistance) {
934 aNewTolerance=sqrt(MaxDistance);
942 Extrema_LocateExtPC refd,otherd;
943 Standard_Real OFirst, OLast;
944 OFirst = Other.FirstParameter();
945 OLast = Other.LastParameter();
947 gp_Pnt pd = CRef.Value(First);
948 gp_Pnt pdo = Other.Value(OFirst);
950 aD = pd.SquareDistance(pdo);
952 if (aD>MaxDistance) {
958 pd = CRef.Value(Last);
959 pdo = Other.Value(OLast);
960 aD = pd.SquareDistance(pdo);
961 if (aD > Tol2 && aD > MaxDistance) {
966 refd.Initialize(CRef, First, Last, CRef.Resolution(Tol));
967 otherd.Initialize(Other, OFirst, OLast, Other.Resolution(Tol));
969 for (i = 2; i< aNC1; i++) {
970 Standard_Real rprm = ((aNC1-i)*First + i*Last)/aNC1;
971 gp_Pnt pref = CRef.Value(rprm);
973 Standard_Real oprm = ((aNC1-i)*OFirst + i*OLast)/aNC1;
974 gp_Pnt pother = Other.Value(oprm);
976 refd.Perform(pother,rprm);
977 if (!refd.IsDone() || refd.SquareDistance() > Tol2) {
979 aD=refd.SquareDistance();
980 if (aD > Tol2 && aD>MaxDistance) {
987 otherd.Perform(pref,oprm);
988 if (!otherd.IsDone() || otherd.SquareDistance() > Tol2) {
990 if (otherd.IsDone()) {
991 aD=otherd.SquareDistance();
992 if (aD > Tol2 && aD>MaxDistance) {
1001 aD=sqrt (MaxDistance);
1005 //=======================================================================
1006 // Function : UpdateEdges
1008 //=======================================================================
1009 void UpdateEdges(const TopoDS_Face& aF)
1011 Standard_Real aTolF, aTolE, aTolV;
1012 TopoDS_Iterator aItF, aItW, aItE;
1015 aTolE=aTolF= BRep_Tool::Tolerance(aF);
1016 aItF.Initialize(aF);
1017 for (; aItF.More(); aItF.Next()) {
1018 const TopoDS_Shape& aS = aItF.Value();
1019 if (aS.ShapeType()==TopAbs_WIRE) {
1020 aItW.Initialize(aS);
1021 for (; aItW.More(); aItW.Next()) {
1022 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aItW.Value());
1023 aTolE = BRep_Tool::Tolerance(aE);
1024 if (aTolE < aTolF) {
1025 aBB.UpdateEdge(aE, aTolF);
1028 //UpdateVertices(aE);
1032 const TopoDS_Vertex& aV=*(TopoDS_Vertex*)&aItF.Value();
1033 aTolV = BRep_Tool::Tolerance(aV);
1034 if (aTolV < aTolE) {
1035 aBB.UpdateVertex(aV, aTolF);