Back to home page

EIC code displayed by LXR

 
 

    


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

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 _GeomGridEval_Line_HeaderFile
0015 #define _GeomGridEval_Line_HeaderFile
0016 
0017 #include <Geom_Line.hxx>
0018 #include <GeomGridEval.hxx>
0019 #include <NCollection_Array1.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 
0022 //! @brief Efficient batch evaluator for line grid points.
0023 //!
0024 //! Uses direct analytical formula: P(t) = Location + t * Direction
0025 //!
0026 //! Usage:
0027 //! @code
0028 //!   GeomGridEval_Line anEvaluator(myGeomLine);
0029 //!   NCollection_Array1<gp_Pnt> aGrid = anEvaluator.EvaluateGrid(myParams);
0030 //! @endcode
0031 class GeomGridEval_Line
0032 {
0033 public:
0034   DEFINE_STANDARD_ALLOC
0035 
0036   //! Constructor with geometry.
0037   //! @param theLine the line geometry to evaluate
0038   GeomGridEval_Line(const occ::handle<Geom_Line>& theLine)
0039       : myGeom(theLine)
0040   {
0041   }
0042 
0043   //! Non-copyable and non-movable.
0044   GeomGridEval_Line(const GeomGridEval_Line&)            = delete;
0045   GeomGridEval_Line& operator=(const GeomGridEval_Line&) = delete;
0046   GeomGridEval_Line(GeomGridEval_Line&&)                 = delete;
0047   GeomGridEval_Line& operator=(GeomGridEval_Line&&)      = delete;
0048 
0049   //! Returns the geometry handle.
0050   const occ::handle<Geom_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_Pnt> EvaluateGrid(const NCollection_Array1<double>& theParams) const
0057   {
0058     if (myGeom.IsNull() || theParams.IsEmpty())
0059     {
0060       return NCollection_Array1<gp_Pnt>();
0061     }
0062 
0063     NCollection_Array1<gp_Pnt> aResult(1, theParams.Length());
0064 
0065     // Extract line data
0066     const gp_Lin& aLin = myGeom->Lin();
0067     const gp_Pnt& aLoc = aLin.Location();
0068     const gp_Dir& aDir = aLin.Direction();
0069 
0070     // Pre-extract coordinates for vectorization potential
0071     const double aLocX = aLoc.X();
0072     const double aLocY = aLoc.Y();
0073     const double aLocZ = aLoc.Z();
0074     const double aDirX = aDir.X();
0075     const double aDirY = aDir.Y();
0076     const double aDirZ = aDir.Z();
0077 
0078     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0079     {
0080       const double t = theParams.Value(i);
0081       aResult.SetValue(i - theParams.Lower() + 1,
0082                        gp_Pnt(aLocX + t * aDirX, aLocY + t * aDirY, aLocZ + t * aDirZ));
0083     }
0084     return aResult;
0085   }
0086 
0087   //! Evaluate all grid points with first derivative.
0088   //! For a line, D1 is constant (the direction vector).
0089   //! @param theParams array of parameter values
0090   //! @return array of CurveD1 (1-based indexing),
0091   //!         or empty array if geometry is null or no parameters
0092   NCollection_Array1<GeomGridEval::CurveD1> EvaluateGridD1(
0093     const NCollection_Array1<double>& theParams) const
0094   {
0095     if (myGeom.IsNull() || theParams.IsEmpty())
0096     {
0097       return NCollection_Array1<GeomGridEval::CurveD1>();
0098     }
0099 
0100     NCollection_Array1<GeomGridEval::CurveD1> aResult(1, theParams.Length());
0101 
0102     const gp_Lin& aLin = myGeom->Lin();
0103     const gp_Pnt& aLoc = aLin.Location();
0104     const gp_Dir& aDir = aLin.Direction();
0105 
0106     const double aLocX = aLoc.X();
0107     const double aLocY = aLoc.Y();
0108     const double aLocZ = aLoc.Z();
0109     const double aDirX = aDir.X();
0110     const double aDirY = aDir.Y();
0111     const double aDirZ = aDir.Z();
0112 
0113     // D1 is constant for a line
0114     const gp_Vec aD1(aDirX, aDirY, aDirZ);
0115 
0116     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0117     {
0118       const double t           = theParams.Value(i);
0119       aResult.ChangeValue(i - theParams.Lower()
0120                           + 1) = {gp_Pnt(aLocX + t * aDirX, aLocY + t * aDirY, aLocZ + t * aDirZ),
0121                                   aD1};
0122     }
0123     return aResult;
0124   }
0125 
0126   //! Evaluate all grid points with first and second derivatives.
0127   //! For a line, D1 is constant and D2 is zero.
0128   //! @param theParams array of parameter values
0129   //! @return array of CurveD2 (1-based indexing),
0130   //!         or empty array if geometry is null or no parameters
0131   NCollection_Array1<GeomGridEval::CurveD2> EvaluateGridD2(
0132     const NCollection_Array1<double>& theParams) const
0133   {
0134     if (myGeom.IsNull() || theParams.IsEmpty())
0135     {
0136       return NCollection_Array1<GeomGridEval::CurveD2>();
0137     }
0138 
0139     NCollection_Array1<GeomGridEval::CurveD2> aResult(1, theParams.Length());
0140 
0141     const gp_Lin& aLin = myGeom->Lin();
0142     const gp_Pnt& aLoc = aLin.Location();
0143     const gp_Dir& aDir = aLin.Direction();
0144 
0145     const double aLocX = aLoc.X();
0146     const double aLocY = aLoc.Y();
0147     const double aLocZ = aLoc.Z();
0148     const double aDirX = aDir.X();
0149     const double aDirY = aDir.Y();
0150     const double aDirZ = aDir.Z();
0151 
0152     const gp_Vec aD1(aDirX, aDirY, aDirZ);
0153     const gp_Vec aD2(0, 0, 0); // Second derivative is zero for a line
0154 
0155     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0156     {
0157       const double t = theParams.Value(i);
0158       aResult.ChangeValue(
0159         i - theParams.Lower()
0160         + 1) = {gp_Pnt(aLocX + t * aDirX, aLocY + t * aDirY, aLocZ + t * aDirZ), aD1, aD2};
0161     }
0162     return aResult;
0163   }
0164 
0165   //! Evaluate all grid points with first, second, and third derivatives.
0166   //! For a line, D1 is constant, D2 and D3 are zero.
0167   //! @param theParams array of parameter values
0168   //! @return array of CurveD3 (1-based indexing),
0169   //!         or empty array if geometry is null or no parameters
0170   NCollection_Array1<GeomGridEval::CurveD3> EvaluateGridD3(
0171     const NCollection_Array1<double>& theParams) const
0172   {
0173     if (myGeom.IsNull() || theParams.IsEmpty())
0174     {
0175       return NCollection_Array1<GeomGridEval::CurveD3>();
0176     }
0177 
0178     NCollection_Array1<GeomGridEval::CurveD3> aResult(1, theParams.Length());
0179 
0180     const gp_Lin& aLin = myGeom->Lin();
0181     const gp_Pnt& aLoc = aLin.Location();
0182     const gp_Dir& aDir = aLin.Direction();
0183 
0184     const double aLocX = aLoc.X();
0185     const double aLocY = aLoc.Y();
0186     const double aLocZ = aLoc.Z();
0187     const double aDirX = aDir.X();
0188     const double aDirY = aDir.Y();
0189     const double aDirZ = aDir.Z();
0190 
0191     const gp_Vec aD1(aDirX, aDirY, aDirZ);
0192     const gp_Vec aZero(0, 0, 0);
0193 
0194     for (int i = theParams.Lower(); i <= theParams.Upper(); ++i)
0195     {
0196       const double t = theParams.Value(i);
0197       aResult.ChangeValue(
0198         i - theParams.Lower()
0199         + 1) = {gp_Pnt(aLocX + t * aDirX, aLocY + t * aDirY, aLocZ + t * aDirZ), aD1, aZero, aZero};
0200     }
0201     return aResult;
0202   }
0203 
0204   //! Evaluate Nth derivative at all grid points.
0205   //! For a line: D1 = Direction, DN = 0 for N > 1.
0206   //! @param theParams array of parameter values
0207   //! @param theN derivative order (N >= 1)
0208   //! @return array of derivative vectors (1-based indexing),
0209   //!         or empty array if geometry is null or no parameters
0210   NCollection_Array1<gp_Vec> EvaluateGridDN(const NCollection_Array1<double>& theParams,
0211                                             int                               theN) const
0212   {
0213     if (myGeom.IsNull() || theParams.IsEmpty() || theN < 1)
0214     {
0215       return NCollection_Array1<gp_Vec>();
0216     }
0217 
0218     NCollection_Array1<gp_Vec> aResult(1, theParams.Length());
0219 
0220     if (theN == 1)
0221     {
0222       // D1 is constant for a line (the direction)
0223       const gp_Dir aDir = myGeom->Lin().Direction();
0224       const gp_Vec aD1(aDir.X(), aDir.Y(), aDir.Z());
0225       for (int i = 1; i <= theParams.Length(); ++i)
0226       {
0227         aResult.SetValue(i, aD1);
0228       }
0229     }
0230     else
0231     {
0232       // All higher derivatives are zero for a line
0233       const gp_Vec aZero(0, 0, 0);
0234       for (int i = 1; i <= theParams.Length(); ++i)
0235       {
0236         aResult.SetValue(i, aZero);
0237       }
0238     }
0239     return aResult;
0240   }
0241 
0242 private:
0243   occ::handle<Geom_Line> myGeom;
0244 };
0245 
0246 #endif // _GeomGridEval_Line_HeaderFile