octree_key.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
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  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  */
00037 
00038 #ifndef OCTREE_KEY_H
00039 #define OCTREE_KEY_H
00040 
00041 namespace pcl
00042 {
00043   namespace octree
00044   {
00046 
00050 
00051     class OctreeKey
00052     {
00053     public:
00054 
00056       OctreeKey () :
00057           x (0), y (0), z (0)
00058       {
00059       }
00060 
00062       OctreeKey (unsigned int keyX, unsigned int keyY, unsigned int keyZ) :
00063           x (keyX), y (keyY), z (keyZ)
00064       {
00065       }
00066 
00068       OctreeKey (const OctreeKey& source) :
00069           x (source.x), y (source.y), z (source.z)
00070       {
00071       }
00072 
00076       bool
00077       operator == (const OctreeKey& b) const
00078       {
00079         return ((b.x == this->x) && (b.y == this->y) && (b.z == this->z));
00080       }
00081 
00085       bool
00086       operator <= (const OctreeKey& b) const
00087       {
00088         return ((b.x >= this->x) && (b.y >= this->y) && (b.z >= this->z));
00089       }
00090 
00094       bool
00095       operator >= (const OctreeKey& b) const
00096       {
00097         return ((b.x <= this->x) && (b.y <= this->y) && (b.z <= this->z));
00098       }
00099 
00103       inline void
00104       pushBranch (unsigned char childIndex)
00105       {
00106         this->x = (this->x << 1) | (!!(childIndex & (1 << 2)));
00107         this->y = (this->y << 1) | (!!(childIndex & (1 << 1)));
00108         this->z = (this->z << 1) | (!!(childIndex & (1 << 0)));
00109       }
00110 
00113       inline void
00114       popBranch ()
00115       {
00116         this->x >>= 1;
00117         this->y >>= 1;
00118         this->z >>= 1;
00119       }
00120 
00125       inline unsigned char
00126       getChildIdxWithDepthMask (unsigned int depthMask) const
00127       {
00128         return static_cast<unsigned char> (((!!(this->x & depthMask)) << 2)
00129                                          | ((!!(this->y & depthMask)) << 1)
00130                                          |  (!!(this->z & depthMask)));
00131       }
00132 
00133       // Indices addressing a voxel at (X, Y, Z)
00134       unsigned int x;
00135       unsigned int y;
00136       unsigned int z;
00137 
00138     };
00139   }
00140 }
00141 
00142 #endif


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:15:57