Back to home page

EIC code displayed by LXR

 
 

    


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

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 _GeomAdaptor_TransformedSurface_HeaderFile
0015 #define _GeomAdaptor_TransformedSurface_HeaderFile
0016 
0017 #include <Adaptor3d_Surface.hxx>
0018 #include <GeomAdaptor_Surface.hxx>
0019 #include <gp_Trsf.hxx>
0020 
0021 #include <optional>
0022 
0023 class Geom_BezierSurface;
0024 class Geom_BSplineSurface;
0025 class Geom_Surface;
0026 
0027 //! An adaptor for surfaces with an applied transformation.
0028 //!
0029 //! This class wraps a GeomAdaptor_Surface and applies a gp_Trsf transformation
0030 //! to all point and derivative evaluations. It serves as a base class for
0031 //! BRepAdaptor_Surface and allows batch evaluation with transformations in
0032 //! GeomGridEval_Surface.
0033 //!
0034 //! The evaluation methods (Value, D0, D1, D2, D3, DN) are marked final
0035 //! to enable optimizations in grid evaluation.
0036 class GeomAdaptor_TransformedSurface : public Adaptor3d_Surface
0037 {
0038   DEFINE_STANDARD_RTTIEXT(GeomAdaptor_TransformedSurface, Adaptor3d_Surface)
0039 public:
0040   //! Creates an undefined surface with identity transformation.
0041   Standard_EXPORT GeomAdaptor_TransformedSurface();
0042 
0043   //! Creates a surface adaptor with transformation.
0044   //! @param theSurface underlying geometry
0045   //! @param theTrsf transformation to apply
0046   Standard_EXPORT GeomAdaptor_TransformedSurface(const occ::handle<Geom_Surface>& theSurface,
0047                                                  const gp_Trsf&                   theTrsf);
0048 
0049   //! Creates a surface adaptor with transformation and parameter bounds.
0050   //! @param theSurface underlying geometry
0051   //! @param theUFirst minimum U parameter
0052   //! @param theULast maximum U parameter
0053   //! @param theVFirst minimum V parameter
0054   //! @param theVLast maximum V parameter
0055   //! @param theTrsf transformation to apply
0056   //! @param theTolU tolerance in U direction
0057   //! @param theTolV tolerance in V direction
0058   Standard_EXPORT GeomAdaptor_TransformedSurface(const occ::handle<Geom_Surface>& theSurface,
0059                                                  const double                     theUFirst,
0060                                                  const double                     theULast,
0061                                                  const double                     theVFirst,
0062                                                  const double                     theVLast,
0063                                                  const gp_Trsf&                   theTrsf,
0064                                                  const double                     theTolU = 0.0,
0065                                                  const double                     theTolV = 0.0);
0066 
0067   //! Shallow copy of adaptor.
0068   Standard_EXPORT occ::handle<Adaptor3d_Surface> ShallowCopy() const override;
0069 
0070   //! Loads the surface geometry.
0071   //! @param theSurface underlying geometry
0072   //! @param theTrsf transformation to apply
0073   Standard_EXPORT void Load(const occ::handle<Geom_Surface>& theSurface, const gp_Trsf& theTrsf);
0074 
0075   //! Loads the surface geometry with parameter bounds.
0076   //! @param theSurface underlying geometry
0077   //! @param theUFirst minimum U parameter
0078   //! @param theULast maximum U parameter
0079   //! @param theVFirst minimum V parameter
0080   //! @param theVLast maximum V parameter
0081   //! @param theTrsf transformation to apply
0082   //! @param theTolU tolerance in U direction
0083   //! @param theTolV tolerance in V direction
0084   Standard_EXPORT void Load(const occ::handle<Geom_Surface>& theSurface,
0085                             const double                     theUFirst,
0086                             const double                     theULast,
0087                             const double                     theVFirst,
0088                             const double                     theVLast,
0089                             const gp_Trsf&                   theTrsf,
0090                             const double                     theTolU = 0.0,
0091                             const double                     theTolV = 0.0);
0092 
0093   //! Sets the transformation.
0094   //! @param theTrsf transformation to apply
0095   Standard_EXPORT void SetTrsf(const gp_Trsf& theTrsf);
0096 
0097   //! Returns true if non-identity transformation is applied.
0098   bool HasTrsf() const { return myTrsf.Form() != gp_Identity; }
0099 
0100   //! Returns the transformation.
0101   const gp_Trsf& Trsf() const { return myTrsf; }
0102 
0103   //! Returns the underlying GeomAdaptor_Surface.
0104   Standard_DEPRECATED(
0105     "Use AdaptorSurfaceOriginal() instead to get the original surface without transformation")
0106   const GeomAdaptor_Surface& Surface() const { return mySurf; }
0107 
0108   //! Returns the underlying original GeomAdaptor_Surface without transformation applied.
0109   const GeomAdaptor_Surface& AdaptorSurfaceOriginal() const { return mySurf; }
0110 
0111   //! Returns an adaptor for the transformed surface state.
0112   //! Uses the original adaptor for identity transformation to preserve existing trimming.
0113   Standard_EXPORT const GeomAdaptor_Surface& AdaptorSurfaceTransformed() const;
0114 
0115   //! Returns the underlying original Geom_Surface without transformation applied.
0116   const occ::handle<Geom_Surface>& GeomSurfaceOriginal() const { return mySurf.Surface(); }
0117 
0118   //! Returns the transformed Geom_Surface cached for current state.
0119   Standard_EXPORT const occ::handle<Geom_Surface>& GeomSurfaceTransformed() const;
0120 
0121   //! Returns the underlying Geom_Surface.
0122   Standard_DEPRECATED("Use GeomSurfaceOriginal() or GeomSurfaceTransformed() instead")
0123   const occ::handle<Geom_Surface>& GeomSurface() const { return GeomSurfaceOriginal(); }
0124 
0125   // Parameter range methods - delegate to underlying surface
0126   double FirstUParameter() const override { return mySurf.FirstUParameter(); }
0127 
0128   double LastUParameter() const override { return mySurf.LastUParameter(); }
0129 
0130   double FirstVParameter() const override { return mySurf.FirstVParameter(); }
0131 
0132   double LastVParameter() const override { return mySurf.LastVParameter(); }
0133 
0134   GeomAbs_Shape UContinuity() const override { return mySurf.UContinuity(); }
0135 
0136   GeomAbs_Shape VContinuity() const override { return mySurf.VContinuity(); }
0137 
0138   int NbUIntervals(const GeomAbs_Shape theS) const override { return mySurf.NbUIntervals(theS); }
0139 
0140   int NbVIntervals(const GeomAbs_Shape theS) const override { return mySurf.NbVIntervals(theS); }
0141 
0142   Standard_EXPORT void UIntervals(NCollection_Array1<double>& theT,
0143                                   const GeomAbs_Shape         theS) const override;
0144 
0145   Standard_EXPORT void VIntervals(NCollection_Array1<double>& theT,
0146                                   const GeomAbs_Shape         theS) const override;
0147 
0148   Standard_EXPORT occ::handle<Adaptor3d_Surface> UTrim(const double theFirst,
0149                                                        const double theLast,
0150                                                        const double theTol) const override;
0151 
0152   Standard_EXPORT occ::handle<Adaptor3d_Surface> VTrim(const double theFirst,
0153                                                        const double theLast,
0154                                                        const double theTol) const override;
0155 
0156   bool IsUClosed() const override { return mySurf.IsUClosed(); }
0157 
0158   bool IsVClosed() const override { return mySurf.IsVClosed(); }
0159 
0160   bool IsUPeriodic() const override { return mySurf.IsUPeriodic(); }
0161 
0162   double UPeriod() const override { return mySurf.UPeriod(); }
0163 
0164   bool IsVPeriodic() const override { return mySurf.IsVPeriodic(); }
0165 
0166   double VPeriod() const override { return mySurf.VPeriod(); }
0167 
0168   //! Returns tolerance in U direction.
0169   double ToleranceU() const { return mySurf.ToleranceU(); }
0170 
0171   //! Returns tolerance in V direction.
0172   double ToleranceV() const { return mySurf.ToleranceV(); }
0173 
0174   //! Point evaluation. Applies transformation after evaluation.
0175   [[nodiscard]] Standard_EXPORT gp_Pnt EvalD0(const double theU, const double theV) const final;
0176 
0177   //! D1 evaluation. Applies transformation after evaluation.
0178   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD1 EvalD1(const double theU,
0179                                                            const double theV) const final;
0180 
0181   //! D2 evaluation. Applies transformation after evaluation.
0182   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD2 EvalD2(const double theU,
0183                                                            const double theV) const final;
0184 
0185   //! D3 evaluation. Applies transformation after evaluation.
0186   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD3 EvalD3(const double theU,
0187                                                            const double theV) const final;
0188 
0189   //! DN evaluation. Applies transformation after evaluation.
0190   [[nodiscard]] Standard_EXPORT gp_Vec EvalDN(const double theU,
0191                                               const double theV,
0192                                               const int    theNu,
0193                                               const int    theNv) const final;
0194 
0195   double UResolution(const double theR3d) const override { return mySurf.UResolution(theR3d); }
0196 
0197   double VResolution(const double theR3d) const override { return mySurf.VResolution(theR3d); }
0198 
0199   GeomAbs_SurfaceType GetType() const override { return mySurf.GetType(); }
0200 
0201   Standard_EXPORT gp_Pln Plane() const override;
0202 
0203   Standard_EXPORT gp_Cylinder Cylinder() const override;
0204 
0205   Standard_EXPORT gp_Cone Cone() const override;
0206 
0207   Standard_EXPORT gp_Sphere Sphere() const override;
0208 
0209   Standard_EXPORT gp_Torus Torus() const override;
0210 
0211   int UDegree() const override { return mySurf.UDegree(); }
0212 
0213   int NbUPoles() const override { return mySurf.NbUPoles(); }
0214 
0215   int VDegree() const override { return mySurf.VDegree(); }
0216 
0217   int NbVPoles() const override { return mySurf.NbVPoles(); }
0218 
0219   int NbUKnots() const override { return mySurf.NbUKnots(); }
0220 
0221   int NbVKnots() const override { return mySurf.NbVKnots(); }
0222 
0223   bool IsURational() const override { return mySurf.IsURational(); }
0224 
0225   bool IsVRational() const override { return mySurf.IsVRational(); }
0226 
0227   Standard_EXPORT occ::handle<Geom_BezierSurface> Bezier() const override;
0228 
0229   Standard_EXPORT occ::handle<Geom_BSplineSurface> BSpline() const override;
0230 
0231   Standard_EXPORT gp_Ax1 AxeOfRevolution() const override;
0232 
0233   Standard_EXPORT gp_Dir Direction() const override;
0234 
0235   Standard_EXPORT occ::handle<Adaptor3d_Curve> BasisCurve() const override;
0236 
0237   Standard_EXPORT occ::handle<Adaptor3d_Surface> BasisSurface() const override;
0238 
0239   Standard_EXPORT double OffsetValue() const override;
0240 
0241 protected:
0242   //! Invalidates transformed cache for subsequent lazy rebuild.
0243   void invalidateTransformedCache();
0244 
0245   //! Ensures transformed cache is built on demand.
0246   //! Non-thread-safe: mutable cache is initialized in const context without synchronization.
0247   void ensureTransformedCache() const;
0248 
0249   //! Rebuilds transformed geometry for current surface and transformation.
0250   //! Non-thread-safe: invoked by ensureTransformedCache() for lazy initialization.
0251   void initTransformedCache() const;
0252 
0253   //! Returns an adaptor for the transformed surface state.
0254   //! Uses the original adaptor for identity transformation to preserve existing trimming.
0255   const GeomAdaptor_Surface& transformedAdaptor() const;
0256 
0257 protected:
0258   GeomAdaptor_Surface                        mySurf;
0259   gp_Trsf                                    myTrsf;
0260   mutable std::optional<GeomAdaptor_Surface> myTransformedAdaptor;
0261 };
0262 
0263 #endif // _GeomAdaptor_TransformedSurface_HeaderFile