broadphase_dynamic_AABB_tree.h
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 
00038 #ifndef FCL_BROAD_PHASE_DYNAMIC_AABB_TREE_H
00039 #define FCL_BROAD_PHASE_DYNAMIC_AABB_TREE_H
00040 
00041 #include "fcl/broadphase/broadphase.h"
00042 #include "fcl/broadphase/hierarchy_tree.h"
00043 #include "fcl/BV/BV.h"
00044 #include "fcl/shape/geometric_shapes_utility.h"
00045 #include <boost/unordered_map.hpp>
00046 #include <boost/bind.hpp>
00047 #include <limits>
00048 
00049 
00050 namespace fcl
00051 {
00052 
00053 class DynamicAABBTreeCollisionManager : public BroadPhaseCollisionManager
00054 {
00055 public:
00056   typedef NodeBase<AABB> DynamicAABBNode;
00057   typedef boost::unordered_map<CollisionObject*, DynamicAABBNode*> DynamicAABBTable;
00058 
00059   int max_tree_nonbalanced_level;
00060   int tree_incremental_balance_pass;
00061   int& tree_topdown_balance_threshold;
00062   int& tree_topdown_level;
00063   int tree_init_level;
00064 
00065   bool octree_as_geometry_collide;
00066   bool octree_as_geometry_distance;
00067 
00068   
00069   DynamicAABBTreeCollisionManager() : tree_topdown_balance_threshold(dtree.bu_threshold),
00070                                       tree_topdown_level(dtree.topdown_level)
00071   {
00072     max_tree_nonbalanced_level = 10;
00073     tree_incremental_balance_pass = 10;
00074     tree_topdown_balance_threshold = 2;
00075     tree_topdown_level = 0;
00076     tree_init_level = 0;
00077     setup_ = false;
00078 
00079     // from experiment, this is the optimal setting
00080     octree_as_geometry_collide = true;
00081     octree_as_geometry_distance = false;
00082   }
00083 
00085   void registerObjects(const std::vector<CollisionObject*>& other_objs);
00086   
00088   void registerObject(CollisionObject* obj);
00089 
00091   void unregisterObject(CollisionObject* obj);
00092 
00094   void setup();
00095 
00097   void update();
00098 
00100   void update(CollisionObject* updated_obj);
00101 
00103   void update(const std::vector<CollisionObject*>& updated_objs);
00104 
00106   void clear()
00107   {
00108     dtree.clear();
00109     table.clear();
00110   }
00111 
00113   void getObjects(std::vector<CollisionObject*>& objs) const
00114   {
00115     objs.resize(this->size());
00116     std::transform(table.begin(), table.end(), objs.begin(), boost::bind(&DynamicAABBTable::value_type::first, _1));
00117   }
00118 
00120   void collide(CollisionObject* obj, void* cdata, CollisionCallBack callback) const;
00121 
00123   void distance(CollisionObject* obj, void* cdata, DistanceCallBack callback) const;
00124 
00126   void collide(void* cdata, CollisionCallBack callback) const;
00127 
00129   void distance(void* cdata, DistanceCallBack callback) const;
00130 
00132   void collide(BroadPhaseCollisionManager* other_manager_, void* cdata, CollisionCallBack callback) const;
00133 
00135   void distance(BroadPhaseCollisionManager* other_manager_, void* cdata, DistanceCallBack callback) const;
00136   
00138   bool empty() const
00139   {
00140     return dtree.empty();
00141   }
00142   
00144   size_t size() const
00145   {
00146     return dtree.size();
00147   }
00148 
00149   const HierarchyTree<AABB>& getTree() const { return dtree; }
00150 
00151 
00152 private:
00153   HierarchyTree<AABB> dtree;
00154   boost::unordered_map<CollisionObject*, DynamicAABBNode*> table;
00155 
00156   bool setup_;
00157 
00158   void update_(CollisionObject* updated_obj);
00159 };
00160 
00161 
00162 
00163 }
00164 
00165 #endif
 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