MeshSpringForceField.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_MESHSPRINGFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_MESHSPRINGFORCEFIELD_H
00027 
00028 #include <sofa/component/forcefield/StiffSpringForceField.h>
00029 #include <set>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace forcefield
00038 {
00039 
00040 template<class DataTypes>
00041 class MeshSpringForceField : public StiffSpringForceField<DataTypes>
00042 {
00043 public:
00044     typedef typename DataTypes::VecCoord VecCoord;
00045     typedef typename DataTypes::VecDeriv VecDeriv;
00046     typedef typename DataTypes::Coord Coord;
00047     typedef typename DataTypes::Deriv Deriv;
00048     typedef typename Coord::value_type Real;
00049     
00050 protected:
00051     Data< Real >  linesStiffness;
00052     Data< Real >  linesDamping;
00053     Data< Real >  trianglesStiffness;
00054     Data< Real >  trianglesDamping;
00055     Data< Real >  quadsStiffness;
00056     Data< Real >  quadsDamping;
00057     Data< Real >  tetrasStiffness;
00058     Data< Real >  tetrasDamping;
00059     Data< Real >  cubesStiffness;
00060     Data< Real >  cubesDamping;
00061 
00062     void addSpring(std::set<std::pair<int,int> >& sset, int m1, int m2, Real stiffness, Real damping);
00063     
00064 public:
00065     MeshSpringForceField()
00066       : linesStiffness(initData(&linesStiffness,Real(0),"linesStiffness","Stiffness for the Lines")), 
00067       linesDamping(initData(&linesDamping,Real(0),"linesDamping","Damping for the Lines")),
00068       trianglesStiffness(initData(&trianglesStiffness,Real(0),"trianglesStiffness","Stiffness for the Triangles")),
00069       trianglesDamping(initData(&trianglesDamping,Real(0),"trianglesDamping","Damping for the Triangles")),
00070       quadsStiffness(initData(&quadsStiffness,Real(0),"quadsStiffness","Stiffness for the Quads")), 
00071       quadsDamping(initData(&quadsDamping,Real(0),"quadsDamping","Damping for the Quads")),
00072       tetrasStiffness(initData(&tetrasStiffness,Real(0),"tetrasStiffness","Stiffness for the Tetras")),
00073       tetrasDamping(initData(&tetrasDamping,Real(0),"tetrasDamping","Damping for the Tetras")),
00074       cubesStiffness(initData(&cubesStiffness,Real(0),"cubesStiffness","Stiffness for the Cubes")),
00075       cubesDamping(initData(&cubesDamping,Real(0),"cubesDamping","Damping for the Cubes"))
00076     {
00077     }
00078         
00079     virtual double getPotentialEnergy();
00080         
00081     
00082     Real getStiffness() const { return linesStiffness.getValue(); }
00083     Real getLinesStiffness() const { return linesStiffness.getValue(); }
00084     Real getTrianglesStiffness() const { return trianglesStiffness.getValue(); }
00085     Real getQuadsStiffness() const { return quadsStiffness.getValue(); }
00086     Real getTetrasStiffness() const { return tetrasStiffness.getValue(); }
00087     Real getCubesStiffness() const { return cubesStiffness.getValue(); }
00088     void setStiffness(Real val)
00089     {
00090         linesStiffness.setValue(val);
00091         trianglesStiffness.setValue(val);
00092         quadsStiffness.setValue(val);
00093         tetrasStiffness.setValue(val);
00094         cubesStiffness.setValue(val);
00095     }
00096     void setLinesStiffness(Real val)
00097     {
00098         linesStiffness.setValue(val);
00099     }
00100     void setTrianglesStiffness(Real val)
00101     {
00102         trianglesStiffness.setValue(val);
00103     }
00104     void setQuadsStiffness(Real val)
00105     {
00106         quadsStiffness.setValue(val);
00107     }
00108     void setTetrasStiffness(Real val)
00109     {
00110         tetrasStiffness.setValue(val);
00111     }
00112     void setCubesStiffness(Real val)
00113     {
00114         cubesStiffness.setValue(val);
00115     }
00116     
00117     Real getDamping() const { return linesDamping.getValue(); }
00118     Real getLinesDamping() const { return linesDamping.getValue(); }
00119     Real getTrianglesDamping() const { return trianglesDamping.getValue(); }
00120     Real getQuadsDamping() const { return quadsDamping.getValue(); }
00121     Real getTetrasDamping() const { return tetrasDamping.getValue(); }
00122     Real getCubesDamping() const { return cubesDamping.getValue(); }
00123     void setDamping(Real val)
00124     {
00125         linesDamping.setValue(val);
00126         trianglesDamping.setValue(val);
00127         quadsDamping.setValue(val);
00128         tetrasDamping.setValue(val);
00129         cubesDamping.setValue(val);
00130     }
00131     void setLinesDamping(Real val)
00132     {
00133         linesDamping.setValue(val);
00134     }
00135     void setTrianglesDamping(Real val)
00136     {
00137         trianglesDamping.setValue(val);
00138     }
00139     void setQuadsDamping(Real val)
00140     {
00141         quadsDamping.setValue(val);
00142     }
00143     void setTetrasDamping(Real val)
00144     {
00145         tetrasDamping.setValue(val);
00146     }
00147     void setCubesDamping(Real val)
00148     {
00149         cubesDamping.setValue(val);
00150     }
00151     
00152     virtual void init();
00153 
00154     void parse(core::objectmodel::BaseObjectDescription* arg);
00155 
00156 };
00157 
00158 } // namespace forcefield
00159 
00160 } // namespace component
00161 
00162 } // namespace sofa
00163 
00164 #endif

Generated on Sun Nov 23 03:02:24 2008 for Sofa by  doxygen 1.5.7.1