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_PENALITYCONTACTFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_PENALITYCONTACTFORCEFIELD_H
00027
00028 #include <sofa/core/componentmodel/behavior/PairInteractionForceField.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/core/CollisionModel.h>
00031 #include <sofa/defaulttype/VecTypes.h>
00032 #include <vector>
00033
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace forcefield
00042 {
00043
00044 template<class DataTypes>
00045 class PenalityContactForceField : public core::componentmodel::behavior::PairInteractionForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00046 {
00047 public:
00048 typedef typename core::componentmodel::behavior::PairInteractionForceField<DataTypes> Inherit;
00049 typedef DataTypes DataTypes1;
00050 typedef DataTypes DataTypes2;
00051 typedef typename DataTypes::VecCoord VecCoord;
00052 typedef typename DataTypes::VecDeriv VecDeriv;
00053 typedef typename DataTypes::Coord Coord;
00054 typedef typename DataTypes::Deriv Deriv;
00055 typedef typename Coord::value_type Real;
00056 typedef core::componentmodel::behavior::MechanicalState<DataTypes> MechanicalState;
00057 protected:
00058
00059 class Contact
00060 {
00061 public:
00062
00063 int m1, m2;
00064 int index1, index2;
00065 Deriv norm;
00066 Real dist;
00067 Real ks;
00068 Real mu_s;
00069 Real mu_v;
00070 Real pen;
00071 int age;
00072
00073
00074 Contact(int _m1=0, int _m2=0, int _index1=0, int _index2=0, Deriv _norm=Deriv(), Real _dist=Real(), Real _ks=Real(), Real _mu_s=Real(), Real _mu_v=Real(), Real _pen=Real(), int _age=0)
00075 : m1(_m1),m2(_m2),index1(_index1),index2(_index2),norm(_norm),dist(_dist),ks(_ks),mu_s(_mu_s),mu_v(_mu_v),pen(_pen),age(_age)
00076 {
00077 }
00078
00079
00080 inline friend std::istream& operator >> ( std::istream& in, Contact& c ){
00081 in>>c.m1>>c.m2>>c.index1>>c.index2>>c.norm>>c.dist>>c.ks>>c.mu_s>>c.mu_v>>c.pen>>c.age;
00082 return in;
00083 }
00084
00085 inline friend std::ostream& operator << ( std::ostream& out, const Contact& c ){
00086 out << c.m1<< " " <<c.m2<< " " << c.index1<< " " <<c.index2<< " " <<c.norm<< " " <<c.dist<<" " <<c.ks<<" " <<c.mu_s<<" " <<c.mu_v<<" " <<c.pen<<" " <<c.age;
00087 return out;
00088 }
00089 };
00090
00091 Data<sofa::helper::vector<Contact> > contacts;
00092
00093
00094 sofa::helper::vector<Contact> prevContacts;
00095
00096 public:
00097
00098 PenalityContactForceField(MechanicalState* object1, MechanicalState* object2)
00099 : Inherit(object1, object2), contacts(initData(&contacts,"contacts", "Contacts"))
00100 {
00101 }
00102
00103 PenalityContactForceField()
00104 {
00105 }
00106
00107 void clear(int reserve = 0);
00108
00109 void addContact(int m1, int m2, int index1, int index2, const Deriv& norm, Real dist, Real ks, Real mu_s = 0.0f, Real mu_v = 0.0f, int oldIndex = 0);
00110
00111 virtual void addForce(VecDeriv& f1, VecDeriv& f2, const VecCoord& x1, const VecCoord& x2, const VecDeriv& v1, const VecDeriv& v2);
00112
00113 virtual void addDForce(VecDeriv& df1, VecDeriv& df2, const VecDeriv& dx1, const VecDeriv& dx2, double kFactor, double bFactor);
00114
00115 virtual double getPotentialEnergy(const VecCoord&, const VecCoord&);
00116
00117
00118 void grabPoint( const core::componentmodel::behavior::MechanicalState<defaulttype::Vec3Types> *tool,
00119 const helper::vector< unsigned int > &index,
00120 helper::vector< std::pair< core::objectmodel::BaseObject*, defaulttype::Vec3f> > &result,
00121 helper::vector< unsigned int > &triangle,
00122 helper::vector< unsigned int > &index_point) ;
00123
00124
00125 void draw();
00126 };
00127
00128 }
00129
00130 }
00131
00132 }
00133
00134 #endif