BarycentricPenalityContact.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_BARYCENTRICPENALITYCONTACT_H
00026 #define SOFA_COMPONENT_COLLISION_BARYCENTRICPENALITYCONTACT_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 #ifdef SOFA_TEST_FRICTION
00032 #include <sofa/component/forcefield/PenalityContactFrictionForceField.h>
00033 #else
00034 #include <sofa/component/forcefield/PenalityContactForceField.h>
00035 #endif
00036 #include <sofa/helper/Factory.h>
00037 #include <sofa/component/collision/BarycentricContactMapper.h>
00038 
00039 
00040 namespace sofa
00041 {
00042 
00043   namespace component
00044   {
00045 
00046     namespace collision
00047     {
00048 
00049       using namespace sofa::defaulttype;
00050 
00051       template < class TCollisionModel1, class TCollisionModel2, class ResponseDataTypes = sofa::defaulttype::Vec3Types >
00052     class BarycentricPenalityContact : public core::componentmodel::collision::Contact
00053     {
00054     public:
00055     typedef TCollisionModel1 CollisionModel1;
00056     typedef TCollisionModel2 CollisionModel2;
00057     typedef core::componentmodel::collision::Intersection Intersection;
00058     typedef core::componentmodel::collision::DetectionOutputVector OutputVector;
00059     typedef core::componentmodel::collision::TDetectionOutputVector<CollisionModel1,CollisionModel2> TOutputVector;
00060     typedef ResponseDataTypes DataTypes1;
00061     typedef ResponseDataTypes DataTypes2;
00062     typedef core::componentmodel::behavior::MechanicalState<DataTypes1> MechanicalState1;
00063     typedef core::componentmodel::behavior::MechanicalState<DataTypes2> MechanicalState2;
00064     typedef typename CollisionModel1::Element CollisionElement1;
00065     typedef typename CollisionModel2::Element CollisionElement2;
00066 #ifdef SOFA_TEST_FRICTION
00067     typedef forcefield::PenalityContactFrictionForceField<ResponseDataTypes> ResponseForceField;
00068 #else
00069     typedef forcefield::PenalityContactForceField<ResponseDataTypes> ResponseForceField;
00070 #endif
00071     protected:
00072     CollisionModel1* model1;
00073     CollisionModel2* model2;
00074     Intersection* intersectionMethod;
00075 
00076     ContactMapper<CollisionModel1,DataTypes1> mapper1;
00077     ContactMapper<CollisionModel2,DataTypes2> mapper2;
00078 
00079     ResponseForceField* ff;
00080     core::objectmodel::BaseContext* parent;
00081     
00082     typedef std::map<core::componentmodel::collision::DetectionOutput::ContactId,int> ContactIndexMap;
00085     ContactIndexMap contactIndex;
00086     public:
00087     BarycentricPenalityContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod);
00088     ~BarycentricPenalityContact();
00089     
00090     void cleanup();
00091     
00092     std::pair<core::CollisionModel*,core::CollisionModel*> getCollisionModels() { return std::make_pair(model1,model2); }
00093     
00094     void setDetectionOutputs(OutputVector* outputs);
00095     
00096     void createResponse(core::objectmodel::BaseContext* group);
00097     
00098     void removeResponse();
00099     
00100     void draw();
00101     
00102     
00103     void getCorrespondingCollisionModels( const core::componentmodel::behavior::InteractionForceField *_ff, 
00104         core::CollisionModel* &_model1, core::CollisionModel* &_model2) 
00105     {
00106       if (static_cast< core::componentmodel::behavior::InteractionForceField * >(ff) == _ff)
00107       {     
00108         _model1 = static_cast< core::CollisionModel *>(model1);
00109         _model2 = static_cast< core::CollisionModel *>(model2);
00110       }
00111     };
00112     };
00113 
00114     } // namespace collision
00115 
00116   } // namespace component
00117 
00118 } // namespace sofa
00119 
00120 #endif

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