42 #ifndef PCL_FILTERS_IMPL_VOXEL_GRID_MINIMUM_H_
43 #define PCL_FILTERS_IMPL_VOXEL_GRID_MINIMUM_H_
46 #include <pcl/common/io.h>
47 #include <pcl/common/point_tests.h>
48 #include <pcl/filters/grid_minimum.h>
60 template <
typename Po
intT>
void
66 PCL_WARN (
"[pcl::%s::applyFilter] No input dataset given!\n", getClassName ().c_str ());
75 applyFilterIndices (indices);
76 pcl::copyPointCloud<PointT> (*input_, indices, output);
80 template <
typename Po
intT>
void
83 indices.resize (indices_->size ());
87 Eigen::Vector4f min_p, max_p;
88 getMinMax3D<PointT> (*input_, *indices_, min_p, max_p);
91 std::int64_t dx =
static_cast<std::int64_t
> ((max_p[0] - min_p[0]) * inverse_resolution_)+1;
92 std::int64_t dy =
static_cast<std::int64_t
> ((max_p[1] - min_p[1]) * inverse_resolution_)+1;
94 if ((dx*dy) >
static_cast<std::int64_t
> (std::numeric_limits<std::int32_t>::max ()))
96 PCL_WARN (
"[pcl::%s::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow.\n", getClassName ().c_str ());
100 Eigen::Vector4i min_b, max_b, div_b, divb_mul;
103 min_b[0] =
static_cast<int> (std::floor (min_p[0] * inverse_resolution_));
104 max_b[0] =
static_cast<int> (std::floor (max_p[0] * inverse_resolution_));
105 min_b[1] =
static_cast<int> (std::floor (min_p[1] * inverse_resolution_));
106 max_b[1] =
static_cast<int> (std::floor (max_p[1] * inverse_resolution_));
109 div_b = max_b - min_b + Eigen::Vector4i::Ones ();
113 divb_mul = Eigen::Vector4i (1, div_b[0], 0, 0);
115 std::vector<point_index_idx> index_vector;
116 index_vector.reserve (indices_->size ());
121 for (
const auto& index : (*indices_))
123 if (!input_->is_dense)
128 int ijk0 =
static_cast<int> (std::floor ((*input_)[index].x * inverse_resolution_) -
static_cast<float> (min_b[0]));
129 int ijk1 =
static_cast<int> (std::floor ((*input_)[index].y * inverse_resolution_) -
static_cast<float> (min_b[1]));
132 int idx = ijk0 * divb_mul[0] + ijk1 * divb_mul[1];
133 index_vector.emplace_back(
static_cast<unsigned int> (idx), index);
138 std::sort (index_vector.begin (), index_vector.end (), std::less<> ());
142 unsigned int total = 0;
143 unsigned int index = 0;
148 std::vector<std::pair<unsigned int, unsigned int> > first_and_last_indices_vector;
151 first_and_last_indices_vector.reserve (index_vector.size ());
152 while (index < index_vector.size ())
154 unsigned int i = index + 1;
155 while (i < index_vector.size () && index_vector[i].idx == index_vector[index].idx)
158 first_and_last_indices_vector.emplace_back(index, i);
163 indices.resize (total);
167 for (
const auto &cp : first_and_last_indices_vector)
169 unsigned int first_index = cp.first;
170 unsigned int last_index = cp.second;
171 unsigned int min_index = index_vector[first_index].cloud_point_index;
172 float min_z = (*input_)[index_vector[first_index].cloud_point_index].z;
174 for (
unsigned int i = first_index + 1; i < last_index; ++i)
176 if ((*input_)[index_vector[i].cloud_point_index].z < min_z)
178 min_z = (*input_)[index_vector[i].cloud_point_index].z;
179 min_index = index_vector[i].cloud_point_index;
183 indices[index] = min_index;
188 oii = indices.size ();
191 indices.resize (oii);
194 #define PCL_INSTANTIATE_GridMinimum(T) template class PCL_EXPORTS pcl::GridMinimum<T>;
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a 2D grid approach.
PointCloud represents the base class in PCL for storing collections of 3D points.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
void clear()
Removes all points in a cloud and sets the width and height to 0.
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
point_index_idx(unsigned int idx_, unsigned int cloud_point_index_)
bool operator<(const point_index_idx &p) const
unsigned int cloud_point_index