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

Better indices in loops #3543

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
6 changes: 3 additions & 3 deletions features/include/pcl/features/from_meshes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace pcl
normals.points[polygons[i].vertices[j]].getNormalVector3fMap() += normal;
}

for ( int i = 0; i < nr_points; ++i )
for (std::size_t i = 0; i < nr_points; ++i)
{
normals.points[i].getNormalVector3fMap().normalize();
pcl::flipNormalTowardsViewpoint(cloud.points[i], 0.0f, 0.0f, 0.0f, normals.points[i].normal_x, normals.points[i].normal_y, normals.points[i].normal_z);
Expand All @@ -69,9 +69,9 @@ namespace pcl
{
assert(cloud.points.size() == normals.points.size());

int nr_points = static_cast<int>(cloud.points.size());
const auto nr_points = cloud.points.size();
covariances.resize(nr_points);
for (int i = 0; i < nr_points; ++i)
for (std::size_t i = 0; i < nr_points; ++i)
{
Eigen::Vector3d normal(normals.points[i].normal_x,
normals.points[i].normal_y,
Expand Down
2 changes: 1 addition & 1 deletion features/include/pcl/features/impl/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pcl::BOARDLocalReferenceFrameEstimation<PointInT, PointNT, PointOutT>::computePo
max_boundary_angle = (2 * static_cast<float> (M_PI)) / static_cast<float> (check_margin_array_size_);
}

for (int curr_neigh = 0; curr_neigh < n_neighbours; ++curr_neigh)
for (std::size_t curr_neigh = 0; curr_neigh < n_neighbours; ++curr_neigh)
{
const int& curr_neigh_idx = neighbours_indices[curr_neigh];
const float& neigh_distance_sqr = neighbours_distances[curr_neigh];
Expand Down
11 changes: 4 additions & 7 deletions features/include/pcl/features/impl/brisk_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pcl::BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::generateKern
pattern_iterator->sigma = static_cast<float> (sigma_scale * scale_list_[scale] * (double (radius_list[ring])) * sin (M_PI / double (number_list[ring])));

// adapt the sizeList if necessary
const unsigned int size = static_cast<const unsigned int> (std::ceil (((scale_list_[scale] * radius_list[ring]) + pattern_iterator->sigma)) + 1);
const unsigned int size = static_cast<unsigned int> (std::ceil (((scale_list_[scale] * radius_list[ring]) + pattern_iterator->sigma)) + 1);

if (size_list_[scale] < size)
size_list_[scale] = size;
Expand All @@ -169,14 +169,11 @@ pcl::BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::generateKern
no_long_pairs_ = 0;

// fill index_change with 0..n if empty
unsigned int ind_size = static_cast<unsigned int> (index_change.size ());
if (ind_size == 0)
if (index_change.empty ())
{
index_change.resize (points_ * (points_ - 1) / 2);
ind_size = static_cast<unsigned int> (index_change.size ());
}
for (unsigned int i = 0; i < ind_size; i++)
index_change[i] = i;
std::iota(index_change.begin (), index_change.end (), 0);

const float d_min_sq = d_min_ * d_min_;
const float d_max_sq = d_max_ * d_max_;
Expand All @@ -201,7 +198,7 @@ pcl::BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::generateKern
else if (norm_sq < d_max_sq)
{
// save to short pairs
assert (no_short_pairs_ < ind_size); // make sure the user passes something sensible
assert (no_short_pairs_ < index_change.size ()); // make sure the user passes something sensible
BriskShortPair& shortPair = short_pairs_[index_change[no_short_pairs_]];
shortPair.j = j;
shortPair.i = i;
Expand Down
8 changes: 4 additions & 4 deletions features/include/pcl/features/impl/cvfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ pcl::CVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSmoot
std::vector<int> nn_indices;
std::vector<float> nn_distances;
// Process all points in the indices vector
for (int i = 0; i < static_cast<int> (cloud.points.size ()); ++i)
for (std::size_t i = 0; i < cloud.points.size (); ++i)
{
if (processed[i])
continue;

std::vector<unsigned int> seed_queue;
int sq_idx = 0;
std::vector<std::size_t> seed_queue;
std::size_t sq_idx = 0;
seed_queue.push_back (i);

processed[i] = true;

while (sq_idx < static_cast<int> (seed_queue.size ()))
while (sq_idx < seed_queue.size ())
{
// Search for sq_idx
if (!tree->radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances))
Expand Down
6 changes: 3 additions & 3 deletions features/include/pcl/features/impl/fpfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::weightPointSPFHSignature (
weight = 1.0f / dists[idx];

// Weight the SPFH of the query point with the SPFH of its neighbors
for (int f1_i = 0; f1_i < nr_bins_f1; ++f1_i)
for (std::size_t f1_i = 0; f1_i < nr_bins_f1; ++f1_i)
{
val_f1 = hist_f1 (indices[idx], f1_i) * weight;
sum_f1 += val_f1;
fpfh_histogram[f1_i] += val_f1;
}

for (int f2_i = 0; f2_i < nr_bins_f2; ++f2_i)
for (std::size_t f2_i = 0; f2_i < nr_bins_f2; ++f2_i)
{
val_f2 = hist_f2 (indices[idx], f2_i) * weight;
sum_f2 += val_f2;
fpfh_histogram[f2_i + nr_bins_f1] += val_f2;
}

for (int f3_i = 0; f3_i < nr_bins_f3; ++f3_i)
for (std::size_t f3_i = 0; f3_i < nr_bins_f3; ++f3_i)
{
val_f3 = hist_f3 (indices[idx], f3_i) * weight;
sum_f3 += val_f3;
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 @@ -107,7 +107,7 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::computeFeature (PointCloud
#ifdef _OPENMP
#pragma omp parallel for shared (spfh_hist_lookup) private (nn_indices, nn_dists) num_threads(threads_)
#endif
for (int i = 0; i < static_cast<int> (spfh_indices_vec.size ()); ++i)
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (spfh_indices_vec.size ()); ++i)
{
// Get the next point index
int p_idx = spfh_indices_vec[i];
Expand All @@ -134,7 +134,7 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::computeFeature (PointCloud
#ifdef _OPENMP
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
// Find the indices of point idx's neighbors...
if (!isFinite ((*input_)[(*indices_)[idx]]) ||
Expand Down
8 changes: 4 additions & 4 deletions features/include/pcl/features/impl/gfpfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ pcl::GFPFHEstimation<PointInT, PointNT, PointOutT>::computeTransitionHistograms
}

// Build a one-dimension histogram out of it.
int flat_index = 0;
for (int m = 0; m < static_cast<int> (transitions.size ()); ++m)
for (int n = m; n < static_cast<int> (transitions[m].size ()); ++n)
std::size_t flat_index = 0;
for (std::size_t m = 0; m < transitions.size (); ++m)
for (std::size_t n = m; n < transitions[m].size (); ++n)
{
transition_histograms[i][flat_index] = transitions[m][n];
++flat_index;
}

assert (flat_index == static_cast<int> (transition_histograms[i].size ()));
assert (flat_index == transition_histograms[i].size ());
}
}

Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/intensity_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
PointOutT &p_out = output.points[idx];

Expand Down Expand Up @@ -194,7 +194,7 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
PointOutT &p_out = output.points[idx];
if (!isFinite ((*surface_) [(*indices_)[idx]]) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,14 @@ pcl::MomentOfInertiaEstimation<PointT>::setIndices (std::size_t row_start, std::
return;
}

std::size_t row_end = row_start + nb_rows;
const std::size_t row_end = row_start + nb_rows;
if (row_end > input_->height)
{
PCL_ERROR ("[PCLBase::setIndices] %d is out of rows range %d", row_end, input_->height);
return;
}

std::size_t col_end = col_start + nb_cols;
const std::size_t col_end = col_start + nb_cols;
if (col_end > input_->width)
{
PCL_ERROR ("[PCLBase::setIndices] %d is out of columns range %d", col_end, input_->width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ template <typename PointSource, typename PointFeature> float
pcl::MultiscaleFeaturePersistence<PointSource, PointFeature>::distanceBetweenFeatures (const std::vector<float> &a,
const std::vector<float> &b)
{
return (pcl::selectNorm<std::vector<float> > (a, b, static_cast<int> (a.size ()), distance_metric_));
return (pcl::selectNorm<std::vector<float> > (a, b, a.size (), distance_metric_));
}


Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/normal_3d_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &ou
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Eigen::Vector4f n;
if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0 ||
Expand All @@ -101,7 +101,7 @@ pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &ou
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Eigen::Vector4f n;
if (!isFinite ((*input_)[(*indices_)[idx]]) ||
Expand Down
9 changes: 4 additions & 5 deletions features/include/pcl/features/impl/our_cvfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ pcl::OURCVFHEstimation<PointInT, PointNT, PointOutT>::extractEuclideanClustersSm
std::vector<int> nn_indices;
std::vector<float> nn_distances;
// Process all points in the indices vector
for (int i = 0; i < static_cast<int> (cloud.points.size ()); ++i)
for (std::size_t i = 0; i < cloud.points.size (); ++i)
{
if (processed[i])
continue;

std::vector<unsigned int> seed_queue;
int sq_idx = 0;
std::vector<std::size_t> seed_queue;
std::size_t sq_idx = 0;
seed_queue.push_back (i);

processed[i] = true;

while (sq_idx < static_cast<int> (seed_queue.size ()))
while (sq_idx < seed_queue.size ())
{
// Search for sq_idx
if (!tree->radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances))
Expand Down Expand Up @@ -237,7 +237,6 @@ pcl::OURCVFHEstimation<PointInT, PointNT, PointOutT>::sgurf (Eigen::Vector3f & c
scatter.setZero ();
float sum_w = 0.f;

//for (int k = 0; k < static_cast<intgrid->points[k].getVector3fMap ();> (grid->points.size ()); k++)
for (const int &index : indices.indices)
{
Eigen::Vector3f pvector = grid->points[index].getVector3fMap ();
Expand Down
13 changes: 7 additions & 6 deletions features/include/pcl/features/impl/rops_estimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pcl::ROPSEstimation <PointInT, PointOutT>::computeFeature (PointCloudOut &output
unsigned int number_of_points = static_cast <unsigned int> (indices_->size ());
output.points.resize (number_of_points, PointOutT ());

for (unsigned int i_point = 0; i_point < number_of_points; i_point++)
for (std::size_t i_point = 0; i_point < number_of_points; i_point++)
{
std::set <unsigned int> local_triangles;
std::vector <int> local_points;
Expand Down Expand Up @@ -181,6 +181,7 @@ pcl::ROPSEstimation <PointInT, PointOutT>::computeFeature (PointCloudOut &output
distribution_matrix.resize (number_of_bins_, number_of_bins_);
getDistributionMatrix (i_proj, min, max, rotated_cloud, distribution_matrix);

// TODO remove this needless copy due to API design
std::vector <float> moments;
computeCentralMoments (distribution_matrix, moments);

Expand All @@ -192,14 +193,14 @@ pcl::ROPSEstimation <PointInT, PointOutT>::computeFeature (PointCloudOut &output
}

float norm = 0.0f;
for (unsigned int i_dim = 0; i_dim < feature_size; i_dim++)
for (std::size_t i_dim = 0; i_dim < feature_size; i_dim++)
norm += std::abs (feature[i_dim]);
if (norm < std::numeric_limits <float>::epsilon ())
norm = 1.0f;
else
norm = 1.0f / norm;

for (unsigned int i_dim = 0; i_dim < feature_size; i_dim++)
for (std::size_t i_dim = 0; i_dim < feature_size; i_dim++)
output.points[i_point].histogram[i_dim] = feature[i_dim] * norm;
}
}
Expand Down Expand Up @@ -288,7 +289,7 @@ pcl::ROPSEstimation <PointInT, PointOutT>::computeLRF (const PointInT& point, co
overall_scatter_matrix.setZero ();
std::vector<float> total_weight (number_of_triangles);
const float denominator = 1.0f / 6.0f;
for (unsigned int i_triangle = 0; i_triangle < number_of_triangles; i_triangle++)
for (std::size_t i_triangle = 0; i_triangle < number_of_triangles; i_triangle++)
{
float factor = distance_weight[i_triangle] * triangle_area[i_triangle] * total_area;
overall_scatter_matrix += factor * scatter_matrices[i_triangle];
Expand Down Expand Up @@ -385,7 +386,7 @@ pcl::ROPSEstimation <PointInT, PointOutT>::transformCloud (const PointInT& point
const unsigned int number_of_points = static_cast <unsigned int> (local_points.size ());
transformed_cloud.points.resize (number_of_points, PointInT ());

for (unsigned int i = 0; i < number_of_points; i++)
for (std::size_t i = 0; i < number_of_points; i++)
{
Eigen::Vector3f transformed_point (
surface_->points[local_points[i]].x - point.x,
Expand Down Expand Up @@ -431,7 +432,7 @@ pcl::ROPSEstimation <PointInT, PointOutT>::rotateCloud (const PointInT& axis, co
max (1) = -std::numeric_limits <float>::max ();
max (2) = -std::numeric_limits <float>::max ();

for (unsigned int i_point = 0; i_point < number_of_points; i_point++)
for (std::size_t i_point = 0; i_point < number_of_points; i_point++)
{
Eigen::Vector3f point (
cloud.points[i_point].x,
Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/rsd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pcl::computeRSD (const pcl::PointCloud<PointInT> &surface, const pcl::PointCloud

// Compute distance by normal angle distribution for points
std::vector<int>::const_iterator i, begin (indices.begin()), end (indices.end());
for(i = begin+1; i != end; ++i)
for (i = begin+1; i != end; ++i)
{
// compute angle between the two lines going through normals (disregard orientation!)
double cosine = normals.points[*i].normal[0] * normals.points[*begin].normal[0] +
Expand Down Expand Up @@ -177,7 +177,7 @@ pcl::computeRSD (const pcl::PointCloud<PointNT> &normals,

// Compute distance by normal angle distribution for points
std::vector<int>::const_iterator i, begin (indices.begin()), end (indices.end());
for(i = begin+1; i != end; ++i)
for (i = begin+1; i != end; ++i)
{
// compute angle between the two lines going through normals (disregard orientation!)
double cosine = normals.points[*i].normal[0] * normals.points[*begin].normal[0] +
Expand Down
3 changes: 1 addition & 2 deletions features/include/pcl/features/impl/shot_lrf_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ pcl::SHOTLocalReferenceFrameEstimationOMP<PointInT, PointOutT>::computeFeature (
}
tree_->setSortedResults (true);

int data_size = static_cast<int> (indices_->size ());
#ifdef _OPENMP
#pragma omp parallel for num_threads(threads_)
#endif
for (int i = 0; i < data_size; ++i)
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (indices_->size ()); ++i)
{
// point result
Eigen::Matrix3f rf;
Expand Down
8 changes: 2 additions & 6 deletions features/include/pcl/features/impl/shot_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,12 @@ pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::computeFeature (

assert(descLength_ == 352);

int data_size = static_cast<int> (indices_->size ());

output.is_dense = true;
// Iterating over the entire index vector
#ifdef _OPENMP
#pragma omp parallel for num_threads(threads_)
#endif
for (int idx = 0; idx < data_size; ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{

Eigen::VectorXf shot;
Expand Down Expand Up @@ -234,14 +232,12 @@ pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::computeFeat
radius1_4_ = search_radius_ / 4;
radius1_2_ = search_radius_ / 2;

int data_size = static_cast<int> (indices_->size ());

output.is_dense = true;
// Iterating over the entire index vector
#ifdef _OPENMP
#pragma omp parallel for num_threads(threads_)
#endif
for (int idx = 0; idx < data_size; ++idx)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Eigen::VectorXf shot;
shot.setZero (descLength_);
Expand Down
2 changes: 1 addition & 1 deletion features/include/pcl/features/impl/spin_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pcl::SpinImageEstimation<PointInT, PointNT, PointOutT>::initCompute ()
template <typename PointInT, typename PointNT, typename PointOutT> void
pcl::SpinImageEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output)
{
for (int i_input = 0; i_input < static_cast<int> (indices_->size ()); ++i_input)
for (std::size_t i_input = 0; i_input < indices_->size (); ++i_input)
{
Eigen::ArrayXXd res = computeSiForPoint (indices_->at (i_input));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pcl::StatisticalMultiscaleInterestRegionExtraction<PointT>::generateCloudGraph (
std::vector<float> k_distances (16);
kdtree.nearestKSearch (static_cast<int> (point_i), 16, k_indices, k_distances);

for (int k_i = 0; k_i < static_cast<int> (k_indices.size ()); ++k_i)
for (std::size_t k_i = 0; k_i < k_indices.size (); ++k_i)
add_edge (point_i, k_indices[k_i], Weight (std::sqrt (k_distances[k_i])), cloud_graph);
}

Expand Down
2 changes: 1 addition & 1 deletion features/include/pcl/features/impl/vfh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pcl::VFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut

// ---[ Step 1b : compute the centroid in normal space
Eigen::Vector4f normal_centroid = Eigen::Vector4f::Zero ();
int cp = 0;
std::size_t cp = 0;

// If the data is dense, we don't need to check for NaN
if (use_given_normal_)
Expand Down
Loading