EllipsoidForceField.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_ELLIPSOIDFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_ELLIPSOIDFORCEFIELD_H
00027 
00028 #include <sofa/core/componentmodel/behavior/ForceField.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/core/objectmodel/Data.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace forcefield
00039 {
00040 
00042 template<class DataTypes>
00043 class EllipsoidForceFieldInternalData
00044 {
00045 public:
00046 };
00047 
00048 template<class DataTypes>
00049 class EllipsoidForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00050 {
00051 public:
00052     typedef core::componentmodel::behavior::ForceField<DataTypes> Inherit;
00053     typedef typename DataTypes::VecCoord VecCoord;
00054     typedef typename DataTypes::VecDeriv VecDeriv;
00055     typedef typename DataTypes::Coord Coord;
00056     typedef typename DataTypes::Deriv Deriv;
00057     typedef typename Coord::value_type Real;
00058     enum { N=Coord::static_size };
00059     typedef defaulttype::Mat<N,N,Real> Mat;
00060     
00061 protected:
00062     class Contact
00063     {
00064     public:
00065         int index;
00066         Mat m;
00067     Contact( int index=0, const Mat& m=Mat())
00068       : index(index), m(m)
00069       {
00070       }
00071 
00072         inline friend std::istream& operator >> ( std::istream& in, Contact& c ){
00073       in>>c.index>>c.m;
00074             return in;
00075         }
00076 
00077         inline friend std::ostream& operator << ( std::ostream& out, const Contact& c ){
00078       out << c.index << " " << c.m ;
00079       return out;
00080         }
00081 
00082     };
00083 
00084     Data<sofa::helper::vector<Contact> > contacts;
00085 
00086     EllipsoidForceFieldInternalData<DataTypes> data;
00087     
00088 public:
00089 
00090     Data<Coord> center;
00091     Data<Coord> vradius;
00092     Data<Real> stiffness;
00093     Data<Real> damping;
00094     Data<defaulttype::Vec3f> color;
00095     Data<bool> bDraw;
00096 
00097     EllipsoidForceField()
00098       : contacts(initData(&contacts,"contacts", "Contacts"))
00099       , center(initData(&center, "center", "ellipsoid center"))
00100       , vradius(initData(&vradius, "vradius", "ellipsoid radius"))
00101       , stiffness(initData(&stiffness, (Real)500, "stiffness", "force stiffness (positive to repulse outward, negative inward)"))
00102       , damping(initData(&damping, (Real)5, "damping", "force damping"))
00103       , color(initData(&color, defaulttype::Vec3f(0.0f,0.5f,1.0f), "color", "ellipsoid color"))
00104       , bDraw(initData(&bDraw, true, "draw", "enable/disable drawing of the ellipsoid"))
00105     {
00106     }
00107 
00108     void setStiffness(Real stiff)
00109     {
00110         stiffness.setValue( stiff );
00111     }
00112 
00113     void setDamping(Real damp)
00114     {
00115         damping.setValue( damp );
00116     }
00117 
00118     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00119 
00120     virtual void addDForce (VecDeriv& df, const VecDeriv& dx, double kFactor, double bFactor);
00121     
00122     virtual double getPotentialEnergy(const VecCoord& x);
00123 
00124     void draw();
00125 };
00126 
00127 } // namespace forcefield
00128 
00129 } // namespace component
00130 
00131 } // namespace sofa
00132 
00133 #endif

Generated on Sun Nov 23 02:55:36 2008 for Sofa by  doxygen 1.5.7.1