ConicalForceField.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
00026
00027
00028
00029
00030
00031
00032
00033
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 }
00152
00153 }
00154
00155 }
00156
00157 #endif