9 #ifndef OCTOMAP_OCTREE_KEY_H
10 #define OCTOMAP_OCTREE_KEY_H
52 #if defined( __GNUC__ ) && !(defined( __clang__ ) && defined( __APPLE__ ) )
53 #include <tr1/unordered_set>
54 #include <tr1/unordered_map>
55 #define OCTREE_KEY_USES_TR1
57 #include <unordered_set>
58 #include <unordered_map>
72 OcTreeKey (
unsigned short int a,
unsigned short int b,
unsigned short int c)
73 {
k[0] = a;
k[1] = b;
k[2] = c; }
75 k[0] = other.
k[0];
k[1] = other.
k[1];
k[2] = other.
k[2];
78 return ((
k[0] == other[0]) && (
k[1] == other[1]) && (
k[2] == other[2]));
81 return( (
k[0] != other[0]) || (
k[1] != other[1]) || (
k[2] != other[2]) );
84 k[0] = other.
k[0];
k[1] = other.
k[1];
k[2] = other.
k[2];
87 const unsigned short int&
operator[] (
unsigned int i)
const {
94 unsigned short int k[3];
100 return key.
k[0] + 1337*key.
k[1] + 345637*key.
k[2];
112 #ifdef OCTREE_KEY_USES_TR1
113 typedef std::tr1::unordered_set<OcTreeKey, OcTreeKey::KeyHash>
KeySet;
115 typedef std::unordered_set<OcTreeKey, OcTreeKey::KeyHash>
KeySet;
123 #ifdef OCTREE_KEY_USES_TR1
124 typedef std::tr1::unordered_map<OcTreeKey, bool, OcTreeKey::KeyHash>
KeyBoolMap;
126 typedef std::unordered_map<OcTreeKey, bool, OcTreeKey::KeyHash>
KeyBoolMap;
155 const_iterator
begin()
const {
return ray.begin(); }
159 reverse_iterator
rend() {
return ray.rend(); }
163 std::vector<OcTreeKey>
ray;
176 inline void computeChildKey (
const unsigned int& pos,
const unsigned short int& center_offset_key,
179 if (pos & 1) child_key[0] = parent_key[0] + center_offset_key;
180 else child_key[0] = parent_key[0] - center_offset_key - (center_offset_key ? 0 : 1);
182 if (pos & 2) child_key[1] = parent_key[1] + center_offset_key;
183 else child_key[1] = parent_key[1] - center_offset_key - (center_offset_key ? 0 : 1);
185 if (pos & 4) child_key[2] = parent_key[2] + center_offset_key;
186 else child_key[2] = parent_key[2] - center_offset_key - (center_offset_key ? 0 : 1);
191 unsigned char pos = 0;
192 if (key.
k[0] & (1 << depth)) pos += 1;
193 if (key.
k[1] & (1 << depth)) pos += 2;
194 if (key.
k[2] & (1 << depth)) pos += 4;
206 unsigned short int mask = 65535 << level;
OctoMap: A probabilistic, flexible, and compact 3D mapping library for robotic systems.
unsigned char computeChildIdx(const OcTreeKey &key, int depth)
generate child index (between 0 and 7) from key at given tree depth
Provides a hash function on Keys.
std::vector< OcTreeKey >::iterator end_of_ray
std::unordered_map< OcTreeKey, bool, OcTreeKey::KeyHash > KeyBoolMap
Data structrure to efficiently track changed nodes as a combination of OcTreeKeys and a bool flag (to...
std::vector< OcTreeKey > ray
OcTreeKey(unsigned short int a, unsigned short int b, unsigned short int c)
OcTreeKey(const OcTreeKey &other)
const Scalar * const_iterator
void computeChildKey(const unsigned int &pos, const unsigned short int ¢er_offset_key, const OcTreeKey &parent_key, OcTreeKey &child_key)
Computes the key of a child node while traversing the octree, given child index and current key...
bool operator!=(const OcTreeKey &other) const
void addKey(OcTreeKey &k)
reverse_iterator rbegin()
bool operator==(const OcTreeKey &other) const
std::unordered_set< OcTreeKey, OcTreeKey::KeyHash > KeySet
Data structure to efficiently compute the nodes to update from a scan insertion using a hash set...
const_iterator end() const
size_t operator()(const OcTreeKey &key) const
const unsigned short int & operator[](unsigned int i) const
std::vector< OcTreeKey >::const_iterator const_iterator
std::vector< OcTreeKey >::iterator iterator
std::vector< OcTreeKey >::reverse_iterator reverse_iterator
OcTreeKey is a container class for internal key addressing.
OcTreeKey & operator=(const OcTreeKey &other)
const_iterator begin() const
OcTreeKey computeIndexKey(unsigned short int level, const OcTreeKey &key)
Generates a unique key for all keys on a certain level of the tree.