EllipsoidForceField.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_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(¢er, "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 }
00128
00129 }
00130
00131 }
00132
00133 #endif