00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PCL_SEARCH_SEARCH_IMPL_HPP_
00039 #define PCL_SEARCH_SEARCH_IMPL_HPP_
00040
00041 #include <pcl/search/search.h>
00042
00044 template <typename PointT>
00045 pcl::search::Search<PointT>::Search (const std::string& name, bool sorted)
00046 : input_ ()
00047 , indices_ ()
00048 , sorted_results_ (sorted)
00049 , name_ (name)
00050 {
00051 }
00052
00054 template <typename PointT> const std::string&
00055 pcl::search::Search<PointT>::getName () const
00056 {
00057 return (name_);
00058 }
00059
00061 template <typename PointT> void
00062 pcl::search::Search<PointT>::setSortedResults (bool sorted)
00063 {
00064 sorted_results_ = sorted;
00065 }
00066
00068 template <typename PointT> bool
00069 pcl::search::Search<PointT>::getSortedResults ()
00070 {
00071 return (sorted_results_);
00072 }
00073
00075 template <typename PointT> void
00076 pcl::search::Search<PointT>::setInputCloud (
00077 const PointCloudConstPtr& cloud, const IndicesConstPtr &indices)
00078 {
00079 input_ = cloud;
00080 indices_ = indices;
00081 }
00082
00083
00085 template <typename PointT> int
00086 pcl::search::Search<PointT>::nearestKSearch (
00087 const PointCloud &cloud, int index, int k,
00088 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const
00089 {
00090 assert (index >= 0 && index < static_cast<int> (cloud.points.size ()) && "Out-of-bounds error in nearestKSearch!");
00091 return (nearestKSearch (cloud.points[index], k, k_indices, k_sqr_distances));
00092 }
00093
00095 template <typename PointT> int
00096 pcl::search::Search<PointT>::nearestKSearch (
00097 int index, int k,
00098 std::vector<int> &k_indices,
00099 std::vector<float> &k_sqr_distances) const
00100 {
00101 if (indices_ == NULL)
00102 {
00103 assert (index >= 0 && index < static_cast<int> (input_->points.size ()) && "Out-of-bounds error in nearestKSearch!");
00104 return (nearestKSearch (input_->points[index], k, k_indices, k_sqr_distances));
00105 }
00106 else
00107 {
00108 assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in nearestKSearch!");
00109 if (index >= static_cast<int> (indices_->size ()) || index < 0)
00110 return (0);
00111 return (nearestKSearch (input_->points[(*indices_)[index]], k, k_indices, k_sqr_distances));
00112 }
00113 }
00114
00116 template <typename PointT> void
00117 pcl::search::Search<PointT>::nearestKSearch (
00118 const PointCloud& cloud, const std::vector<int>& indices,
00119 int k, std::vector< std::vector<int> >& k_indices,
00120 std::vector< std::vector<float> >& k_sqr_distances) const
00121 {
00122 if (indices.empty ())
00123 {
00124 k_indices.resize (cloud.size ());
00125 k_sqr_distances.resize (cloud.size ());
00126 for (size_t i = 0; i < cloud.size (); i++)
00127 nearestKSearch (cloud, static_cast<int> (i), k, k_indices[i], k_sqr_distances[i]);
00128 }
00129 else
00130 {
00131 k_indices.resize (indices.size ());
00132 k_sqr_distances.resize (indices.size ());
00133 for (size_t i = 0; i < indices.size (); i++)
00134 nearestKSearch (cloud, indices[i], k, k_indices[i], k_sqr_distances[i]);
00135 }
00136 }
00137
00139 template <typename PointT> int
00140 pcl::search::Search<PointT>::radiusSearch (
00141 const PointCloud &cloud, int index, double radius,
00142 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
00143 unsigned int max_nn) const
00144 {
00145 assert (index >= 0 && index < static_cast<int> (cloud.points.size ()) && "Out-of-bounds error in radiusSearch!");
00146 return (radiusSearch(cloud.points[index], radius, k_indices, k_sqr_distances, max_nn));
00147 }
00148
00150 template <typename PointT> int
00151 pcl::search::Search<PointT>::radiusSearch (
00152 int index, double radius, std::vector<int> &k_indices,
00153 std::vector<float> &k_sqr_distances, unsigned int max_nn ) const
00154 {
00155 if (indices_ == NULL)
00156 {
00157 assert (index >= 0 && index < static_cast<int> (input_->points.size ()) && "Out-of-bounds error in radiusSearch!");
00158 return (radiusSearch (input_->points[index], radius, k_indices, k_sqr_distances, max_nn));
00159 }
00160 else
00161 {
00162 assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in radiusSearch!");
00163 return (radiusSearch (input_->points[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
00164 }
00165 }
00166
00168 template <typename PointT> void
00169 pcl::search::Search<PointT>::radiusSearch (
00170 const PointCloud& cloud,
00171 const std::vector<int>& indices,
00172 double radius,
00173 std::vector< std::vector<int> >& k_indices,
00174 std::vector< std::vector<float> > &k_sqr_distances,
00175 unsigned int max_nn) const
00176 {
00177 if (indices.empty ())
00178 {
00179 k_indices.resize (cloud.size ());
00180 k_sqr_distances.resize (cloud.size ());
00181 for (size_t i = 0; i < cloud.size (); i++)
00182 radiusSearch (cloud, static_cast<int> (i), radius,k_indices[i], k_sqr_distances[i], max_nn);
00183 }
00184 else
00185 {
00186 k_indices.resize (indices.size ());
00187 k_sqr_distances.resize (indices.size ());
00188 for (size_t i = 0; i < indices.size (); i++)
00189 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn);
00190 }
00191 }
00192
00194 template <typename PointT> void
00195 pcl::search::Search<PointT>::sortResults (
00196 std::vector<int>& indices, std::vector<float>& distances) const
00197 {
00198 std::vector<int> order (indices.size ());
00199 for (size_t idx = 0; idx < order.size (); ++idx)
00200 order [idx] = static_cast<int> (idx);
00201
00202 Compare compare (distances);
00203 sort (order.begin (), order.end (), compare);
00204
00205 std::vector<int> sorted (indices.size ());
00206 for (size_t idx = 0; idx < order.size (); ++idx)
00207 sorted [idx] = indices[order [idx]];
00208
00209 indices = sorted;
00210
00211
00212 sort (distances.begin (), distances.end ());
00213 }
00214
00215 #define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search<T>;
00216
00217 #endif //#ifndef _PCL_SEARCH_SEARCH_IMPL_HPP_
00218
00219