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

Transform classic loops to range-based for loops in module features #2853

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/3dsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ pcl::ShapeContext3DEstimation<PointInT, PointNT, PointOutT>::computePoint (
const size_t neighb_cnt = searchForNeighbors ((*indices_)[index], search_radius_, nn_indices, nn_dists);
if (neighb_cnt == 0)
{
for (size_t i = 0; i < desc.size (); ++i)
desc[i] = std::numeric_limits<float>::quiet_NaN ();
for (float &descriptor : desc)
descriptor = std::numeric_limits<float>::quiet_NaN ();

memset (rf, 0, sizeof (rf[0]) * 9);
return (false);
Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ pcl::BOARDLocalReferenceFrameEstimation<PointInT, PointNT, PointOutT>::normalDis
Eigen::Vector3f normal_mean;
normal_mean.setZero ();

for (size_t i = 0; i < normal_indices.size (); ++i)
for (const int &normal_index : normal_indices)
{
const PointNT& curPt = normal_cloud[normal_indices[i]];
const PointNT& curPt = normal_cloud[normal_index];

normal_mean += curPt.getNormalVector3fMap ();
}
Expand Down
10 changes: 5 additions & 5 deletions features/include/pcl/features/impl/boundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ pcl::BoundaryEstimation<PointInT, PointNT, PointOutT>::isBoundaryPoint (
float max_dif = FLT_MIN, dif;
int cp = 0;

for (size_t i = 0; i < indices.size (); ++i)
for (const int &index : indices)
{
if (!std::isfinite (cloud.points[indices[i]].x) ||
!std::isfinite (cloud.points[indices[i]].y) ||
!std::isfinite (cloud.points[indices[i]].z))
if (!std::isfinite (cloud.points[index].x) ||
!std::isfinite (cloud.points[index].y) ||
!std::isfinite (cloud.points[index].z))
continue;

Eigen::Vector4f delta = cloud.points[indices[i]].getVector4fMap () - q_point.getVector4fMap ();
Eigen::Vector4f delta = cloud.points[index].getVector4fMap () - q_point.getVector4fMap ();
if (delta == Eigen::Vector4f::Zero())
continue;

Expand Down
6 changes: 3 additions & 3 deletions features/include/pcl/features/impl/crh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ pcl::CRHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut

float sum_w = 0, w = 0;
int bin = 0;
for (size_t i = 0; i < grid.points.size (); ++i)
for (const auto &point : grid.points)
{
bin = static_cast<int> ((((atan2 (grid.points[i].normal_y, grid.points[i].normal_x) + M_PI) * 180 / M_PI) / bin_angle)) % nbins;
w = std::sqrt (grid.points[i].normal_y * grid.points[i].normal_y + grid.points[i].normal_x * grid.points[i].normal_x);
bin = static_cast<int> ((((atan2 (point.normal_y, point.normal_x) + M_PI) * 180 / M_PI) / bin_angle)) % nbins;
w = std::sqrt (point.normal_y * point.normal_y + point.normal_x * point.normal_x);
sum_w += w;
spatial_data[bin] += w;
}
Expand Down
20 changes: 10 additions & 10 deletions features/include/pcl/features/impl/cvfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ pcl::CVFHEstimation<PointInT, PointNT, PointOutT>::filterNormalsWithHighCurvatur
size_t in, out;
in = out = 0;

for (int i = 0; i < static_cast<int> (indices_to_use.size ()); i++)
for (const int &index : indices_to_use)
{
if (cloud.points[indices_to_use[i]].curvature > threshold)
if (cloud.points[index].curvature > threshold)
{
indices_out[out] = indices_to_use[i];
indices_out[out] = index;
out++;
}
else
{
indices_in[in] = indices_to_use[i];
indices_in[in] = index;
in++;
}
}
Expand Down Expand Up @@ -273,19 +273,19 @@ pcl::CVFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut
if (clusters.size () > 0)
{ // ---[ Step 1b.1 : If yes, compute CVFH using the cluster information

for (size_t i = 0; i < clusters.size (); ++i) //for each cluster
for (const auto &cluster : clusters) //for each cluster
{
Eigen::Vector4f avg_normal = Eigen::Vector4f::Zero ();
Eigen::Vector4f avg_centroid = Eigen::Vector4f::Zero ();

for (size_t j = 0; j < clusters[i].indices.size (); j++)
for (const auto &index : cluster.indices)
{
avg_normal += normals_filtered_cloud->points[clusters[i].indices[j]].getNormalVector4fMap ();
avg_centroid += normals_filtered_cloud->points[clusters[i].indices[j]].getVector4fMap ();
avg_normal += normals_filtered_cloud->points[index].getNormalVector4fMap ();
avg_centroid += normals_filtered_cloud->points[index].getVector4fMap ();
}

avg_normal /= static_cast<float> (clusters[i].indices.size ());
avg_centroid /= static_cast<float> (clusters[i].indices.size ());
avg_normal /= static_cast<float> (cluster.indices.size ());
avg_centroid /= static_cast<float> (cluster.indices.size ());

Eigen::Vector4f centroid_test;
pcl::compute3DCentroid (*normals_filtered_cloud, centroid_test);
Expand Down
52 changes: 26 additions & 26 deletions features/include/pcl/features/impl/esf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,35 +270,35 @@ pcl::ESFEstimation<PointInT, PointOutT>::computeESF (
float weights[10] = {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f};

hist.reserve (binsize * 10);
for (int i = 0; i < binsize; i++)
hist.push_back (h_a3_in[i] * weights[0]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_a3_out[i] * weights[1]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_a3_mix[i] * weights[2]);

for (int i = 0; i < binsize; i++)
hist.push_back (h_d3_in[i] * weights[3]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_d3_out[i] * weights[4]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_d3_mix[i] * weights[5]);

for (int i = 0; i < binsize; i++)
hist.push_back (h_in[i]*0.5f * weights[6]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_out[i] * weights[7]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_mix[i] * weights[8]);
for (int i = 0; i < binsize; i++)
hist.push_back (h_mix_ratio[i]*0.5f * weights[9]);
for (const float &i : h_a3_in)
hist.push_back (i * weights[0]);
for (const float &i : h_a3_out)
hist.push_back (i * weights[1]);
for (const float &i : h_a3_mix)
hist.push_back (i * weights[2]);

for (const float &i : h_d3_in)
hist.push_back (i * weights[3]);
for (const float &i : h_d3_out)
hist.push_back (i * weights[4]);
for (const float &i : h_d3_mix)
hist.push_back (i * weights[5]);

for (const float &i : h_in)
hist.push_back (i*0.5f * weights[6]);
for (const float &i : h_out)
hist.push_back (i * weights[7]);
for (const float &i : h_mix)
hist.push_back (i * weights[8]);
for (const float &i : h_mix_ratio)
hist.push_back (i*0.5f * weights[9]);

float sm = 0;
for (size_t i = 0; i < hist.size (); i++)
sm += hist[i];
for (const float &i : hist)
sm += i;

for (size_t i = 0; i < hist.size (); i++)
hist[i] /= sm;
for (float &i : hist)
i /= sm;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 7 additions & 7 deletions features/include/pcl/features/impl/fpfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computePointSPFHSignature (
float hist_incr = 100.0f / static_cast<float>(indices.size () - 1);

// Iterate over all the points in the neighborhood
for (size_t idx = 0; idx < indices.size (); ++idx)
for (const int &index : indices)
{
// Avoid unnecessary returns
if (p_idx == indices[idx])
if (p_idx == index)
continue;

// Compute the pair P to NNi
if (!computePairFeatures (cloud, normals, p_idx, indices[idx], pfh_tuple[0], pfh_tuple[1], pfh_tuple[2], pfh_tuple[3]))
if (!computePairFeatures (cloud, normals, p_idx, index, pfh_tuple[0], pfh_tuple[1], pfh_tuple[2], pfh_tuple[3]))
continue;

// Normalize the f1, f2, f3 features and push them in the histogram
Expand Down Expand Up @@ -259,8 +259,8 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut

// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices
// instead of indices into surface_->points
for (size_t i = 0; i < nn_indices.size (); ++i)
nn_indices[i] = spfh_hist_lookup[nn_indices[i]];
for (int &nn_index : nn_indices)
nn_index = spfh_hist_lookup[nn_index];

// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ...
weightPointSPFHSignature (hist_f1_, hist_f2_, hist_f3_, nn_indices, nn_dists, fpfh_histogram_);
Expand All @@ -287,8 +287,8 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut

// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices
// instead of indices into surface_->points
for (size_t i = 0; i < nn_indices.size (); ++i)
nn_indices[i] = spfh_hist_lookup[nn_indices[i]];
for (int &nn_index : nn_indices)
nn_index = spfh_hist_lookup[nn_index];

// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ...
weightPointSPFHSignature (hist_f1_, hist_f2_, hist_f3_, nn_indices, nn_dists, fpfh_histogram_);
Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/fpfh_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::computeFeature (PointCloud

// ... and remap the nn_indices values so that they represent row indices in the spfh_hist_* matrices
// instead of indices into surface_->points
for (size_t i = 0; i < nn_indices.size (); ++i)
nn_indices[i] = spfh_hist_lookup[nn_indices[i]];
for (int &nn_index : nn_indices)
nn_index = spfh_hist_lookup[nn_index];

// Compute the FPFH signature (i.e. compute a weighted combination of local SPFH signatures) ...
Eigen::VectorXf fpfh_histogram = Eigen::VectorXf::Zero (nr_bins);
Expand Down
22 changes: 11 additions & 11 deletions features/include/pcl/features/impl/gfpfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ pcl::GFPFHEstimation<PointInT, PointNT, PointOutT>::computeTransitionHistograms
transition_histograms[i].resize ((getNumberOfClasses () + 2) * (getNumberOfClasses () + 1) / 2, 0);

std::vector< std::vector <int> > transitions (getNumberOfClasses () + 1);
for (size_t k = 0; k < transitions.size (); ++k)
for (auto &transition : transitions)
{
transitions[k].resize (getNumberOfClasses () + 1, 0);
transition.resize (getNumberOfClasses () + 1, 0);
}

for (size_t k = 1; k < label_histograms[i].size (); ++k)
Expand Down Expand Up @@ -208,9 +208,9 @@ pcl::GFPFHEstimation<PointInT, PointNT, PointOutT>::computeDistanceHistogram (co

const float range = max_value - min_value;
const int max_bin = descriptorSize () - 1;
for (size_t i = 0; i < distances.size (); ++i)
for (const float &distance : distances)
{
const float raw_bin = static_cast<float> (descriptorSize ()) * (distances[i] - min_value) / range;
const float raw_bin = static_cast<float> (descriptorSize ()) * (distance - min_value) / range;
int bin = std::min (max_bin, static_cast<int> (floor (raw_bin)));
histogram[bin] += 1;
}
Expand All @@ -224,12 +224,12 @@ pcl::GFPFHEstimation<PointInT, PointNT, PointOutT>::computeMeanHistogram (const
assert (histograms.size () > 0);

mean_histogram.resize (histograms[0].size (), 0);
for (size_t i = 0; i < histograms.size (); ++i)
for (size_t j = 0; j < histograms[i].size (); ++j)
mean_histogram[j] += static_cast<float> (histograms[i][j]);
for (const auto &histogram : histograms)
for (size_t j = 0; j < histogram.size (); ++j)
mean_histogram[j] += static_cast<float> (histogram[j]);

for (size_t i = 0; i < mean_histogram.size (); ++i)
mean_histogram[i] /= static_cast<float> (histograms.size ());
for (float &i : mean_histogram)
i /= static_cast<float> (histograms.size ());
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -252,9 +252,9 @@ template <typename PointInT, typename PointNT, typename PointOutT> boost::uint32
pcl::GFPFHEstimation<PointInT, PointNT, PointOutT>::getDominantLabel (const std::vector<int>& indices)
{
std::vector<uint32_t> counts (getNumberOfClasses () + 1, 0);
for (size_t i = 0; i < indices.size (); ++i)
for (const int &nn_index : indices)
{
uint32_t label = labels_->points[indices[i]].label;
uint32_t label = labels_->points[nn_index].label;
counts[label] += 1;
}

Expand Down
6 changes: 3 additions & 3 deletions features/include/pcl/features/impl/grsd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ pcl::GRSDEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut
{
int source_type = types[idx];
std::vector<int> neighbors = grid.getNeighborCentroidIndices (cloud_downsampled->points[idx], relative_coordinates_all_);
for (size_t id_n = 0; id_n < neighbors.size (); id_n++)
for (const int &neighbor : neighbors)
{
int neighbor_type;
if (neighbors[id_n] == -1) // empty
if (neighbor == -1) // empty
neighbor_type = NR_CLASS;
else
neighbor_type = types[neighbors[id_n]];
neighbor_type = types[neighbor];
transition_matrix (source_type, neighbor_type)++;
}
}
Expand Down
18 changes: 9 additions & 9 deletions features/include/pcl/features/impl/intensity_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pcl::IntensityGradientEstimation <PointInT, PointNT, PointOutT, IntensitySelecto
Eigen::Matrix3f A = Eigen::Matrix3f::Zero ();
Eigen::Vector3f b = Eigen::Vector3f::Zero ();

for (size_t i_point = 0; i_point < indices.size (); ++i_point)
for (const int &nn_index : indices)
{
PointInT p = cloud.points[indices[i_point]];
PointInT p = cloud.points[nn_index];
if (!std::isfinite (p.x) ||
!std::isfinite (p.y) ||
!std::isfinite (p.z) ||
Expand Down Expand Up @@ -171,10 +171,10 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
float mean_intensity = 0;
// Initialize to 0
centroid.setZero ();
for (size_t i = 0; i < nn_indices.size (); ++i)
for (const int &nn_index : nn_indices)
{
centroid += surface_->points[nn_indices[i]].getVector3fMap ();
mean_intensity += intensity_ (surface_->points[nn_indices[i]]);
centroid += surface_->points[nn_index].getVector3fMap ();
mean_intensity += intensity_ (surface_->points[nn_index]);
}
centroid /= static_cast<float> (nn_indices.size ());
mean_intensity /= static_cast<float> (nn_indices.size ());
Expand Down Expand Up @@ -209,14 +209,14 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
// Initialize to 0
centroid.setZero ();
unsigned cp = 0;
for (size_t i = 0; i < nn_indices.size (); ++i)
for (const int &nn_index : nn_indices)
{
// Check if the point is invalid
if (!isFinite ((*surface_) [nn_indices[i]]))
if (!isFinite ((*surface_) [nn_index]))
continue;

centroid += surface_->points [nn_indices[i]].getVector3fMap ();
mean_intensity += intensity_ (surface_->points [nn_indices[i]]);
centroid += surface_->points [nn_index].getVector3fMap ();
mean_intensity += intensity_ (surface_->points [nn_index]);
++cp;
}
centroid /= static_cast<float> (cp);
Expand Down
8 changes: 4 additions & 4 deletions features/include/pcl/features/impl/moment_invariants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ pcl::MomentInvariantsEstimation<PointInT, PointOutT>::computePointMomentInvarian
float mu200 = 0, mu020 = 0, mu002 = 0, mu110 = 0, mu101 = 0, mu011 = 0;

// Iterate over the nearest neighbors set
for (size_t nn_idx = 0; nn_idx < indices.size (); ++nn_idx)
for (const int &index : indices)
{
// Demean the points
temp_pt_[0] = cloud.points[indices[nn_idx]].x - xyz_centroid_[0];
temp_pt_[1] = cloud.points[indices[nn_idx]].y - xyz_centroid_[1];
temp_pt_[2] = cloud.points[indices[nn_idx]].z - xyz_centroid_[2];
temp_pt_[0] = cloud.points[index].x - xyz_centroid_[0];
temp_pt_[1] = cloud.points[index].y - xyz_centroid_[1];
temp_pt_[2] = cloud.points[index].z - xyz_centroid_[2];

mu200 += temp_pt_[0] * temp_pt_[0];
mu020 += temp_pt_[1] * temp_pt_[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ pcl::MultiscaleFeaturePersistence<PointSource, PointFeature>::calculateMeanFeatu
float normalization_factor = 0.0f;
for (std::vector<std::vector<std::vector<float> > >::iterator scale_it = features_at_scale_vectorized_.begin (); scale_it != features_at_scale_vectorized_.end(); ++scale_it) {
normalization_factor += static_cast<float> (scale_it->size ());
for (std::vector<std::vector<float> >::iterator feature_it = scale_it->begin (); feature_it != scale_it->end (); ++feature_it)
for (const auto &feature : *scale_it)
for (int dim_i = 0; dim_i < feature_representation_->getNumberOfDimensions (); ++dim_i)
mean_feature_[dim_i] += (*feature_it)[dim_i];
mean_feature_[dim_i] += feature[dim_i];
}

for (int dim_i = 0; dim_i < feature_representation_->getNumberOfDimensions (); ++dim_i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ pcl::OrganizedEdgeBase<PointT, PointLT>::extractEdges (pcl::PointCloud<PointLT>&
int dx = 0;
int dy = 0;
int num_of_invalid_pt = 0;
for (int d_idx = 0; d_idx < num_of_ngbr; d_idx++)
for (const auto &direction : directions)
{
int nghr_idx = curr_idx + directions[d_idx].d_index;
int nghr_idx = curr_idx + direction.d_index;
assert (nghr_idx >= 0 && nghr_idx < input_->points.size ());
if (!std::isfinite (input_->points[nghr_idx].z))
{
dx += directions[d_idx].d_x;
dy += directions[d_idx].d_y;
dx += direction.d_x;
dy += direction.d_y;
num_of_invalid_pt++;
}
}
Expand Down
Loading