38 #ifndef PCL_SEARCH_SEARCH_IMPL_HPP_
39 #define PCL_SEARCH_SEARCH_IMPL_HPP_
41 #include <pcl/search/search.h>
44 template <
typename Po
intT>
48 , sorted_results_ (sorted)
54 template <
typename Po
intT>
const std::string&
61 template <
typename Po
intT>
void
64 sorted_results_ = sorted;
68 template <
typename Po
intT>
bool
71 return (sorted_results_);
75 template <
typename Po
intT>
void
85 template <
typename Po
intT>
int
88 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances)
const
90 assert (index >= 0 && index < static_cast<int> (cloud.
points.size ()) &&
"Out-of-bounds error in nearestKSearch!");
91 return (nearestKSearch (cloud.
points[index], k, k_indices, k_sqr_distances));
95 template <
typename Po
intT>
int
98 std::vector<int> &k_indices,
99 std::vector<float> &k_sqr_distances)
const
101 if (indices_ == NULL)
103 assert (index >= 0 && index < static_cast<int> (input_->points.size ()) &&
"Out-of-bounds error in nearestKSearch!");
104 return (nearestKSearch (input_->points[index], k, k_indices, k_sqr_distances));
108 assert (index >= 0 && index < static_cast<int> (indices_->size ()) &&
"Out-of-bounds error in nearestKSearch!");
109 if (index >= static_cast<int> (indices_->size ()) || index < 0)
111 return (nearestKSearch (input_->points[(*indices_)[index]], k, k_indices, k_sqr_distances));
116 template <
typename Po
intT>
void
118 const PointCloud& cloud,
const std::vector<int>& indices,
119 int k, std::vector< std::vector<int> >& k_indices,
120 std::vector< std::vector<float> >& k_sqr_distances)
const
122 if (indices.empty ())
124 k_indices.resize (cloud.
size ());
125 k_sqr_distances.resize (cloud.
size ());
126 for (
size_t i = 0; i < cloud.
size (); i++)
127 nearestKSearch (cloud, static_cast<int> (i), k, k_indices[i], k_sqr_distances[i]);
131 k_indices.resize (indices.size ());
132 k_sqr_distances.resize (indices.size ());
133 for (
size_t i = 0; i < indices.size (); i++)
134 nearestKSearch (cloud, indices[i], k, k_indices[i], k_sqr_distances[i]);
139 template <
typename Po
intT>
int
141 const PointCloud &cloud,
int index,
double radius,
142 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
143 unsigned int max_nn)
const
145 assert (index >= 0 && index < static_cast<int> (cloud.
points.size ()) &&
"Out-of-bounds error in radiusSearch!");
146 return (radiusSearch(cloud.
points[index], radius, k_indices, k_sqr_distances, max_nn));
150 template <
typename Po
intT>
int
152 int index,
double radius, std::vector<int> &k_indices,
153 std::vector<float> &k_sqr_distances,
unsigned int max_nn )
const
155 if (indices_ == NULL)
157 assert (index >= 0 && index < static_cast<int> (input_->points.size ()) &&
"Out-of-bounds error in radiusSearch!");
158 return (radiusSearch (input_->points[index], radius, k_indices, k_sqr_distances, max_nn));
162 assert (index >= 0 && index < static_cast<int> (indices_->size ()) &&
"Out-of-bounds error in radiusSearch!");
163 return (radiusSearch (input_->points[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
168 template <
typename Po
intT>
void
171 const std::vector<int>& indices,
173 std::vector< std::vector<int> >& k_indices,
174 std::vector< std::vector<float> > &k_sqr_distances,
175 unsigned int max_nn)
const
177 if (indices.empty ())
179 k_indices.resize (cloud.
size ());
180 k_sqr_distances.resize (cloud.
size ());
181 for (
size_t i = 0; i < cloud.
size (); i++)
182 radiusSearch (cloud, static_cast<int> (i), radius,k_indices[i], k_sqr_distances[i], max_nn);
186 k_indices.resize (indices.size ());
187 k_sqr_distances.resize (indices.size ());
188 for (
size_t i = 0; i < indices.size (); i++)
189 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn);
194 template <
typename Po
intT>
void
196 std::vector<int>& indices, std::vector<float>& distances)
const
198 std::vector<int> order (indices.size ());
199 for (
size_t idx = 0; idx < order.size (); ++idx)
200 order [idx] = static_cast<int> (idx);
202 Compare compare (distances);
203 sort (order.begin (), order.end (), compare);
205 std::vector<int> sorted (indices.size ());
206 for (
size_t idx = 0; idx < order.size (); ++idx)
207 sorted [idx] = indices[order [idx]];
212 sort (distances.begin (), distances.end ());
215 #define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search<T>;
217 #endif //#ifndef _PCL_SEARCH_SEARCH_IMPL_HPP_
Search(const std::string &name="", bool sorted=false)
Constructor.
virtual const std::string & getName() const
Returns the search method name.
boost::shared_ptr< const std::vector< int > > IndicesConstPtr
virtual int radiusSearch(const PointT &point, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const =0
Search for all the nearest neighbors of the query point in a given radius.
void sortResults(std::vector< int > &indices, std::vector< float > &distances) const
virtual void setSortedResults(bool sorted)
sets whether the results should be sorted (ascending in the distance) or not
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
virtual int nearestKSearch(const PointT &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const =0
Search for the k-nearest neighbors for the given query point.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
PointCloud::ConstPtr PointCloudConstPtr
virtual void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Pass the input dataset that the search will be performed on.