38 #ifndef PCL_GRAPH_IMPL_VOXEL_GRID_GRAPH_BUILDER_CPP
39 #define PCL_GRAPH_IMPL_VOXEL_GRID_GRAPH_BUILDER_CPP
42 #include <boost/unordered_map.hpp>
44 #include <pcl/common/io.h>
45 #include <pcl/common/common.h>
46 #include <pcl/common/centroid.h>
48 #pragma GCC diagnostic push
49 #pragma GCC diagnostic ignored "-Wignored-qualifiers"
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wpedantic"
52 #include <pcl/octree/octree.h>
53 #pragma GCC diagnostic pop
54 #pragma GCC diagnostic pop
62 #pragma GCC diagnostic push
63 #pragma GCC diagnostic ignored "-Wunused-function"
70 static size_t hash_value(
const OctreeKey& b)
72 return boost::hash_value(b.key_);
78 #pragma GCC diagnostic pop
80 template <
typename Po
intT,
typename GraphT>
void
90 typename pcl::PointCloud<PointT>::Ptr transformed(
new pcl::PointCloud<PointT>);
91 pcl::copyPointCloud(*input_, *transformed);
92 for (
size_t i = 0; i < transformed->size(); ++i)
94 PointT& p = transformed->points[i];
101 pcl::getMinMax3D(*transformed, *indices_,
min,
max);
104 typedef pcl::octree::OctreePointCloud<PointT> Octree;
105 Octree octree(voxel_resolution_);
107 octree.setInputCloud(transformed, indices_);
108 octree.addPointsFromInputCloud();
110 graph = GraphT(octree.getLeafCount());
112 typedef boost::unordered_map<pcl::octree::OctreeKey, VertexId> KeyVertexMap;
113 KeyVertexMap key_to_vertex_map;
115 point_to_vertex_map_.clear();
118 typename Octree::LeafNodeIterator leaf_itr = octree.leaf_depth_begin();
119 for (
VertexId v = 0; leaf_itr != octree.leaf_depth_end(); ++leaf_itr, ++
v)
123 pcl::CentroidPoint<PointInT> centroid;
124 std::vector<int>&
indices = leaf_itr.getLeafContainer().getPointIndicesVector();
127 centroid.add(input_->operator[](
index));
128 point_to_vertex_map_[
index] =
v;
130 centroid.get(graph[
v]);
133 octree::OctreeKey key = leaf_itr.getCurrentOctreeKey();
134 key_to_vertex_map[key] =
v;
137 octree::OctreeKey neighbor_key;
138 for (
int dx = (key.x > 0) ? -1 : 0; dx <= 1; ++dx)
140 neighbor_key.x =
static_cast<std::uint32_t
>(key.x + dx);
141 for (
int dy = (key.y > 0) ? -1 : 0; dy <= 1; ++dy)
143 neighbor_key.y =
static_cast<std::uint32_t
>(key.y + dy);
144 for (
int dz = (key.z > 0) ? -1 : 0; dz <= 1; ++dz)
146 neighbor_key.z =
static_cast<std::uint32_t
>(key.z + dz);
147 typename KeyVertexMap::iterator f = key_to_vertex_map.find(neighbor_key);
148 if (f != key_to_vertex_map.end() &&
v != f->second)
150 boost::add_edge(
v, f->second, graph);
156 graph.m_graph.m_point_cloud->header = input_->header;