broadphase_interval_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 
00037 #ifndef FCL_BROAD_PHASE_INTERVAL_TREE_H
00038 #define FCL_BROAD_PHASE_INTERVAL_TREE_H
00039 
00040 #include "fcl/broadphase/broadphase.h"
00041 #include "fcl/broadphase/interval_tree.h"
00042 #include <deque>
00043 #include <map>
00044 
00045 namespace fcl
00046 {
00047 
00049 class IntervalTreeCollisionManager : public BroadPhaseCollisionManager
00050 {
00051 public:
00052   IntervalTreeCollisionManager() : setup_(false)
00053   {
00054     for(int i = 0; i < 3; ++i)
00055       interval_trees[i] = NULL;
00056   }
00057 
00058   ~IntervalTreeCollisionManager()
00059   {
00060     clear();
00061   }
00062 
00064   void registerObject(CollisionObject* obj);
00065 
00067   void unregisterObject(CollisionObject* obj);
00068 
00070   void setup();
00071 
00073   void update();
00074 
00076   void update(CollisionObject* updated_obj);
00077 
00079   void update(const std::vector<CollisionObject*>& updated_objs);
00080 
00082   void clear();
00083 
00085   void getObjects(std::vector<CollisionObject*>& objs) const;
00086 
00088   void collide(CollisionObject* obj, void* cdata, CollisionCallBack callback) const;
00089 
00091   void distance(CollisionObject* obj, void* cdata, DistanceCallBack callback) const;
00092 
00094   void collide(void* cdata, CollisionCallBack callback) const;
00095 
00097   void distance(void* cdata, DistanceCallBack callback) const;
00098 
00100   void collide(BroadPhaseCollisionManager* other_manager, void* cdata, CollisionCallBack callback) const;
00101 
00103   void distance(BroadPhaseCollisionManager* other_manager, void* cdata, DistanceCallBack callback) const;
00104 
00106   bool empty() const;
00107   
00109   inline size_t size() const { return endpoints[0].size() / 2; }
00110 
00111 protected:
00112 
00113 
00115   struct EndPoint
00116   {
00118     CollisionObject* obj;
00119 
00121     FCL_REAL value;
00122 
00124     char minmax;
00125   };
00126 
00128   struct SAPInterval : public SimpleInterval
00129   {
00130     CollisionObject* obj;
00131     SAPInterval(double low_, double high_, CollisionObject* obj_) : SimpleInterval()
00132     {
00133       low = low_;
00134       high = high_;
00135       obj = obj_;
00136     }
00137   };
00138 
00139 
00140   bool checkColl(std::deque<SimpleInterval*>::const_iterator pos_start, std::deque<SimpleInterval*>::const_iterator pos_end, CollisionObject* obj, void* cdata, CollisionCallBack callback) const;
00141 
00142   bool checkDist(std::deque<SimpleInterval*>::const_iterator pos_start, std::deque<SimpleInterval*>::const_iterator pos_end, CollisionObject* obj, void* cdata, DistanceCallBack callback, FCL_REAL& min_dist) const;
00143 
00144   bool collide_(CollisionObject* obj, void* cdata, CollisionCallBack callback) const;
00145 
00146   bool distance_(CollisionObject* obj, void* cdata, DistanceCallBack callback, FCL_REAL& min_dist) const;
00147 
00149   std::vector<EndPoint> endpoints[3];
00150 
00152   IntervalTree* interval_trees[3];
00153 
00154   std::map<CollisionObject*, SAPInterval*> obj_interval_maps[3];
00155 
00157   bool setup_;
00158 };
00159 
00160 
00161 }
00162 
00163 #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