Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2015 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 _BRepGProp_Gauss_HeaderFile
0015 #define _BRepGProp_Gauss_HeaderFile
0016 
0017 #include <NCollection_Handle.hxx>
0018 #include <NCollection_Array1.hxx>
0019 
0020 template<typename T> class math_VectorBase;
0021 using math_Vector = math_VectorBase<double>;
0022 
0023 //! Class performs computing of the global inertia properties
0024 //! of geometric object in 3D space by adaptive and non-adaptive
0025 //! 2D Gauss integration algorithms.
0026 class BRepGProp_Gauss
0027 {
0028   //! Auxiliary structure for storing of inertial moments.
0029   struct Inertia
0030   {
0031     //! Mass of the current system (without density).
0032     //! May correspond to: length, area, volume.
0033     Standard_Real Mass;
0034 
0035     //! Static moments of inertia.
0036     Standard_Real Ix;
0037     Standard_Real Iy;
0038     Standard_Real Iz;
0039 
0040     //! Quadratic moments of inertia.
0041     Standard_Real Ixx;
0042     Standard_Real Iyy;
0043     Standard_Real Izz;
0044     Standard_Real Ixy;
0045     Standard_Real Ixz;
0046     Standard_Real Iyz;
0047 
0048     //! Default constructor.
0049     Inertia();
0050 
0051     //! Zeroes all values.
0052     void Reset();
0053   };
0054 
0055   typedef NCollection_Handle< NCollection_Array1<Inertia> > InertiaArray;
0056   typedef Standard_Real(*BRepGProp_GaussFunc)(const Standard_Real, const Standard_Real);
0057 
0058 public: //! @name public API
0059 
0060   //! Describes types of geometric objects.
0061   //! - Vinert is 3D closed region of space delimited with:
0062   //! -- Surface;
0063   //! -- Point and Surface;
0064   //! -- Plane and Surface.
0065   //! - Sinert is face in 3D space.
0066   typedef enum { Vinert = 0, Sinert } BRepGProp_GaussType;
0067 
0068   //! Constructor
0069   Standard_EXPORT explicit BRepGProp_Gauss(const BRepGProp_GaussType theType);
0070 
0071   //! Computes the global properties of a solid region of 3D space which can be
0072   //! delimited by the surface and point or surface and plane. Surface can be closed.
0073   //! The method is quick and its precision is enough for many cases of analytical surfaces.
0074   //! Non-adaptive 2D Gauss integration with predefined numbers of Gauss points
0075   //! is used. Numbers of points depend on types of surfaces and curves.
0076   //! Error of the computation is not calculated.
0077   //! @param theSurface - bounding surface of the region;
0078   //! @param theLocation - location of the point or the plane;
0079   //! @param theCoeff - plane coefficients;
0080   //! @param theIsByPoint - flag of restricition (point/plane);
0081   //! @param theOutMass[out] - mass (volume) of region;
0082   //! @param theOutGravityCenter[out] - garvity center of region;
0083   //! @param theOutInertia[out] - matrix of inertia;
0084   Standard_EXPORT void Compute(
0085     const BRepGProp_Face&  theSurface,
0086     const gp_Pnt&          theLocation,
0087     const Standard_Real    theCoeff[],
0088     const Standard_Boolean theIsByPoint,
0089     Standard_Real&         theOutMass,
0090     gp_Pnt&                theOutGravityCenter,
0091     gp_Mat&                theOutInertia);
0092 
0093   //! Computes the global properties of a surface. Surface can be closed.
0094   //! The method is quick and its precision is enough for many cases of analytical surfaces.
0095   //! Non-adaptive 2D Gauss integration with predefined numbers of Gauss points
0096   //! is used. Numbers of points depend on types of surfaces and curves.
0097   //! Error of the computation is not calculated.
0098   //! @param theSurface - bounding surface of the region;
0099   //! @param theLocation - surface location;
0100   //! @param theOutMass[out] - mass (volume) of region;
0101   //! @param theOutGravityCenter[out] - garvity center of region;
0102   //! @param theOutInertia[out] - matrix of inertia;
0103   Standard_EXPORT void Compute(
0104     const BRepGProp_Face&  theSurface,
0105     const gp_Pnt&          theLocation,
0106     Standard_Real&         theOutMass,
0107     gp_Pnt&                theOutGravityCenter,
0108     gp_Mat&                theOutInertia);
0109 
0110   //! Computes the global properties of a region of 3D space which can be
0111   //! delimited by the surface and point or surface and plane. Surface can be closed.
0112   //! The method is quick and its precision is enough for many cases of analytical surfaces.
0113   //! Non-adaptive 2D Gauss integration with predefined numbers of Gauss points is used.
0114   //! Numbers of points depend on types of surfaces and curves.
0115   //! Error of the computation is not calculated.
0116   //! @param theSurface - bounding surface of the region;
0117   //! @param theDomain - surface boundings;
0118   //! @param theLocation - location of the point or the plane;
0119   //! @param theCoeff - plane coefficients;
0120   //! @param theIsByPoint - flag of restricition (point/plane);
0121   //! @param theOutMass[out] - mass (volume) of region;
0122   //! @param theOutGravityCenter[out] - garvity center of region;
0123   //! @param theOutInertia[out] - matrix of inertia;
0124   Standard_EXPORT void Compute(
0125     BRepGProp_Face&        theSurface,
0126     BRepGProp_Domain&      theDomain,
0127     const gp_Pnt&          theLocation,
0128     const Standard_Real    theCoeff[],
0129     const Standard_Boolean theIsByPoint,
0130     Standard_Real&         theOutMass,
0131     gp_Pnt&                theOutGravityCenter,
0132     gp_Mat&                theOutInertia);
0133 
0134   //! Computes the global properties of a surface. Surface can be closed.
0135   //! The method is quick and its precision is enough for many cases of analytical surfaces.
0136   //! Non-adaptive 2D Gauss integration with predefined numbers of Gauss points
0137   //! is used. Numbers of points depend on types of surfaces and curves.
0138   //! Error of the computation is not calculated.
0139   //! @param theSurface - bounding surface of the region;
0140   //! @param theDomain - surface boundings;
0141   //! @param theLocation - surface location;
0142   //! @param theOutMass[out] - mass (volume) of region;
0143   //! @param theOutGravityCenter[out] - garvity center of region;
0144   //! @param theOutInertia[out] - matrix of inertia;
0145   Standard_EXPORT void Compute(
0146     BRepGProp_Face&        theSurface,
0147     BRepGProp_Domain&      theDomain,
0148     const gp_Pnt&          theLocation,
0149     Standard_Real&         theOutMass,
0150     gp_Pnt&                theOutGravityCenter,
0151     gp_Mat&                theOutInertia);
0152 
0153   //! Computes the global properties of the region of 3D space which can be
0154   //! delimited by the surface and point or surface and plane.
0155   //! Adaptive 2D Gauss integration is used.
0156   //! If Epsilon more than 0.001 then algorithm performs non-adaptive integration.
0157   //! @param theSurface - bounding surface of the region;
0158   //! @param theDomain - surface boundings;
0159   //! @param theLocation - location of the point or the plane;
0160   //! @param theEps - maximal relative error of computed mass (volume) for face;
0161   //! @param theCoeff - plane coefficients;
0162   //! @param theIsByPoint - flag of restricition (point/plane);
0163   //! @param theOutMass[out] - mass (volume) of region;
0164   //! @param theOutGravityCenter[out] - garvity center of region;
0165   //! @param theOutInertia[out] - matrix of inertia;
0166   //! @return value of error which is calculated as
0167   //! Abs((M(i+1)-M(i))/M(i+1)), M(i+1) and M(i) are values
0168   //! for two successive steps of adaptive integration.
0169   Standard_EXPORT Standard_Real Compute(
0170     BRepGProp_Face&        theSurface,
0171     BRepGProp_Domain&      theDomain,
0172     const gp_Pnt&          theLocation,
0173     const Standard_Real    theEps,
0174     const Standard_Real    theCoeff[],
0175     const Standard_Boolean theByPoint,
0176     Standard_Real&         theOutMass,
0177     gp_Pnt&                theOutGravityCenter,
0178     gp_Mat&                theOutInertia);
0179 
0180   //! Computes the global properties of the face. Adaptive 2D Gauss integration is used.
0181   //! If Epsilon more than 0.001 then algorithm performs non-adaptive integration.
0182   //! @param theSurface - bounding surface of the region;
0183   //! @param theDomain - surface boundings;
0184   //! @param theLocation - surface location;
0185   //! @param theEps - maximal relative error of computed mass (square) for face;
0186   //! @param theOutMass[out] - mass (volume) of region;
0187   //! @param theOutGravityCenter[out] - garvity center of region;
0188   //! @param theOutInertia[out] - matrix of inertia;
0189   //! @return value of error which is calculated as
0190   //! Abs((M(i+1)-M(i))/M(i+1)), M(i+1) and M(i) are values
0191   //! for two successive steps of adaptive integration.
0192   Standard_EXPORT Standard_Real Compute(
0193     BRepGProp_Face&        theSurface,
0194     BRepGProp_Domain&      theDomain,
0195     const gp_Pnt&          theLocation,
0196     const Standard_Real    theEps,
0197     Standard_Real&         theOutMass,
0198     gp_Pnt&                theOutGravityCenter,
0199     gp_Mat&                theOutInertia);
0200 
0201 private: //! @name private methods
0202 
0203   BRepGProp_Gauss(BRepGProp_Gauss const&);
0204   BRepGProp_Gauss& operator= (BRepGProp_Gauss const&);
0205 
0206   void computeVInertiaOfElementaryPart(
0207     const gp_Pnt&             thePoint,
0208     const gp_Vec&             theNormal,
0209     const gp_Pnt&             theLocation,
0210     const Standard_Real       theWeight,
0211     const Standard_Real       theCoeff[],
0212     const Standard_Boolean    theIsByPoint,
0213     BRepGProp_Gauss::Inertia& theOutInertia);
0214 
0215   void computeSInertiaOfElementaryPart(
0216     const gp_Pnt&             thePoint,
0217     const gp_Vec&             theNormal,
0218     const gp_Pnt&             theLocation,
0219     const Standard_Real       theWeight,
0220     BRepGProp_Gauss::Inertia& theOutInertia);
0221 
0222   void checkBounds(
0223     const Standard_Real theU1,
0224     const Standard_Real theU2,
0225     const Standard_Real theV1,
0226     const Standard_Real theV2);
0227 
0228   void addAndRestoreInertia(
0229     const BRepGProp_Gauss::Inertia& theInInertia,
0230     BRepGProp_Gauss::Inertia&       theOutInertia);
0231 
0232   void multAndRestoreInertia(
0233     const Standard_Real       theValue,
0234     BRepGProp_Gauss::Inertia& theInertia);
0235 
0236   void convert(
0237     const BRepGProp_Gauss::Inertia& theInertia,
0238     gp_Pnt&                         theOutGravityCenter,
0239     gp_Mat&                         theOutMatrixOfInertia,
0240     Standard_Real&                  theOutMass);
0241 
0242   void convert(
0243     const BRepGProp_Gauss::Inertia& theInertia,
0244     const Standard_Real             theCoeff[],
0245     const Standard_Boolean          theIsByPoint,
0246     gp_Pnt&                         theOutGravityCenter,
0247     gp_Mat&                         theOutMatrixOfInertia,
0248     Standard_Real&                  theOutMass);
0249 
0250   static Standard_Integer MaxSubs(
0251     const Standard_Integer theN,
0252     const Standard_Integer theCoeff = 32);
0253 
0254   static void Init(
0255     NCollection_Handle<math_Vector>&         theOutVec,
0256     const Standard_Real    theValue,
0257     const Standard_Integer theFirst = 0,
0258     const Standard_Integer theLast  = 0);
0259 
0260   static void InitMass(
0261     const Standard_Real    theValue,
0262     const Standard_Integer theFirst,
0263     const Standard_Integer theLast,
0264     InertiaArray&          theArray);
0265 
0266   static Standard_Integer FillIntervalBounds(
0267     const Standard_Real         theA,
0268     const Standard_Real         theB,
0269     const TColStd_Array1OfReal& theKnots,
0270     const Standard_Integer      theNumSubs,
0271     InertiaArray&               theInerts,
0272     NCollection_Handle<math_Vector>&              theParam1,
0273     NCollection_Handle<math_Vector>&              theParam2,
0274     NCollection_Handle<math_Vector>&              theError,
0275     NCollection_Handle<math_Vector>&              theCommonError);
0276 
0277 private: //! @name private fields
0278 
0279   BRepGProp_GaussType myType; //!< Type of geometric object
0280   BRepGProp_GaussFunc add;    //!< Pointer on the add function
0281   BRepGProp_GaussFunc mult;   //!< Pointer on the mult function
0282 };
0283 
0284 #endif