SparseGridSpringForceField.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_SPARSEGRIDSPRINGFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_SPARSEGRIDSPRINGFORCEFIELD_H
00027 
00028 #include <sofa/component/forcefield/StiffSpringForceField.h>
00029 #include <sofa/component/topology/MultiResSparseGridTopology.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace forcefield
00038 {
00039 
00040 template<class DataTypes>
00041 class SparseGridSpringForceField : public StiffSpringForceField<DataTypes>
00042 {
00044 public:
00045     typedef StiffSpringForceField<DataTypes> Inherit;
00046     typedef typename DataTypes::VecCoord VecCoord;
00047     typedef typename DataTypes::VecDeriv VecDeriv;
00048     typedef typename DataTypes::Coord Coord;
00049     typedef typename DataTypes::Deriv Deriv;
00050     typedef typename Coord::value_type Real;
00051     
00052 protected:
00053 
00054     DataField< Real > linesStiffness;
00055     DataField< Real > linesDamping;
00056     DataField< Real > quadsStiffness;
00057     DataField< Real > quadsDamping;
00058     DataField< Real > cubesStiffness;
00059     DataField< Real > cubesDamping;
00060 
00061     DataField< std::string > filename;
00062     typedef topology::MultiResSparseGridTopology::SparseGrid Voxels;
00063     typedef topology::MultiResSparseGridTopology::SparseGrid::Index3D Index3D;
00064 
00065  
00066 public:
00067     SparseGridSpringForceField(core::componentmodel::behavior::MechanicalState<DataTypes>* object1, core::componentmodel::behavior::MechanicalState<DataTypes>* object2)
00068     : StiffSpringForceField<DataTypes>(object1, object2),
00069       linesStiffness  (dataField(&linesStiffness,Real(0),"linesStiffness","Lines Stiffness"))
00070       , linesDamping  (dataField(&linesDamping  ,Real(0),"linesDamping"  ,"Lines Damping"))
00071       , quadsStiffness(dataField(&quadsStiffness,Real(0),"quadsStiffness","Quads Stiffness"))
00072       , quadsDamping  (dataField(&quadsDamping  ,Real(0),"quadsDamping"  ,"Quads Damping"))
00073       , cubesStiffness(dataField(&cubesStiffness,Real(0),"cubesStiffness","Cubes Stiffness"))
00074       , cubesDamping  (dataField(&cubesDamping  ,Real(0),"cubesDamping"  ,"Cubes Damping"))
00075     {
00076     }
00077     
00078     SparseGridSpringForceField()
00079     : 
00080       linesStiffness  (dataField(&linesStiffness,Real(0),"linesStiffness","Lines Stiffness"))
00081       , linesDamping  (dataField(&linesDamping  ,Real(0),"linesDamping"  ,"Lines Damping"))
00082       , quadsStiffness(dataField(&quadsStiffness,Real(0),"quadsStiffness","Quads Stiffness"))
00083       , quadsDamping  (dataField(&quadsDamping  ,Real(0),"quadsDamping"  ,"Quads Damping"))
00084       , cubesStiffness(dataField(&cubesStiffness,Real(0),"cubesStiffness","Cubes Stiffness"))
00085       , cubesDamping  (dataField(&cubesDamping  ,Real(0),"cubesDamping"  ,"Cubes Damping"))
00086     {
00087     }
00088     
00089     virtual void parse(core::objectmodel::BaseObjectDescription* arg);
00090 
00091     Real getStiffness() const { return linesStiffness.getValue(); }
00092     Real getLinesStiffness() const { return linesStiffness.getValue(); }
00093     Real getQuadsStiffness() const { return quadsStiffness.getValue(); }
00094     Real getCubesStiffness() const { return cubesStiffness.getValue(); }
00095     void setStiffness(Real val)
00096     {
00097         linesStiffness.setValue(val);
00098         quadsStiffness.setValue(val);
00099         cubesStiffness.setValue(val);
00100     }
00101     void setLinesStiffness(Real val)
00102     {
00103         linesStiffness.setValue(val);
00104     }
00105     void setQuadsStiffness(Real val)
00106     {
00107         quadsStiffness.setValue(val);
00108     }
00109     void setCubesStiffness(Real val)
00110     {
00111         cubesStiffness.setValue(val);
00112     }
00113 
00114     
00115     Real getDamping() const { return linesDamping.getValue(); }
00116     Real getLinesDamping() const { return linesDamping.getValue(); }
00117     Real getQuadsDamping() const { return quadsDamping.getValue(); }
00118     Real getCubesDamping() const { return cubesDamping.getValue(); }
00119     void setDamping(Real val)
00120     {
00121         linesDamping.setValue(val);
00122         quadsDamping.setValue(val);
00123         cubesDamping.setValue(val);
00124     }
00125     void setLinesDamping(Real val)
00126     {
00127         linesDamping.setValue(val);
00128     }
00129     void setQuadsDamping(Real val)
00130     {
00131         quadsDamping.setValue(val);
00132     }
00133     void setCubesDamping(Real val)
00134     {
00135         cubesDamping.setValue(val);
00136     }
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     void setFileName(char* name)
00145     {
00146       filename.setValue( std::string(name) );
00147     }
00148 
00149     char * getFileName()const{return filename.getValue();}
00150 };
00151 
00152 } // namespace forcefield
00153 
00154 } // namespace component
00155 
00156 } // namespace sofa
00157 
00158 #endif

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