UniformMass.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_MASS_UNIFORMMASS_H
00026 #define SOFA_COMPONENT_MASS_UNIFORMMASS_H
00027
00028 #include <sofa/defaulttype/VecTypes.h>
00029 #include <sofa/core/componentmodel/behavior/Mass.h>
00030 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00031 #include <sofa/component/contextobject/CoordinateSystem.h>
00032 #include <sofa/defaulttype/BaseVector.h>
00033
00034 namespace sofa
00035 {
00036
00037 namespace component
00038 {
00039
00040 namespace mass
00041 {
00042
00043 using namespace sofa::defaulttype;
00044
00045 template <class DataTypes, class MassType>
00046 class UniformMass : public core::componentmodel::behavior::Mass<DataTypes>, public virtual core::objectmodel::BaseObject
00047 {
00048 public:
00049 typedef core::componentmodel::behavior::Mass<DataTypes> Inherited;
00050 typedef typename DataTypes::VecCoord VecCoord;
00051 typedef typename DataTypes::VecDeriv VecDeriv;
00052 typedef typename DataTypes::Coord Coord;
00053 typedef typename DataTypes::Deriv Deriv;
00054 typedef typename Coord::value_type Real;
00055
00056 Data<MassType> mass;
00057 Data<double> totalMass;
00058
00060 Data< bool > showCenterOfGravity;
00061 Data< float > showAxisSize;
00062
00063 public:
00064 UniformMass();
00065
00066 ~UniformMass();
00067
00068 void setMass(const MassType& mass);
00069 const MassType& getMass() const { return mass.getValue(); }
00070
00071 double getTotalMass() const { return totalMass.getValue(); }
00072 void setTotalMass(double m);
00073
00074
00075
00076 virtual void parse(core::objectmodel::BaseObjectDescription* arg);
00077 void init();
00078
00079 void addMDx(VecDeriv& f, const VecDeriv& dx, double factor = 1.0);
00080
00081 void accFromF(VecDeriv& a, const VecDeriv& f);
00082
00083 void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00084
00085 double getKineticEnergy(const VecDeriv& v);
00086
00087 double getPotentialEnergy(const VecCoord& x);
00088
00089 void addMDxToVector(defaulttype::BaseVector *resVect, const VecDeriv *dx, SReal mFact, unsigned int& offset);
00090
00091 void addGravityToV(double dt);
00092
00094 void addMToMatrix(defaulttype::BaseMatrix * mat, double mFact, unsigned int &offset);
00095
00096 double getElementMass(unsigned int index);
00097
00098 void draw();
00099
00100 bool addBBox(double* minBBox, double* maxBBox);
00101 };
00102
00103 }
00104
00105 }
00106
00107 }
00108
00109 #endif
00110