Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:27:58

0001 // Created on: 1992-03-26
0002 // Created by: Herve LEGRAND
0003 // Copyright (c) 1992-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 _GeomLProp_CLProps_HeaderFile
0018 #define _GeomLProp_CLProps_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 #include <Standard_OutOfRange.hxx>
0024 
0025 #include <gp_Pnt.hxx>
0026 #include <gp_Pnt2d.hxx>
0027 #include <gp_Vec.hxx>
0028 #include <gp_Vec2d.hxx>
0029 #include <gp_Dir.hxx>
0030 #include <gp_Dir2d.hxx>
0031 #include <LProp_Status.hxx>
0032 
0033 #include <Geom_Curve.hxx>
0034 #include <Geom2d_Curve.hxx>
0035 #include <LProp_CurveUtils.hxx>
0036 
0037 //! Implementation class for computing local properties of a curve:
0038 //! point, derivatives up to order 3, tangent, curvature, normal,
0039 //! and centre of curvature.
0040 //! Parameterized by geometric types (Pnt/Vec/Dir) and curve type.
0041 //! @tparam Pnt the point type (gp_Pnt for 3D, gp_Pnt2d for 2D)
0042 //! @tparam Vec the vector type (gp_Vec for 3D, gp_Vec2d for 2D)
0043 //! @tparam Dir the direction type (gp_Dir for 3D, gp_Dir2d for 2D)
0044 //! @tparam CurveType the curve storage type
0045 //! @tparam Access the access policy for evaluating curve derivatives
0046 template <typename Pnt,
0047           typename Vec,
0048           typename Dir,
0049           typename CurveType,
0050           typename Access = LProp_CurveUtils::DirectAccess>
0051 class GeomLProp_CLPropsBase
0052 {
0053 public:
0054   DEFINE_STANDARD_ALLOC
0055 
0056   //! Initializes the local properties of the curve <C>
0057   //! The current point and the derivatives are
0058   //! computed at the same time, which allows an
0059   //! optimization of the computation time.
0060   //! <N> indicates the maximum number of derivations to
0061   //! be done (0, 1, 2 or 3). For example, to compute
0062   //! only the tangent, N should be equal to 1.
0063   //! <Resolution> is the linear tolerance (it is used to test
0064   //! if a vector is null).
0065   GeomLProp_CLPropsBase(const CurveType& C, const int N, const double Resolution)
0066       : myCurve(C),
0067         myU(RealLast()),
0068         myDerOrder(N),
0069         myCN(4),
0070         myLinTol(Resolution),
0071         myTangentStatus(LProp_Undecided)
0072   {
0073     Standard_OutOfRange_Raise_if(N < 0 || N > 3, "GeomLProp_CLProps::GeomLProp_CLProps()");
0074   }
0075 
0076   //! Same as previous constructor but here the parameter is
0077   //! set to the value <U>.
0078   //! All the computations done will be related to <C> and <U>.
0079   GeomLProp_CLPropsBase(const CurveType& C, const double U, const int N, const double Resolution)
0080       : myCurve(C),
0081         myDerOrder(N),
0082         myCN(4),
0083         myLinTol(Resolution),
0084         myTangentStatus(LProp_Undecided)
0085   {
0086     Standard_OutOfRange_Raise_if(N < 0 || N > 3, "GeomLProp_CLProps::GeomLProp_CLProps()");
0087     SetParameter(U);
0088   }
0089 
0090   //! Same as previous constructor but here the parameter is
0091   //! set to the value <U> and the curve is set
0092   //! with SetCurve.
0093   //! the curve can have a empty constructor
0094   //! All the computations done will be related to <C> and <U>
0095   //! when the functions "set" will be done.
0096   GeomLProp_CLPropsBase(const int N, const double Resolution)
0097       : myCurve{},
0098         myU(RealLast()),
0099         myDerOrder(N),
0100         myCN(0),
0101         myLinTol(Resolution),
0102         myTangentStatus(LProp_Undecided)
0103   {
0104     Standard_OutOfRange_Raise_if(N < 0 || N > 3, "GeomLProp_CLProps() - invalid input");
0105   }
0106 
0107   //! Initializes the local properties of the curve
0108   //! for the parameter value <U>.
0109   void SetParameter(const double U)
0110   {
0111     LProp_CurveUtils::SetParameter<Access>(myCurve,
0112                                            U,
0113                                            myU,
0114                                            myDerOrder,
0115                                            myPnt,
0116                                            myDerivArr,
0117                                            myTangentStatus);
0118   }
0119 
0120   //! Initializes the local properties of the curve
0121   //! for the new curve.
0122   void SetCurve(const CurveType& C)
0123   {
0124     myCurve = C;
0125     myCN    = 4;
0126   }
0127 
0128   //! Returns the Point.
0129   const Pnt& Value() const { return myPnt; }
0130 
0131   //! Returns the first derivative.
0132   //! The derivative is computed if it has not been yet.
0133   const Vec& D1()
0134   {
0135     return LProp_CurveUtils::EnsureDeriv<Access>(myCurve, myU, myDerOrder, 1, myPnt, myDerivArr);
0136   }
0137 
0138   //! Returns the second derivative.
0139   //! The derivative is computed if it has not been yet.
0140   const Vec& D2()
0141   {
0142     return LProp_CurveUtils::EnsureDeriv<Access>(myCurve, myU, myDerOrder, 2, myPnt, myDerivArr);
0143   }
0144 
0145   //! Returns the third derivative.
0146   //! The derivative is computed if it has not been yet.
0147   const Vec& D3()
0148   {
0149     return LProp_CurveUtils::EnsureDeriv<Access>(myCurve, myU, myDerOrder, 3, myPnt, myDerivArr);
0150   }
0151 
0152   //! Returns True if the tangent is defined.
0153   //! For example, the tangent is not defined if the
0154   //! three first derivatives are all null.
0155   bool IsTangentDefined()
0156   {
0157     return LProp_CurveUtils::IsTangentDefined<Vec>(*this,
0158                                                    myCN,
0159                                                    myLinTol,
0160                                                    mySignificantFirstDerivativeOrder,
0161                                                    myTangentStatus);
0162   }
0163 
0164   //! output the tangent direction <D>.
0165   void Tangent(Dir& D)
0166   {
0167     LProp_CurveUtils::Tangent<Access>(*this,
0168                                       myCurve,
0169                                       myU,
0170                                       myDerivArr,
0171                                       myPnt,
0172                                       mySignificantFirstDerivativeOrder,
0173                                       D);
0174   }
0175 
0176   //! Returns the curvature.
0177   double Curvature()
0178   {
0179     return LProp_CurveUtils::Curvature(*this,
0180                                        myDerivArr[0],
0181                                        myDerivArr[1],
0182                                        myLinTol,
0183                                        mySignificantFirstDerivativeOrder,
0184                                        myCurvature);
0185   }
0186 
0187   //! Returns the normal direction <N>.
0188   void Normal(Dir& N)
0189   {
0190     LProp_CurveUtils::Normal(*this, myDerivArr[0], myDerivArr[1], myLinTol, N);
0191   }
0192 
0193   //! Returns the centre of curvature <P>.
0194   void CentreOfCurvature(Pnt& P)
0195   {
0196     LProp_CurveUtils::CentreOfCurvature(*this,
0197                                         myPnt,
0198                                         myDerivArr[0],
0199                                         myDerivArr[1],
0200                                         myLinTol,
0201                                         myCurvature,
0202                                         P);
0203   }
0204 
0205 private:
0206   CurveType    myCurve;
0207   double       myU;
0208   int          myDerOrder;
0209   int          myCN;
0210   double       myLinTol;
0211   Pnt          myPnt;
0212   Vec          myDerivArr[3];
0213   double       myCurvature = 0.0;
0214   LProp_Status myTangentStatus;
0215   int          mySignificantFirstDerivativeOrder = 0;
0216 };
0217 
0218 //! Default 3D curve local properties class using occ::handle<Geom_Curve>.
0219 using GeomLProp_CLProps = GeomLProp_CLPropsBase<gp_Pnt, gp_Vec, gp_Dir, occ::handle<Geom_Curve>>;
0220 
0221 //! Default 2D curve local properties class using occ::handle<Geom2d_Curve>.
0222 using GeomLProp_CLProps2d =
0223   GeomLProp_CLPropsBase<gp_Pnt2d, gp_Vec2d, gp_Dir2d, occ::handle<Geom2d_Curve>>;
0224 
0225 #endif // _GeomLProp_CLProps_HeaderFile