Go to the documentation of this file.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_KEYPOINTS_UNIFORM_SAMPLING_IMPL_H_
00039 #define PCL_KEYPOINTS_UNIFORM_SAMPLING_IMPL_H_
00040
00041 #include <pcl/common/common.h>
00042 #include <pcl/keypoints/uniform_sampling.h>
00043
00045 template <typename PointInT> void
00046 pcl::UniformSampling<PointInT>::detectKeypoints (PointCloudOut &output)
00047 {
00048
00049 if (!input_)
00050 {
00051 PCL_WARN ("[pcl::%s::detectKeypoints] No input dataset given!\n", getClassName ().c_str ());
00052 output.width = output.height = 0;
00053 output.points.clear ();
00054 return;
00055 }
00056
00057 output.height = 1;
00058 output.is_dense = true;
00059
00060 Eigen::Vector4f min_p, max_p;
00061
00062 pcl::getMinMax3D<PointInT>(*input_, min_p, max_p);
00063
00064
00065 min_b_[0] = static_cast<int> (floor (min_p[0] * inverse_leaf_size_[0]));
00066 max_b_[0] = static_cast<int> (floor (max_p[0] * inverse_leaf_size_[0]));
00067 min_b_[1] = static_cast<int> (floor (min_p[1] * inverse_leaf_size_[1]));
00068 max_b_[1] = static_cast<int> (floor (max_p[1] * inverse_leaf_size_[1]));
00069 min_b_[2] = static_cast<int> (floor (min_p[2] * inverse_leaf_size_[2]));
00070 max_b_[2] = static_cast<int> (floor (max_p[2] * inverse_leaf_size_[2]));
00071
00072
00073 div_b_ = max_b_ - min_b_ + Eigen::Vector4i::Ones ();
00074 div_b_[3] = 0;
00075
00076
00077 leaves_.clear ();
00078
00079
00080 divb_mul_ = Eigen::Vector4i (1, div_b_[0], div_b_[0] * div_b_[1], 0);
00081
00082
00083 for (size_t cp = 0; cp < indices_->size (); ++cp)
00084 {
00085 if (!input_->is_dense)
00086
00087 if (!pcl_isfinite (input_->points[(*indices_)[cp]].x) ||
00088 !pcl_isfinite (input_->points[(*indices_)[cp]].y) ||
00089 !pcl_isfinite (input_->points[(*indices_)[cp]].z))
00090 continue;
00091
00092 Eigen::Vector4i ijk = Eigen::Vector4i::Zero ();
00093 ijk[0] = static_cast<int> (floor (input_->points[(*indices_)[cp]].x * inverse_leaf_size_[0]));
00094 ijk[1] = static_cast<int> (floor (input_->points[(*indices_)[cp]].y * inverse_leaf_size_[1]));
00095 ijk[2] = static_cast<int> (floor (input_->points[(*indices_)[cp]].z * inverse_leaf_size_[2]));
00096
00097
00098 int idx = (ijk - min_b_).dot (divb_mul_);
00099 Leaf& leaf = leaves_[idx];
00100
00101 if (leaf.idx == -1)
00102 {
00103 leaf.idx = (*indices_)[cp];
00104 continue;
00105 }
00106
00107
00108 float diff_cur = (input_->points[(*indices_)[cp]].getVector4fMap () - ijk.cast<float> ()).squaredNorm ();
00109 float diff_prev = (input_->points[leaf.idx].getVector4fMap () - ijk.cast<float> ()).squaredNorm ();
00110
00111
00112 if (diff_cur < diff_prev)
00113 leaf.idx = (*indices_)[cp];
00114 }
00115
00116
00117 output.points.resize (leaves_.size ());
00118 int cp = 0;
00119
00120 for (typename boost::unordered_map<size_t, Leaf>::const_iterator it = leaves_.begin (); it != leaves_.end (); ++it)
00121 output.points[cp++] = it->second.idx;
00122 output.width = static_cast<uint32_t> (output.points.size ());
00123 }
00124
00125 #define PCL_INSTANTIATE_UniformSampling(T) template class PCL_EXPORTS pcl::UniformSampling<T>;
00126
00127 #endif // PCL_KEYPOINTS_UNIFORM_SAMPLING_IMPL_H_
00128