FrictionContact.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
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     //  std::cout << id << std::endl;
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     // Polynome de Cantor de Nē sur N bijectif f(x,y)=((x+y)^2+3x+y)/2
00122     return ((x+y)*(x+y)+3*x+y)/2;
00123 }
00124 
00125 } // collision
00126 
00127 } // component
00128 
00129 } // sofa
00130 
00131 #endif // SOFA_COMPONENT_COLLISION_FRICTIONCONTACT_H

Generated on Sun Nov 23 02:33:46 2008 for Sofa by  doxygen 1.5.7.1