Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApproximateProgressiveMorphologicalFilter: check for finite-ness #5756

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <pcl/common/common.h>
#include <pcl/common/io.h>
#include <pcl/common/point_tests.h> // for isFinite
#include <pcl/filters/morphological_filter.h>
#include <pcl/segmentation/approximate_progressive_morphological_filter.h>
#include <pcl/point_cloud.h>
Expand Down Expand Up @@ -122,26 +123,51 @@ pcl::ApproximateProgressiveMorphologicalFilter<PointT>::extract (Indices& ground
Eigen::MatrixXf Zf (rows, cols);
Zf.setConstant (std::numeric_limits<float>::quiet_NaN ());

if (input_->is_dense) {
#pragma omp parallel for \
default(none) \
shared(A, global_min) \
num_threads(threads_)
for (int i = 0; i < static_cast<int>(input_->size ()); ++i)
{
// ...then test for lower points within the cell
PointT p = (*input_)[i];
int row = std::floor((p.y - global_min.y ()) / cell_size_);
int col = std::floor((p.x - global_min.x ()) / cell_size_);

if (p.z < A (row, col) || std::isnan (A (row, col)))
{
A (row, col) = p.z;
for (int i = 0; i < static_cast<int>(input_->size ()); ++i) {
// ...then test for lower points within the cell
const PointT& p = (*input_)[i];
int row = std::floor((p.y - global_min.y ()) / cell_size_);
int col = std::floor((p.x - global_min.x ()) / cell_size_);

if (p.z < A (row, col) || std::isnan (A (row, col)))
A (row, col) = p.z;
}
}
else {
#pragma omp parallel for \
default(none) \
shared(A, global_min) \
num_threads(threads_)
for (int i = 0; i < static_cast<int>(input_->size ()); ++i) {
// ...then test for lower points within the cell
const PointT& p = (*input_)[i];
if (!pcl::isFinite(p))
continue;
int row = std::floor((p.y - global_min.y ()) / cell_size_);
int col = std::floor((p.x - global_min.x ()) / cell_size_);

if (p.z < A (row, col) || std::isnan (A (row, col)))
A (row, col) = p.z;
}
}

// Ground indices are initially limited to those points in the input cloud we
// wish to process
ground = *indices_;
if (input_->is_dense) {
ground = *indices_;
}
else {
ground.clear();
ground.reserve(indices_->size());
for (const auto& index: *indices_)
if (pcl::isFinite((*input_)[index]))
ground.push_back(index);
}

// Progressively filter ground returns using morphological open
for (std::size_t i = 0; i < window_sizes.size (); ++i)
Expand Down Expand Up @@ -229,7 +255,7 @@ pcl::ApproximateProgressiveMorphologicalFilter<PointT>::extract (Indices& ground
Indices pt_indices;
for (std::size_t p_idx = 0; p_idx < ground.size (); ++p_idx)
{
PointT p = (*cloud)[p_idx];
const PointT& p = (*cloud)[p_idx];
int erow = static_cast<int> (std::floor ((p.y - global_min.y ()) / cell_size_));
int ecol = static_cast<int> (std::floor ((p.x - global_min.x ()) / cell_size_));

Expand Down