TrianglePressureForceField.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_TRIANGLEPRESSUREFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGLEPRESSUREFORCEFIELD_H
00027
00028
00029 #include <sofa/core/componentmodel/behavior/ForceField.h>
00030 #include <sofa/component/topology/TriangleSubsetData.h>
00031
00032
00033
00034 namespace sofa
00035 {
00036
00037 namespace component
00038 {
00039
00040 namespace forcefield
00041 {
00042
00043 using namespace sofa::defaulttype;
00044 using namespace sofa::component::topology;
00045
00046 template<class DataTypes>
00047 class TrianglePressureForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00048 {
00049 public:
00050 typedef typename DataTypes::VecCoord VecCoord;
00051 typedef typename DataTypes::VecDeriv VecDeriv;
00052 typedef typename DataTypes::Coord Coord ;
00053 typedef typename DataTypes::Deriv Deriv ;
00054 typedef typename Coord::value_type Real ;
00055
00056 protected:
00057
00058 class TrianglePressureInformation
00059 {
00060 public:
00061 Real area;
00062 Deriv force;
00063
00064 TrianglePressureInformation() {}
00065 TrianglePressureInformation(const TrianglePressureInformation &e)
00066 : area(e.area),force(e.force)
00067 { }
00068 };
00069
00070 TriangleSubsetData<TrianglePressureInformation> trianglePressureMap;
00071
00072 sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00073
00074 Data<Deriv> pressure;
00075
00076 Data<std::string> triangleList;
00077
00079 Data<Deriv> normal;
00080
00081 Data<Real> dmin;
00082 Data<Real> dmax;
00083
00084 public:
00085
00086 TrianglePressureForceField():
00087 pressure(initData(&pressure, "pressure", "Pressure force per unit area"))
00088 , triangleList(initData(&triangleList,std::string(),"triangleList", "Indices of triangles separated with commas where a pressure is applied"))
00089 , normal(initData(&normal,"normal", "Normal direction for the plane selection of triangles"))
00090 , dmin(initData(&dmin,(Real)0.0, "dmin", "Minimum distance from the origin along the normal direction"))
00091 , dmax(initData(&dmax,(Real)0.0, "dmax", "Maximum distance from the origin along the normal direction"))
00092 {
00093 }
00094
00095 virtual ~TrianglePressureForceField();
00096
00097 virtual void init();
00098
00099 virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00100 virtual void addDForce (VecDeriv& , const VecDeriv& ) {}
00101 virtual double getPotentialEnergy(const VecCoord& x);
00102
00103
00104 virtual void handleTopologyChange();
00105
00106
00107 void draw();
00108
00109 void setDminAndDmax(const double _dmin, const double _dmax) {
00110 dmin.setValue((Real)_dmin);dmax.setValue((Real)_dmax);}
00111 void setNormal(const Coord n) { normal.setValue(n);}
00112
00113 void setPressure(Deriv _pressure) { this->pressure = _pressure; updateTriangleInformation(); }
00114
00115 protected :
00116 void selectTrianglesAlongPlane();
00117 void selectTrianglesFromString();
00118 void updateTriangleInformation();
00119 void initTriangleInformation();
00120 bool isPointInPlane(Coord p) {
00121 Real d=dot(p,normal.getValue());
00122 if ((d>dmin.getValue())&& (d<dmax.getValue()))
00123 return true;
00124 else
00125 return false;
00126 }
00127 };
00128
00129
00130 }
00131
00132 }
00133
00134 }
00135
00136 #endif