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_Sphere_HeaderFile
0015 #define _GeomGridEval_Sphere_HeaderFile
0016 
0017 #include <Geom_SphericalSurface.hxx>
0018 #include <GeomGridEval.hxx>
0019 #include <NCollection_Array1.hxx>
0020 #include <NCollection_Array2.hxx>
0021 #include <Standard.hxx>
0022 #include <Standard_DefineAlloc.hxx>
0023 
0024 //! @brief Efficient batch evaluator for sphere grid points.
0025 //!
0026 //! Uses analytical formula:
0027 //! P(u,v) = Center + R * (cos(v) * cos(u) * XDir + cos(v) * sin(u) * YDir + sin(v) * ZDir)
0028 //!
0029 //! Where U is longitude (0 to 2*PI) and V is latitude (-PI/2 to PI/2).
0030 //!
0031 //! Usage:
0032 //! @code
0033 //!   GeomGridEval_Sphere anEvaluator(myGeomSphere);
0034 //!   NCollection_Array2<gp_Pnt> aGrid = anEvaluator.EvaluateGrid(myUParams, myVParams);
0035 //! @endcode
0036 class GeomGridEval_Sphere
0037 {
0038 public:
0039   DEFINE_STANDARD_ALLOC
0040 
0041   //! Constructor with geometry.
0042   //! @param theSphere the spherical surface geometry to evaluate
0043   GeomGridEval_Sphere(const occ::handle<Geom_SphericalSurface>& theSphere)
0044       : myGeom(theSphere)
0045   {
0046   }
0047 
0048   //! Non-copyable and non-movable.
0049   GeomGridEval_Sphere(const GeomGridEval_Sphere&)            = delete;
0050   GeomGridEval_Sphere& operator=(const GeomGridEval_Sphere&) = delete;
0051   GeomGridEval_Sphere(GeomGridEval_Sphere&&)                 = delete;
0052   GeomGridEval_Sphere& operator=(GeomGridEval_Sphere&&)      = delete;
0053 
0054   //! Returns the geometry handle.
0055   const occ::handle<Geom_SphericalSurface>& Geometry() const { return myGeom; }
0056 
0057   //! Evaluate grid points at Cartesian product of U and V parameters.
0058   //! @param theUParams array of U parameter values (longitude)
0059   //! @param theVParams array of V parameter values (latitude)
0060   //! @return 2D array of evaluated points (1-based indexing)
0061   Standard_EXPORT NCollection_Array2<gp_Pnt> EvaluateGrid(
0062     const NCollection_Array1<double>& theUParams,
0063     const NCollection_Array1<double>& theVParams) const;
0064 
0065   //! Evaluate grid points with first partial derivatives.
0066   //! @param theUParams array of U parameter values (longitude)
0067   //! @param theVParams array of V parameter values (latitude)
0068   //! @return 2D array of SurfD1 (1-based indexing)
0069   Standard_EXPORT NCollection_Array2<GeomGridEval::SurfD1> EvaluateGridD1(
0070     const NCollection_Array1<double>& theUParams,
0071     const NCollection_Array1<double>& theVParams) const;
0072 
0073   //! Evaluate grid points with first and second partial derivatives.
0074   //! @param theUParams array of U parameter values (longitude)
0075   //! @param theVParams array of V parameter values (latitude)
0076   //! @return 2D array of SurfD2 (1-based indexing)
0077   Standard_EXPORT NCollection_Array2<GeomGridEval::SurfD2> EvaluateGridD2(
0078     const NCollection_Array1<double>& theUParams,
0079     const NCollection_Array1<double>& theVParams) const;
0080 
0081   //! Evaluate grid points with derivatives up to third order.
0082   //! @param theUParams array of U parameter values (longitude)
0083   //! @param theVParams array of V parameter values (latitude)
0084   //! @return 2D array of SurfD3 (1-based indexing)
0085   Standard_EXPORT NCollection_Array2<GeomGridEval::SurfD3> EvaluateGridD3(
0086     const NCollection_Array1<double>& theUParams,
0087     const NCollection_Array1<double>& theVParams) const;
0088 
0089   //! Evaluate partial derivative d^(NU+NV)S/(dU^NU dV^NV) at all grid points.
0090   //! For orders 1-3, reuses EvaluateGridD1/D2/D3.
0091   //! For orders > 3, uses geometry DN method.
0092   //! @param theUParams array of U parameter values (longitude)
0093   //! @param theVParams array of V parameter values (latitude)
0094   //! @param theNU derivative order in U direction
0095   //! @param theNV derivative order in V direction
0096   //! @return 2D array of derivative vectors (1-based indexing)
0097   Standard_EXPORT NCollection_Array2<gp_Vec> EvaluateGridDN(
0098     const NCollection_Array1<double>& theUParams,
0099     const NCollection_Array1<double>& theVParams,
0100     int                               theNU,
0101     int                               theNV) const;
0102 
0103 private:
0104   //! Pre-extracted sphere data for efficient evaluation.
0105   struct Data
0106   {
0107     double CX, CY, CZ; //!< Center coordinates
0108     double XX, XY, XZ; //!< XDir coordinates
0109     double YX, YY, YZ; //!< YDir coordinates
0110     double ZX, ZY, ZZ; //!< ZDir coordinates
0111     double Radius;
0112   };
0113 
0114   //! Pre-computed U-dependent values for optimized grid evaluation.
0115   struct UContext
0116   {
0117     double cosU, sinU;
0118     double dirUX, dirUY, dirUZ;    //!< DirU = cosU*XDir + sinU*YDir
0119     double dDirUX, dDirUY, dDirUZ; //!< DerivDirU = -sinU*XDir + cosU*YDir
0120   };
0121 
0122   //! Extract sphere data for evaluation.
0123   Data extractData() const;
0124 
0125   //! Pre-compute U-dependent values.
0126   static UContext computeUContext(const Data& theData, double theU);
0127 
0128   //! Compute point with pre-computed U context.
0129   static gp_Pnt computeD0(const Data& theData, const UContext& theUCtx, double theV);
0130 
0131   //! Compute point with D1 with pre-computed U context.
0132   static GeomGridEval::SurfD1 computeD1(const Data& theData, const UContext& theUCtx, double theV);
0133 
0134   //! Compute point with D2 with pre-computed U context.
0135   static GeomGridEval::SurfD2 computeD2(const Data& theData, const UContext& theUCtx, double theV);
0136 
0137   //! Compute point with D3 with pre-computed U context.
0138   static GeomGridEval::SurfD3 computeD3(const Data& theData, const UContext& theUCtx, double theV);
0139 
0140   //! Compute DN with pre-computed U context.
0141   static gp_Vec computeDN(const Data&     theData,
0142                           const UContext& theUCtx,
0143                           double          theV,
0144                           int             theNU,
0145                           int             theNV);
0146 
0147   occ::handle<Geom_SphericalSurface> myGeom;
0148 };
0149 
0150 #endif // _GeomGridEval_Sphere_HeaderFile