Point Cloud Library (PCL)  1.10.0
octree_key.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #pragma once
39 
40 namespace pcl
41 {
42  namespace octree
43  {
44  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45  /** \brief @b Octree key class
46  * \note Octree keys contain integer indices for each coordinate axis in order to address an octree leaf node.
47  * \author Julius Kammerl (julius@kammerl.de)
48  */
49  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50  class OctreeKey
51  {
52  public:
53 
54  /** \brief Empty constructor. */
55  OctreeKey () :
56  x (0), y (0), z (0)
57  {
58  }
59 
60  /** \brief Constructor for key initialization. */
61  OctreeKey (unsigned int keyX, unsigned int keyY, unsigned int keyZ) :
62  x (keyX), y (keyY), z (keyZ)
63  {
64  }
65 
66  /** \brief Copy constructor. */
67  OctreeKey (const OctreeKey& source)
68  {
69  memcpy(key_, source.key_, sizeof(key_));
70  }
71 
72  OctreeKey& operator=(const OctreeKey&) = default;
73 
74  /** \brief Operator== for comparing octree keys with each other.
75  * \return "true" if leaf node indices are identical; "false" otherwise.
76  * */
77  bool
78  operator == (const OctreeKey& b) const
79  {
80  return ((b.x == this->x) && (b.y == this->y) && (b.z == this->z));
81  }
82 
83  /** \brief Inequal comparison operator
84  * \param[in] other OctreeIteratorBase to compare with
85  * \return "true" if the current and other iterators are different ; "false" otherwise.
86  */
87  bool operator!= (const OctreeKey& other) const
88  {
89  return !operator== (other);
90  }
91 
92  /** \brief Operator<= for comparing octree keys with each other.
93  * \return "true" if key indices are not greater than the key indices of b ; "false" otherwise.
94  * */
95  bool
96  operator <= (const OctreeKey& b) const
97  {
98  return ((b.x >= this->x) && (b.y >= this->y) && (b.z >= this->z));
99  }
100 
101  /** \brief Operator>= for comparing octree keys with each other.
102  * \return "true" if key indices are not smaller than the key indices of b ; "false" otherwise.
103  * */
104  bool
105  operator >= (const OctreeKey& b) const
106  {
107  return ((b.x <= this->x) && (b.y <= this->y) && (b.z <= this->z));
108  }
109 
110  /** \brief push a child node to the octree key
111  * \param[in] childIndex index of child node to be added (0-7)
112  * */
113  inline void
114  pushBranch (unsigned char childIndex)
115  {
116  this->x = (this->x << 1) | (!!(childIndex & (1 << 2)));
117  this->y = (this->y << 1) | (!!(childIndex & (1 << 1)));
118  this->z = (this->z << 1) | (!!(childIndex & (1 << 0)));
119  }
120 
121  /** \brief pop child node from octree key
122  * */
123  inline void
125  {
126  this->x >>= 1;
127  this->y >>= 1;
128  this->z >>= 1;
129  }
130 
131  /** \brief get child node index using depthMask
132  * \param[in] depthMask bit mask with single bit set at query depth
133  * \return child node index
134  * */
135  inline unsigned char
136  getChildIdxWithDepthMask (unsigned int depthMask) const
137  {
138  return static_cast<unsigned char> (((!!(this->x & depthMask)) << 2)
139  | ((!!(this->y & depthMask)) << 1)
140  | (!!(this->z & depthMask)));
141  }
142 
143  /* \brief maximum depth that can be addressed */
144  static const unsigned char maxDepth = static_cast<unsigned char>(sizeof(std::uint32_t)*8);
145 
146  // Indices addressing a voxel at (X, Y, Z)
147 
148  union
149  {
150  struct
151  {
155  };
157  };
158 
159 
160  };
161  }
162 }
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::uint32_t
std::uint32_t uint32_t
Definition: pcl_macros.h:96
pcl::octree::OctreeKey::pushBranch
void pushBranch(unsigned char childIndex)
push a child node to the octree key
Definition: octree_key.h:114
pcl::octree::OctreeKey::OctreeKey
OctreeKey(unsigned int keyX, unsigned int keyY, unsigned int keyZ)
Constructor for key initialization.
Definition: octree_key.h:61
pcl::octree::OctreeKey::maxDepth
static const unsigned char maxDepth
Definition: octree_key.h:144
pcl::octree::OctreeKey::OctreeKey
OctreeKey(const OctreeKey &source)
Copy constructor.
Definition: octree_key.h:67
pcl::octree::OctreeKey::popBranch
void popBranch()
pop child node from octree key
Definition: octree_key.h:124
pcl::octree::OctreeKey
Octree key class
Definition: octree_key.h:50
pcl::octree::OctreeKey::operator!=
bool operator!=(const OctreeKey &other) const
Inequal comparison operator.
Definition: octree_key.h:87
pcl::octree::OctreeKey::operator>=
bool operator>=(const OctreeKey &b) const
Operator>= for comparing octree keys with each other.
Definition: octree_key.h:105
pcl::octree::OctreeKey::operator=
OctreeKey & operator=(const OctreeKey &)=default
pcl::octree::OctreeKey::z
std::uint32_t z
Definition: octree_key.h:154
pcl::octree::OctreeKey::OctreeKey
OctreeKey()
Empty constructor.
Definition: octree_key.h:55
pcl::octree::OctreeKey::operator==
bool operator==(const OctreeKey &b) const
Operator== for comparing octree keys with each other.
Definition: octree_key.h:78
pcl::octree::OctreeKey::getChildIdxWithDepthMask
unsigned char getChildIdxWithDepthMask(unsigned int depthMask) const
get child node index using depthMask
Definition: octree_key.h:136
pcl::octree::OctreeKey::x
std::uint32_t x
Definition: octree_key.h:152
pcl::octree::OctreeKey::y
std::uint32_t y
Definition: octree_key.h:153
pcl::octree::OctreeKey::operator<=
bool operator<=(const OctreeKey &b) const
Operator<= for comparing octree keys with each other.
Definition: octree_key.h:96
pcl::octree::OctreeKey::key_
std::uint32_t key_[3]
Definition: octree_key.h:156