DiagonalMass.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_DIAGONALMASS_H
00026 #define SOFA_COMPONENT_MASS_DIAGONALMASS_H
00027
00028 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00029 #pragma once
00030 #endif
00031
00032 #include <sofa/defaulttype/VecTypes.h>
00033 #include <sofa/core/componentmodel/behavior/Mass.h>
00034 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00035 #include <sofa/core/objectmodel/Event.h>
00036 #include <sofa/component/topology/PointData.h>
00037 #include <sofa/helper/vector.h>
00038
00039 #include <sofa/component/topology/EdgeSetGeometryAlgorithms.h>
00040 #include <sofa/component/topology/TriangleSetGeometryAlgorithms.h>
00041 #include <sofa/component/topology/TetrahedronSetGeometryAlgorithms.h>
00042 #include <sofa/component/topology/QuadSetGeometryAlgorithms.h>
00043 #include <sofa/component/topology/HexahedronSetGeometryAlgorithms.h>
00044
00045 namespace sofa
00046 {
00047
00048 namespace component
00049 {
00050
00051 namespace mass
00052 {
00053
00054
00055
00056 template <class DataTypes, class MassType>
00057 class DiagonalMass : public core::componentmodel::behavior::Mass<DataTypes>, public virtual core::objectmodel::BaseObject
00058 {
00059 public:
00060 typedef core::componentmodel::behavior::Mass<DataTypes> Inherited;
00061 typedef typename DataTypes::VecCoord VecCoord;
00062 typedef typename DataTypes::VecDeriv VecDeriv;
00063 typedef typename DataTypes::Coord Coord;
00064 typedef typename DataTypes::Deriv Deriv;
00065 typedef typename DataTypes::Real Real;
00066
00067 typedef sofa::component::topology::PointData<MassType> VecMass;
00068 typedef helper::vector<MassType> MassVector;
00069
00070
00071 typedef enum {
00072 TOPOLOGY_UNKNOWN=0,
00073 TOPOLOGY_EDGESET=1,
00074 TOPOLOGY_TRIANGLESET=2,
00075 TOPOLOGY_TETRAHEDRONSET=3,
00076 TOPOLOGY_QUADSET=4,
00077 TOPOLOGY_HEXAHEDRONSET=5
00078 } TopologyType;
00079
00080 Data< VecMass > f_mass;
00082 Data< Real > m_massDensity;
00083
00085 Data< bool > showCenterOfGravity;
00086 Data< float > showAxisSize;
00087
00088 protected:
00089
00090
00091 class Loader;
00093 TopologyType topologyType;
00094
00095 public:
00096
00097 sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00098
00099 sofa::component::topology::EdgeSetGeometryAlgorithms<DataTypes>* edgeGeo;
00100 sofa::component::topology::TriangleSetGeometryAlgorithms<DataTypes>* triangleGeo;
00101 sofa::component::topology::QuadSetGeometryAlgorithms<DataTypes>* quadGeo;
00102 sofa::component::topology::TetrahedronSetGeometryAlgorithms<DataTypes>* tetraGeo;
00103 sofa::component::topology::HexahedronSetGeometryAlgorithms<DataTypes>* hexaGeo;
00104
00105 DiagonalMass();
00106
00107 ~DiagonalMass();
00108
00109
00110
00111 bool load(const char *filename);
00112
00113 void clear();
00114
00115 virtual void reinit();
00116 virtual void init();
00117 virtual void parse(core::objectmodel::BaseObjectDescription* arg);
00118
00119 TopologyType getMassTopologyType() const {
00120 return topologyType;
00121 }
00122 Real getMassDensity() const {
00123 return m_massDensity.getValue();
00124 }
00125
00126
00127
00128 virtual void handleTopologyChange();
00129
00130 void setMassDensity(Real m) {
00131 m_massDensity.setValue(m);
00132 }
00133
00134
00135 void addMass(const MassType& mass);
00136
00137 void resize(int vsize);
00138
00139
00140 void addMDx(VecDeriv& f, const VecDeriv& dx, double factor = 1.0);
00141
00142 void accFromF(VecDeriv& a, const VecDeriv& f);
00143
00144 void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00145
00146 double getKineticEnergy(const VecDeriv& v);
00147
00148 double getPotentialEnergy(const VecCoord& x);
00149
00150 void addGravityToV(double dt);
00151
00153 void addMToMatrix(defaulttype::BaseMatrix * mat, double mFact, unsigned int &offset);
00154
00155 double getElementMass(unsigned int index);
00156
00157 void draw();
00158
00159 bool addBBox(double* minBBox, double* maxBBox);
00160 };
00161
00162 }
00163
00164 }
00165
00166 }
00167
00168 #endif