NarrowPhaseDetection.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_COMPONENT_COLLISION_NARROWPHASEDETECTION_H
00028 #define SOFA_COMPONENT_COLLISION_NARROWPHASEDETECTION_H
00029 
00030 #include <sofa/core/componentmodel/collision/Detection.h>
00031 #include <vector>
00032 #include <map>
00033 #include <algorithm>
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace core
00039 {
00040 
00041 namespace componentmodel
00042 {
00043 
00044 namespace collision
00045 {
00046 
00051 class NarrowPhaseDetection : virtual public Detection
00052 {
00053 public:
00054     typedef std::map< std::pair<core::CollisionModel*, core::CollisionModel* >, DetectionOutputVector* > DetectionOutputMap;
00055 
00057     virtual ~NarrowPhaseDetection() { }
00058 
00060     virtual void beginNarrowPhase()
00061     {
00062         for (DetectionOutputMap::iterator it = outputsMap.begin(); it!=outputsMap.end(); it++)
00063         {
00064             if (it->second)
00065                 it->second->clear();
00066         }
00067     }
00068 
00070     virtual void addCollisionPair (const std::pair<core::CollisionModel*, core::CollisionModel*>& cmPair) = 0;
00071 
00073     virtual void addCollisionPairs(const sofa::helper::vector< std::pair<core::CollisionModel*, core::CollisionModel*> >& v)
00074     {
00075         for (sofa::helper::vector< std::pair<core::CollisionModel*, core::CollisionModel*> >::const_iterator it = v.begin(); it!=v.end(); it++)
00076             addCollisionPair(*it);
00077     }
00078 
00079     virtual void endNarrowPhase()
00080     {
00081         DetectionOutputMap::iterator it = outputsMap.begin();
00082         while(it!=outputsMap.end())
00083         {
00084             if (!it->second || it->second->empty())
00085             {
00086                 DetectionOutputMap::iterator it2 = it;
00087                 ++it2;
00088                 delete it->second;
00089                 outputsMap.erase(it);
00090                 it = it2;
00091             }
00092             else
00093             {
00094                 ++it;
00095             }
00096         }
00097     }
00098 
00099     //sofa::helper::vector<std::pair<core::CollisionElementIterator, core::CollisionElementIterator> >& getCollisionElementPairs() { return elemPairs; }
00100 
00101     DetectionOutputMap& getDetectionOutputs()
00102     {
00103         return outputsMap;
00104     }
00105 
00106 protected:
00107     DetectionOutputMap outputsMap;
00108     std::map<Instance, DetectionOutputMap> storedOutputsMap;
00109 
00110     virtual void changeInstanceNP(Instance inst)
00111     {
00112         storedOutputsMap[instance].swap(outputsMap);
00113         outputsMap.swap(storedOutputsMap[inst]);
00114     }
00115 };
00116 
00117 } // namespace collision
00118 
00119 } // namespace componentmodel
00120 
00121 } // namespace core
00122 
00123 } // namespace sofa
00124 
00125 #endif

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