38 #ifndef PCL_GRAPH_IMPL_NEAREST_NEIGHBORS_GRAPH_BUILDER_CPP
39 #define PCL_GRAPH_IMPL_NEAREST_NEIGHBORS_GRAPH_BUILDER_CPP
41 #include <pcl/common/io.h>
42 #include <pcl/common/point_tests.h>
43 #include <pcl/point_types.h>
44 #include <pcl/search/kdtree.h>
45 #include <pcl/search/organized.h>
49 template <
typename Po
intT,
typename GraphT>
61 for (
size_t i = 0; i < indices_->size(); ++i)
63 if (!pcl::isFinite(input_->operator[](indices_->operator[](i))))
65 fake_indices_ =
false;
69 indices_->operator[](k++) = indices_->operator[](i);
77 typename pcl::PointCloud<PointOutT>::Ptr cloud(
new pcl::PointCloud<PointOutT>);
78 pcl::copyPointCloud(*input_, *indices_, *cloud);
79 graph = GraphT(cloud);
85 if (cloud->isOrganized())
87 search_.reset(
new pcl::search::OrganizedNeighbor<PointOutT>);
92 search_.reset(
new pcl::search::KdTree<PointOutT>);
97 std::vector<int> neighbors(num_neighbors_ + 1);
98 std::vector<float> distances(num_neighbors_ + 1);
99 search_->setInputCloud(cloud);
100 for (
size_t i = 0; i < cloud->size(); ++i)
104 search_->nearestKSearch(i, num_neighbors_ + 1, neighbors, distances);
105 for (
size_t j = 1; j < neighbors.size(); ++j)
106 if (!boost::edge(i, neighbors[j], graph).second)
108 boost::add_edge(i, neighbors[j], graph);
115 for (
size_t i = 0; i < indices_->size(); ++i)
117 point_to_vertex_map_[indices_->operator[](i)] =
v++;