00001 /*********************************************************************** 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 00005 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 00006 * 00007 * THE BSD LICENSE 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *************************************************************************/ 00030 00031 /*********************************************************************** 00032 * Author: Vincent Rabaud 00033 *************************************************************************/ 00034 00035 #ifndef RTABMAP_FLANN_DYNAMIC_BITSET_H_ 00036 #define RTABMAP_FLANN_DYNAMIC_BITSET_H_ 00037 00038 //#define FLANN_USE_BOOST 1 00039 #if FLANN_USE_BOOST 00040 #include <boost/dynamic_bitset.hpp> 00041 typedef boost::dynamic_bitset<> DynamicBitset; 00042 #else 00043 00044 #include <limits.h> 00045 00046 namespace rtflann { 00047 00052 class DynamicBitset 00053 { 00054 public: 00057 DynamicBitset() : size_(0) 00058 { 00059 } 00060 00064 DynamicBitset(size_t size) 00065 { 00066 resize(size); 00067 reset(); 00068 } 00069 00072 void clear() 00073 { 00074 std::fill(bitset_.begin(), bitset_.end(), 0); 00075 } 00076 00080 bool empty() const 00081 { 00082 return bitset_.empty(); 00083 } 00084 00087 void reset() 00088 { 00089 std::fill(bitset_.begin(), bitset_.end(), 0); 00090 } 00091 00095 void reset(size_t index) 00096 { 00097 bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_)); 00098 } 00099 00106 void reset_block(size_t index) 00107 { 00108 bitset_[index / cell_bit_size_] = 0; 00109 } 00110 00114 void resize(size_t size) 00115 { 00116 size_ = size; 00117 bitset_.resize(size / cell_bit_size_ + 1); 00118 } 00119 00123 void set(size_t index) 00124 { 00125 bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_); 00126 } 00127 00130 size_t size() const 00131 { 00132 return size_; 00133 } 00134 00139 bool test(size_t index) const 00140 { 00141 return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0; 00142 } 00143 00144 private: 00145 template <typename Archive> 00146 void serialize(Archive& ar) 00147 { 00148 ar & size_; 00149 ar & bitset_; 00150 } 00151 friend struct serialization::access; 00152 00153 private: 00154 std::vector<size_t> bitset_; 00155 size_t size_; 00156 static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t); 00157 }; 00158 00159 } // namespace flann 00160 00161 #endif 00162 00163 #endif // FLANN_DYNAMIC_BITSET_H_