FrictionContact.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_COLLISION_FRICTIONCONTACT_H
00026 #define SOFA_COMPONENT_COLLISION_FRICTIONCONTACT_H
00027
00028 #include <sofa/core/componentmodel/collision/Contact.h>
00029 #include <sofa/core/componentmodel/collision/Intersection.h>
00030 #include <sofa/component/mapping/BarycentricMapping.h>
00031 #include <sofa/component/constraint/UnilateralInteractionConstraint.h>
00032 #include <sofa/helper/Factory.h>
00033 #include <sofa/component/collision/BarycentricContactMapper.h>
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace collision
00042 {
00043
00044 using namespace sofa::defaulttype;
00045
00046 class Identifier
00047 {
00048 public:
00049 Identifier()
00050 {
00051 if (!availableId.empty())
00052 {
00053 id = availableId.front();
00054 availableId.pop_front();
00055 }
00056 else
00057 id = cpt++;
00058
00059
00060 }
00061
00062 virtual ~Identifier()
00063 {
00064 availableId.push_back(id);
00065 }
00066
00067 protected:
00068 static unsigned int cpt;
00069 unsigned int id;
00070 static std::list<unsigned int> availableId;
00071 };
00072
00073
00074 template <class TCollisionModel1, class TCollisionModel2>
00075 class FrictionContact : public core::componentmodel::collision::Contact, public Identifier
00076 {
00077 public:
00078 typedef TCollisionModel1 CollisionModel1;
00079 typedef TCollisionModel2 CollisionModel2;
00080 typedef core::componentmodel::collision::Intersection Intersection;
00081 typedef typename CollisionModel1::DataTypes DataTypes1;
00082 typedef typename CollisionModel2::DataTypes DataTypes2;
00083 typedef core::componentmodel::behavior::MechanicalState<DataTypes1> MechanicalState1;
00084 typedef core::componentmodel::behavior::MechanicalState<DataTypes2> MechanicalState2;
00085 typedef typename CollisionModel1::Element CollisionElement1;
00086 typedef typename CollisionModel2::Element CollisionElement2;
00087 typedef core::componentmodel::collision::DetectionOutputVector OutputVector;
00088 typedef core::componentmodel::collision::TDetectionOutputVector<CollisionModel1,CollisionModel2> TOutputVector;
00089
00090 protected:
00091 CollisionModel1* model1;
00092 CollisionModel2* model2;
00093 Intersection* intersectionMethod;
00094
00095 ContactMapper<CollisionModel1,DataTypes1> mapper1;
00096 ContactMapper<CollisionModel2,DataTypes2> mapper2;
00097
00098 constraint::UnilateralInteractionConstraint<Vec3Types>* c;
00099 core::objectmodel::BaseContext* parent;
00100
00101 double mu;
00102
00103 public:
00104
00105 FrictionContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod);
00106 virtual ~FrictionContact();
00107
00108 void cleanup();
00109
00110 std::pair<core::CollisionModel*,core::CollisionModel*> getCollisionModels() { return std::make_pair(model1,model2); }
00111
00112 void setDetectionOutputs(OutputVector* outputs);
00113
00114 void createResponse(core::objectmodel::BaseContext* group);
00115
00116 void removeResponse();
00117 };
00118
00119 long cantorPolynomia(unsigned long x, unsigned long y)
00120 {
00121
00122 return ((x+y)*(x+y)+3*x+y)/2;
00123 }
00124
00125 }
00126
00127 }
00128
00129 }
00130
00131 #endif // SOFA_COMPONENT_COLLISION_FRICTIONCONTACT_H