38#ifndef PCL_SEARCH_SEARCH_IMPL_HPP_
39#define PCL_SEARCH_SEARCH_IMPL_HPP_
41#include <pcl/search/search.h>
44template <
typename Po
intT>
53template <
typename Po
intT>
const std::string&
60template <
typename Po
intT>
void
67template <
typename Po
intT>
bool
74template <
typename Po
intT>
bool
85template <
typename Po
intT>
int
88 Indices &k_indices, std::vector<float> &k_sqr_distances)
const
90 assert (index >= 0 && index <
static_cast<index_t> (cloud.
size ()) &&
"Out-of-bounds error in nearestKSearch!");
91 return (
nearestKSearch (cloud[index], k, k_indices, k_sqr_distances));
95template <
typename Po
intT>
int
99 std::vector<float> &k_sqr_distances)
const
103 assert (index >= 0 && index <
static_cast<index_t> (
input_->size ()) &&
"Out-of-bounds error in nearestKSearch!");
106 assert (index >= 0 && index <
static_cast<index_t> (indices_->size ()) &&
"Out-of-bounds error in nearestKSearch!");
107 if (index >=
static_cast<index_t> (indices_->size ()) || index < 0)
109 return (nearestKSearch ((*input_)[(*indices_)[index]], k, k_indices, k_sqr_distances));
113template <
typename Po
intT>
void
116 int k, std::vector<Indices>& k_indices,
117 std::vector< std::vector<float> >& k_sqr_distances)
const
119 if (indices.empty ())
121 k_indices.resize (cloud.
size ());
122 k_sqr_distances.resize (cloud.
size ());
123 for (std::size_t i = 0; i < cloud.
size (); i++)
128 k_indices.resize (indices.size ());
129 k_sqr_distances.resize (indices.size ());
130 for (std::size_t i = 0; i < indices.size (); i++)
131 nearestKSearch (cloud, indices[i], k, k_indices[i], k_sqr_distances[i]);
136template <
typename Po
intT>
int
139 Indices &k_indices, std::vector<float> &k_sqr_distances,
140 unsigned int max_nn)
const
142 assert (index >= 0 && index <
static_cast<index_t> (cloud.
size ()) &&
"Out-of-bounds error in radiusSearch!");
143 return (
radiusSearch(cloud[index], radius, k_indices, k_sqr_distances, max_nn));
147template <
typename Po
intT>
int
150 std::vector<float> &k_sqr_distances,
unsigned int max_nn )
const
154 assert (index >= 0 && index <
static_cast<index_t> (
input_->size ()) &&
"Out-of-bounds error in radiusSearch!");
157 assert (index >= 0 && index <
static_cast<index_t> (
indices_->size ()) &&
"Out-of-bounds error in radiusSearch!");
162template <
typename Po
intT>
void
167 std::vector<Indices>& k_indices,
168 std::vector< std::vector<float> > &k_sqr_distances,
169 unsigned int max_nn)
const
171 if (indices.empty ())
173 k_indices.resize (cloud.
size ());
174 k_sqr_distances.resize (cloud.
size ());
175 for (std::size_t i = 0; i < cloud.
size (); i++)
176 radiusSearch (cloud,
static_cast<index_t> (i), radius,k_indices[i], k_sqr_distances[i], max_nn);
180 k_indices.resize (indices.size ());
181 k_sqr_distances.resize (indices.size ());
182 for (std::size_t i = 0; i < indices.size (); i++)
183 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn);
188template <
typename Po
intT>
void
192 Indices order (indices.size ());
193 for (std::size_t idx = 0; idx < order.size (); ++idx)
194 order [idx] =
static_cast<index_t> (idx);
197 std::sort (order.begin (), order.end (), compare);
199 Indices sorted (indices.size ());
200 for (std::size_t idx = 0; idx < order.size (); ++idx)
201 sorted [idx] = indices[order [idx]];
209#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...
PointCloudConstPtr input_
void sortResults(Indices &indices, std::vector< float > &distances) const
virtual const std::string & getName() const
Returns the search method name.
typename PointCloud::ConstPtr PointCloudConstPtr
virtual bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Pass the input dataset that the search will be performed on.
Search(const std::string &name="", bool sorted=false)
Constructor.
pcl::IndicesConstPtr IndicesConstPtr
pcl::PointCloud< PointT > PointCloud
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.