Contact.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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_CORE_COMPONENTMODEL_COLLISION_CONTACT_H
00028 #define SOFA_CORE_COMPONENTMODEL_COLLISION_CONTACT_H
00029 
00030 #include <sofa/core/componentmodel/collision/DetectionOutput.h>
00031 #include <sofa/core/componentmodel/collision/Intersection.h>
00032 #include <sofa/core/objectmodel/Context.h>
00033 #include <sofa/helper/Factory.h>
00034 
00035 #include <sofa/core/componentmodel/behavior/InteractionForceField.h>
00036 #include <vector>
00037 
00038 namespace sofa
00039 {
00040 
00041 namespace core
00042 {
00043 
00044 namespace componentmodel
00045 {
00046 
00047 namespace collision
00048 {
00064 class Contact : public virtual objectmodel::BaseObject
00065 {
00066 public:
00067     
00069     virtual ~Contact() { }
00070     
00072     virtual std::pair< core::CollisionModel*, core::CollisionModel* > getCollisionModels() = 0;
00073     
00075     virtual void setDetectionOutputs(DetectionOutputVector* outputs) = 0;
00076     
00077     virtual void createResponse(objectmodel::BaseContext* group) = 0;
00078     
00079     virtual void removeResponse() = 0;
00080 
00082     virtual bool keepAlive() { return false; }
00083 
00085     virtual void setKeepAlive(bool /* val */) {}
00086     
00087     virtual void getCorrespondingCollisionModels( const core::componentmodel::behavior::InteractionForceField *, 
00088                                                  core::CollisionModel*& /* */, core::CollisionModel*& /* */) {};
00089 
00090     typedef helper::Factory< std::string, Contact, std::pair<std::pair<core::CollisionModel*,core::CollisionModel*>,Intersection*> > Factory;
00091 
00093     static Contact* Create(const std::string& type, core::CollisionModel* model1, core::CollisionModel* model2, Intersection* intersectionMethod);
00094 
00095     template<class RealContact>
00096     static void create(RealContact*& obj, std::pair<std::pair<core::CollisionModel*,core::CollisionModel*>,Intersection*> arg)
00097     {
00098         typedef typename RealContact::CollisionModel1 RealCollisionModel1;
00099         typedef typename RealContact::CollisionModel2 RealCollisionModel2;
00100         typedef typename RealContact::Intersection RealIntersection;
00101         RealCollisionModel1* model1 = dynamic_cast<RealCollisionModel1*>(arg.first.first);
00102         RealCollisionModel2* model2 = dynamic_cast<RealCollisionModel2*>(arg.first.second);
00103         RealIntersection* inter  = dynamic_cast<RealIntersection*>(arg.second);
00104         // CHANGE(Jeremie A. 2007-12-07): disable automatic swapping of the models, as it brings hard to find bugs where the order does not match the DetectionOutputs...
00105         // The Intersector class is now modified so that they are swapped to an unique order at the detection phase of the pipeline.
00106         /* if (model1==NULL || model2==NULL)
00107         { // Try the other way around
00108             model1 = dynamic_cast<RealCollisionModel1*>(arg.first.second);
00109             model2 = dynamic_cast<RealCollisionModel2*>(arg.first.first);
00110         }
00111         */
00112         if (model1==NULL || model2==NULL || inter==NULL) return;
00113         obj = new RealContact(model1, model2, inter);
00114     }
00115 
00116 };
00117 
00118 } // namespace collision
00119 
00120 } // namespace componentmodel
00121 
00122 } // namespace core
00123 
00124 } // namespace sofa
00125 
00126 #endif

Generated on Sun Nov 23 02:29:24 2008 for Sofa by  doxygen 1.5.7.1