UniformMass.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
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 //protected:
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     // -- Mass interface
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 } // namespace mass
00104 
00105 } // namespace component
00106 
00107 } // namespace sofa
00108 
00109 #endif
00110 

Generated on Sun Nov 23 03:38:51 2008 for Sofa by  doxygen 1.5.7.1