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>
47 , sorted_results_ (sorted)
53 template <
typename Po
intT>
const std::string&
60 template <
typename Po
intT>
void
63 sorted_results_ = sorted;
67 template <
typename Po
intT>
bool
70 return (sorted_results_);
74 template <
typename Po
intT>
bool
85 template <
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));
95 template <
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!");
104 return (nearestKSearch ((*input_)[index], k, k_indices, k_sqr_distances));
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));
113 template <
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 #pragma omp parallel for num_threads(num_threads_) default(none) shared(cloud, k, k_indices, k_sqr_distances)
124 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(cloud.
size ()); i++)
125 nearestKSearch (cloud,
static_cast<index_t> (i), k, k_indices[i], k_sqr_distances[i]);
129 k_indices.resize (indices.size ());
130 k_sqr_distances.resize (indices.size ());
131 #pragma omp parallel for num_threads(num_threads_) default(none) shared(cloud, indices, k, k_indices, k_sqr_distances)
132 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(indices.size ()); i++)
133 nearestKSearch (cloud, indices[i], k, k_indices[i], k_sqr_distances[i]);
138 template <
typename Po
intT>
int
141 Indices &k_indices, std::vector<float> &k_sqr_distances,
142 unsigned int max_nn)
const
144 assert (index >= 0 && index <
static_cast<index_t> (cloud.
size ()) &&
"Out-of-bounds error in radiusSearch!");
145 return (radiusSearch(cloud[index], radius, k_indices, k_sqr_distances, max_nn));
149 template <
typename Po
intT>
int
152 std::vector<float> &k_sqr_distances,
unsigned int max_nn )
const
156 assert (index >= 0 && index <
static_cast<index_t> (input_->size ()) &&
"Out-of-bounds error in radiusSearch!");
157 return (radiusSearch ((*input_)[index], radius, k_indices, k_sqr_distances, max_nn));
159 assert (index >= 0 && index <
static_cast<index_t> (indices_->size ()) &&
"Out-of-bounds error in radiusSearch!");
160 return (radiusSearch ((*input_)[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
164 template <
typename Po
intT>
void
169 std::vector<Indices>& k_indices,
170 std::vector< std::vector<float> > &k_sqr_distances,
171 unsigned int max_nn)
const
173 if (indices.empty ())
175 k_indices.resize (cloud.
size ());
176 k_sqr_distances.resize (cloud.
size ());
177 #pragma omp parallel for num_threads(num_threads_) default(none) shared(cloud, radius, k_indices, k_sqr_distances, max_nn)
178 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(cloud.
size ()); i++)
179 radiusSearch (cloud,
static_cast<index_t> (i), radius,k_indices[i], k_sqr_distances[i], max_nn);
183 k_indices.resize (indices.size ());
184 k_sqr_distances.resize (indices.size ());
185 #pragma omp parallel for num_threads(num_threads_) default(none) shared(cloud, indices, radius, k_indices, k_sqr_distances, max_nn)
186 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(indices.size ()); i++)
187 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn);
192 template <
typename Po
intT>
void
194 Indices& indices, std::vector<float>& distances)
const
196 Indices order (indices.size ());
197 for (std::size_t idx = 0; idx < order.size (); ++idx)
198 order [idx] =
static_cast<index_t> (idx);
200 Compare compare (distances);
201 std::sort (order.begin (), order.end (), compare);
203 Indices sorted (indices.size ());
204 for (std::size_t idx = 0; idx < order.size (); ++idx)
205 sorted [idx] = indices[order [idx]];
210 std::sort (distances.begin (), distances.end ());
213 #define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search<T>;
PointCloud represents the base class in PCL for storing collections of 3D points.
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
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
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.