$search
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 COLLISION_SPACE_CCD_INTERVAL_TREE_H 00039 #define COLLISION_SPACE_CCD_INTERVAL_TREE_H 00040 00041 #include <deque> 00042 #include <limits> 00043 00045 namespace collision_space_ccd 00046 { 00047 00053 struct Interval 00054 { 00055 public: 00056 Interval() {} 00057 virtual ~Interval() {} 00058 virtual void print() {} 00059 00060 double low, high; 00061 }; 00062 00063 class IntervalTreeNode 00064 { 00065 friend class IntervalTree; 00066 public: 00068 void print(IntervalTreeNode* left, IntervalTreeNode* right) const; 00069 00070 IntervalTreeNode(); 00071 00072 IntervalTreeNode(Interval* new_interval); 00073 00074 ~IntervalTreeNode(); 00075 00076 protected: 00077 00078 Interval* stored_interval; 00079 00080 double key; 00081 00082 double high; 00083 00084 double max_high; 00085 00086 bool red; /* if red = false then the node is black */ 00087 00088 IntervalTreeNode* left; 00089 00090 IntervalTreeNode* right; 00091 00092 IntervalTreeNode* parent; 00093 }; 00094 00099 struct it_recursion_node 00100 { 00101 public: 00102 IntervalTreeNode* start_node; 00103 00104 unsigned int parent_index; 00105 00106 bool try_right_branch; 00107 }; 00108 00109 00111 class IntervalTree 00112 { 00113 public: 00114 00115 IntervalTree(); 00116 00117 ~IntervalTree(); 00118 00120 void print() const; 00121 00123 Interval* deleteNode(IntervalTreeNode* node); 00124 00126 IntervalTreeNode* insert(Interval* new_interval); 00127 00129 IntervalTreeNode* getPredecessor(IntervalTreeNode* node) const; 00130 00132 IntervalTreeNode* getSuccessor(IntervalTreeNode* node) const; 00133 00135 std::deque<Interval*> query(double low, double high); 00136 00137 protected: 00138 00139 IntervalTreeNode* root; 00140 00141 IntervalTreeNode* nil; 00142 00144 void leftRotate(IntervalTreeNode* node); 00145 00147 void rightRotate(IntervalTreeNode* node); 00148 00150 void recursiveInsert(IntervalTreeNode* node); 00151 00153 void recursivePrint(IntervalTreeNode* node) const; 00154 00156 void fixupMaxHigh(IntervalTreeNode* node); 00157 00158 void deleteFixup(IntervalTreeNode* node); 00159 00160 private: 00161 unsigned int recursion_node_stack_size; 00162 it_recursion_node* recursion_node_stack; 00163 unsigned int current_parent; 00164 unsigned int recursion_node_stack_top; 00165 }; 00166 00167 } 00168 00169 #endif 00170 00171