Intersection.inl

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_INTERSECTION_INL
00028 #define SOFA_CORE_COMPONENTMODEL_COLLISION_INTERSECTION_INL
00029 
00030 #include <sofa/core/componentmodel/collision/Intersection.h>
00031 #include <sofa/helper/Factory.h>
00032 
00033 namespace sofa
00034 {
00035 
00036 namespace core
00037 {
00038 
00039 namespace componentmodel
00040 {
00041 
00042 namespace collision
00043 {
00044 
00045 using namespace sofa::defaulttype;
00046 using namespace sofa::helper;
00047 
00048 template<class Elem1, class Elem2, class T>
00049 class MemberElementIntersector : public ElementIntersector
00050 {
00051 public:
00052     typedef typename Elem1::Model Model1;
00053     typedef typename Elem2::Model Model2;
00054     MemberElementIntersector(T* ptr) : impl(ptr) {}
00056     bool canIntersect(core::CollisionElementIterator elem1, core::CollisionElementIterator elem2)
00057     {
00058         Elem1 e1(elem1);
00059         Elem2 e2(elem2);
00060         return impl->testIntersection(e1, e2);
00061     }
00062     
00065     int beginIntersect(core::CollisionModel* model1, core::CollisionModel* model2, DetectionOutputVector*& contacts)
00066     {
00067         Model1* m1 = static_cast<Model1*>(model1);
00068         Model2* m2 = static_cast<Model2*>(model2);
00069         if (contacts == NULL)
00070         {
00071             contacts = impl->createOutputVector(m1,m2);
00072         }
00073         return impl->beginIntersection(m1, m2, impl->getOutputVector(m1, m2, contacts));
00074     }
00075 
00077     int intersect(core::CollisionElementIterator elem1, core::CollisionElementIterator elem2,  DetectionOutputVector* contacts)
00078     {
00079         Elem1 e1(elem1);
00080         Elem2 e2(elem2);
00081         return impl->computeIntersection(e1, e2, impl->getOutputVector(e1.getCollisionModel(), e2.getCollisionModel(), contacts));
00082     }
00083 
00084     std::string name() const
00085     {
00086         return gettypename(typeid(Elem1))+std::string("-")+gettypename(typeid(Elem2));
00087     }
00088 
00090     int endIntersect(core::CollisionModel* model1, core::CollisionModel* model2, DetectionOutputVector* contacts)
00091     {
00092         Model1* m1 = static_cast<Model1*>(model1);
00093         Model2* m2 = static_cast<Model2*>(model2);
00094         return impl->endIntersection(m1, m2, impl->getOutputVector(m1, m2, contacts));
00095     }
00096 
00097 protected:
00098     T* impl;
00099 };
00100 
00101 template<class Model1, class Model2, class T>
00102 void IntersectorMap::add(T* ptr)
00103 {
00104     const objectmodel::ClassInfo* c1 = &classid(Model1);
00105     const objectmodel::ClassInfo* c2 = &classid(Model2);
00106     classes.insert(c1);
00107     classes.insert(c2);
00108     castMap.clear();
00109     // rebuild castMap
00110     for (std::set<const objectmodel::ClassInfo* >::iterator it = classes.begin(); it != classes.end(); ++it)
00111         castMap.insert(std::make_pair((*it)->type(),(*it)->type()));
00112     (*this)[std::make_pair(c1->type(),c2->type())] =
00113         new MemberElementIntersector<typename Model1::Element, typename Model2::Element, T>(ptr);
00114 }
00115 
00116 template<class Model1, class Model2>
00117 void IntersectorMap::ignore()
00118 {
00119     const objectmodel::ClassInfo* c1 = &classid(Model1);
00120     const objectmodel::ClassInfo* c2 = &classid(Model2);
00121     classes.insert(c1);
00122     classes.insert(c2);
00123     castMap.clear();
00124     // rebuild castMap
00125     for (std::set<const objectmodel::ClassInfo* >::iterator it = classes.begin(); it != classes.end(); ++it)
00126         castMap.insert(std::make_pair((*it)->type(),(*it)->type()));
00127     (*this)[std::make_pair(c1->type(),c2->type())] = 
00128         NULL;
00129 }
00130 
00131 } // namespace collision
00132 
00133 } // namespace componentmodel
00134 
00135 } // namespace core
00136 
00137 } // namespace sofa
00138 
00139 #endif

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