Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
octree_key.h
Go to the documentation of this file.
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 #ifndef OCTREE_KEY_H
39 #define OCTREE_KEY_H
40 
41 namespace pcl
42 {
43  namespace octree
44  {
46 
50  class OctreeKey
52  {
53  public:
54 
56  OctreeKey () :
57  x (0), y (0), z (0)
58  {
59  }
60 
62  OctreeKey (unsigned int keyX, unsigned int keyY, unsigned int keyZ) :
63  x (keyX), y (keyY), z (keyZ)
64  {
65  }
66 
68  OctreeKey (const OctreeKey& source) :
69  x (source.x), y (source.y), z (source.z)
70  {
71  }
72 
76  bool
77  operator == (const OctreeKey& b) const
78  {
79  return ((b.x == this->x) && (b.y == this->y) && (b.z == this->z));
80  }
81 
85  bool
86  operator <= (const OctreeKey& b) const
87  {
88  return ((b.x >= this->x) && (b.y >= this->y) && (b.z >= this->z));
89  }
90 
94  bool
95  operator >= (const OctreeKey& b) const
96  {
97  return ((b.x <= this->x) && (b.y <= this->y) && (b.z <= this->z));
98  }
99 
103  inline void
104  pushBranch (unsigned char childIndex)
105  {
106  this->x = (this->x << 1) | (!!(childIndex & (1 << 2)));
107  this->y = (this->y << 1) | (!!(childIndex & (1 << 1)));
108  this->z = (this->z << 1) | (!!(childIndex & (1 << 0)));
109  }
110 
113  inline void
115  {
116  this->x >>= 1;
117  this->y >>= 1;
118  this->z >>= 1;
119  }
120 
125  inline unsigned char
126  getChildIdxWithDepthMask (unsigned int depthMask) const
127  {
128  return static_cast<unsigned char> (((!!(this->x & depthMask)) << 2)
129  | ((!!(this->y & depthMask)) << 1)
130  | (!!(this->z & depthMask)));
131  }
132 
133  // Indices addressing a voxel at (X, Y, Z)
134  unsigned int x;
135  unsigned int y;
136  unsigned int z;
137 
138  };
139  }
140 }
141 
142 #endif