broadphase_bruteforce.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00037 #include "fcl/broadphase/broadphase_bruteforce.h"
00038 #include <limits>
00039 
00040 namespace fcl
00041 {
00042 
00043 void NaiveCollisionManager::registerObjects(const std::vector<CollisionObject*>& other_objs)
00044 {
00045   std::copy(other_objs.begin(), other_objs.end(), std::back_inserter(objs));
00046 }
00047 
00048 void NaiveCollisionManager::unregisterObject(CollisionObject* obj)
00049 {
00050   objs.remove(obj);
00051 }
00052 
00053 void NaiveCollisionManager::registerObject(CollisionObject* obj)
00054 {
00055   objs.push_back(obj);
00056 }
00057 
00058 void NaiveCollisionManager::setup()
00059 {
00060 
00061 }
00062 
00063 void NaiveCollisionManager::update()
00064 {
00065 
00066 }
00067 
00068 void NaiveCollisionManager::clear()
00069 {
00070   objs.clear();
00071 }
00072 
00073 void NaiveCollisionManager::getObjects(std::vector<CollisionObject*>& objs_) const
00074 {
00075   objs_.resize(objs.size());
00076   std::copy(objs.begin(), objs.end(), objs_.begin());
00077 }
00078 
00079 void NaiveCollisionManager::collide(CollisionObject* obj, void* cdata, CollisionCallBack callback) const
00080 {
00081   if(size() == 0) return;
00082 
00083   for(std::list<CollisionObject*>::const_iterator it = objs.begin(), end = objs.end(); it != end; ++it)
00084   {
00085     if(callback(obj, *it, cdata))
00086       return;
00087   }
00088 }
00089 
00090 void NaiveCollisionManager::distance(CollisionObject* obj, void* cdata, DistanceCallBack callback) const
00091 {
00092   if(size() == 0) return;
00093 
00094   FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00095   for(std::list<CollisionObject*>::const_iterator it = objs.begin(), end = objs.end(); 
00096       it != end; ++it)
00097   {
00098     if(obj->getAABB().distance((*it)->getAABB()) < min_dist)
00099     {
00100       if(callback(obj, *it, cdata, min_dist))
00101         return;
00102     }
00103   }
00104 }
00105 
00106 void NaiveCollisionManager::collide(void* cdata, CollisionCallBack callback) const
00107 {
00108   if(size() == 0) return;
00109 
00110   for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end = objs.end(); 
00111       it1 != end; ++it1)
00112   {
00113     std::list<CollisionObject*>::const_iterator it2 = it1; it2++;
00114     for(; it2 != end; ++it2)
00115     {
00116       if((*it1)->getAABB().overlap((*it2)->getAABB()))
00117         if(callback(*it1, *it2, cdata))
00118           return;
00119     }
00120   }
00121 }
00122 
00123 void NaiveCollisionManager::distance(void* cdata, DistanceCallBack callback) const
00124 {
00125   if(size() == 0) return;
00126   
00127   FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00128   for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end = objs.end(); it1 != end; ++it1)
00129   {
00130     std::list<CollisionObject*>::const_iterator it2 = it1; it2++;
00131     for(; it2 != end; ++it2)
00132     {
00133       if((*it1)->getAABB().distance((*it2)->getAABB()) < min_dist)
00134       {
00135         if(callback(*it1, *it2, cdata, min_dist))
00136           return;
00137       }
00138     }
00139   }
00140 }
00141 
00142 void NaiveCollisionManager::collide(BroadPhaseCollisionManager* other_manager_, void* cdata, CollisionCallBack callback) const
00143 {
00144   NaiveCollisionManager* other_manager = static_cast<NaiveCollisionManager*>(other_manager_);
00145   
00146   if((size() == 0) || (other_manager->size() == 0)) return;
00147 
00148   if(this == other_manager) 
00149   {
00150     collide(cdata, callback);
00151     return;
00152   }
00153 
00154   for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end1 = objs.end(); it1 != end1; ++it1)
00155   {
00156     for(std::list<CollisionObject*>::const_iterator it2 = other_manager->objs.begin(), end2 = other_manager->objs.end(); it2 != end2; ++it2)
00157     {
00158       if((*it1)->getAABB().overlap((*it2)->getAABB()))
00159         if(callback((*it1), (*it2), cdata))
00160           return;
00161     }
00162   }
00163 }
00164 
00165 void NaiveCollisionManager::distance(BroadPhaseCollisionManager* other_manager_, void* cdata, DistanceCallBack callback) const
00166 {
00167   NaiveCollisionManager* other_manager = static_cast<NaiveCollisionManager*>(other_manager_);
00168 
00169   if((size() == 0) || (other_manager->size() == 0)) return;
00170 
00171   if(this == other_manager)
00172   {
00173     distance(cdata, callback);
00174     return;
00175   }
00176   
00177   FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00178   for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end1 = objs.end(); it1 != end1; ++it1)
00179   {
00180     for(std::list<CollisionObject*>::const_iterator it2 = other_manager->objs.begin(), end2 = other_manager->objs.end(); it2 != end2; ++it2)
00181     {
00182       if((*it1)->getAABB().distance((*it2)->getAABB()) < min_dist)
00183       {
00184         if(callback(*it1, *it2, cdata, min_dist))
00185           return;
00186       }
00187     }
00188   }
00189 }
00190 
00191 bool NaiveCollisionManager::empty() const
00192 {
00193   return objs.empty();
00194 }
00195 
00196 
00197 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


fcl
Author(s): Jia Pan
autogenerated on Tue Jan 15 2013 16:05:30