ConicalForceField.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 //
00026 // C++ Interface: ConicalForceField
00027 //
00028 // Description: 
00029 //
00030 //
00031 // Author: The SOFA team </www.sofa-framework.org>, (C) 2007
00032 //
00033 // Copyright: See COPYING file that comes with this distribution
00034 //
00035 //
00036 #ifndef SOFA_COMPONENT_FORCEFIELD_CONICALFORCEFIELD_H
00037 #define SOFA_COMPONENT_FORCEFIELD_CONICALFORCEFIELD_H
00038 
00039 #include <sofa/core/componentmodel/behavior/ForceField.h>
00040 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00041 #include <sofa/core/objectmodel/Data.h>
00042 
00043 namespace sofa
00044 {
00045 
00046 namespace component
00047 {
00048 
00049 namespace forcefield
00050 {
00051 
00053 template<class DataTypes>
00054 class ConicalForceFieldInternalData
00055 {
00056 public:
00057 };
00058 
00059 template<class DataTypes>
00060 class ConicalForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00061 {
00062 public:
00063     typedef core::componentmodel::behavior::ForceField<DataTypes> Inherit;
00064     typedef typename DataTypes::VecCoord VecCoord;
00065     typedef typename DataTypes::VecDeriv VecDeriv;
00066     typedef typename DataTypes::Coord Coord;
00067     typedef typename DataTypes::Deriv Deriv;
00068     typedef typename Coord::value_type Real;
00069     
00070 protected:
00071     class Contact
00072     {
00073     public:
00074         int index;
00075         Coord normal;
00076         Coord pos;
00077     Contact( int index=0, Coord normal=Coord(),Coord pos=Coord())
00078       : index(index),normal(normal),pos(pos)
00079       {
00080       }
00081 
00082         inline friend std::istream& operator >> ( std::istream& in, Contact& c ){
00083       in>>c.index>>c.normal>>c.pos;
00084             return in;
00085         }
00086 
00087         inline friend std::ostream& operator << ( std::ostream& out, const Contact& c ){
00088       out << c.index << " " << c.normal << " " << c.pos ;
00089       return out;
00090         }
00091 
00092     };
00093 
00094     Data<sofa::helper::vector<Contact> > contacts;
00095 
00096     ConicalForceFieldInternalData<DataTypes> data;
00097     
00098 public:
00099 
00100     Data<Coord> coneCenter;
00101     Data<Coord> coneHeight;
00102     Data<Real> coneAngle;
00103 
00104     Data<Real> stiffness;
00105     Data<Real> damping;
00106     Data<defaulttype::Vec3f> color;
00107     Data<bool> bDraw;
00108 
00109     ConicalForceField()
00110       : coneCenter(initData(&coneCenter, "coneCenter", "cone center"))
00111       , coneHeight(initData(&coneHeight, "coneHeight", "cone height"))
00112       , coneAngle(initData(&coneAngle, (Real)10, "coneAngle", "cone angle"))
00113 
00114       , stiffness(initData(&stiffness, (Real)500, "stiffness", "force stiffness"))
00115       , damping(initData(&damping, (Real)5, "damping", "force damping"))
00116       , color(initData(&color, defaulttype::Vec3f(0.0f,0.0f,1.0f), "color", "cone color"))
00117       , bDraw(initData(&bDraw, true, "draw", "enable/disable drawing of the cone"))
00118     {
00119     }
00120 
00121     void setCone(const Coord& center, Coord height, Real angle)
00122     {
00123         coneCenter.setValue( center );
00124     coneHeight.setValue( height );
00125     coneAngle.setValue( angle );
00126     }
00127 
00128     void setStiffness(Real stiff)
00129     {
00130         stiffness.setValue( stiff );
00131     }
00132 
00133     void setDamping(Real damp)
00134     {
00135         damping.setValue( damp );
00136     }
00137 
00138     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00139 
00140     virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00141     
00142     virtual double getPotentialEnergy(const VecCoord& x);
00143 
00144     virtual void updateStiffness( const VecCoord& x );
00145 
00146     virtual bool isIn(Coord p);
00147 
00148     void draw();
00149 };
00150 
00151 } // namespace forcefield
00152 
00153 } // namespace component
00154 
00155 } // namespace sofa
00156 
00157 #endif

Generated on Sun Nov 23 02:53:21 2008 for Sofa by  doxygen 1.5.7.1