PlaneForceField.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_INTERACTIONFORCEFIELD_PLANEFORCEFIELD_H
00026 #define SOFA_COMPONENT_INTERACTIONFORCEFIELD_PLANEFORCEFIELD_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 PlaneForceFieldInternalData
00044 {
00045 public:
00046 };
00047
00048 template<class DataTypes>
00049 class PlaneForceField : 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 sofa::helper::vector<unsigned int> contacts;
00061
00062 PlaneForceFieldInternalData<DataTypes> data;
00063
00064 public:
00065
00066 Data<Deriv> planeNormal;
00067 Data<Real> planeD;
00068 Data<Real> stiffness;
00069 Data<Real> damping;
00070 Data<defaulttype::Vec3f> color;
00071 Data<bool> bDraw;
00072
00073 PlaneForceField()
00074 : planeNormal(initData(&planeNormal, "normal", "plane normal"))
00075 , planeD(initData(&planeD, (Real)0, "d", "plane d coef"))
00076 , stiffness(initData(&stiffness, (Real)500, "stiffness", "force stiffness"))
00077 , damping(initData(&damping, (Real)5, "damping", "force damping"))
00078 , color(initData(&color, defaulttype::Vec3f(0.0f,.5f,.2f), "color", "plane color"))
00079 , bDraw(initData(&bDraw, false, "draw", "enable/disable drawing of plane"))
00080 {
00081 Deriv n;
00082 DataTypes::set(n, 0, 1, 0);
00083 planeNormal.setValue(n);
00084 }
00085
00086 void setPlane(const Deriv& normal, Real d)
00087 {
00088 Real n = normal.norm();
00089 planeNormal.setValue( normal / n);
00090 planeD.setValue( d / n );
00091 }
00092
00093 void setMState( core::componentmodel::behavior::MechanicalState<DataTypes>* mstate ){ this->mstate = mstate; }
00094
00095 void setStiffness(Real stiff)
00096 {
00097 stiffness.setValue( stiff );
00098 }
00099
00100 void setDamping(Real damp)
00101 {
00102 damping.setValue( damp );
00103 }
00104
00105 void rotate( Deriv axe, Real angle );
00106
00107 virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00108
00109 virtual void addDForce (VecDeriv& df, const VecDeriv& dx, double kFactor, double bFactor);
00110
00111 virtual double getPotentialEnergy(const VecCoord& x);
00112
00113 virtual void updateStiffness( const VecCoord& x );
00114
00115 void draw();
00116 void drawPlane(float size=1000.0f);
00117 bool addBBox(double* minBBox, double* maxBBox);
00118
00119 };
00120
00121 }
00122
00123 }
00124
00125 }
00126
00127 #endif