Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:56

0001 // Created on: 1995-07-18
0002 // Created by: Modelistation
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Extrema_GGenExtPC_HeaderFile
0018 #define _Extrema_GGenExtPC_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <math_FunctionRoots.hxx>
0024 #include <StdFail_NotDone.hxx>
0025 #include <Standard_OutOfRange.hxx>
0026 
0027 //! Generic class for finding extremal distances between a point and a curve.
0028 //!
0029 //! This template class searches for all parameter values u where the distance
0030 //! function F(u) = distance(P, C(u)) has an extremum, i.e., where dF/du = 0.
0031 //!
0032 //! @tparam TheCurve   The curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d)
0033 //! @tparam TheTool    The curve tool providing static methods (FirstParameter, LastParameter)
0034 //! @tparam ThePOnC    The point-on-curve type (e.g., Extrema_POnCurv, Extrema_POnCurv2d)
0035 //! @tparam ThePoint   The point type (e.g., gp_Pnt, gp_Pnt2d)
0036 //! @tparam ThePCF     The point-curve function type for extremum computation
0037 template <typename TheCurve, typename TheTool, typename ThePOnC, typename ThePoint, typename ThePCF>
0038 class Extrema_GGenExtPC
0039 {
0040 public:
0041   DEFINE_STANDARD_ALLOC
0042 
0043   //! Default constructor.
0044   Extrema_GGenExtPC()
0045       : myDone(false),
0046         myInit(false),
0047         mynbsample(0),
0048         myumin(0.0),
0049         myusup(0.0),
0050         mytolu(0.0),
0051         mytolF(0.0)
0052   {
0053   }
0054 
0055   //! Calculates all extremum distances between point P and curve C.
0056   //! @param theP       The point
0057   //! @param theC       The curve
0058   //! @param theNbSample Number of sample points for root finding
0059   //! @param theTolU    Tolerance on parameter u
0060   //! @param theTolF    Tolerance on function value
0061   Extrema_GGenExtPC(const ThePoint& theP,
0062                     const TheCurve& theC,
0063                     const int       theNbSample,
0064                     const double    theTolU,
0065                     const double    theTolF)
0066       : myF(theP, theC)
0067   {
0068     Initialize(theC, theNbSample, theTolU, theTolF);
0069     Perform(theP);
0070   }
0071 
0072   //! Calculates all extremum distances in a given parameter range.
0073   //! @param theP       The point
0074   //! @param theC       The curve
0075   //! @param theNbSample Number of sample points for root finding
0076   //! @param theUmin    Lower bound of parameter range
0077   //! @param theUsup    Upper bound of parameter range
0078   //! @param theTolU    Tolerance on parameter u
0079   //! @param theTolF    Tolerance on function value
0080   Extrema_GGenExtPC(const ThePoint& theP,
0081                     const TheCurve& theC,
0082                     const int       theNbSample,
0083                     const double    theUmin,
0084                     const double    theUsup,
0085                     const double    theTolU,
0086                     const double    theTolF)
0087       : myF(theP, theC)
0088   {
0089     Initialize(theC, theNbSample, theUmin, theUsup, theTolU, theTolF);
0090     Perform(theP);
0091   }
0092 
0093   //! Initializes the algorithm with the full curve parameter range.
0094   //! @param theC       The curve
0095   //! @param theNbU     Number of sample points
0096   //! @param theTolU    Tolerance on parameter u
0097   //! @param theTolF    Tolerance on function value
0098   void Initialize(const TheCurve& theC,
0099                   const int       theNbU,
0100                   const double    theTolU,
0101                   const double    theTolF)
0102   {
0103     myInit     = true;
0104     mynbsample = theNbU;
0105     mytolu     = theTolU;
0106     mytolF     = theTolF;
0107     myF.Initialize(theC);
0108     myumin = TheTool::FirstParameter(theC);
0109     myusup = TheTool::LastParameter(theC);
0110   }
0111 
0112   //! Initializes the algorithm with a specified parameter range.
0113   //! @param theC       The curve
0114   //! @param theNbU     Number of sample points
0115   //! @param theUmin    Lower bound of parameter range
0116   //! @param theUsup    Upper bound of parameter range
0117   //! @param theTolU    Tolerance on parameter u
0118   //! @param theTolF    Tolerance on function value
0119   void Initialize(const TheCurve& theC,
0120                   const int       theNbU,
0121                   const double    theUmin,
0122                   const double    theUsup,
0123                   const double    theTolU,
0124                   const double    theTolF)
0125   {
0126     myInit     = true;
0127     mynbsample = theNbU;
0128     mytolu     = theTolU;
0129     mytolF     = theTolF;
0130     myF.Initialize(theC);
0131     myumin = theUmin;
0132     myusup = theUsup;
0133   }
0134 
0135   //! Initializes only the parameter range and tolerances.
0136   //! @param theNbU     Number of sample points
0137   //! @param theUmin    Lower bound of parameter range
0138   //! @param theUsup    Upper bound of parameter range
0139   //! @param theTolU    Tolerance on parameter u
0140   //! @param theTolF    Tolerance on function value
0141   void Initialize(const int    theNbU,
0142                   const double theUmin,
0143                   const double theUsup,
0144                   const double theTolU,
0145                   const double theTolF)
0146   {
0147     mynbsample = theNbU;
0148     mytolu     = theTolU;
0149     mytolF     = theTolF;
0150     myumin     = theUmin;
0151     myusup     = theUsup;
0152   }
0153 
0154   //! Initializes the curve for the function.
0155   //! @param theC The curve
0156   void Initialize(const TheCurve& theC) { myF.Initialize(theC); }
0157 
0158   //! Performs the extremum search for the given point.
0159   //! @param theP The point to find extrema from
0160   void Perform(const ThePoint& theP)
0161   {
0162     myF.SetPoint(theP);
0163     myF.SubIntervalInitialize(myumin, myusup);
0164     myDone = false;
0165 
0166     math_FunctionRoots S(myF, myumin, myusup, mynbsample, mytolu, mytolF, mytolF);
0167     if (!S.IsDone() || S.IsAllNull())
0168     {
0169       return;
0170     }
0171 
0172     myDone = true;
0173   }
0174 
0175   //! Returns true if the distances are found.
0176   bool IsDone() const { return myDone; }
0177 
0178   //! Returns the number of extremum distances.
0179   //! @return Number of extrema found
0180   int NbExt() const
0181   {
0182     if (!IsDone())
0183     {
0184       throw StdFail_NotDone();
0185     }
0186     return myF.NbExt();
0187   }
0188 
0189   //! Returns the Nth extremum square distance.
0190   //! @param theN Index of the extremum (1-based)
0191   //! @return Square distance value
0192   double SquareDistance(const int theN) const
0193   {
0194     if ((theN < 1) || (theN > NbExt()))
0195     {
0196       throw Standard_OutOfRange();
0197     }
0198     return myF.SquareDistance(theN);
0199   }
0200 
0201   //! Returns true if the Nth extremum distance is a minimum.
0202   //! @param theN Index of the extremum (1-based)
0203   //! @return true if minimum, false if maximum
0204   bool IsMin(const int theN) const
0205   {
0206     if ((theN < 1) || (theN > NbExt()))
0207     {
0208       throw Standard_OutOfRange();
0209     }
0210     return myF.IsMin(theN);
0211   }
0212 
0213   //! Returns the point of the Nth extremum distance.
0214   //! @param theN Index of the extremum (1-based)
0215   //! @return The point on curve
0216   const ThePOnC& Point(const int theN) const
0217   {
0218     if ((theN < 1) || (theN > NbExt()))
0219     {
0220       throw Standard_OutOfRange();
0221     }
0222     return myF.Point(theN);
0223   }
0224 
0225 private:
0226   bool   myDone;
0227   bool   myInit;
0228   int    mynbsample;
0229   double myumin;
0230   double myusup;
0231   double mytolu;
0232   double mytolF;
0233   ThePCF myF;
0234 };
0235 
0236 #endif // _Extrema_GGenExtPC_HeaderFile