Back to home page

EIC code displayed by LXR

 
 

    


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

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_GenLocateExtCC_HeaderFile
0018 #define _Extrema_GenLocateExtCC_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <math_FunctionSetRoot.hxx>
0024 #include <math_Vector.hxx>
0025 #include <StdFail_NotDone.hxx>
0026 
0027 //! Template class for locating local extremum of distance between two curves.
0028 //! Searches for a pair of parameter values (U,V) such that dist(C1(u),C2(v))
0029 //! passes through an extremum, and (U,V) is the solution closest to (U0,V0).
0030 //!
0031 //! @tparam TheCurve   Curve type (e.g., Adaptor3d_Curve, Adaptor2d_Curve2d)
0032 //! @tparam TheTool    Tool for curve operations
0033 //! @tparam ThePOnC    Point on curve type
0034 //! @tparam TheCCLocF  Function type for curve-curve local extremum
0035 template <typename TheCurve, typename TheTool, typename ThePOnC, typename TheCCLocF>
0036 class Extrema_GenLocateExtCC
0037 {
0038 public:
0039   DEFINE_STANDARD_ALLOC
0040 
0041   //! Calculates the distance between two curves C1 and C2.
0042   //! Searches for a local extremum starting from initial parameters (U0, V0).
0043   //! @param theC1   First curve
0044   //! @param theC2   Second curve
0045   //! @param theU0   Initial parameter on first curve
0046   //! @param theV0   Initial parameter on second curve
0047   //! @param theTolU Tolerance on parameter of first curve
0048   //! @param theTolV Tolerance on parameter of second curve
0049   Extrema_GenLocateExtCC(const TheCurve& theC1,
0050                          const TheCurve& theC2,
0051                          const double    theU0,
0052                          const double    theV0,
0053                          const double    theTolU,
0054                          const double    theTolV)
0055   {
0056     myDone   = false;
0057     mySqDist = RealLast();
0058 
0059     double Uinf = TheTool::FirstParameter(theC1);
0060     double Usup = TheTool::LastParameter(theC1);
0061     double Uu;
0062     if (Uinf > Usup)
0063     {
0064       Uu   = Uinf;
0065       Uinf = Usup;
0066       Usup = Uu;
0067     }
0068 
0069     double Vinf = TheTool::FirstParameter(theC2);
0070     double Vsup = TheTool::LastParameter(theC2);
0071     if (Vinf > Vsup)
0072     {
0073       Uu   = Vinf;
0074       Vinf = Vsup;
0075       Vsup = Uu;
0076     }
0077 
0078     TheCCLocF   F(theC1, theC2);
0079     math_Vector Tol(1, 2);
0080     Tol(1)      = theTolU;
0081     Tol(2)      = theTolV;
0082     double Tolf = 1.e-10;
0083 
0084     math_Vector Start(1, 2);
0085     math_Vector Uuinf(1, 2);
0086     math_Vector Uusup(1, 2);
0087 
0088     Start(1) = theU0;
0089     Start(2) = theV0;
0090 
0091     Uuinf(1) = Uinf;
0092     Uuinf(2) = Vinf;
0093     Uusup(1) = Usup;
0094     Uusup(2) = Vsup;
0095 
0096     math_FunctionSetRoot S(F, Tol);
0097     S.Perform(F, Start, Uuinf, Uusup);
0098 
0099     if (S.IsDone() && F.NbExt() > 0)
0100     {
0101       mySqDist = F.SquareDistance(1);
0102       F.Points(1, myPoint1, myPoint2);
0103       Start(1) = myPoint1.Parameter();
0104       Start(2) = myPoint2.Parameter();
0105       math_Vector Ff(1, 2);
0106       F.Value(Start, Ff);
0107       if ((Ff(1) < Tolf) && (Ff(2) < Tolf))
0108         myDone = true;
0109     }
0110   }
0111 
0112   //! Returns True if the distance is found.
0113   bool IsDone() const { return myDone; }
0114 
0115   //! Returns the value of the extremum square distance.
0116   double SquareDistance() const
0117   {
0118     if (!IsDone())
0119     {
0120       throw StdFail_NotDone();
0121     }
0122     return mySqDist;
0123   }
0124 
0125   //! Returns the points of the extremum distance.
0126   //! @param theP1 Point on first curve
0127   //! @param theP2 Point on second curve
0128   void Point(ThePOnC& theP1, ThePOnC& theP2) const
0129   {
0130     if (!IsDone())
0131     {
0132       throw StdFail_NotDone();
0133     }
0134     theP1 = myPoint1;
0135     theP2 = myPoint2;
0136   }
0137 
0138 private:
0139   bool    myDone;
0140   double  mySqDist;
0141   ThePOnC myPoint1;
0142   ThePOnC myPoint2;
0143 };
0144 
0145 #endif // _Extrema_GenLocateExtCC_HeaderFile