From 0034be42c9f1c0a6094aa85e63f3fed80fb81d54 Mon Sep 17 00:00:00 2001 From: asuraven Date: Tue, 13 Jul 2021 17:17:51 +0300 Subject: [PATCH] from patch --- src/BOPTools/BOPTools_AlgoTools_1.cxx | 3 +- src/BRepCheck/BRepCheck_Edge.cxx | 2 +- src/BRepLib/BRepLib_CheckCurveOnSurface.cxx | 55 +++++---- src/BRepLib/BRepLib_CheckCurveOnSurface.hxx | 39 +----- src/BRepLib/BRepLib_ValidateEdge.cxx | 72 ++++++++--- src/BRepLib/BRepLib_ValidateEdge.hxx | 47 +++++--- src/BRepOffset/BRepOffset_SimpleOffset.cxx | 2 +- src/BRepTools/BRepTools.cxx | 13 +- src/GeomLib/GeomLib_CheckCurveOnSurface.cxx | 126 ++++++-------------- src/GeomLib/GeomLib_CheckCurveOnSurface.hxx | 42 ++----- src/IntTools/IntTools_Tools.cxx | 13 +- src/ShapeAnalysis/ShapeAnalysis_Edge.cxx | 10 +- 12 files changed, 199 insertions(+), 225 deletions(-) diff --git a/src/BOPTools/BOPTools_AlgoTools_1.cxx b/src/BOPTools/BOPTools_AlgoTools_1.cxx index 613af81479..987ffcbfce 100644 --- a/src/BOPTools/BOPTools_AlgoTools_1.cxx +++ b/src/BOPTools/BOPTools_AlgoTools_1.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -806,7 +807,7 @@ void CorrectEdgeTolerance (const TopoDS_Edge& myShape, Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape()); Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape)); - Standard_Real aNewTol=Tol; + Standard_Real aNewTol = Tol; Standard_Boolean SameParameter = TE->SameParameter(); Standard_Boolean SameRange = TE->SameRange(); diff --git a/src/BRepCheck/BRepCheck_Edge.cxx b/src/BRepCheck/BRepCheck_Edge.cxx index 48c3b8c56e..a02086a779 100644 --- a/src/BRepCheck/BRepCheck_Edge.cxx +++ b/src/BRepCheck/BRepCheck_Edge.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -294,7 +295,6 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S) case TopAbs_FACE: if (!myCref.IsNull()) { - Standard_Boolean SameParameter = TE->SameParameter(); Standard_Boolean SameRange = TE->SameRange(); // Modified by skv - Tue Apr 27 11:48:13 2004 Begin diff --git a/src/BRepLib/BRepLib_CheckCurveOnSurface.cxx b/src/BRepLib/BRepLib_CheckCurveOnSurface.cxx index c9a3257c81..c6adc33a40 100644 --- a/src/BRepLib/BRepLib_CheckCurveOnSurface.cxx +++ b/src/BRepLib/BRepLib_CheckCurveOnSurface.cxx @@ -12,8 +12,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include +#include #include +#include +#include +#include #include #include #include @@ -36,9 +41,7 @@ BRepLib_CheckCurveOnSurface::BRepLib_CheckCurveOnSurface //function : Init //purpose : //======================================================================= -void BRepLib_CheckCurveOnSurface::Init - (const TopoDS_Edge& theEdge, - const TopoDS_Face& theFace) +void BRepLib_CheckCurveOnSurface::Init(const TopoDS_Edge& theEdge, const TopoDS_Face& theFace) { myCOnSurfGeom.Init(); @@ -53,26 +56,34 @@ void BRepLib_CheckCurveOnSurface::Init return; } - // - TopLoc_Location aLocE, aLocF, aLocC2D; - Standard_Real aFirst = 0.0, aLast = 0.0; - // // 3D curve initialization - const Handle(Geom_Curve)& aC3dTmp = BRep_Tool::Curve(theEdge, aLocE, aFirst, aLast); - const Handle(Geom_Curve) aC3d(Handle(Geom_Curve)::DownCast(aC3dTmp->Transformed(aLocE.Transformation()))); + const Handle(Adaptor3d_Curve) anAdaptor3dCurve = new BRepAdaptor_Curve(theEdge); // Surface initialization - const Handle(Geom_Surface)& aSTmp = BRep_Tool::Surface(theFace, aLocF); - const Handle(Geom_Surface) aS(Handle(Geom_Surface)::DownCast(aSTmp->Transformed(aLocF.Transformation()))); - // + + TopLoc_Location aLocation; + Standard_Real aFirstParam, aLastParam; + + Handle(Geom2d_Curve) aGeom2dCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirstParam, aLastParam); + Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(theFace); + // 2D curves initialization - myPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, aFirst, aLast); + Handle(Adaptor2d_Curve2d) anAdaptorCurve = + new Geom2dAdaptor_Curve(aGeom2dCurve, aFirstParam, aLastParam); + Handle(GeomAdaptor_Surface) aGeomAdaptorSurface = new GeomAdaptor_Surface(aGeomSurface); + + myAdaptorCurveOnSurface = new Adaptor3d_CurveOnSurface(anAdaptorCurve, aGeomAdaptorSurface); if(BRep_Tool::IsClosed(theEdge, theFace)) - myPCurve2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(theEdge.Reversed()), - theFace, aFirst, aLast); + { + Handle(Geom2d_Curve) aGeom2dReversedCurve = + BRep_Tool::CurveOnSurface(TopoDS::Edge(theEdge.Reversed()), theFace, aFirstParam, aLastParam); + Handle(Adaptor2d_Curve2d) anAdaptorReversedCurve = + new Geom2dAdaptor_Curve(aGeom2dReversedCurve, aFirstParam, aLastParam); + myAdaptorCurveOnSurface2 = new Adaptor3d_CurveOnSurface(anAdaptorReversedCurve, aGeomAdaptorSurface); + } - myCOnSurfGeom.Init(aC3d, aS, aFirst, aLast); + myCOnSurfGeom.Init(anAdaptor3dCurve); } //======================================================================= @@ -82,17 +93,17 @@ void BRepLib_CheckCurveOnSurface::Init void BRepLib_CheckCurveOnSurface::Perform(const Standard_Boolean isMultiThread) { // Compute the max distance - Compute(myPCurve, isMultiThread); + Compute(myAdaptorCurveOnSurface, isMultiThread); if (ErrorStatus()) { return; } // - if (!myPCurve2.IsNull()) + if (!myAdaptorCurveOnSurface2.IsNull()) { - // compute max distance for myPCurve2 + // compute max distance for myAdaptorCurveOnSurface2 // (for the second curve on closed surface) - Compute(myPCurve2, isMultiThread); + Compute(myAdaptorCurveOnSurface2, isMultiThread); } } @@ -100,8 +111,8 @@ void BRepLib_CheckCurveOnSurface::Perform(const Standard_Boolean isMultiThread) //function : Compute //purpose : if isTheMTDisabled == TRUE parallelization is not used //======================================================================= -void BRepLib_CheckCurveOnSurface::Compute(const Handle(Geom2d_Curve)& thePCurve, +void BRepLib_CheckCurveOnSurface::Compute(const Handle(Adaptor3d_CurveOnSurface)& theCurveOnSurface, const Standard_Boolean isMultiThread) { - myCOnSurfGeom.Perform(thePCurve, isMultiThread); + myCOnSurfGeom.Perform(theCurveOnSurface, isMultiThread); } diff --git a/src/BRepLib/BRepLib_CheckCurveOnSurface.hxx b/src/BRepLib/BRepLib_CheckCurveOnSurface.hxx index a30aae6521..2de289c3f8 100644 --- a/src/BRepLib/BRepLib_CheckCurveOnSurface.hxx +++ b/src/BRepLib/BRepLib_CheckCurveOnSurface.hxx @@ -38,38 +38,7 @@ public: //! Performs the calculation //! If isMultiThread == Standard_True then computation will be performed in parallel. - Standard_EXPORT void Perform(const Standard_Boolean isMultiThread = Standard_True); - - //! Returns source 3D-Curve - const Handle(Geom_Curve)& Curve() const - { - return myCOnSurfGeom.Curve(); - } - - //! Returns mine 2D-Curve - const Handle(Geom2d_Curve)& PCurve() const - { - return myPCurve; - } - - //! Returns 2nd 2D-Curve (if it exists, e.g. for seam-edge) - const Handle(Geom2d_Curve)& PCurve2() const - { - return myPCurve2; - } - - //! Returns source surface - const Handle(Geom_Surface)& Surface() const - { - return myCOnSurfGeom.Surface(); - } - - //! Returns first and last parameter of the curves - //! (2D- and 3D-curves are considered to have same range) - void Range (Standard_Real& theFirst, Standard_Real& theLast) - { - myCOnSurfGeom.Range(theFirst, theLast); - } + Standard_EXPORT void Perform (const Standard_Boolean isMultiThread = Standard_True); //! Returns true if the max distance has been found Standard_Boolean IsDone() const @@ -105,14 +74,14 @@ protected: //! Computes the max distance for the 3d curve of //! and 2d curve //! If isMultiThread == Standard_True then computation will be performed in parallel. - Standard_EXPORT void Compute (const Handle(Geom2d_Curve)& thePCurve, + Standard_EXPORT void Compute (const Handle(Adaptor3d_CurveOnSurface)& theCurveOnSurface, const Standard_Boolean isMultiThread); private: GeomLib_CheckCurveOnSurface myCOnSurfGeom; - Handle(Geom2d_Curve) myPCurve; - Handle(Geom2d_Curve) myPCurve2; + Handle(Adaptor3d_CurveOnSurface) myAdaptorCurveOnSurface; + Handle(Adaptor3d_CurveOnSurface) myAdaptorCurveOnSurface2; }; #endif // _BRepLib_CheckCurveOnSurface_HeaderFile diff --git a/src/BRepLib/BRepLib_ValidateEdge.cxx b/src/BRepLib/BRepLib_ValidateEdge.cxx index f97a13640e..4cbed66e0f 100644 --- a/src/BRepLib/BRepLib_ValidateEdge.cxx +++ b/src/BRepLib/BRepLib_ValidateEdge.cxx @@ -1,3 +1,4 @@ + // Copyright (c) 2021 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. @@ -11,12 +12,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include #include #include #include +#include #include +#include //============================================================================= //function : BRepLib_ValidateEdge @@ -32,7 +34,8 @@ BRepLib_ValidateEdge::BRepLib_ValidateEdge(Handle(Adaptor3d_Curve) theReferenceC myToleranceForChecking(0), myCalculatedDistance(0), myExitIfToleranceExceeded(Standard_False), - myIsDone(Standard_False) + myIsDone(Standard_False), + myIsExactMethod(Standard_True) { } //============================================================================= @@ -41,7 +44,7 @@ BRepLib_ValidateEdge::BRepLib_ValidateEdge(Handle(Adaptor3d_Curve) theReferenceC //============================================================================= Standard_Boolean BRepLib_ValidateEdge::CheckTolerance(Standard_Real theToleranceToCheck) { - return correctTolerance(theToleranceToCheck) > myCalculatedDistance; + return CorrectTolerance(theToleranceToCheck) > myCalculatedDistance; } //============================================================================= @@ -68,15 +71,15 @@ void BRepLib_ValidateEdge::UpdateTolerance(Standard_Real& theToleranceToUpdate) } //============================================================================= -//function : correctTolerance +//function : CorrectTolerance //purpose : //============================================================================= -Standard_Real BRepLib_ValidateEdge::correctTolerance(Standard_Real theTolerance) +Standard_Real BRepLib_ValidateEdge::CorrectTolerance(Standard_Real theTolerance) { const Handle(Adaptor3d_Surface)& aSurface = myOtherCurve->GetSurface(); - Standard_Real aCurvePrecision = BRepCheck::PrecCurve(*myReferenceCurve); - Standard_Real aSurfacePrecision = BRepCheck::PrecSurface(aSurface); - Standard_Real aToleranceDelta = (aCurvePrecision > aSurfacePrecision) ? aCurvePrecision : aSurfacePrecision; + Standard_Real aCurvePrecition = BRepCheck::PrecCurve(*myReferenceCurve); + Standard_Real aSurfacePrecition = BRepCheck::PrecSurface(aSurface); + Standard_Real aToleranceDelta = (aCurvePrecition > aSurfacePrecition) ? aCurvePrecition : aSurfacePrecition; Standard_Real aCorrectedTolerance = theTolerance + aToleranceDelta; return aCorrectedTolerance; } @@ -88,7 +91,7 @@ Standard_Real BRepLib_ValidateEdge::correctTolerance(Standard_Real theTolerance) void BRepLib_ValidateEdge::SetExitIfToleranceExceeded(Standard_Real theToleranceForChecking) { myExitIfToleranceExceeded = Standard_True; - myToleranceForChecking = correctTolerance(theToleranceForChecking); + myToleranceForChecking = CorrectTolerance(theToleranceForChecking); } //============================================================================= @@ -96,6 +99,22 @@ void BRepLib_ValidateEdge::SetExitIfToleranceExceeded(Standard_Real theTolerance //purpose : //============================================================================= void BRepLib_ValidateEdge::Process() +{ + if (myIsExactMethod && mySameParameter) + { + ProcessExact(); + } + else + { + ProcessApprox(); + } +} + +//============================================================================= +//function : ProcessApprox +//purpose : +//============================================================================= +void BRepLib_ValidateEdge::ProcessApprox() { myIsDone = Standard_True; Standard_Real aSquareToleranceForChecking = myToleranceForChecking * myToleranceForChecking; @@ -126,7 +145,7 @@ void BRepLib_ValidateEdge::Process() // Stop process for best performance if (myExitIfToleranceExceeded && aMaxSquareDistance > aSquareToleranceForChecking) { - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); return; } } @@ -142,7 +161,7 @@ void BRepLib_ValidateEdge::Process() } if (myExitIfToleranceExceeded && aMaxSquareDistance > aSquareToleranceForChecking) { - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); return; } @@ -155,7 +174,7 @@ void BRepLib_ValidateEdge::Process() } if (myExitIfToleranceExceeded && aMaxSquareDistance > aSquareToleranceForChecking) { - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); return; } @@ -165,11 +184,11 @@ void BRepLib_ValidateEdge::Process() for (Standard_Integer i = 1; i < aControlPointsNumber; i++) { Standard_Real aReferenceParam = ((aControlPointsNumber - i) * aReferenceFirstParam + i * aReferenceLastParam) / aControlPointsNumber; - gp_Pnt aReferenceExtremaPoint = myReferenceCurve->Value(aReferenceParam); + gp_Pnt aReferencePoint = myReferenceCurve->Value(aReferenceParam); Standard_Real anOtherParam = ((aControlPointsNumber - i) * anOtherFirstParam + i * anOtherLastParam) / aControlPointsNumber; - gp_Pnt anOtherExtremaPoint = myOtherCurve->Value(anOtherParam); + gp_Pnt anOtherPoint = myOtherCurve->Value(anOtherParam); - aReferenceExtrema.Perform(anOtherExtremaPoint, aReferenceParam); + aReferenceExtrema.Perform(anOtherPoint, aReferenceParam); if (aReferenceExtrema.IsDone()) { if (aReferenceExtrema.SquareDistance() > aMaxSquareDistance) @@ -178,7 +197,7 @@ void BRepLib_ValidateEdge::Process() } if (myExitIfToleranceExceeded && aMaxSquareDistance > aSquareToleranceForChecking) { - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); return; } } @@ -189,7 +208,7 @@ void BRepLib_ValidateEdge::Process() return; } - anOtherExtrema.Perform(aReferenceExtremaPoint, anOtherParam); + anOtherExtrema.Perform(aReferencePoint, anOtherParam); if (anOtherExtrema.IsDone()) { if (anOtherExtrema.SquareDistance() > aMaxSquareDistance) @@ -198,7 +217,7 @@ void BRepLib_ValidateEdge::Process() } if (myExitIfToleranceExceeded && aMaxSquareDistance > aSquareToleranceForChecking) { - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); return; } } @@ -210,5 +229,20 @@ void BRepLib_ValidateEdge::Process() } } } - myCalculatedDistance = Sqrt(aMaxSquareDistance); + myCalculatedDistance = sqrt(aMaxSquareDistance); +} + +//============================================================================= +//function : ProcessExact +//purpose : +//============================================================================= +void BRepLib_ValidateEdge::ProcessExact() +{ + GeomLib_CheckCurveOnSurface aCheckCurveOnSurface(myReferenceCurve); + aCheckCurveOnSurface.Perform(myOtherCurve); + myIsDone = aCheckCurveOnSurface.IsDone(); + if (myIsDone) + { + myCalculatedDistance = aCheckCurveOnSurface.MaxDistance(); + } } diff --git a/src/BRepLib/BRepLib_ValidateEdge.hxx b/src/BRepLib/BRepLib_ValidateEdge.hxx index 48fc25c7f2..b04158b621 100644 --- a/src/BRepLib/BRepLib_ValidateEdge.hxx +++ b/src/BRepLib/BRepLib_ValidateEdge.hxx @@ -21,8 +21,9 @@ class Adaptor3d_Curve; class Adaptor3d_CurveOnSurface; -//! Computes the max distance between 3D-curve and curve on -//! surface in fixed points number +//! Computes the max distance between 3D-curve and curve on surface. +//! This class uses 2 methods: approximate using finite +//! number of points (default) and exact class BRepLib_ValidateEdge { public: @@ -32,42 +33,57 @@ public: Standard_Boolean theSameParameter); //! Set control points number (if you need a value other than 22) - void SetControlPointsNumber(Standard_Integer theControlPointsNumber) + Standard_EXPORT void SetControlPointsNumber(Standard_Integer theControlPointsNumber) { myControlPointsNumber = theControlPointsNumber; } - //! Sets the maximal allowed distance in the Process() function. If the distance greater than - //! theToleranceForChecking the Process() function stops. Use this for best performance - //! in case of checking of tolerance. - Standard_EXPORT void SetExitIfToleranceExceeded(Standard_Real theToleranceForChecking); + //! Sets method to calculate distance: Calculating in finite number of points (if theIsExact + //! is false, faster, but possible not correct result) or exact calculating by using + //! BRepLib_CheckCurveOnSurface class (if theIsExact is true, slowly, but more correctly. + //! Default method is exact + void SetExactMathod(Standard_Boolean theIsExact) + { + myIsExactMethod = theIsExact; + } + + //! Sets limit to compute a distance in the Process() function. If the distance greater than + //! theToleranceForChecking the Process() function stopped. Use this in case checking of + //! tolerance for best performcnce. Has no effect in case using exact method. + void SetExitIfToleranceExceeded(Standard_Real theToleranceForChecking); //! Computes the max distance for the 3d curve //! and curve on surface . If the SetExitIfToleranceExceeded() - //! function was called before contains first - //! greater than SetExitIfToleranceExceeded() parameter value + //! function was called before containts first + //! greater than SetExitIfToleranceExceeded() parameter value. In case + //! using exact method always computes real max distance. Standard_EXPORT void Process(); //! Returns true if the distance has been found for all points - Standard_Boolean IsDone() + Standard_EXPORT Standard_Boolean IsDone() { return myIsDone; } - //! Returns true if computed distance is less than + //! Returns true if compute distance less than Standard_EXPORT Standard_Boolean CheckTolerance(Standard_Real theToleranceToCheck); //! Returns max distance Standard_EXPORT Standard_Real GetMaxDistance(); - //! Increase if max distance is greater than + //! Increace if max distance is greater than Standard_EXPORT void UpdateTolerance(Standard_Real& theToleranceToUpdate); private: //! Adds some margin for distance checking - Standard_Real correctTolerance(Standard_Real theTolerance); + Standard_Real CorrectTolerance(Standard_Real theTolerance); + + //! Calculating in finite number of points + void ProcessApprox(); + + //! Calculating by using BRepLib_CheckCurveOnSurface class + void ProcessExact(); -private: Handle(Adaptor3d_Curve) myReferenceCurve; Handle(Adaptor3d_CurveOnSurface) myOtherCurve; Standard_Boolean mySameParameter; @@ -76,6 +92,7 @@ private: Standard_Real myCalculatedDistance; Standard_Boolean myExitIfToleranceExceeded; Standard_Boolean myIsDone; + Standard_Boolean myIsExactMethod; }; -#endif // _BRepLib_ValidateEdge_HeaderFile \ No newline at end of file +#endif _BRepLib_ValidateEdge_HeaderFile diff --git a/src/BRepOffset/BRepOffset_SimpleOffset.cxx b/src/BRepOffset/BRepOffset_SimpleOffset.cxx index b8d804f7a7..b26071959a 100644 --- a/src/BRepOffset/BRepOffset_SimpleOffset.cxx +++ b/src/BRepOffset/BRepOffset_SimpleOffset.cxx @@ -299,9 +299,9 @@ void BRepOffset_SimpleOffset::FillEdgeData(const TopoDS_Edge& theEdge, // It is necessary to compute maximal deviation (tolerance). BRepLib_ValidateEdge aValidateEdge(aCurve3d, aCurveOnSurf, Standard_True); aValidateEdge.Process(); + Standard_Real aMaxTol1 = aValidateEdge.GetMaxDistance(); if (aValidateEdge.IsDone()) { - Standard_Real aMaxTol1 = aValidateEdge.GetMaxDistance(); anEdgeTol = Max (anEdgeTol, aMaxTol1); } } diff --git a/src/BRepTools/BRepTools.cxx b/src/BRepTools/BRepTools.cxx index 156ca3fb21..6c69c1fbe1 100644 --- a/src/BRepTools/BRepTools.cxx +++ b/src/BRepTools/BRepTools.cxx @@ -15,6 +15,7 @@ // commercial license or contractual agreement. +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1329,9 +1331,16 @@ Standard_Real BRepTools::EvalAndUpdateTol(const TopoDS_Edge& theE, first = Max(first, C2d->FirstParameter()); last = Min(last, C2d->LastParameter()); } + const Handle(Adaptor3d_Curve) aGeomAdaptorCurve = new GeomAdaptor_Curve(C3d, first, last); - GeomLib_CheckCurveOnSurface CT(C3d, S, first, last); - CT.Perform(C2d); + Handle(Adaptor2d_Curve2d) aGeom2dAdaptorCurve = new Geom2dAdaptor_Curve(C2d, first, last); + Handle(GeomAdaptor_Surface) aGeomAdaptorSurface = new GeomAdaptor_Surface(S); + + Handle(Adaptor3d_CurveOnSurface) anAdaptor3dCurveOnSurface = + new Adaptor3d_CurveOnSurface(aGeom2dAdaptorCurve, aGeomAdaptorSurface); + + GeomLib_CheckCurveOnSurface CT(aGeomAdaptorCurve); + CT.Perform(anAdaptor3dCurveOnSurface); if(CT.IsDone()) { newtol = CT.MaxDistance(); diff --git a/src/GeomLib/GeomLib_CheckCurveOnSurface.cxx b/src/GeomLib/GeomLib_CheckCurveOnSurface.cxx index 5693499324..0e5dc24b1b 100644 --- a/src/GeomLib/GeomLib_CheckCurveOnSurface.cxx +++ b/src/GeomLib/GeomLib_CheckCurveOnSurface.cxx @@ -14,16 +14,16 @@ #include -#include #include #include #include +#include #include #include +#include #include #include #include -#include #include #include #include @@ -46,8 +46,8 @@ Standard_Boolean MinComputing( Standard_Real& theBestValue, Standard_Real& theBestParameter); -static Standard_Integer FillSubIntervals( const Handle(Geom_Curve)& theCurve3d, - const Handle(Geom2d_Curve)& theCurve2d, +static Standard_Integer FillSubIntervals( const Handle(Adaptor3d_Curve)& theCurve3d, + const Handle(Adaptor2d_Curve2d)& theCurve2d, const Standard_Real theFirst, const Standard_Real theLast, Standard_Integer &theNbParticles, @@ -61,12 +61,12 @@ class GeomLib_CheckCurveOnSurface_TargetFunc : public math_MultipleVarFunctionWithHessian { public: - GeomLib_CheckCurveOnSurface_TargetFunc( const Adaptor3d_Curve& theC3D, - const Adaptor3d_Curve& theAdCS, + GeomLib_CheckCurveOnSurface_TargetFunc(const Handle(Adaptor3d_Curve)& theC3D, + const Handle(Adaptor3d_Curve)& theCurveOnSurface, const Standard_Real theFirst, const Standard_Real theLast): myCurve1(theC3D), - myCurve2(theAdCS), + myCurve2(theCurveOnSurface), myFirst(theFirst), myLast(theLast) { @@ -96,8 +96,8 @@ class GeomLib_CheckCurveOnSurface_TargetFunc : if (!CheckParameter(theX)) return Standard_False; - const gp_Pnt aP1(myCurve1.Value(theX)), - aP2(myCurve2.Value(theX)); + const gp_Pnt aP1(myCurve1->Value(theX)), + aP2(myCurve2->Value(theX)); theFVal = -1.0*aP1.SquareDistance(aP2); } @@ -139,13 +139,13 @@ class GeomLib_CheckCurveOnSurface_TargetFunc : // if (!theDeriv2) { - myCurve1.D1(theX, aP1, aDC1); - myCurve2.D1(theX, aP2, aDC2); + myCurve1->D1(theX, aP1, aDC1); + myCurve2->D1(theX, aP2, aDC2); } else { - myCurve1.D2(theX, aP1, aDC1, aDCC1); - myCurve2.D2(theX, aP2, aDC2, aDCC2); + myCurve1->D2(theX, aP1, aDC1, aDCC1); + myCurve2->D2(theX, aP2, aDC2, aDCC2); } const gp_Vec aVec1(aP1, aP2), aVec2(aDC2-aDC1); @@ -223,8 +223,8 @@ class GeomLib_CheckCurveOnSurface_TargetFunc : return ((myFirst <= theParam) && (theParam <= myLast)); } - const Adaptor3d_Curve& myCurve1; - const Adaptor3d_Curve& myCurve2; + const Handle(Adaptor3d_Curve)& myCurve1; + const Handle(Adaptor3d_Curve)& myCurve2; const Standard_Real myFirst; const Standard_Real myLast; }; @@ -237,15 +237,13 @@ class GeomLib_CheckCurveOnSurface_Local { public: GeomLib_CheckCurveOnSurface_Local( - const Handle(Geom_Curve)& theCurve3D, - const Handle(Geom2d_Curve)& theCurve2D, - const Handle(Geom_Surface)& theSurface, + const Handle(Adaptor3d_Curve)& theCurve3D, + const Handle(Adaptor3d_Curve)& theCurveOnSurface, const TColStd_Array1OfReal& theIntervalsArr, const Standard_Real theEpsilonRange, const Standard_Integer theNbParticles): myCurve3D(theCurve3D), - myCurve2D(theCurve2D), - mySurface(theSurface), + myCurveOnSurface(theCurveOnSurface), mySubIntervals(theIntervalsArr), myEpsilonRange(theEpsilonRange), myNbParticles(theNbParticles), @@ -261,13 +259,7 @@ public: //This optimal value will be put in corresponding (depending on theIndex - the //identificator of the current interval in mySubIntervals array) cell of //myArrOfDist and myArrOfParam arrays. - const GeomAdaptor_Curve anAC(myCurve3D); - const Handle(Adaptor2d_Curve2d) anAd2dC = new Geom2dAdaptor_Curve(myCurve2D); - const Handle(Adaptor3d_Surface) anAdS = new GeomAdaptor_Surface(mySurface); - - const Adaptor3d_CurveOnSurface anACS(anAd2dC, anAdS); - - GeomLib_CheckCurveOnSurface_TargetFunc aFunc( anAC, anACS, + GeomLib_CheckCurveOnSurface_TargetFunc aFunc(myCurve3D, myCurveOnSurface, mySubIntervals.Value(theIndex), mySubIntervals.Value(theIndex+1)); @@ -303,9 +295,8 @@ public: private: GeomLib_CheckCurveOnSurface_Local operator=(GeomLib_CheckCurveOnSurface_Local&); - const Handle(Geom_Curve)& myCurve3D; - const Handle(Geom2d_Curve)& myCurve2D; - const Handle(Geom_Surface)& mySurface; + const Handle(Adaptor3d_Curve)& myCurve3D; + const Handle(Adaptor3d_Curve)& myCurveOnSurface; const TColStd_Array1OfReal& mySubIntervals; const Standard_Real myEpsilonRange; @@ -320,8 +311,6 @@ private: //======================================================================= GeomLib_CheckCurveOnSurface::GeomLib_CheckCurveOnSurface() : - myFirst(0.), - myLast(0.), myErrorStatus(0), myMaxDistance(RealLast()), myMaxParameter(0.), @@ -334,15 +323,9 @@ GeomLib_CheckCurveOnSurface::GeomLib_CheckCurveOnSurface() //purpose : //======================================================================= GeomLib_CheckCurveOnSurface:: - GeomLib_CheckCurveOnSurface(const Handle(Geom_Curve)& theCurve, - const Handle(Geom_Surface)& theSurface, - const Standard_Real theFirst, - const Standard_Real theLast, + GeomLib_CheckCurveOnSurface(const Handle(Adaptor3d_Curve)& theCurve, const Standard_Real theTolRange): myCurve(theCurve), - mySurface(theSurface), - myFirst(theFirst), - myLast(theLast), myErrorStatus(0), myMaxDistance(RealLast()), myMaxParameter(0.), @@ -357,9 +340,6 @@ GeomLib_CheckCurveOnSurface:: void GeomLib_CheckCurveOnSurface::Init() { myCurve.Nullify(); - mySurface.Nullify(); - myFirst = 0.0; - myLast = 0.0; myErrorStatus = 0; myMaxDistance = RealLast(); myMaxParameter = 0.0; @@ -370,16 +350,10 @@ void GeomLib_CheckCurveOnSurface::Init() //function : Init //purpose : //======================================================================= -void GeomLib_CheckCurveOnSurface::Init( const Handle(Geom_Curve)& theCurve, - const Handle(Geom_Surface)& theSurface, - const Standard_Real theFirst, - const Standard_Real theLast, +void GeomLib_CheckCurveOnSurface::Init( const Handle(Adaptor3d_Curve)& theCurve, const Standard_Real theTolRange) { myCurve = theCurve; - mySurface = theSurface; - myFirst = theFirst; - myLast = theLast; myErrorStatus = 0; myMaxDistance = RealLast(); myMaxParameter = 0.0; @@ -390,26 +364,16 @@ void GeomLib_CheckCurveOnSurface::Init( const Handle(Geom_Curve)& theCurve, //function : Perform //purpose : //======================================================================= -void GeomLib_CheckCurveOnSurface::Perform(const Handle(Geom2d_Curve)& thePCurve, +void GeomLib_CheckCurveOnSurface::Perform(const Handle(Adaptor3d_CurveOnSurface)& theCurveOnSurface, const Standard_Boolean isMultiThread) { if( myCurve.IsNull() || - mySurface.IsNull() || - thePCurve.IsNull()) + theCurveOnSurface.IsNull()) { myErrorStatus = 1; return; } - if(((myCurve->FirstParameter() - myFirst) > myTolRange) || - ((myCurve->LastParameter() - myLast) < -myTolRange) || - ((thePCurve->FirstParameter() - myFirst) > myTolRange) || - ((thePCurve->LastParameter() - myLast) < -myTolRange)) - { - myErrorStatus = 2; - return; - } - const Standard_Real anEpsilonRange = 1.e-3; Standard_Integer aNbParticles = 3; @@ -422,8 +386,8 @@ void GeomLib_CheckCurveOnSurface::Perform(const Handle(Geom2d_Curve)& thePCurve, //number of particles should be equal to n. const Standard_Integer aNbSubIntervals = - FillSubIntervals( myCurve, thePCurve, - myFirst, myLast, aNbParticles); + FillSubIntervals( myCurve, theCurveOnSurface->GetCurve(), + myCurve->FirstParameter(), myCurve->LastParameter(), aNbParticles); if(!aNbSubIntervals) { @@ -435,12 +399,13 @@ void GeomLib_CheckCurveOnSurface::Perform(const Handle(Geom2d_Curve)& thePCurve, OCC_CATCH_SIGNALS TColStd_Array1OfReal anIntervals(1, aNbSubIntervals+1); - FillSubIntervals(myCurve, thePCurve, myFirst, myLast, aNbParticles, &anIntervals); + FillSubIntervals(myCurve, theCurveOnSurface->GetCurve(), + myCurve->FirstParameter(), myCurve->LastParameter(), aNbParticles, &anIntervals); - GeomLib_CheckCurveOnSurface_Local aComp(myCurve, thePCurve, - mySurface, anIntervals, anEpsilonRange, aNbParticles); + GeomLib_CheckCurveOnSurface_Local aComp(myCurve,theCurveOnSurface, anIntervals, + anEpsilonRange, aNbParticles); - OSD_Parallel::For(anIntervals.Lower(), anIntervals.Upper(), aComp, !isMultiThread); + OSD_Parallel::For(anIntervals.Lower(), anIntervals.Upper(), aComp, false/*!isMultiThread*/); aComp.OptimalValues(myMaxDistance, myMaxParameter); @@ -458,8 +423,8 @@ void GeomLib_CheckCurveOnSurface::Perform(const Handle(Geom2d_Curve)& thePCurve, // (fills theSubIntervals array). // Returns number of subintervals. //======================================================================= -Standard_Integer FillSubIntervals(const Handle(Geom_Curve)& theCurve3d, - const Handle(Geom2d_Curve)& theCurve2d, +Standard_Integer FillSubIntervals(const Handle(Adaptor3d_Curve)& theCurve3d, + const Handle(Adaptor2d_Curve2d)& theCurve2d, const Standard_Real theFirst, const Standard_Real theLast, Standard_Integer &theNbParticles, @@ -475,28 +440,13 @@ Standard_Integer FillSubIntervals(const Handle(Geom_Curve)& theCurve3d, Standard_Boolean isTrimmed3D = Standard_False, isTrimmed2D = Standard_False; // - if (theCurve3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) - { - aBS3DCurv = Handle(Geom_BSplineCurve):: - DownCast(Handle(Geom_TrimmedCurve):: - DownCast(theCurve3d)->BasisCurve()); - isTrimmed3D = Standard_True; - } - else + if (theCurve3d->GetType() == GeomAbs_BSplineCurve) { - aBS3DCurv = Handle(Geom_BSplineCurve)::DownCast(theCurve3d); + aBS3DCurv = theCurve3d->BSpline(); } - - if (theCurve2d->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) - { - aBS2DCurv = Handle(Geom2d_BSplineCurve):: - DownCast(Handle(Geom2d_TrimmedCurve):: - DownCast(theCurve2d)->BasisCurve()); - isTrimmed2D = Standard_True; - } - else + if (theCurve2d->GetType() == GeomAbs_BSplineCurve) { - aBS2DCurv = Handle(Geom2d_BSplineCurve)::DownCast(theCurve2d); + aBS2DCurv = theCurve2d->BSpline(); } Handle(TColStd_HArray1OfReal) anArrKnots3D, anArrKnots2D; diff --git a/src/GeomLib/GeomLib_CheckCurveOnSurface.hxx b/src/GeomLib/GeomLib_CheckCurveOnSurface.hxx index 1e89a2191a..01ebf359cc 100644 --- a/src/GeomLib/GeomLib_CheckCurveOnSurface.hxx +++ b/src/GeomLib/GeomLib_CheckCurveOnSurface.hxx @@ -15,10 +15,13 @@ #ifndef _GeomLib_CheckCurveOnSurface_HeaderFile #define _GeomLib_CheckCurveOnSurface_HeaderFile -#include +#include #include #include +class GeomAdaptor_Curve; +class Adaptor2d_Curve2d; +class Adaptor3d_CurveOnSurface; class Geom_Surface; class Geom2d_Curve; @@ -35,18 +38,12 @@ public: //! Constructor Standard_EXPORT - GeomLib_CheckCurveOnSurface(const Handle(Geom_Curve)& theCurve, - const Handle(Geom_Surface)& theSurface, - const Standard_Real theFirst, - const Standard_Real theLast, + GeomLib_CheckCurveOnSurface(const Handle(Adaptor3d_Curve)& theCurve, const Standard_Real theTolRange = Precision::PConfusion()); //! Sets the data for the algorithm - Standard_EXPORT void Init (const Handle(Geom_Curve)& theCurve, - const Handle(Geom_Surface)& theSurface, - const Standard_Real theFirst, - const Standard_Real theLast, + Standard_EXPORT void Init (const Handle(Adaptor3d_Curve)& theCurve, const Standard_Real theTolRange = Precision::PConfusion()); //! Initializes all members by default values @@ -55,29 +52,9 @@ public: //! Computes the max distance for the 3d curve //! and 2d curve //! If isMultiThread == Standard_True then computation will be performed in parallel. - Standard_EXPORT void Perform(const Handle(Geom2d_Curve)& thePCurve, + Standard_EXPORT void Perform(const Handle(Adaptor3d_CurveOnSurface)& theCurveOnSurface, const Standard_Boolean isMultiThread = Standard_True); - //! Returns my3DCurve - const Handle(Geom_Curve)& Curve() const - { - return myCurve; - } - - //! Returns mySurface - const Handle(Geom_Surface)& Surface() const - { - return mySurface; - } - - //! Returns first and last parameter of the curves - //! (2D- and 3D-curves are considered to have same range) - void Range (Standard_Real& theFirst, Standard_Real& theLast) - { - theFirst = myFirst; - theLast = myLast; - } - //! Returns true if the max distance has been found Standard_Boolean IsDone() const { @@ -109,10 +86,7 @@ public: private: - Handle(Geom_Curve) myCurve; - Handle(Geom_Surface) mySurface; - Standard_Real myFirst; - Standard_Real myLast; + Handle(Adaptor3d_Curve) myCurve; Standard_Integer myErrorStatus; Standard_Real myMaxDistance; Standard_Real myMaxParameter; diff --git a/src/IntTools/IntTools_Tools.cxx b/src/IntTools/IntTools_Tools.cxx index a50033b0a7..bf7b91e634 100644 --- a/src/IntTools/IntTools_Tools.cxx +++ b/src/IntTools/IntTools_Tools.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -797,8 +798,16 @@ Standard_Boolean IntTools_Tools::ComputeTolerance { GeomLib_CheckCurveOnSurface aCS; // - aCS.Init(theCurve3D, theSurf, theFirst, theLast, theTolRange); - aCS.Perform (theCurve2D, theToRunParallel); + const Handle(Adaptor3d_Curve) aGeomAdaptorCurve = new GeomAdaptor_Curve(theCurve3D, theFirst, theLast); + + Handle(Adaptor2d_Curve2d) aGeom2dAdaptorCurve = new Geom2dAdaptor_Curve(theCurve2D, theFirst, theLast); + Handle(GeomAdaptor_Surface) aGeomAdaptorSurface = new GeomAdaptor_Surface(theSurf); + + Handle(Adaptor3d_CurveOnSurface) anAdaptor3dCurveOnSurface = + new Adaptor3d_CurveOnSurface(aGeom2dAdaptorCurve, aGeomAdaptorSurface); + + aCS.Init(aGeomAdaptorCurve, theTolRange); + aCS.Perform(anAdaptor3dCurveOnSurface, theToRunParallel); if (!aCS.IsDone()) { return Standard_False; } diff --git a/src/ShapeAnalysis/ShapeAnalysis_Edge.cxx b/src/ShapeAnalysis/ShapeAnalysis_Edge.cxx index 77c4b1d178..b6c8cbee6b 100644 --- a/src/ShapeAnalysis/ShapeAnalysis_Edge.cxx +++ b/src/ShapeAnalysis/ShapeAnalysis_Edge.cxx @@ -830,11 +830,11 @@ Standard_Boolean ShapeAnalysis_Edge::CheckSameParameter (const TopoDS_Edge& edge Handle(Adaptor3d_CurveOnSurface) ACS = new Adaptor3d_CurveOnSurface(GHPC, GAHS); - BRepLib_ValidateEdge aValidateEdgeOnPlane(aGAC, ACS, SameParameter); - aValidateEdgeOnPlane.SetControlPointsNumber(NbControl - 1); - aValidateEdgeOnPlane.Process(); - aValidateEdgeOnPlane.UpdateTolerance(maxdev); - if (!aValidateEdgeOnPlane.IsDone()) + BRepLib_ValidateEdge aValidateEdge(aGAC, ACS, Standard_True); + aValidateEdge.SetControlPointsNumber(NbControl - 1); + aValidateEdge.Process(); + aValidateEdge.UpdateTolerance(maxdev); + if (!aValidateEdge.IsDone()) { myStatus |= ShapeExtend::EncodeStatus(ShapeExtend_FAIL2); } -- 2.39.5