Back to home page

EIC code displayed by LXR

 
 

    


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

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 _GeomEval_RepSurfaceDesc_HeaderFile
0015 #define _GeomEval_RepSurfaceDesc_HeaderFile
0016 
0017 #include <Geom_Surface.hxx>
0018 #include <Precision.hxx>
0019 #include <Standard_Transient.hxx>
0020 
0021 #include <cmath>
0022 #include <cstddef>
0023 #include <optional>
0024 
0025 namespace GeomEval_RepSurfaceDesc
0026 {
0027 //! 2D diagonal affine parameter map with optional UV swap.
0028 //! Without swap: uRep = ScaleU*u + OffsetU, vRep = ScaleV*v + OffsetV.
0029 //! With swap:    uRep = ScaleU*v + OffsetU, vRep = ScaleV*u + OffsetV.
0030 struct Map2d
0031 {
0032   double ScaleU  = 1.0;
0033   double OffsetU = 0.0;
0034   double ScaleV  = 1.0;
0035   double OffsetV = 0.0;
0036   bool   SwapUV  = false;
0037 
0038   bool IsIdentity() const
0039   {
0040     return std::abs(ScaleU - 1.0) < Precision::Confusion()
0041            && std::abs(ScaleV - 1.0) < Precision::Confusion()
0042            && std::abs(OffsetU) < Precision::Confusion()
0043            && std::abs(OffsetV) < Precision::Confusion() && !SwapUV;
0044   }
0045 
0046   bool IsValid() const
0047   {
0048     return std::abs(ScaleU) > Precision::Confusion() && std::abs(ScaleV) > Precision::Confusion();
0049   }
0050 
0051   void Map(const double theU, const double theV, double& theURep, double& theVRep) const
0052   {
0053     if (SwapUV)
0054     {
0055       theURep = ScaleU * theV + OffsetU;
0056       theVRep = ScaleV * theU + OffsetV;
0057     }
0058     else
0059     {
0060       theURep = ScaleU * theU + OffsetU;
0061       theVRep = ScaleV * theV + OffsetV;
0062     }
0063   }
0064 };
0065 
0066 //! 2D parameter domain.
0067 struct Domain2d
0068 {
0069   double UFirst = 0.0;
0070   double ULast  = 1.0;
0071   double VFirst = 0.0;
0072   double VLast  = 1.0;
0073 
0074   bool Contains(const double theU, const double theV) const
0075   {
0076     return (theU >= UFirst - Precision::Confusion()) && (theU <= ULast + Precision::Confusion())
0077            && (theV >= VFirst - Precision::Confusion()) && (theV <= VLast + Precision::Confusion());
0078   }
0079 };
0080 
0081 //! Abstract base descriptor for surface evaluation representation.
0082 //! Holds the representation handle and a Kind tag for switch-based dispatch.
0083 class Base : public Standard_Transient
0084 {
0085 public:
0086   //! Descriptor kind for switch-based dispatch (no RTTI needed).
0087   enum class Kind
0088   {
0089     Full,         //!< fully equivalent, no derivative limit, no domain, no map
0090     DerivBounded, //!< full domain + identity map, limited to MaxDerivOrder
0091     Mapped        //!< has MaxDerivOrder + optional Domain + ParamMap
0092   };
0093 
0094   occ::handle<Geom_Surface> Representation; //!< geometry used for evaluation
0095 
0096   //! Returns the descriptor kind.
0097   virtual Kind GetKind() const = 0;
0098 
0099   DEFINE_STANDARD_RTTI_INLINE(Base, Standard_Transient)
0100 
0101 protected:
0102   Base() = default;
0103 };
0104 
0105 //! Fully equivalent descriptor: no derivative limit, no domain, no map.
0106 //! Fastest evaluation path - direct delegation to Representation.
0107 class Full : public Base
0108 {
0109 public:
0110   Kind GetKind() const override { return Kind::Full; }
0111 
0112   DEFINE_STANDARD_RTTI_INLINE(Full, Base)
0113 };
0114 
0115 //! Derivative-bounded descriptor: full domain, identity map, limited to MaxDerivOrder.
0116 class DerivBounded : public Base
0117 {
0118 public:
0119   std::size_t MaxDerivOrder = 3; //!< max supported derivative order
0120 
0121   Kind GetKind() const override { return Kind::DerivBounded; }
0122 
0123   DEFINE_STANDARD_RTTI_INLINE(DerivBounded, Base)
0124 };
0125 
0126 //! Mapped descriptor for surface evaluation representation.
0127 //! Adds optional bounded domain and diagonal affine parameter map with optional UV swap.
0128 //! Evaluation requires: domain check -> map parameters -> evaluate -> scale derivatives.
0129 //! Future subclasses can support multi-region descriptors with per-patch UV domains and maps.
0130 class Mapped : public Base
0131 {
0132 public:
0133   std::size_t             MaxDerivOrder = 3; //!< max supported derivative order
0134   std::optional<Domain2d> Domain;            //!< nullopt = full domain
0135   Map2d                   ParamMap;          //!< affine parameter transform
0136 
0137   Kind GetKind() const override { return Kind::Mapped; }
0138 
0139   DEFINE_STANDARD_RTTI_INLINE(Mapped, Base)
0140 };
0141 } // namespace GeomEval_RepSurfaceDesc
0142 
0143 #endif // _GeomEval_RepSurfaceDesc_HeaderFile