38#ifndef PCL_SEARCH_SEARCH_IMPL_HPP_
39#define PCL_SEARCH_SEARCH_IMPL_HPP_
41#include <pcl/search/search.h>
44template <
typename Po
intT>
47 , sorted_results_ (sorted)
53template <
typename Po
intT>
const std::string&
60template <
typename Po
intT>
void
63 sorted_results_ = sorted;
67template <
typename Po
intT>
bool
70 return (sorted_results_);
74template <
typename Po
intT>
void
84template <
typename Po
intT>
int
87 Indices &k_indices, std::vector<float> &k_sqr_distances)
const
89 assert (index >= 0 && index <
static_cast<index_t> (cloud.
size ()) &&
"Out-of-bounds error in nearestKSearch!");
90 return (nearestKSearch (cloud[index], k, k_indices, k_sqr_distances));
94template <
typename Po
intT>
int
98 std::vector<float> &k_sqr_distances)
const
102 assert (index >= 0 && index <
static_cast<index_t> (input_->size ()) &&
"Out-of-bounds error in nearestKSearch!");
103 return (nearestKSearch ((*input_)[index], k, k_indices, k_sqr_distances));
105 assert (index >= 0 && index <
static_cast<index_t> (indices_->size ()) &&
"Out-of-bounds error in nearestKSearch!");
106 if (index >=
static_cast<index_t> (indices_->size ()) || index < 0)
108 return (nearestKSearch ((*input_)[(*indices_)[index]], k, k_indices, k_sqr_distances));
112template <
typename Po
intT>
void
115 int k, std::vector<Indices>& k_indices,
116 std::vector< std::vector<float> >& k_sqr_distances)
const
118 if (indices.empty ())
120 k_indices.resize (cloud.
size ());
121 k_sqr_distances.resize (cloud.
size ());
122 for (std::size_t i = 0; i < cloud.
size (); i++)
123 nearestKSearch (cloud,
static_cast<index_t> (i), k, k_indices[i], k_sqr_distances[i]);
127 k_indices.resize (indices.size ());
128 k_sqr_distances.resize (indices.size ());
129 for (std::size_t i = 0; i < indices.size (); i++)
130 nearestKSearch (cloud, indices[i], k, k_indices[i], k_sqr_distances[i]);
135template <
typename Po
intT>
int
138 Indices &k_indices, std::vector<float> &k_sqr_distances,
139 unsigned int max_nn)
const
141 assert (index >= 0 && index <
static_cast<index_t> (cloud.
size ()) &&
"Out-of-bounds error in radiusSearch!");
142 return (radiusSearch(cloud[index], radius, k_indices, k_sqr_distances, max_nn));
146template <
typename Po
intT>
int
149 std::vector<float> &k_sqr_distances,
unsigned int max_nn )
const
153 assert (index >= 0 && index <
static_cast<index_t> (input_->size ()) &&
"Out-of-bounds error in radiusSearch!");
154 return (radiusSearch ((*input_)[index], radius, k_indices, k_sqr_distances, max_nn));
156 assert (index >= 0 && index <
static_cast<index_t> (indices_->size ()) &&
"Out-of-bounds error in radiusSearch!");
157 return (radiusSearch ((*input_)[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
161template <
typename Po
intT>
void
166 std::vector<Indices>& k_indices,
167 std::vector< std::vector<float> > &k_sqr_distances,
168 unsigned int max_nn)
const
170 if (indices.empty ())
172 k_indices.resize (cloud.
size ());
173 k_sqr_distances.resize (cloud.
size ());
174 for (std::size_t i = 0; i < cloud.
size (); i++)
175 radiusSearch (cloud,
static_cast<index_t> (i), radius,k_indices[i], k_sqr_distances[i], max_nn);
179 k_indices.resize (indices.size ());
180 k_sqr_distances.resize (indices.size ());
181 for (std::size_t i = 0; i < indices.size (); i++)
182 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn);
187template <
typename Po
intT>
void
189 Indices& indices, std::vector<float>& distances)
const
191 Indices order (indices.size ());
192 for (std::size_t idx = 0; idx < order.size (); ++idx)
193 order [idx] =
static_cast<index_t> (idx);
195 Compare compare (distances);
196 sort (order.begin (), order.end (), compare);
198 Indices sorted (indices.size ());
199 for (std::size_t idx = 0; idx < order.size (); ++idx)
200 sorted [idx] = indices[order [idx]];
205 sort (distances.begin (), distances.end ());
208#define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search<T>;
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
virtual void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Pass the input dataset that the search will be performed on.
void sortResults(Indices &indices, std::vector< float > &distances) const
virtual const std::string & getName() const
Returns the search method name.
typename PointCloud::ConstPtr PointCloudConstPtr
Search(const std::string &name="", bool sorted=false)
Constructor.
pcl::IndicesConstPtr IndicesConstPtr
virtual int nearestKSearch(const PointT &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const =0
Search for the k-nearest neighbors for the given query point.
virtual void setSortedResults(bool sorted)
sets whether the results should be sorted (ascending in the distance) or not
virtual int radiusSearch(const PointT &point, double radius, Indices &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.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
IndicesAllocator<> Indices
Type used for indices in PCL.