octree_pointcloud_voxelcentroid.hpp
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-2011, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id: octree_pointcloud_voxelcentroid.hpp 6459 2012-07-18 07:50:37Z dpb $
00038  */
00039 
00040 #ifndef PCL_OCTREE_VOXELCENTROID_HPP
00041 #define PCL_OCTREE_VOXELCENTROID_HPP
00042 
00043 #include <pcl/octree/octree_pointcloud_voxelcentroid.h>
00044 
00046 template<typename PointT, typename LeafContainerT, typename BranchContainerT> bool
00047 pcl::octree::OctreePointCloudVoxelCentroid<PointT, LeafContainerT, BranchContainerT>::getVoxelCentroidAtPoint (
00048     const PointT& point_arg, PointT& voxel_centroid_arg) const
00049 {
00050   OctreeKey key;
00051   LeafNode* leaf = 0;
00052 
00053   // generate key
00054   genOctreeKeyforPoint (point_arg, key);
00055 
00056   leaf = this->findLeaf (key);
00057 
00058   if (leaf)
00059   {
00060     LeafContainerT* container = leaf;
00061     container->getCentroid (voxel_centroid_arg);
00062   }
00063 
00064   return (leaf != 0);
00065 }
00066 
00068 template<typename PointT, typename LeafContainerT, typename BranchContainerT> size_t
00069 pcl::octree::OctreePointCloudVoxelCentroid<PointT, LeafContainerT, BranchContainerT>::getVoxelCentroids (
00070     typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const
00071 {
00072   OctreeKey new_key;
00073 
00074   // reset output vector
00075   voxel_centroid_list_arg.clear ();
00076   voxel_centroid_list_arg.reserve (this->leaf_count_);
00077 
00078   getVoxelCentroidsRecursive (this->root_node_, new_key, voxel_centroid_list_arg );
00079 
00080   // return size of centroid vector
00081   return (voxel_centroid_list_arg.size ());
00082 }
00083 
00085 template<typename PointT, typename LeafContainerT, typename BranchContainerT> void
00086 pcl::octree::OctreePointCloudVoxelCentroid<PointT, LeafContainerT, BranchContainerT>::getVoxelCentroidsRecursive (
00087     const BranchNode* branch_arg, OctreeKey& key_arg,
00088     typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const
00089 {
00090   // child iterator
00091   unsigned char child_idx;
00092 
00093   // iterate over all children
00094   for (child_idx = 0; child_idx < 8; child_idx++)
00095   {
00096     // if child exist
00097     if (branch_arg->hasChild (child_idx))
00098     {
00099       // add current branch voxel to key
00100       key_arg.pushBranch (child_idx);
00101 
00102       OctreeNode *child_node = branch_arg->getChildPtr (child_idx);
00103 
00104       switch (child_node->getNodeType ())
00105       {
00106         case BRANCH_NODE:
00107         {
00108           // recursively proceed with indexed child branch
00109           getVoxelCentroidsRecursive (static_cast<const BranchNode*> (child_node), key_arg, voxel_centroid_list_arg);
00110           break;
00111         }
00112         case LEAF_NODE:
00113         {
00114           PointT new_centroid;
00115 
00116           LeafNode* container = static_cast<LeafNode*> (child_node);
00117 
00118           container->getContainer().getCentroid (new_centroid);
00119 
00120           voxel_centroid_list_arg.push_back (new_centroid);
00121           break;
00122         }
00123         default:
00124           break;
00125        }
00126 
00127       // pop current branch voxel from key
00128       key_arg.popBranch ();
00129     }
00130   }
00131 }
00132 
00133 
00134 #define PCL_INSTANTIATE_OctreePointCloudVoxelCentroid(T) template class PCL_EXPORTS pcl::octree::OctreePointCloudVoxelCentroid<T>;
00135 
00136 #endif
00137 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:19