RegularGridSpringForceField.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_FORCEFIELD_REGULARGRIDSPRINGFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_REGULARGRIDSPRINGFORCEFIELD_H
00027 
00028 #include <sofa/component/forcefield/StiffSpringForceField.h>
00029 #include <sofa/component/topology/RegularGridTopology.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace forcefield
00038 {
00039 
00040 template<class DataTypes>
00041 class RegularGridSpringForceField : public StiffSpringForceField<DataTypes>
00042 {
00043     double m_potentialEnergy;
00044 public:
00045     typedef StiffSpringForceField<DataTypes> Inherit;
00046     typedef typename Inherit::Spring Spring;    
00047         typedef typename DataTypes::VecCoord VecCoord;
00048     typedef typename DataTypes::VecDeriv VecDeriv;
00049     typedef typename DataTypes::Coord Coord;
00050     typedef typename DataTypes::Deriv Deriv;
00051     typedef typename Coord::value_type Real;
00052 
00053     //virtual const char* getTypeName() const { return "RegularGridSpringForceField"; }
00054     
00055 protected:
00056     Data< Real > linesStiffness;
00057     Data< Real > linesDamping;
00058     Data< Real > quadsStiffness;
00059     Data< Real > quadsDamping;
00060     Data< Real > cubesStiffness;
00061     Data< Real > cubesDamping;
00062     
00063 public:
00064     RegularGridSpringForceField(core::componentmodel::behavior::MechanicalState<DataTypes>* object1, core::componentmodel::behavior::MechanicalState<DataTypes>* object2)
00065     : StiffSpringForceField<DataTypes>(object1, object2),
00066       linesStiffness  (initData(&linesStiffness,Real(0),"linesStiffness","Lines Stiffness"))
00067       , linesDamping  (initData(&linesDamping  ,Real(0),"linesDamping"  ,"Lines Damping"))
00068       , quadsStiffness(initData(&quadsStiffness,Real(0),"quadsStiffness","Quads Stiffness"))
00069       , quadsDamping  (initData(&quadsDamping  ,Real(0),"quadsDamping"  ,"Quads Damping"))
00070       , cubesStiffness(initData(&cubesStiffness,Real(0),"cubesStiffness","Cubes Stiffness"))
00071       , cubesDamping  (initData(&cubesDamping  ,Real(0),"cubesDamping"  ,"Cubes Damping"))
00072       , topology(NULL)
00073     {
00074     }
00075     
00076     RegularGridSpringForceField()
00077     :     
00078       linesStiffness  (initData(&linesStiffness,Real(0),"linesStiffness","Lines Stiffness"))
00079       , linesDamping  (initData(&linesDamping  ,Real(0),"linesDamping"  ,"Lines Damping"))
00080       , quadsStiffness(initData(&quadsStiffness,Real(0),"quadsStiffness","Quads Stiffness"))
00081       , quadsDamping  (initData(&quadsDamping  ,Real(0),"quadsDamping"  ,"Quads Damping"))
00082       , cubesStiffness(initData(&cubesStiffness,Real(0),"cubesStiffness","Cubes Stiffness"))
00083       , cubesDamping  (initData(&cubesDamping  ,Real(0),"cubesDamping"  ,"Cubes Damping"))
00084       , topology(NULL)
00085     {
00086     }
00087     
00088     Real getStiffness() const { return linesStiffness.getValue(); }
00089     Real getLinesStiffness() const { return linesStiffness.getValue(); }
00090     Real getQuadsStiffness() const { return quadsStiffness.getValue(); }
00091     Real getCubesStiffness() const { return cubesStiffness.getValue(); }
00092     void setStiffness(Real val)
00093     {
00094         linesStiffness.setValue(val);
00095         quadsStiffness.setValue(val);
00096         cubesStiffness.setValue(val);
00097     }
00098     void setLinesStiffness(Real val)
00099     {
00100         linesStiffness.setValue(val);
00101     }
00102     void setQuadsStiffness(Real val)
00103     {
00104         quadsStiffness.setValue(val);
00105     }
00106     void setCubesStiffness(Real val)
00107     {
00108         cubesStiffness.setValue(val);
00109     }
00110     
00111     Real getDamping() const { return linesDamping.getValue(); }
00112     Real getLinesDamping() const { return linesDamping.getValue(); }
00113     Real getQuadsDamping() const { return quadsDamping.getValue(); }
00114     Real getCubesDamping() const { return cubesDamping.getValue(); }
00115     void setDamping(Real val)
00116     {
00117         linesDamping.setValue(val);
00118         quadsDamping.setValue(val);
00119         cubesDamping.setValue(val);
00120     }
00121     void setLinesDamping(Real val)
00122     {
00123         linesDamping.setValue(val);
00124     }
00125     void setQuadsDamping(Real val)
00126     {
00127         quadsDamping.setValue(val);
00128     }
00129     void setCubesDamping(Real val)
00130     {
00131         cubesDamping.setValue(val);
00132     }
00133 
00134     virtual void parse(core::objectmodel::BaseObjectDescription* arg);
00135 
00136     virtual void init();
00137     
00138     virtual void addForce(VecDeriv& f1, VecDeriv& f2, const VecCoord& x1, const VecCoord& x2, const VecDeriv& v1, const VecDeriv& v2);
00139     
00140     virtual void addDForce(VecDeriv& df1, VecDeriv& df2, const VecDeriv& dx1, const VecDeriv& dx2, double kFactor, double bFactor);
00141 
00142     virtual void draw();
00143 
00144 protected:
00145     topology::RegularGridTopology* topology;
00146 };
00147 
00148 } // namespace forcefield
00149 
00150 } // namespace component
00151 
00152 } // namespace sofa
00153 
00154 #endif

Generated on Sun Nov 23 03:04:54 2008 for Sofa by  doxygen 1.5.7.1