Point Cloud Library (PCL)  1.7.0
octree_pointcloud_voxelcentroid.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id: octree_pointcloud_voxelcentroid.hpp 6459 2012-07-18 07:50:37Z dpb $
38  */
39 
40 #ifndef PCL_OCTREE_VOXELCENTROID_HPP
41 #define PCL_OCTREE_VOXELCENTROID_HPP
42 
43 #include <pcl/octree/octree_pointcloud_voxelcentroid.h>
44 
45 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 template<typename PointT, typename LeafContainerT, typename BranchContainerT> bool
48  const PointT& point_arg, PointT& voxel_centroid_arg) const
49 {
50  OctreeKey key;
51  LeafNode* leaf = 0;
52 
53  // generate key
54  genOctreeKeyforPoint (point_arg, key);
55 
56  leaf = this->findLeaf (key);
57 
58  if (leaf)
59  {
60  LeafContainerT* container = leaf;
61  container->getCentroid (voxel_centroid_arg);
62  }
63 
64  return (leaf != 0);
65 }
66 
67 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68 template<typename PointT, typename LeafContainerT, typename BranchContainerT> size_t
71 {
72  OctreeKey new_key;
73 
74  // reset output vector
75  voxel_centroid_list_arg.clear ();
76  voxel_centroid_list_arg.reserve (this->leaf_count_);
77 
78  getVoxelCentroidsRecursive (this->root_node_, new_key, voxel_centroid_list_arg );
79 
80  // return size of centroid vector
81  return (voxel_centroid_list_arg.size ());
82 }
83 
84 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 template<typename PointT, typename LeafContainerT, typename BranchContainerT> void
87  const BranchNode* branch_arg, OctreeKey& key_arg,
89 {
90  // child iterator
91  unsigned char child_idx;
92 
93  // iterate over all children
94  for (child_idx = 0; child_idx < 8; child_idx++)
95  {
96  // if child exist
97  if (branch_arg->hasChild (child_idx))
98  {
99  // add current branch voxel to key
100  key_arg.pushBranch (child_idx);
101 
102  OctreeNode *child_node = branch_arg->getChildPtr (child_idx);
103 
104  switch (child_node->getNodeType ())
105  {
106  case BRANCH_NODE:
107  {
108  // recursively proceed with indexed child branch
109  getVoxelCentroidsRecursive (static_cast<const BranchNode*> (child_node), key_arg, voxel_centroid_list_arg);
110  break;
111  }
112  case LEAF_NODE:
113  {
114  PointT new_centroid;
115 
116  LeafNode* container = static_cast<LeafNode*> (child_node);
117 
118  container->getContainer().getCentroid (new_centroid);
119 
120  voxel_centroid_list_arg.push_back (new_centroid);
121  break;
122  }
123  default:
124  break;
125  }
126 
127  // pop current branch voxel from key
128  key_arg.popBranch ();
129  }
130  }
131 }
132 
133 
134 #define PCL_INSTANTIATE_OctreePointCloudVoxelCentroid(T) template class PCL_EXPORTS pcl::octree::OctreePointCloudVoxelCentroid<T>;
135 
136 #endif
137