38 #ifndef PCL_FILTERS_UNIFORM_SAMPLING_IMPL_H_
39 #define PCL_FILTERS_UNIFORM_SAMPLING_IMPL_H_
42 #include <pcl/filters/uniform_sampling.h>
43 #include <pcl/common/point_tests.h>
46 template <
typename Po
intT>
void
50 indices.resize (indices_->size ());
51 removed_indices_->resize (indices_->size ());
55 Eigen::Vector4f min_p, max_p;
57 pcl::getMinMax3D<PointT>(*input_, min_p, max_p);
60 min_b_[0] =
static_cast<int> (std::floor (min_p[0] * inverse_leaf_size_[0]));
61 max_b_[0] =
static_cast<int> (std::floor (max_p[0] * inverse_leaf_size_[0]));
62 min_b_[1] =
static_cast<int> (std::floor (min_p[1] * inverse_leaf_size_[1]));
63 max_b_[1] =
static_cast<int> (std::floor (max_p[1] * inverse_leaf_size_[1]));
64 min_b_[2] =
static_cast<int> (std::floor (min_p[2] * inverse_leaf_size_[2]));
65 max_b_[2] =
static_cast<int> (std::floor (max_p[2] * inverse_leaf_size_[2]));
68 div_b_ = max_b_ - min_b_ + Eigen::Vector4i::Ones ();
75 divb_mul_ = Eigen::Vector4i (1, div_b_[0], div_b_[0] * div_b_[1], 0);
78 for (
const auto& cp : *indices_)
80 if (!input_->is_dense)
85 if (extract_removed_indices_)
86 (*removed_indices_)[rii++] = cp;
91 Eigen::Vector4i ijk = Eigen::Vector4i::Zero ();
92 ijk[0] =
static_cast<int> (std::floor ((*input_)[cp].x * inverse_leaf_size_[0]));
93 ijk[1] =
static_cast<int> (std::floor ((*input_)[cp].y * inverse_leaf_size_[1]));
94 ijk[2] =
static_cast<int> (std::floor ((*input_)[cp].z * inverse_leaf_size_[2]));
97 int idx = (ijk - min_b_).dot (divb_mul_);
98 Leaf& leaf = leaves_[idx];
111 Eigen::Vector4f voxel_center = (ijk.cast<
float>() + Eigen::Vector4f::Constant(0.5)) * search_radius_;
114 float diff_cur = ((*input_)[cp].getVector4fMap () - voxel_center).squaredNorm ();
115 float diff_prev = ((*input_)[leaf.
idx].getVector4fMap () - voxel_center).squaredNorm ();
118 if (diff_cur < diff_prev)
120 if (extract_removed_indices_)
121 (*removed_indices_)[rii++] = leaf.
idx;
126 if (extract_removed_indices_)
127 (*removed_indices_)[rii++] = cp;
130 removed_indices_->resize(rii);
133 indices.resize (leaves_.size ());
134 for (
const auto& leaf : leaves_)
136 if (leaf.second.count >= min_points_per_voxel_)
137 indices[oii++] = leaf.second.idx;
140 indices.resize (oii);
142 indices.swap(*removed_indices_);
146 #define PCL_INSTANTIATE_UniformSampling(T) template class PCL_EXPORTS pcl::UniformSampling<T>;
Define standard C methods and C++ classes that are common to all methods.
IndicesAllocator<> Indices
Type used for indices in PCL.
constexpr bool isXYZFinite(const PointT &) noexcept