Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-18 08:29:20

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