Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:20:19

0001 // Created on: 1993-05-14
0002 // Created by: Bruno DUMORTIER
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _GeomAdaptor_Surface_HeaderFile
0018 #define _GeomAdaptor_Surface_HeaderFile
0019 
0020 #include <Adaptor3d_Curve.hxx>
0021 #include <Adaptor3d_Surface.hxx>
0022 #include <BSplSLib_Cache.hxx>
0023 #include <GeomAbs_Shape.hxx>
0024 #include <Geom_Surface.hxx>
0025 #include <gp_Ax1.hxx>
0026 #include <gp_Cone.hxx>
0027 #include <gp_Cylinder.hxx>
0028 #include <gp_Dir.hxx>
0029 #include <gp_Pln.hxx>
0030 #include <gp_Sphere.hxx>
0031 #include <gp_Torus.hxx>
0032 #include <gp_XYZ.hxx>
0033 #include <Standard_NullObject.hxx>
0034 #include <NCollection_Array1.hxx>
0035 
0036 #include <variant>
0037 
0038 class GeomAdaptor_Curve;
0039 class Geom_OffsetSurface;
0040 class Geom_BezierSurface;
0041 
0042 namespace GeomEval_RepSurfaceDesc
0043 {
0044 class Base;
0045 }
0046 
0047 //! An interface between the services provided by any
0048 //! surface from the package Geom and those required
0049 //! of the surface by algorithms which use it.
0050 //! Creation of the loaded surface the surface is C1 by piece
0051 //!
0052 //! Polynomial coefficients of BSpline surfaces used for their evaluation are
0053 //! cached for better performance. Therefore these evaluations are not
0054 //! thread-safe and parallel evaluations need to be prevented.
0055 class GeomAdaptor_Surface : public Adaptor3d_Surface
0056 {
0057   DEFINE_STANDARD_RTTIEXT(GeomAdaptor_Surface, Adaptor3d_Surface)
0058 public:
0059   //! Internal structure for extrusion surface evaluation data.
0060   struct ExtrusionData
0061   {
0062     occ::handle<Adaptor3d_Curve>               BasisCurve; //!< Adaptor for basis curve
0063     gp_XYZ                                     Direction;  //!< Extrusion direction XYZ (normalized)
0064     occ::handle<GeomEval_RepSurfaceDesc::Base> EvalRep;    //!< Eval representation descriptor
0065   };
0066 
0067   //! Internal structure for revolution surface evaluation data.
0068   struct RevolutionData
0069   {
0070     occ::handle<Adaptor3d_Curve>               BasisCurve; //!< Adaptor for basis curve
0071     gp_Ax1                                     Axis;       //!< Revolution axis
0072     occ::handle<GeomEval_RepSurfaceDesc::Base> EvalRep;    //!< Eval representation descriptor
0073   };
0074 
0075   //! Internal structure for offset surface evaluation data.
0076   struct OffsetData
0077   {
0078     occ::handle<GeomAdaptor_Surface> BasisAdaptor; //!< Adaptor for basis surface
0079     occ::handle<GeomAdaptor_Surface>
0080       EquivalentAdaptor; //!< Adaptor for equivalent surface (if exists)
0081     occ::handle<Geom_OffsetSurface>
0082            OffsetSurface; //!< Original offset surface for osculating queries
0083     double Offset = 0.0;  //!< Offset distance
0084     occ::handle<GeomEval_RepSurfaceDesc::Base> EvalRep; //!< Eval representation descriptor
0085   };
0086 
0087   //! Internal structure for Bezier surface cache data.
0088   struct BezierData
0089   {
0090     occ::handle<Geom_BezierSurface>            Surface; //!< Bezier surface to prevent downcasts
0091     mutable occ::handle<BSplSLib_Cache>        Cache;   //!< Cached data for evaluation
0092     occ::handle<GeomEval_RepSurfaceDesc::Base> EvalRep; //!< Eval representation descriptor
0093   };
0094 
0095   //! Internal structure for BSpline surface cache data.
0096   struct BSplineData
0097   {
0098     occ::handle<Geom_BSplineSurface>           Surface; //!< BSpline surface to prevent downcasts
0099     mutable occ::handle<BSplSLib_Cache>        Cache;   //!< Cached data for evaluation
0100     occ::handle<GeomEval_RepSurfaceDesc::Base> EvalRep; //!< Eval representation descriptor
0101   };
0102 
0103   //! Variant type for surface-specific evaluation data.
0104   using SurfaceDataVariant = std::variant<std::monostate,
0105                                           gp_Pln,
0106                                           gp_Cylinder,
0107                                           gp_Cone,
0108                                           gp_Sphere,
0109                                           gp_Torus,
0110                                           ExtrusionData,
0111                                           RevolutionData,
0112                                           OffsetData,
0113                                           BezierData,
0114                                           BSplineData>;
0115 
0116 public:
0117   GeomAdaptor_Surface()
0118       : myUFirst(0.),
0119         myULast(0.),
0120         myVFirst(0.),
0121         myVLast(0.),
0122         myTolU(0.),
0123         myTolV(0.),
0124         mySurfaceType(GeomAbs_OtherSurface)
0125   {
0126   }
0127 
0128   GeomAdaptor_Surface(const occ::handle<Geom_Surface>& theSurf)
0129       : myTolU(0.),
0130         myTolV(0.)
0131   {
0132     Load(theSurf);
0133   }
0134 
0135   //! Standard_ConstructionError is raised if UFirst>ULast or VFirst>VLast
0136   GeomAdaptor_Surface(const occ::handle<Geom_Surface>& theSurf,
0137                       const double                     theUFirst,
0138                       const double                     theULast,
0139                       const double                     theVFirst,
0140                       const double                     theVLast,
0141                       const double                     theTolU = 0.0,
0142                       const double                     theTolV = 0.0)
0143   {
0144     Load(theSurf, theUFirst, theULast, theVFirst, theVLast, theTolU, theTolV);
0145   }
0146 
0147   //! Shallow copy of adaptor
0148   Standard_EXPORT occ::handle<Adaptor3d_Surface> ShallowCopy() const override;
0149 
0150   void Load(const occ::handle<Geom_Surface>& theSurf)
0151   {
0152     if (theSurf.IsNull())
0153     {
0154       throw Standard_NullObject("GeomAdaptor_Surface::Load");
0155     }
0156 
0157     double aU1, aU2, aV1, aV2;
0158     theSurf->Bounds(aU1, aU2, aV1, aV2);
0159     load(theSurf, aU1, aU2, aV1, aV2);
0160   }
0161 
0162   //! Standard_ConstructionError is raised if theUFirst>theULast or theVFirst>theVLast
0163   void Load(const occ::handle<Geom_Surface>& theSurf,
0164             const double                     theUFirst,
0165             const double                     theULast,
0166             const double                     theVFirst,
0167             const double                     theVLast,
0168             const double                     theTolU = 0.0,
0169             const double                     theTolV = 0.0)
0170   {
0171     if (theSurf.IsNull())
0172     {
0173       throw Standard_NullObject("GeomAdaptor_Surface::Load");
0174     }
0175     if (theUFirst > theULast || theVFirst > theVLast)
0176     {
0177       throw Standard_ConstructionError("GeomAdaptor_Surface::Load");
0178     }
0179 
0180     load(theSurf, theUFirst, theULast, theVFirst, theVLast, theTolU, theTolV);
0181   }
0182 
0183   const occ::handle<Geom_Surface>& Surface() const { return mySurface; }
0184 
0185   double FirstUParameter() const override { return myUFirst; }
0186 
0187   double LastUParameter() const override { return myULast; }
0188 
0189   double FirstVParameter() const override { return myVFirst; }
0190 
0191   double LastVParameter() const override { return myVLast; }
0192 
0193   //! Returns the parametric bounds of the surface.
0194   //! @param[out] theU1 minimum U parameter
0195   //! @param[out] theU2 maximum U parameter
0196   //! @param[out] theV1 minimum V parameter
0197   //! @param[out] theV2 maximum V parameter
0198   void Bounds(double& theU1, double& theU2, double& theV1, double& theV2) const
0199   {
0200     theU1 = FirstUParameter();
0201     theU2 = LastUParameter();
0202     theV1 = FirstVParameter();
0203     theV2 = LastVParameter();
0204   }
0205 
0206   //! Returns tolerance in U direction.
0207   double ToleranceU() const { return myTolU; }
0208 
0209   //! Returns tolerance in V direction.
0210   double ToleranceV() const { return myTolV; }
0211 
0212   Standard_EXPORT GeomAbs_Shape UContinuity() const override;
0213 
0214   Standard_EXPORT GeomAbs_Shape VContinuity() const override;
0215 
0216   //! Returns the number of U intervals for continuity
0217   //! <S>. May be one if UContinuity(me) >= <S>
0218   Standard_EXPORT int NbUIntervals(const GeomAbs_Shape S) const override;
0219 
0220   //! Returns the number of V intervals for continuity
0221   //! <S>. May be one if VContinuity(me) >= <S>
0222   Standard_EXPORT int NbVIntervals(const GeomAbs_Shape S) const override;
0223 
0224   //! Returns the intervals with the requested continuity
0225   //! in the U direction.
0226   Standard_EXPORT void UIntervals(NCollection_Array1<double>& T,
0227                                   const GeomAbs_Shape         S) const override;
0228 
0229   //! Returns the intervals with the requested continuity
0230   //! in the V direction.
0231   Standard_EXPORT void VIntervals(NCollection_Array1<double>& T,
0232                                   const GeomAbs_Shape         S) const override;
0233 
0234   //! Returns a surface trimmed in the U direction
0235   //! equivalent of <me> between
0236   //! parameters <First> and <Last>. <Tol> is used to
0237   //! test for 3d points confusion.
0238   //! If <First> >= <Last>
0239   Standard_EXPORT occ::handle<Adaptor3d_Surface> UTrim(const double First,
0240                                                        const double Last,
0241                                                        const double Tol) const override;
0242 
0243   //! Returns a surface trimmed in the V direction between
0244   //! parameters <First> and <Last>. <Tol> is used to
0245   //! test for 3d points confusion.
0246   //! If <First> >= <Last>
0247   Standard_EXPORT occ::handle<Adaptor3d_Surface> VTrim(const double First,
0248                                                        const double Last,
0249                                                        const double Tol) const override;
0250 
0251   Standard_EXPORT bool IsUClosed() const override;
0252 
0253   Standard_EXPORT bool IsVClosed() const override;
0254 
0255   Standard_EXPORT bool IsUPeriodic() const override;
0256 
0257   Standard_EXPORT double UPeriod() const override;
0258 
0259   Standard_EXPORT bool IsVPeriodic() const override;
0260 
0261   Standard_EXPORT double VPeriod() const override;
0262 
0263   //! Point evaluation. Raises an exception on failure.
0264   [[nodiscard]] Standard_EXPORT gp_Pnt EvalD0(const double theU, const double theV) const final;
0265 
0266   //! D1 evaluation. Raises an exception on failure.
0267   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD1 EvalD1(const double theU,
0268                                                            const double theV) const final;
0269 
0270   //! D2 evaluation. Raises an exception on failure.
0271   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD2 EvalD2(const double theU,
0272                                                            const double theV) const final;
0273 
0274   //! D3 evaluation. Raises an exception on failure.
0275   [[nodiscard]] Standard_EXPORT Geom_Surface::ResD3 EvalD3(const double theU,
0276                                                            const double theV) const final;
0277 
0278   //! DN evaluation. Raises an exception on failure.
0279   [[nodiscard]] Standard_EXPORT gp_Vec EvalDN(const double theU,
0280                                               const double theV,
0281                                               const int    theNu,
0282                                               const int    theNv) const final;
0283 
0284   //! Returns the parametric U resolution corresponding
0285   //! to the real space resolution <R3d>.
0286   Standard_EXPORT double UResolution(const double R3d) const override;
0287 
0288   //! Returns the parametric V resolution corresponding
0289   //! to the real space resolution <R3d>.
0290   Standard_EXPORT double VResolution(const double R3d) const override;
0291 
0292   //! Returns the type of the surface: Plane, Cylinder,
0293   //! Cone, Sphere, Torus, BezierSurface,
0294   //! BSplineSurface, SurfaceOfRevolution,
0295   //! SurfaceOfExtrusion, OtherSurface
0296   GeomAbs_SurfaceType GetType() const override { return mySurfaceType; }
0297 
0298   Standard_EXPORT gp_Pln Plane() const override;
0299 
0300   Standard_EXPORT gp_Cylinder Cylinder() const override;
0301 
0302   Standard_EXPORT gp_Cone Cone() const override;
0303 
0304   Standard_EXPORT gp_Sphere Sphere() const override;
0305 
0306   Standard_EXPORT gp_Torus Torus() const override;
0307 
0308   Standard_EXPORT int UDegree() const override;
0309 
0310   Standard_EXPORT int NbUPoles() const override;
0311 
0312   Standard_EXPORT int VDegree() const override;
0313 
0314   Standard_EXPORT int NbVPoles() const override;
0315 
0316   Standard_EXPORT int NbUKnots() const override;
0317 
0318   Standard_EXPORT int NbVKnots() const override;
0319 
0320   Standard_EXPORT bool IsURational() const override;
0321 
0322   Standard_EXPORT bool IsVRational() const override;
0323 
0324   //! This will NOT make a copy of the
0325   //! Bezier Surface : If you want to modify
0326   //! the Surface please make a copy yourself
0327   //! Also it will NOT trim the surface to
0328   //! myU/VFirst/Last.
0329   Standard_EXPORT occ::handle<Geom_BezierSurface> Bezier() const override;
0330 
0331   //! This will NOT make a copy of the
0332   //! BSpline Surface : If you want to modify
0333   //! the Surface please make a copy yourself
0334   //! Also it will NOT trim the surface to
0335   //! myU/VFirst/Last.
0336   Standard_EXPORT occ::handle<Geom_BSplineSurface> BSpline() const override;
0337 
0338   Standard_EXPORT gp_Ax1 AxeOfRevolution() const override;
0339 
0340   Standard_EXPORT gp_Dir Direction() const override;
0341 
0342   Standard_EXPORT occ::handle<Adaptor3d_Curve> BasisCurve() const override;
0343 
0344   Standard_EXPORT occ::handle<Adaptor3d_Surface> BasisSurface() const override;
0345 
0346   Standard_EXPORT double OffsetValue() const override;
0347 
0348 private:
0349   Standard_EXPORT void Span(const int Side,
0350                             const int Ideb,
0351                             const int Ifin,
0352                             int&      OutIdeb,
0353                             int&      OutIfin,
0354                             const int FKIndx,
0355                             const int LKIndx) const;
0356 
0357   Standard_EXPORT bool IfUVBound(const double U,
0358                                  const double V,
0359                                  int&         Ideb,
0360                                  int&         Ifin,
0361                                  int&         IVdeb,
0362                                  int&         IVfin,
0363                                  const int    USide,
0364                                  const int    VSide) const;
0365 
0366   Standard_EXPORT void load(const occ::handle<Geom_Surface>& S,
0367                             const double                     UFirst,
0368                             const double                     ULast,
0369                             const double                     VFirst,
0370                             const double                     VLast,
0371                             const double                     TolU = 0.0,
0372                             const double                     TolV = 0.0);
0373 
0374   //! Rebuilds B-spline cache
0375   //! \param theU first parameter to identify the span for caching
0376   //! \param theV second parameter to identify the span for caching
0377   Standard_EXPORT void RebuildCache(const double theU, const double theV) const;
0378 
0379 protected:
0380   occ::handle<Geom_Surface> mySurface;
0381   double                    myUFirst;
0382   double                    myULast;
0383   double                    myVFirst;
0384   double                    myVLast;
0385   double                    myTolU;
0386   double                    myTolV;
0387   GeomAbs_SurfaceType       mySurfaceType;
0388   SurfaceDataVariant        mySurfaceData; ///< Surface-specific evaluation data
0389 };
0390 
0391 #endif // _GeomAdaptor_Surface_HeaderFile