SphereForceField.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_FORCEFIELD_SPHEREFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_SPHEREFORCEFIELD_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 SphereForceFieldInternalData
00044 {
00045 public:
00046 };
00047
00048 template<class DataTypes>
00049 class SphereForceField : 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
00059 protected:
00060 class Contact
00061 {
00062 public:
00063 int index;
00064 Coord normal;
00065 Real fact;
00066 Contact( int index=0, Coord normal=Coord(),Real fact=Real(0))
00067 : index(index),normal(normal),fact(fact)
00068 {
00069 }
00070
00071 inline friend std::istream& operator >> ( std::istream& in, Contact& c ){
00072 in>>c.index>>c.normal>>c.fact;
00073 return in;
00074 }
00075
00076 inline friend std::ostream& operator << ( std::ostream& out, const Contact& c ){
00077 out << c.index << " " << c.normal << " " << c.fact ;
00078 return out;
00079 }
00080
00081 };
00082
00083 Data<sofa::helper::vector<Contact> > contacts;
00084
00085 SphereForceFieldInternalData<DataTypes> data;
00086
00087 public:
00088
00089 Data<Coord> sphereCenter;
00090 Data<Real> sphereRadius;
00091 Data<Real> stiffness;
00092 Data<Real> damping;
00093 Data<defaulttype::Vec3f> color;
00094 Data<bool> bDraw;
00095
00096 SphereForceField()
00097 : contacts(initData(&contacts,"contacts", "Contacts"))
00098 , sphereCenter(initData(&sphereCenter, "center", "sphere center"))
00099 , sphereRadius(initData(&sphereRadius, (Real)1, "radius", "sphere radius"))
00100 , stiffness(initData(&stiffness, (Real)500, "stiffness", "force stiffness"))
00101 , damping(initData(&damping, (Real)5, "damping", "force damping"))
00102 , color(initData(&color, defaulttype::Vec3f(0.0f,0.0f,1.0f), "color", "sphere color"))
00103 , bDraw(initData(&bDraw, true, "draw", "enable/disable drawing of the sphere"))
00104 {
00105 }
00106
00107 void setSphere(const Coord& center, Real radius)
00108 {
00109 sphereCenter.setValue( center );
00110 sphereRadius.setValue( radius );
00111 }
00112
00113 void setStiffness(Real stiff)
00114 {
00115 stiffness.setValue( stiff );
00116 }
00117
00118 void setDamping(Real damp)
00119 {
00120 damping.setValue( damp );
00121 }
00122
00123 virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00124
00125 virtual void addDForce (VecDeriv& df, const VecDeriv& dx, double kFactor, double bFactor);
00126
00127 virtual double getPotentialEnergy(const VecCoord& x);
00128
00129 virtual void updateStiffness( const VecCoord& x );
00130
00131 void draw();
00132 };
00133
00134 }
00135
00136 }
00137
00138 }
00139
00140 #endif