From b551ee47b24e90cfb430ee4474f569e1411cd7bc Mon Sep 17 00:00:00 2001 From: Norm Evangelista Date: Tue, 21 Feb 2023 02:17:59 -0800 Subject: [PATCH] Added modernize-use-emplace, modernize-loop-convert clang-tidy check (#5610) Fixed some odd misspellings Fixed formatting escapes Ran 'build format' to resolve clang-format issues Debugging odd compile error Fixed more issues from CI Addressed CI issues and review feedback Added missing const Added yet more missing const Reverted another omp parallel for Reverted for third-party code Disabled clang-tidy for third-party code --- .clang-tidy | 3 ++ common/include/pcl/point_types_conversion.h | 8 ++--- .../impl/multiscale_feature_persistence.hpp | 4 +-- features/include/pcl/features/our_cvfh.h | 8 ++--- features/src/narf.cpp | 6 ++-- .../pcl/filters/impl/covariance_sampling.hpp | 4 +-- .../include/pcl/filters/impl/crop_hull.hpp | 4 +-- .../pcl/filters/impl/local_maximum.hpp | 8 ++--- geometry/include/pcl/geometry/mesh_base.h | 29 ++++++++++-------- .../impl/smoothed_surfaces_keypoint.hpp | 12 ++++---- .../pcl/keypoints/impl/trajkovic_2d.hpp | 2 ++ .../pcl/ml/impl/dt/decision_tree_trainer.hpp | 14 +++------ .../pcl/people/impl/head_based_subcluster.hpp | 4 +-- .../pcl/recognition/3rdparty/metslib/model.hh | 8 +++-- .../3rdparty/metslib/tabu-search.hh | 4 ++- .../include/pcl/recognition/impl/hv/hv_go.hpp | 6 ++-- .../recognition/impl/linemod/line_rgbd.hpp | 30 ++++++++----------- .../include/pcl/registration/impl/ndt_2d.hpp | 4 +-- .../impl/sac_model_sphere.hpp | 10 +++---- test/features/test_normal_estimation.cpp | 8 ++--- test/io/test_iterators.cpp | 4 ++- test/io/test_octree_compression.cpp | 4 +-- test/search/test_organized_index.cpp | 8 ++--- test/surface/test_poisson.cpp | 4 +-- tools/fast_bilateral_filter.cpp | 4 ++- tools/normal_estimation.cpp | 4 ++- 26 files changed, 106 insertions(+), 98 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 80625eda8a4..35542031548 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,10 +5,13 @@ Checks: > cppcoreguidelines-pro-type-static-cast-downcast, google-readability-casting, modernize-deprecated-headers, + modernize-loop-convert, modernize-redundant-void-arg, modernize-replace-random-shuffle, modernize-return-braced-init-list, + modernize-shrink-to-fit, modernize-use-auto, + modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, diff --git a/common/include/pcl/point_types_conversion.h b/common/include/pcl/point_types_conversion.h index a4afdace339..23f8e68d860 100644 --- a/common/include/pcl/point_types_conversion.h +++ b/common/include/pcl/point_types_conversion.h @@ -173,12 +173,12 @@ namespace pcl f[2] /= 1.08883; // CIEXYZ -> CIELAB - for (int i = 0; i < 3; ++i) { - if (f[i] > 0.008856) { - f[i] = std::pow(f[i], 1.0 / 3.0); + for (float & xyz : f) { + if (xyz > 0.008856) { + xyz = std::pow(xyz, 1.0 / 3.0); } else { - f[i] = 7.787 * f[i] + 16.0 / 116.0; + xyz = 7.787 * xyz + 16.0 / 116.0; } } diff --git a/features/include/pcl/features/impl/multiscale_feature_persistence.hpp b/features/include/pcl/features/impl/multiscale_feature_persistence.hpp index 932aad8d5e5..a44ec8b148c 100644 --- a/features/include/pcl/features/impl/multiscale_feature_persistence.hpp +++ b/features/include/pcl/features/impl/multiscale_feature_persistence.hpp @@ -91,10 +91,10 @@ pcl::MultiscaleFeaturePersistence::computeFeaturesAtA features_at_scale_.reserve (scale_values_.size ()); features_at_scale_vectorized_.clear (); features_at_scale_vectorized_.reserve (scale_values_.size ()); - for (std::size_t scale_i = 0; scale_i < scale_values_.size (); ++scale_i) + for (float & scale_value : scale_values_) { FeatureCloudPtr feature_cloud (new FeatureCloud ()); - computeFeatureAtScale (scale_values_[scale_i], feature_cloud); + computeFeatureAtScale (scale_value, feature_cloud); features_at_scale_.push_back(feature_cloud); // Vectorize each feature and insert it into the vectorized feature storage diff --git a/features/include/pcl/features/our_cvfh.h b/features/include/pcl/features/our_cvfh.h index a40503fdb42..f1f42251641 100644 --- a/features/include/pcl/features/our_cvfh.h +++ b/features/include/pcl/features/our_cvfh.h @@ -190,8 +190,8 @@ namespace pcl inline void getCentroidClusters (std::vector > & centroids) { - for (std::size_t i = 0; i < centroids_dominant_orientations_.size (); ++i) - centroids.push_back (centroids_dominant_orientations_[i]); + for (const auto & centroids_dominant_orientation : centroids_dominant_orientations_) + centroids.push_back (centroids_dominant_orientation); } /** \brief Get the normal centroids used to compute different CVFH descriptors @@ -200,8 +200,8 @@ namespace pcl inline void getCentroidNormalClusters (std::vector > & centroids) { - for (std::size_t i = 0; i < dominant_normals_.size (); ++i) - centroids.push_back (dominant_normals_[i]); + for (const auto & dominant_normal : dominant_normals_) + centroids.push_back (dominant_normal); } /** \brief Sets max. Euclidean distance between points to be added to the cluster diff --git a/features/src/narf.cpp b/features/src/narf.cpp index 556e741eccb..8e07b71270d 100644 --- a/features/src/narf.cpp +++ b/features/src/narf.cpp @@ -376,6 +376,8 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud< schedule(dynamic, 10) \ num_threads(max_no_of_threads) //!!! nizar 20110408 : for OpenMP sake on MSVC this must be kept signed + // Disable lint since this 'for' is part of the pragma + // NOLINTNEXTLINE(modernize-loop-convert) for (std::ptrdiff_t idx = 0; idx < static_cast(interest_points.size ()); ++idx) { const auto& interest_point = interest_points[idx]; @@ -389,7 +391,7 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud< else { if (!rotation_invariant) { -# pragma omp critical +#pragma omp critical { feature_list.push_back(feature); } @@ -409,7 +411,7 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud< delete feature2; continue; } -# pragma omp critical +#pragma omp critical { feature_list.push_back(feature2); } diff --git a/filters/include/pcl/filters/impl/covariance_sampling.hpp b/filters/include/pcl/filters/impl/covariance_sampling.hpp index df675d1923f..99d8da8f550 100644 --- a/filters/include/pcl/filters/impl/covariance_sampling.hpp +++ b/filters/include/pcl/filters/impl/covariance_sampling.hpp @@ -75,8 +75,8 @@ pcl::CovarianceSampling::initCompute () } average_norm /= static_cast(scaled_points_.size ()); - for (std::size_t p_i = 0; p_i < scaled_points_.size (); ++p_i) - scaled_points_[p_i] /= static_cast(average_norm); + for (auto & scaled_point : scaled_points_) + scaled_point /= static_cast(average_norm); return (true); } diff --git a/filters/include/pcl/filters/impl/crop_hull.hpp b/filters/include/pcl/filters/impl/crop_hull.hpp index ef34a021bd4..dbe8f5d07bc 100644 --- a/filters/include/pcl/filters/impl/crop_hull.hpp +++ b/filters/include/pcl/filters/impl/crop_hull.hpp @@ -153,10 +153,10 @@ pcl::CropHull::applyFilter3D (Indices &indices) Eigen::Vector3f(0.856514f, 0.508771f, 0.0868081f) }; - for (std::size_t poly = 0; poly < hull_polygons_.size (); poly++) + for (const auto & hull_polygon : hull_polygons_) for (std::size_t ray = 0; ray < 3; ray++) crossings[ray] += rayTriangleIntersect - ((*input_)[(*indices_)[index]], rays[ray], hull_polygons_[poly], *hull_cloud_); + ((*input_)[(*indices_)[index]], rays[ray], hull_polygon, *hull_cloud_); bool crosses = (crossings[0]&1) + (crossings[1]&1) + (crossings[2]&1) > 1; if ((crop_outside_ && crosses) || (!crop_outside_ && !crosses)) diff --git a/filters/include/pcl/filters/impl/local_maximum.hpp b/filters/include/pcl/filters/impl/local_maximum.hpp index 2b770d3efa9..59c821bb362 100644 --- a/filters/include/pcl/filters/impl/local_maximum.hpp +++ b/filters/include/pcl/filters/impl/local_maximum.hpp @@ -154,9 +154,9 @@ pcl::LocalMaximum::applyFilterIndices (Indices &indices) // Check to see if a neighbor is higher than the query point float query_z = (*input_)[iii].z; - for (std::size_t k = 0; k < radius_indices.size (); ++k) // the query point itself is in the (unsorted) radius_indices, but that is okay since we compare with ">" + for (const auto& radius_index : radius_indices) // the query point itself is in the (unsorted) radius_indices, but that is okay since we compare with ">" { - if ((*input_)[radius_indices[k]].z > query_z) + if ((*input_)[radius_index].z > query_z) { // Query point is not the local max, no need to check others point_is_max[iii] = false; @@ -168,9 +168,9 @@ pcl::LocalMaximum::applyFilterIndices (Indices &indices) // visited, excluding them from future consideration as local maxima if (point_is_max[iii]) { - for (std::size_t k = 0; k < radius_indices.size (); ++k) // the query point itself is in the (unsorted) radius_indices, but it must also be marked as visited + for (const auto& radius_index : radius_indices) // the query point itself is in the (unsorted) radius_indices, but it must also be marked as visited { - point_is_visited[radius_indices[k]] = true; + point_is_visited[radius_index] = true; } } diff --git a/geometry/include/pcl/geometry/mesh_base.h b/geometry/include/pcl/geometry/mesh_base.h index 991ac56470e..d9346bab944 100644 --- a/geometry/include/pcl/geometry/mesh_base.h +++ b/geometry/include/pcl/geometry/mesh_base.h @@ -323,25 +323,28 @@ class MeshBase { } // Adjust the indices - for (auto it = vertices_.begin(); it != vertices_.end(); ++it) { - if (it->idx_outgoing_half_edge_.isValid()) { - it->idx_outgoing_half_edge_ = - new_half_edge_indices[it->idx_outgoing_half_edge_.get()]; + for (auto& vertex : vertices_) { + if (vertex.idx_outgoing_half_edge_.isValid()) { + vertex.idx_outgoing_half_edge_ = + new_half_edge_indices[vertex.idx_outgoing_half_edge_.get()]; } } - for (auto it = half_edges_.begin(); it != half_edges_.end(); ++it) { - it->idx_terminating_vertex_ = - new_vertex_indices[it->idx_terminating_vertex_.get()]; - it->idx_next_half_edge_ = new_half_edge_indices[it->idx_next_half_edge_.get()]; - it->idx_prev_half_edge_ = new_half_edge_indices[it->idx_prev_half_edge_.get()]; - if (it->idx_face_.isValid()) { - it->idx_face_ = new_face_indices[it->idx_face_.get()]; + for (auto& half_edge : half_edges_) { + half_edge.idx_terminating_vertex_ = + new_vertex_indices[half_edge.idx_terminating_vertex_.get()]; + half_edge.idx_next_half_edge_ = + new_half_edge_indices[half_edge.idx_next_half_edge_.get()]; + half_edge.idx_prev_half_edge_ = + new_half_edge_indices[half_edge.idx_prev_half_edge_.get()]; + if (half_edge.idx_face_.isValid()) { + half_edge.idx_face_ = new_face_indices[half_edge.idx_face_.get()]; } } - for (auto it = faces_.begin(); it != faces_.end(); ++it) { - it->idx_inner_half_edge_ = new_half_edge_indices[it->idx_inner_half_edge_.get()]; + for (auto& face : faces_) { + face.idx_inner_half_edge_ = + new_half_edge_indices[face.idx_inner_half_edge_.get()]; } } diff --git a/keypoints/include/pcl/keypoints/impl/smoothed_surfaces_keypoint.hpp b/keypoints/include/pcl/keypoints/impl/smoothed_surfaces_keypoint.hpp index 2c1a3dff2ca..4f612bcb649 100644 --- a/keypoints/include/pcl/keypoints/impl/smoothed_surfaces_keypoint.hpp +++ b/keypoints/include/pcl/keypoints/impl/smoothed_surfaces_keypoint.hpp @@ -52,7 +52,7 @@ pcl::SmoothedSurfacesKeypoint::addSmoothedPointCloud (const Poi clouds_.push_back (cloud); cloud_normals_.push_back (normals); cloud_trees_.push_back (kdtree); - scales_.push_back (std::pair (scale, scales_.size ())); + scales_.emplace_back(scale, scales_.size ()); } @@ -115,15 +115,15 @@ pcl::SmoothedSurfacesKeypoint::detectKeypoints (PointCloudT &ou if (is_min || is_max) { bool passed_min = true, passed_max = true; - for (std::size_t scale_i = 0; scale_i < scales_.size (); ++scale_i) + for (const auto & scale : scales_) { - std::size_t cloud_i = scales_[scale_i].second; + std::size_t cloud_i = scale.second; // skip input cloud if (cloud_i == clouds_.size () - 1) continue; nn_indices.clear (); nn_distances.clear (); - cloud_trees_[cloud_i]->radiusSearch (point_i, scales_[scale_i].first * neighborhood_constant_, nn_indices, nn_distances); + cloud_trees_[cloud_i]->radiusSearch (point_i, scale.first * neighborhood_constant_, nn_indices, nn_distances); bool is_min_other_scale = true, is_max_other_scale = true; for (const auto &nn_index : nn_indices) @@ -225,7 +225,7 @@ pcl::SmoothedSurfacesKeypoint::initCompute () } // Add the input cloud as the last index - scales_.push_back (std::pair (input_scale_, scales_.size ())); + scales_.emplace_back(input_scale_, scales_.size ()); clouds_.push_back (input_); cloud_normals_.push_back (normals_); cloud_trees_.push_back (tree_); @@ -241,7 +241,7 @@ pcl::SmoothedSurfacesKeypoint::initCompute () } PCL_INFO ("Scales: "); - for (std::size_t i = 0; i < scales_.size (); ++i) PCL_INFO ("(%d %f), ", scales_[i].second, scales_[i].first); + for (const auto & scale : scales_) PCL_INFO ("(%d %f), ", scale.second, scale.first); PCL_INFO ("\n"); return (true); diff --git a/keypoints/include/pcl/keypoints/impl/trajkovic_2d.hpp b/keypoints/include/pcl/keypoints/impl/trajkovic_2d.hpp index 94c465aa1a5..8b1c1463834 100644 --- a/keypoints/include/pcl/keypoints/impl/trajkovic_2d.hpp +++ b/keypoints/include/pcl/keypoints/impl/trajkovic_2d.hpp @@ -246,6 +246,8 @@ TrajkovicKeypoint2D::detectKeypoints (PointClou shared(height, indices, occupency_map, output, width) \ num_threads(threads_) #endif + // Disable lint since this 'for' is part of the pragma + // NOLINTNEXTLINE(modernize-loop-convert) for (std::ptrdiff_t i = 0; i < static_cast (indices.size ()); ++i) { int idx = indices[i]; diff --git a/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp b/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp index be2d3610847..c1e7aaeef68 100644 --- a/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp +++ b/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp @@ -159,21 +159,15 @@ DecisionTreeTrainer:: if (!thresholds_.empty()) { // compute information gain for each threshold and store threshold with highest // information gain - for (std::size_t threshold_index = 0; threshold_index < thresholds_.size(); - ++threshold_index) { + for (const float& threshold : thresholds_) { - const float information_gain = - stats_estimator_->computeInformationGain(data_set_, - examples, - label_data, - feature_results, - flags, - thresholds_[threshold_index]); + const float information_gain = stats_estimator_->computeInformationGain( + data_set_, examples, label_data, feature_results, flags, threshold); if (information_gain > best_feature_information_gain) { best_feature_information_gain = information_gain; best_feature_index = static_cast(feature_index); - best_feature_threshold = thresholds_[threshold_index]; + best_feature_threshold = threshold; } } } diff --git a/people/include/pcl/people/impl/head_based_subcluster.hpp b/people/include/pcl/people/impl/head_based_subcluster.hpp index 43d333832eb..7c9866fcf27 100644 --- a/people/include/pcl/people/impl/head_based_subcluster.hpp +++ b/people/include/pcl/people/impl/head_based_subcluster.hpp @@ -270,9 +270,9 @@ pcl::people::HeadBasedSubclustering::subcluster (std::vector::const_iterator it = cluster_indices_.begin(); it != cluster_indices_.end(); ++it) + for(const auto & cluster_index : cluster_indices_) { - pcl::people::PersonCluster cluster(cloud_, *it, ground_coeffs_, sqrt_ground_coeffs_, head_centroid_, vertical_); // PersonCluster creation + pcl::people::PersonCluster cluster(cloud_, cluster_index, ground_coeffs_, sqrt_ground_coeffs_, head_centroid_, vertical_); // PersonCluster creation clusters.push_back(cluster); } diff --git a/recognition/include/pcl/recognition/3rdparty/metslib/model.hh b/recognition/include/pcl/recognition/3rdparty/metslib/model.hh index d2403bfc484..50657e39f90 100644 --- a/recognition/include/pcl/recognition/3rdparty/metslib/model.hh +++ b/recognition/include/pcl/recognition/3rdparty/metslib/model.hh @@ -36,6 +36,8 @@ #define METS_MODEL_HH_ namespace mets { +// Exempt third-party code from clang-tidy +// NOLINTBEGIN /// @brief Type of the objective/cost function. /// @@ -656,7 +658,7 @@ namespace mets { /// @brief Dtor. ~swap_full_neighborhood() override { - for(auto it = moves_m.begin(); + for(auto it = moves_m.begin(); it != moves_m.end(); ++it) delete *it; } @@ -681,7 +683,7 @@ namespace mets { /// @brief Dtor. ~invert_full_neighborhood() override { - for(auto it = moves_m.begin(); + for(auto it = moves_m.begin(); it != moves_m.end(); ++it) delete *it; } @@ -711,7 +713,7 @@ namespace mets { const Tp r) const { return l->operator==(*r); } }; - +// NOLINTEND } //________________________________________________________________________ diff --git a/recognition/include/pcl/recognition/3rdparty/metslib/tabu-search.hh b/recognition/include/pcl/recognition/3rdparty/metslib/tabu-search.hh index 1a92a0bf7e7..dfe82d960eb 100644 --- a/recognition/include/pcl/recognition/3rdparty/metslib/tabu-search.hh +++ b/recognition/include/pcl/recognition/3rdparty/metslib/tabu-search.hh @@ -497,7 +497,9 @@ mets::tabu_list_chain::is_tabu(feasible_solution& sol, /* const */ move& mov) co inline mets::simple_tabu_list::~simple_tabu_list() { - for(move_map_type::iterator m = tabu_hash_m.begin(); + // Disable lint for third-party code + // NOLINTNEXTLINE(modernize-loop-convert) + for(move_map_type::iterator m = tabu_hash_m.begin(); m!=tabu_hash_m.end(); ++m) delete m->first; } diff --git a/recognition/include/pcl/recognition/impl/hv/hv_go.hpp b/recognition/include/pcl/recognition/impl/hv/hv_go.hpp index 51cff240b59..4783f7018d5 100644 --- a/recognition/include/pcl/recognition/impl/hv/hv_go.hpp +++ b/recognition/include/pcl/recognition/impl/hv/hv_go.hpp @@ -410,9 +410,9 @@ void pcl::GlobalHypothesesVerification::SAOptimize(std::vector 1) { - occupied_multiple+=complete_cloud_occupancy_by_RM_[i]; + for(const auto& i : complete_cloud_occupancy_by_RM_) { + if(i > 1) { + occupied_multiple+=i; } } diff --git a/recognition/include/pcl/recognition/impl/linemod/line_rgbd.hpp b/recognition/include/pcl/recognition/impl/linemod/line_rgbd.hpp index a340e254439..5fdd7028f53 100644 --- a/recognition/include/pcl/recognition/impl/linemod/line_rgbd.hpp +++ b/recognition/include/pcl/recognition/impl/linemod/line_rgbd.hpp @@ -167,10 +167,8 @@ LineRGBD::loadTemplates (const std::string &file_name, con float max_y = -std::numeric_limits::max (); float max_z = -std::numeric_limits::max (); std::size_t counter = 0; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (const auto & p : template_point_cloud) { - const PointXYZRGBA & p = template_point_cloud[j]; - if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -200,9 +198,9 @@ LineRGBD::loadTemplates (const std::string &file_name, con bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f; bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (auto & j : template_point_cloud) { - PointXYZRGBA p = template_point_cloud[j]; + PointXYZRGBA p = j; if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -211,7 +209,7 @@ LineRGBD::loadTemplates (const std::string &file_name, con p.y -= center_y; p.z -= center_z; - template_point_cloud[j] = p; + j = p; } } @@ -254,10 +252,8 @@ LineRGBD::createAndAddTemplate ( float max_y = -std::numeric_limits::max (); float max_z = -std::numeric_limits::max (); std::size_t counter = 0; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (const auto & p : template_point_cloud) { - const PointXYZRGBA & p = template_point_cloud[j]; - if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -287,9 +283,9 @@ LineRGBD::createAndAddTemplate ( bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f; bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (auto & j : template_point_cloud) { - PointXYZRGBA p = template_point_cloud[j]; + PointXYZRGBA p = j; if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -298,7 +294,7 @@ LineRGBD::createAndAddTemplate ( p.y -= center_y; p.z -= center_z; - template_point_cloud[j] = p; + j = p; } } @@ -345,10 +341,8 @@ LineRGBD::addTemplate (const SparseQuantizedMultiModTempla float max_y = -std::numeric_limits::max (); float max_z = -std::numeric_limits::max (); std::size_t counter = 0; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (const auto & p : template_point_cloud) { - const PointXYZRGBA & p = template_point_cloud[j]; - if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -378,9 +372,9 @@ LineRGBD::addTemplate (const SparseQuantizedMultiModTempla bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f; bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f; - for (std::size_t j = 0; j < template_point_cloud.size (); ++j) + for (auto & j : template_point_cloud) { - PointXYZRGBA p = template_point_cloud[j]; + PointXYZRGBA p = j; if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z)) continue; @@ -389,7 +383,7 @@ LineRGBD::addTemplate (const SparseQuantizedMultiModTempla p.y -= center_y; p.z -= center_z; - template_point_cloud[j] = p; + j = p; } } diff --git a/registration/include/pcl/registration/impl/ndt_2d.hpp b/registration/include/pcl/registration/impl/ndt_2d.hpp index 3f790cd6e2f..1aeb6d1bdb0 100644 --- a/registration/include/pcl/registration/impl/ndt_2d.hpp +++ b/registration/include/pcl/registration/impl/ndt_2d.hpp @@ -121,8 +121,8 @@ class NormalDist { Eigen::Vector2d sx = Eigen::Vector2d::Zero(); Eigen::Matrix2d sxx = Eigen::Matrix2d::Zero(); - for (auto i = pt_indices_.cbegin(); i != pt_indices_.cend(); i++) { - Eigen::Vector2d p(cloud[*i].x, cloud[*i].y); + for (const auto& pt_index : pt_indices_) { + Eigen::Vector2d p(cloud[pt_index].x, cloud[pt_index].y); sx += p; sxx += p * p.transpose(); } diff --git a/sample_consensus/include/pcl/sample_consensus/impl/sac_model_sphere.hpp b/sample_consensus/include/pcl/sample_consensus/impl/sac_model_sphere.hpp index 3b77afdb75b..6834afb601e 100644 --- a/sample_consensus/include/pcl/sample_consensus/impl/sac_model_sphere.hpp +++ b/sample_consensus/include/pcl/sample_consensus/impl/sac_model_sphere.hpp @@ -399,20 +399,20 @@ pcl::SampleConsensusModelSphere::projectPoints ( pcl::for_each_type (NdConcatenateFunctor (input_->points[i], projected_points.points[i])); // Iterate through the 3d points and calculate the distances from them to the sphere - for (std::size_t i = 0; i < inliers.size (); ++i) + for (const auto& inlier : inliers) { // what i have: // P : Sample Point - const Eigen::Vector3d P (input_->points[inliers[i]].x, input_->points[inliers[i]].y, input_->points[inliers[i]].z); + const Eigen::Vector3d P (input_->points[inlier].x, input_->points[inlier].y, input_->points[inlier].z); const Eigen::Vector3d direction = (P - C).normalized(); // K : Point on Sphere const Eigen::Vector3d K = C + r * direction; - projected_points.points[inliers[i]].x = static_cast (K[0]); - projected_points.points[inliers[i]].y = static_cast (K[1]); - projected_points.points[inliers[i]].z = static_cast (K[2]); + projected_points.points[inlier].x = static_cast (K[0]); + projected_points.points[inlier].y = static_cast (K[1]); + projected_points.points[inlier].z = static_cast (K[2]); } } else diff --git a/test/features/test_normal_estimation.cpp b/test/features/test_normal_estimation.cpp index d1eb8d5e0aa..558ab312991 100644 --- a/test/features/test_normal_estimation.cpp +++ b/test/features/test_normal_estimation.cpp @@ -191,10 +191,10 @@ TEST (PCL, TranslatedNormalEstimation) NormalEstimation n; PointCloud translatedCloud(cloud); - for(size_t i = 0; i < translatedCloud.size(); ++i) { - translatedCloud[i].x += 100; - translatedCloud[i].y += 100; - translatedCloud[i].z += 100; + for(auto & i : translatedCloud) { + i.x += 100; + i.y += 100; + i.z += 100; } // computePointNormal (indices, Vector) diff --git a/test/io/test_iterators.cpp b/test/io/test_iterators.cpp index c44cbd564be..d09c71e8ec2 100644 --- a/test/io/test_iterators.cpp +++ b/test/io/test_iterators.cpp @@ -59,7 +59,9 @@ TEST (PCL, Iterators) { Point mean (0,0,0); - for (auto it = cloud.begin(); it != cloud.end(); ++it) + // Disable lint since this test is testing begin() and end() + // NOLINTNEXTLINE(modernize-loop-convert) + for (auto it = cloud.begin(); it != cloud.end(); ++it) { for (int i=0;i<3;i++) mean.data[i] += it->data[i]; } diff --git a/test/io/test_octree_compression.cpp b/test/io/test_octree_compression.cpp index 6cf9f2f2342..a044a33b07f 100644 --- a/test/io/test_octree_compression.cpp +++ b/test/io/test_octree_compression.cpp @@ -177,8 +177,8 @@ TEST(PCL, OctreeDeCompressionFile) pcl::io::OctreePointCloudCompression PointCloudDecoder; // iterate over various voxel sizes - for (std::size_t i = 0; i < sizeof(voxel_sizes)/sizeof(voxel_sizes[0]); i++) { - pcl::octree::OctreePointCloud octree(voxel_sizes[i]); + for (const float& voxel_size : voxel_sizes) { + pcl::octree::OctreePointCloud octree(voxel_size); pcl::PointCloud::Ptr cloud_out(new pcl::PointCloud()); octree.setInputCloud((*input_cloud_ptr).makeShared()); octree.addPointsFromInputCloud(); diff --git a/test/search/test_organized_index.cpp b/test/search/test_organized_index.cpp index f4ba1e4c390..582099e7bc5 100644 --- a/test/search/test_organized_index.cpp +++ b/test/search/test_organized_index.cpp @@ -303,9 +303,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search) // bruteforce radius search std::size_t cloudSearchBruteforce_size_lower = 0, cloudSearchBruteforce_size_upper = 0; - for (auto it = cloudIn->points.cbegin(); it != cloudIn->points.cend(); ++it) + for (const auto& point : cloudIn->points) { - const auto pointDist = pcl_tests::point_distance(*it, searchPoint); + const auto pointDist = pcl_tests::point_distance(point, searchPoint); if (pointDist <= (searchRadius+TOLERANCE)) { ++cloudSearchBruteforce_size_upper; @@ -501,9 +501,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_ // bruteforce radius search std::size_t cloudSearchBruteforce_size_lower = 0, cloudSearchBruteforce_size_upper = 0; - for (auto it = cloudIn->points.cbegin(); it != cloudIn->points.cend(); ++it) + for (const auto& point : cloudIn->points) { - const auto pointDist = pcl_tests::point_distance(*it, searchPoint); + const auto pointDist = pcl_tests::point_distance(point, searchPoint); if (pointDist <= (searchRadius+TOLERANCE)) { ++cloudSearchBruteforce_size_upper; diff --git a/test/surface/test_poisson.cpp b/test/surface/test_poisson.cpp index 75491a17592..b6a0ec1bf10 100644 --- a/test/surface/test_poisson.cpp +++ b/test/surface/test_poisson.cpp @@ -75,8 +75,8 @@ TEST (PCL, Poisson) ASSERT_EQ (mesh.polygons.size (), 4828); // All polygons should be triangles - for (std::size_t i = 0; i < mesh.polygons.size (); ++i) - EXPECT_EQ (mesh.polygons[i].vertices.size (), 3); + for (const auto & polygon : mesh.polygons) + EXPECT_EQ (polygon.vertices.size (), 3); EXPECT_EQ (mesh.polygons[10].vertices[0], 197); EXPECT_EQ (mesh.polygons[10].vertices[1], 198); diff --git a/tools/fast_bilateral_filter.cpp b/tools/fast_bilateral_filter.cpp index 1832d83e2bf..0c3d8d2fa8c 100644 --- a/tools/fast_bilateral_filter.cpp +++ b/tools/fast_bilateral_filter.cpp @@ -116,13 +116,15 @@ batchProcess (const std::vector &pcd_files, std::string &output_dir #pragma omp parallel for \ default(none) \ shared(output_dir, pcd_files, sigma_r, sigma_s) + // Disable lint since this 'for' is part of the pragma + // NOLINTNEXTLINE(modernize-loop-convert) for (int i = 0; i < static_cast(pcd_files.size ()); ++i) { // Load the first file Eigen::Vector4f translation; Eigen::Quaternionf rotation; pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2); - if (!loadCloud (pcd_files[i], *cloud, translation, rotation)) + if (!loadCloud (pcd_files[i], *cloud, translation, rotation)) continue; // Perform the feature estimation diff --git a/tools/normal_estimation.cpp b/tools/normal_estimation.cpp index f340ddb8816..aee26bf2aeb 100644 --- a/tools/normal_estimation.cpp +++ b/tools/normal_estimation.cpp @@ -135,13 +135,15 @@ batchProcess (const std::vector &pcd_files, std::string &output_dir #pragma omp parallel for \ default(none) \ shared(k, output_dir, pcd_files, radius) + // Disable lint since this 'for' is part of the pragma + // NOLINTNEXTLINE(modernize-loop-convert) for (int i = 0; i < static_cast(pcd_files.size ()); ++i) { // Load the first file Eigen::Vector4f translation; Eigen::Quaternionf rotation; pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2); - if (!loadCloud (pcd_files[i], *cloud, translation, rotation)) + if (!loadCloud (pcd_files[i], *cloud, translation, rotation)) continue; // Perform the feature estimation