Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:17:24

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_GenLocateExtPC_HeaderFile
0018 #define _Extrema_GenLocateExtPC_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <math_FunctionRoot.hxx>
0024 #include <StdFail_NotDone.hxx>
0025 
0026 #include <cmath>
0027 
0028 //! Template class for local extremum search between a point and a curve.
0029 //! Searches for a local extremum of distance between a point and a curve
0030 //! near an initial parameter value.
0031 //!
0032 //! @tparam TheCurve   Curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d, void*)
0033 //! @tparam TheTool    Tool for curve operations (e.g., Extrema_CurveTool, Extrema_Curve2dTool)
0034 //! @tparam ThePOnC    Point on curve type (e.g., Extrema_POnCurv, Extrema_POnCurv2d)
0035 //! @tparam ThePnt     Point type (e.g., gp_Pnt, gp_Pnt2d)
0036 //! @tparam ThePCLocF  Function type for root finding
0037 template <typename TheCurve,
0038           typename TheTool,
0039           typename ThePOnC,
0040           typename ThePnt,
0041           typename ThePCLocF>
0042 class Extrema_GenLocateExtPC
0043 {
0044 public:
0045   DEFINE_STANDARD_ALLOC
0046 
0047   //! Default constructor.
0048   Extrema_GenLocateExtPC()
0049       : myDone(false),
0050         mytolU(0.0),
0051         myumin(0.0),
0052         myusup(0.0)
0053   {
0054   }
0055 
0056   //! Calculates the distance with a close point.
0057   //! The close point is defined by the parameter value U0.
0058   //! The function F(u)=distance(P,C(u)) has an extremum
0059   //! when g(u)=dF/du=0. The algorithm searches a zero
0060   //! near the close point.
0061   //! TolU is used to decide to stop the iterations.
0062   //! At the nth iteration, the criteria is:
0063   //! abs(Un - Un-1) < TolU.
0064   Extrema_GenLocateExtPC(const ThePnt&   theP,
0065                          const TheCurve& theC,
0066                          const double    theU0,
0067                          const double    theTolU)
0068   {
0069     Initialize(theC, TheTool::FirstParameter(theC), TheTool::LastParameter(theC), theTolU);
0070     Perform(theP, theU0);
0071   }
0072 
0073   //! Calculates the distance with a close point.
0074   //! The close point is defined by the parameter value U0.
0075   //! The function F(u)=distance(P,C(u)) has an extremum
0076   //! when g(u)=dF/du=0. The algorithm searches a zero
0077   //! near the close point.
0078   //! Zeros are searched between Umin and Usup.
0079   //! TolU is used to decide to stop the iterations.
0080   //! At the nth iteration, the criteria is:
0081   //! abs(Un - Un-1) < TolU.
0082   Extrema_GenLocateExtPC(const ThePnt&   theP,
0083                          const TheCurve& theC,
0084                          const double    theU0,
0085                          const double    theUmin,
0086                          const double    theUsup,
0087                          const double    theTolU)
0088   {
0089     Initialize(theC, theUmin, theUsup, theTolU);
0090     Perform(theP, theU0);
0091   }
0092 
0093   //! Sets the fields of the algorithm.
0094   void Initialize(const TheCurve& theC,
0095                   const double    theUmin,
0096                   const double    theUsup,
0097                   const double    theTolU)
0098   {
0099     myDone = false;
0100     myF.Initialize(theC);
0101     myumin = theUmin;
0102     myusup = theUsup;
0103     mytolU = theTolU;
0104   }
0105 
0106   //! The algorithm is done with the point P.
0107   //! An exception is raised if the fields have not been initialized.
0108   void Perform(const ThePnt& theP, const double theU0)
0109   {
0110     myF.SetPoint(theP);
0111     math_FunctionRoot S(myF, theU0, mytolU, myumin, myusup);
0112     myDone = S.IsDone();
0113     if (myDone)
0114     {
0115       double         uu, ff;
0116       const ThePOnC& PP = Point();
0117       uu                = PP.Parameter();
0118       if (myF.Value(uu, ff))
0119       {
0120         if (std::abs(ff) >= 1.e-07)
0121           myDone = false;
0122       }
0123       else
0124         myDone = false;
0125     }
0126   }
0127 
0128   //! Returns True if the distance is found.
0129   bool IsDone() const { return myDone; }
0130 
0131   //! Returns the value of the extremum square distance.
0132   double SquareDistance() const
0133   {
0134     if (!IsDone())
0135     {
0136       throw StdFail_NotDone();
0137     }
0138     return myF.SquareDistance(1);
0139   }
0140 
0141   //! Returns True if the extremum distance is a minimum.
0142   bool IsMin() const
0143   {
0144     if (!IsDone())
0145     {
0146       throw StdFail_NotDone();
0147     }
0148     return myF.IsMin(1);
0149   }
0150 
0151   //! Returns the point of the extremum distance.
0152   const ThePOnC& Point() const
0153   {
0154     if (!IsDone())
0155     {
0156       throw StdFail_NotDone();
0157     }
0158     return myF.Point(1);
0159   }
0160 
0161 private:
0162   bool      myDone;
0163   double    mytolU;
0164   double    myumin;
0165   double    myusup;
0166   ThePCLocF myF;
0167 };
0168 
0169 #endif // _Extrema_GenLocateExtPC_HeaderFile