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 for (std::size_t i = 0; i < cloud.
size (); i++)
124 nearestKSearch (cloud, static_cast<index_t> (i), k, k_indices[i], k_sqr_distances[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]);
136 template <
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));
147 template <
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!");
155 return (radiusSearch ((*input_)[index], radius, k_indices, k_sqr_distances, max_nn));
157 assert (index >= 0 && index < static_cast<index_t> (indices_->size ()) &&
"Out-of-bounds error in radiusSearch!");
158 return (radiusSearch ((*input_)[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
162 template <
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);
188 template <
typename Po
intT>
void
190 Indices& indices, std::vector<float>& distances)
const
192 Indices order (indices.size ());
193 for (std::size_t idx = 0; idx < order.size (); ++idx)
194 order [idx] = static_cast<index_t> (idx);
196 Compare compare (distances);
197 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]];
206 sort (distances.begin (), distances.end ());
209 #define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search<T>;
211 #endif //#ifndef _PCL_SEARCH_SEARCH_IMPL_HPP_
virtual const std::string & getName() const
Returns the search method name.
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
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.
void sortResults(Indices &indices, std::vector< float > &distances) const
pcl::IndicesConstPtr IndicesConstPtr
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
virtual void setSortedResults(bool sorted)
sets whether the results should be sorted (ascending in the distance) or not
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.
IndicesAllocator<> Indices
Type used for indices in PCL.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
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.
typename PointCloud::ConstPtr PointCloudConstPtr