Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:04

0001 // Copyright (c) 2025 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Geom2dGridEval_Line_HeaderFile
0015 #define _Geom2dGridEval_Line_HeaderFile
0016 
0017 #include <Geom2d_Line.hxx>
0018 #include <Geom2dGridEval.hxx>
0019 #include <NCollection_Array1.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 
0022 //! @brief Efficient batch evaluator for 2D line grid points.
0023 //!
0024 //! Uses direct analytical formula: P(t) = Location + t * Direction
0025 //!
0026 //! Usage:
0027 //! @code
0028 //!   Geom2dGridEval_Line anEvaluator(myGeom2dLine);
0029 //!   NCollection_Array1<gp_Pnt2d> aGrid = anEvaluator.EvaluateGrid(myParams);
0030 //! @endcode
0031 class Geom2dGridEval_Line
0032 {
0033 public:
0034   DEFINE_STANDARD_ALLOC
0035 
0036   //! Constructor with geometry.
0037   //! @param theLine the 2D line geometry to evaluate
0038   Geom2dGridEval_Line(const occ::handle<Geom2d_Line>& theLine)
0039       : myGeom(theLine)
0040   {
0041   }
0042 
0043   //! Non-copyable and non-movable.
0044   Geom2dGridEval_Line(const Geom2dGridEval_Line&)            = delete;
0045   Geom2dGridEval_Line& operator=(const Geom2dGridEval_Line&) = delete;
0046   Geom2dGridEval_Line(Geom2dGridEval_Line&&)                 = delete;
0047   Geom2dGridEval_Line& operator=(Geom2dGridEval_Line&&)      = delete;
0048 
0049   //! Returns the geometry handle.
0050   const occ::handle<Geom2d_Line>& Geometry() const { return myGeom; }
0051 
0052   //! Evaluate all grid points.
0053   //! @param theParams array of parameter values
0054   //! @return array of evaluated points (1-based indexing),
0055   //!         or empty array if geometry is null or no parameters
0056   NCollection_Array1<gp_Pnt2d> EvaluateGrid(const NCollection_Array1<double>& theParams) const
0057   {
0058     if (myGeom.IsNull() || theParams.IsEmpty())
0059     {
0060       return NCollection_Array1<gp_Pnt2d>();
0061     }
0062 
0063     NCollection_Array1<gp_Pnt2d> aResult(1, theParams.Length());
0064 
0065     const gp_Lin2d& aLin = myGeom->Lin2d();
0066     const gp_Pnt2d& aLoc = aLin.Location();
0067     const gp_Dir2d& aDir = aLin.Direction();
0068 
0069     const double aLocX = aLoc.X();
0070     const double aLocY = aLoc.Y();
0071     const double aDirX = aDir.X();
0072     const double aDirY = aDir.Y();
0073 
0074     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0075     {
0076       const double t = theParams.Value(i);
0077       aResult.SetValue(i - theParams.Lower() + 1, gp_Pnt2d(aLocX + t * aDirX, aLocY + t * aDirY));
0078     }
0079     return aResult;
0080   }
0081 
0082   //! Evaluate all grid points with first derivative.
0083   //! For a line, D1 is constant (the direction vector).
0084   //! @param theParams array of parameter values
0085   //! @return array of CurveD1 (1-based indexing),
0086   //!         or empty array if geometry is null or no parameters
0087   NCollection_Array1<Geom2dGridEval::CurveD1> EvaluateGridD1(
0088     const NCollection_Array1<double>& theParams) const
0089   {
0090     if (myGeom.IsNull() || theParams.IsEmpty())
0091     {
0092       return NCollection_Array1<Geom2dGridEval::CurveD1>();
0093     }
0094 
0095     NCollection_Array1<Geom2dGridEval::CurveD1> aResult(1, theParams.Length());
0096 
0097     const gp_Lin2d& aLin = myGeom->Lin2d();
0098     const gp_Pnt2d& aLoc = aLin.Location();
0099     const gp_Dir2d& aDir = aLin.Direction();
0100 
0101     const double aLocX = aLoc.X();
0102     const double aLocY = aLoc.Y();
0103     const double aDirX = aDir.X();
0104     const double aDirY = aDir.Y();
0105 
0106     const gp_Vec2d aD1(aDirX, aDirY);
0107 
0108     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0109     {
0110       const double t           = theParams.Value(i);
0111       aResult.ChangeValue(i - theParams.Lower()
0112                           + 1) = {gp_Pnt2d(aLocX + t * aDirX, aLocY + t * aDirY), aD1};
0113     }
0114     return aResult;
0115   }
0116 
0117   //! Evaluate all grid points with first and second derivatives.
0118   //! For a line, D1 is constant and D2 is zero.
0119   //! @param theParams array of parameter values
0120   //! @return array of CurveD2 (1-based indexing),
0121   //!         or empty array if geometry is null or no parameters
0122   NCollection_Array1<Geom2dGridEval::CurveD2> EvaluateGridD2(
0123     const NCollection_Array1<double>& theParams) const
0124   {
0125     if (myGeom.IsNull() || theParams.IsEmpty())
0126     {
0127       return NCollection_Array1<Geom2dGridEval::CurveD2>();
0128     }
0129 
0130     NCollection_Array1<Geom2dGridEval::CurveD2> aResult(1, theParams.Length());
0131 
0132     const gp_Lin2d& aLin = myGeom->Lin2d();
0133     const gp_Pnt2d& aLoc = aLin.Location();
0134     const gp_Dir2d& aDir = aLin.Direction();
0135 
0136     const double aLocX = aLoc.X();
0137     const double aLocY = aLoc.Y();
0138     const double aDirX = aDir.X();
0139     const double aDirY = aDir.Y();
0140 
0141     const gp_Vec2d aD1(aDirX, aDirY);
0142     const gp_Vec2d aD2(0, 0);
0143 
0144     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0145     {
0146       const double t           = theParams.Value(i);
0147       aResult.ChangeValue(i - theParams.Lower()
0148                           + 1) = {gp_Pnt2d(aLocX + t * aDirX, aLocY + t * aDirY), aD1, aD2};
0149     }
0150     return aResult;
0151   }
0152 
0153   //! Evaluate all grid points with first, second, and third derivatives.
0154   //! For a line, D1 is constant, D2 and D3 are zero.
0155   //! @param theParams array of parameter values
0156   //! @return array of CurveD3 (1-based indexing),
0157   //!         or empty array if geometry is null or no parameters
0158   NCollection_Array1<Geom2dGridEval::CurveD3> EvaluateGridD3(
0159     const NCollection_Array1<double>& theParams) const
0160   {
0161     if (myGeom.IsNull() || theParams.IsEmpty())
0162     {
0163       return NCollection_Array1<Geom2dGridEval::CurveD3>();
0164     }
0165 
0166     NCollection_Array1<Geom2dGridEval::CurveD3> aResult(1, theParams.Length());
0167 
0168     const gp_Lin2d& aLin = myGeom->Lin2d();
0169     const gp_Pnt2d& aLoc = aLin.Location();
0170     const gp_Dir2d& aDir = aLin.Direction();
0171 
0172     const double aLocX = aLoc.X();
0173     const double aLocY = aLoc.Y();
0174     const double aDirX = aDir.X();
0175     const double aDirY = aDir.Y();
0176 
0177     const gp_Vec2d aD1(aDirX, aDirY);
0178     const gp_Vec2d aZero(0, 0);
0179 
0180     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0181     {
0182       const double t = theParams.Value(i);
0183       aResult.ChangeValue(
0184         i - theParams.Lower()
0185         + 1) = {gp_Pnt2d(aLocX + t * aDirX, aLocY + t * aDirY), aD1, aZero, aZero};
0186     }
0187     return aResult;
0188   }
0189 
0190   //! Evaluate Nth derivative at all grid points.
0191   //! For a line: D1 = Direction, DN = 0 for N > 1.
0192   //! @param theParams array of parameter values
0193   //! @param theN derivative order (N >= 1)
0194   //! @return array of derivative vectors (1-based indexing),
0195   //!         or empty array if geometry is null or no parameters
0196   NCollection_Array1<gp_Vec2d> EvaluateGridDN(const NCollection_Array1<double>& theParams,
0197                                               int                               theN) const
0198   {
0199     if (myGeom.IsNull() || theParams.IsEmpty() || theN < 1)
0200     {
0201       return NCollection_Array1<gp_Vec2d>();
0202     }
0203 
0204     NCollection_Array1<gp_Vec2d> aResult(1, theParams.Length());
0205 
0206     if (theN == 1)
0207     {
0208       const gp_Dir2d aDir = myGeom->Lin2d().Direction();
0209       const gp_Vec2d aD1(aDir.X(), aDir.Y());
0210       for (int i = 1; i <= theParams.Length(); ++i)
0211       {
0212         aResult.SetValue(i, aD1);
0213       }
0214     }
0215     else
0216     {
0217       const gp_Vec2d aZero(0, 0);
0218       for (int i = 1; i <= theParams.Length(); ++i)
0219       {
0220         aResult.SetValue(i, aZero);
0221       }
0222     }
0223     return aResult;
0224   }
0225 
0226 private:
0227   occ::handle<Geom2d_Line> myGeom;
0228 };
0229 
0230 #endif // _Geom2dGridEval_Line_HeaderFile