Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:37

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_Surface.hxx>
0021 #include <BSplSLib_Cache.hxx>
0022 #include <GeomAbs_Shape.hxx>
0023 #include <GeomEvaluator_Surface.hxx>
0024 #include <Geom_Surface.hxx>
0025 #include <Standard_NullObject.hxx>
0026 #include <TColStd_Array1OfReal.hxx>
0027 
0028 DEFINE_STANDARD_HANDLE(GeomAdaptor_Surface, Adaptor3d_Surface)
0029 
0030 //! An interface between the services provided by any
0031 //! surface from the package Geom and those required
0032 //! of the surface by algorithms which use it.
0033 //! Creation of the loaded surface the surface is C1 by piece
0034 //!
0035 //! Polynomial coefficients of BSpline surfaces used for their evaluation are
0036 //! cached for better performance. Therefore these evaluations are not
0037 //! thread-safe and parallel evaluations need to be prevented.
0038 class GeomAdaptor_Surface  : public Adaptor3d_Surface
0039 {
0040   DEFINE_STANDARD_RTTIEXT(GeomAdaptor_Surface, Adaptor3d_Surface)
0041 public:
0042 
0043   GeomAdaptor_Surface()
0044   : myUFirst(0.), myULast(0.),
0045     myVFirst(0.), myVLast (0.),
0046     myTolU(0.),   myTolV(0.),
0047     mySurfaceType (GeomAbs_OtherSurface) {}
0048 
0049   GeomAdaptor_Surface(const Handle(Geom_Surface)& theSurf)
0050   : myTolU(0.), myTolV(0.)
0051   {
0052     Load (theSurf);
0053   }
0054 
0055   //! Standard_ConstructionError is raised if UFirst>ULast or VFirst>VLast
0056   GeomAdaptor_Surface (const Handle(Geom_Surface)& theSurf,
0057                        const Standard_Real theUFirst, const Standard_Real theULast,
0058                        const Standard_Real theVFirst, const Standard_Real theVLast,
0059                        const Standard_Real theTolU = 0.0, const Standard_Real theTolV = 0.0)
0060   {
0061     Load (theSurf, theUFirst, theULast, theVFirst, theVLast, theTolU, theTolV);
0062   }
0063 
0064   //! Shallow copy of adaptor
0065   Standard_EXPORT virtual Handle(Adaptor3d_Surface) ShallowCopy() const Standard_OVERRIDE;
0066 
0067   void Load (const Handle(Geom_Surface)& theSurf)
0068   {
0069     if (theSurf.IsNull()) { throw Standard_NullObject("GeomAdaptor_Surface::Load"); }
0070 
0071     Standard_Real aU1, aU2, aV1, aV2;
0072     theSurf->Bounds (aU1, aU2, aV1, aV2);
0073     load (theSurf, aU1, aU2, aV1, aV2);
0074   }
0075 
0076   //! Standard_ConstructionError is raised if theUFirst>theULast or theVFirst>theVLast
0077   void Load (const Handle(Geom_Surface)& theSurf,
0078              const Standard_Real theUFirst, const Standard_Real theULast,
0079              const Standard_Real theVFirst, const Standard_Real theVLast,
0080              const Standard_Real theTolU = 0.0, const Standard_Real theTolV = 0.0)
0081   {
0082     if (theSurf.IsNull()) { throw Standard_NullObject("GeomAdaptor_Surface::Load"); }
0083     if (theUFirst > theULast || theVFirst > theVLast) { throw Standard_ConstructionError("GeomAdaptor_Surface::Load"); }
0084 
0085     load (theSurf, theUFirst, theULast, theVFirst, theVLast, theTolU, theTolV);
0086   }
0087 
0088   const Handle(Geom_Surface)& Surface() const { return mySurface; }
0089 
0090   virtual Standard_Real FirstUParameter() const Standard_OVERRIDE { return myUFirst; }
0091 
0092   virtual Standard_Real LastUParameter() const Standard_OVERRIDE { return myULast; }
0093 
0094   virtual Standard_Real FirstVParameter() const Standard_OVERRIDE { return myVFirst; }
0095 
0096   virtual Standard_Real LastVParameter() const Standard_OVERRIDE { return myVLast; }
0097 
0098   Standard_EXPORT GeomAbs_Shape UContinuity() const Standard_OVERRIDE;
0099   
0100   Standard_EXPORT GeomAbs_Shape VContinuity() const Standard_OVERRIDE;
0101   
0102   //! Returns the number of U intervals for  continuity
0103   //! <S>. May be one if UContinuity(me) >= <S>
0104   Standard_EXPORT Standard_Integer NbUIntervals (const GeomAbs_Shape S) const Standard_OVERRIDE;
0105   
0106   //! Returns the number of V intervals for  continuity
0107   //! <S>. May be one if VContinuity(me) >= <S>
0108   Standard_EXPORT Standard_Integer NbVIntervals (const GeomAbs_Shape S) const Standard_OVERRIDE;
0109   
0110   //! Returns the  intervals with the requested continuity
0111   //! in the U direction.
0112   Standard_EXPORT void UIntervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const Standard_OVERRIDE;
0113   
0114   //! Returns the  intervals with the requested continuity
0115   //! in the V direction.
0116   Standard_EXPORT void VIntervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const Standard_OVERRIDE;
0117   
0118   //! Returns    a  surface trimmed in the U direction
0119   //! equivalent   of  <me>  between
0120   //! parameters <First>  and <Last>. <Tol>  is used  to
0121   //! test for 3d points confusion.
0122   //! If <First> >= <Last>
0123   Standard_EXPORT Handle(Adaptor3d_Surface) UTrim (const Standard_Real First, const Standard_Real Last, const Standard_Real Tol) const Standard_OVERRIDE;
0124   
0125   //! Returns    a  surface trimmed in the V direction  between
0126   //! parameters <First>  and <Last>. <Tol>  is used  to
0127   //! test for 3d points confusion.
0128   //! If <First> >= <Last>
0129   Standard_EXPORT Handle(Adaptor3d_Surface) VTrim (const Standard_Real First, const Standard_Real Last, const Standard_Real Tol) const Standard_OVERRIDE;
0130   
0131   Standard_EXPORT Standard_Boolean IsUClosed() const Standard_OVERRIDE;
0132   
0133   Standard_EXPORT Standard_Boolean IsVClosed() const Standard_OVERRIDE;
0134   
0135   Standard_EXPORT Standard_Boolean IsUPeriodic() const Standard_OVERRIDE;
0136   
0137   Standard_EXPORT Standard_Real UPeriod() const Standard_OVERRIDE;
0138   
0139   Standard_EXPORT Standard_Boolean IsVPeriodic() const Standard_OVERRIDE;
0140   
0141   Standard_EXPORT Standard_Real VPeriod() const Standard_OVERRIDE;
0142   
0143   //! Computes the point of parameters U,V on the surface.
0144   Standard_EXPORT gp_Pnt Value (const Standard_Real U, const Standard_Real V) const Standard_OVERRIDE;
0145   
0146   //! Computes the point of parameters U,V on the surface.
0147   Standard_EXPORT void D0 (const Standard_Real U, const Standard_Real V, gp_Pnt& P) const Standard_OVERRIDE;
0148   
0149   //! Computes the point  and the first derivatives on
0150   //! the surface.
0151   //!
0152   //! Warning : On the specific case of BSplineSurface:
0153   //! if the surface is cut in interval of continuity at least C1,
0154   //! the derivatives are computed on the current interval.
0155   //! else the derivatives are computed on the basis surface.
0156   Standard_EXPORT void D1 (const Standard_Real U, const Standard_Real V, gp_Pnt& P, gp_Vec& D1U, gp_Vec& D1V) const Standard_OVERRIDE;
0157   
0158   //! Computes   the point,  the  first  and  second
0159   //! derivatives on the surface.
0160   //!
0161   //! Warning : On the specific case of BSplineSurface:
0162   //! if the surface is cut in interval of continuity at least C2,
0163   //! the derivatives are computed on the current interval.
0164   //! else the derivatives are computed on the basis surface.
0165   Standard_EXPORT void D2 (const Standard_Real U, const Standard_Real V, gp_Pnt& P, gp_Vec& D1U, gp_Vec& D1V, gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV) const Standard_OVERRIDE;
0166   
0167   //! Computes the point,  the first, second and third
0168   //! derivatives on the surface.
0169   //!
0170   //! Warning : On the specific case of BSplineSurface:
0171   //! if the surface is cut in interval of continuity at least C3,
0172   //! the derivatives are computed on the current interval.
0173   //! else the derivatives are computed on the basis surface.
0174   Standard_EXPORT void D3 (const Standard_Real U, const Standard_Real V, gp_Pnt& P, gp_Vec& D1U, gp_Vec& D1V, gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV, gp_Vec& D3U, gp_Vec& D3V, gp_Vec& D3UUV, gp_Vec& D3UVV) const Standard_OVERRIDE;
0175   
0176   //! Computes the derivative of order Nu in the
0177   //! direction U and Nv in the direction V at the point P(U, V).
0178   //!
0179   //! Warning : On the specific case of BSplineSurface:
0180   //! if the surface is cut in interval of continuity CN,
0181   //! the derivatives are computed on the current interval.
0182   //! else the derivatives are computed on the basis surface.
0183   //! Raised if Nu + Nv < 1 or Nu < 0 or Nv < 0.
0184   Standard_EXPORT gp_Vec DN (const Standard_Real U, const Standard_Real V, const Standard_Integer Nu, const Standard_Integer Nv) const Standard_OVERRIDE;
0185   
0186   //! Returns the parametric U  resolution corresponding
0187   //! to the real space resolution <R3d>.
0188   Standard_EXPORT Standard_Real UResolution (const Standard_Real R3d) const Standard_OVERRIDE;
0189   
0190   //! Returns the parametric V  resolution corresponding
0191   //! to the real space resolution <R3d>.
0192   Standard_EXPORT Standard_Real VResolution (const Standard_Real R3d) const Standard_OVERRIDE;
0193   
0194   //! Returns the type of the surface : Plane, Cylinder,
0195   //! Cone,      Sphere,        Torus,    BezierSurface,
0196   //! BSplineSurface,               SurfaceOfRevolution,
0197   //! SurfaceOfExtrusion, OtherSurface
0198   virtual GeomAbs_SurfaceType GetType() const Standard_OVERRIDE { return mySurfaceType; }
0199 
0200   Standard_EXPORT gp_Pln Plane() const Standard_OVERRIDE;
0201   
0202   Standard_EXPORT gp_Cylinder Cylinder() const Standard_OVERRIDE;
0203   
0204   Standard_EXPORT gp_Cone Cone() const Standard_OVERRIDE;
0205   
0206   Standard_EXPORT gp_Sphere Sphere() const Standard_OVERRIDE;
0207   
0208   Standard_EXPORT gp_Torus Torus() const Standard_OVERRIDE;
0209   
0210   Standard_EXPORT Standard_Integer UDegree() const Standard_OVERRIDE;
0211   
0212   Standard_EXPORT Standard_Integer NbUPoles() const Standard_OVERRIDE;
0213   
0214   Standard_EXPORT Standard_Integer VDegree() const Standard_OVERRIDE;
0215   
0216   Standard_EXPORT Standard_Integer NbVPoles() const Standard_OVERRIDE;
0217   
0218   Standard_EXPORT Standard_Integer NbUKnots() const Standard_OVERRIDE;
0219   
0220   Standard_EXPORT Standard_Integer NbVKnots() const Standard_OVERRIDE;
0221   
0222   Standard_EXPORT Standard_Boolean IsURational() const Standard_OVERRIDE;
0223   
0224   Standard_EXPORT Standard_Boolean IsVRational() const Standard_OVERRIDE;
0225   
0226   //! This will NOT make a copy of the
0227   //! Bezier Surface : If you want to modify
0228   //! the Surface please make a copy yourself
0229   //! Also it will NOT trim the surface to
0230   //! myU/VFirst/Last.
0231   Standard_EXPORT Handle(Geom_BezierSurface) Bezier() const Standard_OVERRIDE;
0232   
0233   //! This will NOT make a copy of the
0234   //! BSpline Surface : If you want to modify
0235   //! the Surface please make a copy yourself
0236   //! Also it will NOT trim the surface to
0237   //! myU/VFirst/Last.
0238   Standard_EXPORT Handle(Geom_BSplineSurface) BSpline() const Standard_OVERRIDE;
0239   
0240   Standard_EXPORT gp_Ax1 AxeOfRevolution() const Standard_OVERRIDE;
0241   
0242   Standard_EXPORT gp_Dir Direction() const Standard_OVERRIDE;
0243   
0244   Standard_EXPORT Handle(Adaptor3d_Curve) BasisCurve() const Standard_OVERRIDE;
0245   
0246   Standard_EXPORT Handle(Adaptor3d_Surface) BasisSurface() const Standard_OVERRIDE;
0247   
0248   Standard_EXPORT Standard_Real OffsetValue() const Standard_OVERRIDE;
0249 
0250 private:
0251 
0252   Standard_EXPORT void Span (const Standard_Integer Side, const Standard_Integer Ideb, const Standard_Integer Ifin, Standard_Integer& OutIdeb, Standard_Integer& OutIfin, const Standard_Integer FKIndx, const Standard_Integer LKIndx) const;
0253   
0254   Standard_EXPORT Standard_Boolean IfUVBound (const Standard_Real U, const Standard_Real V, Standard_Integer& Ideb, Standard_Integer& Ifin, Standard_Integer& IVdeb, Standard_Integer& IVfin, const Standard_Integer USide, const Standard_Integer VSide) const;
0255   
0256   Standard_EXPORT void load (const Handle(Geom_Surface)& S, const Standard_Real UFirst, const Standard_Real ULast, const Standard_Real VFirst, const Standard_Real VLast, const Standard_Real TolU = 0.0, const Standard_Real TolV = 0.0);
0257   
0258   //! Rebuilds B-spline cache
0259   //! \param theU first parameter to identify the span for caching
0260   //! \param theV second parameter to identify the span for caching
0261   Standard_EXPORT void RebuildCache (const Standard_Real theU, const Standard_Real theV) const;
0262 
0263   protected:
0264 
0265   Handle(Geom_Surface) mySurface;
0266   Standard_Real myUFirst;
0267   Standard_Real myULast;
0268   Standard_Real myVFirst;
0269   Standard_Real myVLast;
0270   Standard_Real myTolU;
0271   Standard_Real myTolV;
0272   
0273   Handle(Geom_BSplineSurface) myBSplineSurface; ///< B-spline representation to prevent downcasts
0274   mutable Handle(BSplSLib_Cache) mySurfaceCache; ///< Cached data for B-spline or Bezier surface
0275 
0276   GeomAbs_SurfaceType mySurfaceType;
0277   Handle(GeomEvaluator_Surface) myNestedEvaluator; ///< Calculates values of nested complex surfaces (offset surface, surface of extrusion or revolution)
0278 };
0279 
0280 #endif // _GeomAdaptor_Surface_HeaderFile