Skip to content

Commit b551ee4

Browse files
authored
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
1 parent 83d3ba5 commit b551ee4

File tree

26 files changed

+106
-98
lines changed

26 files changed

+106
-98
lines changed

.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ Checks: >
55
cppcoreguidelines-pro-type-static-cast-downcast,
66
google-readability-casting,
77
modernize-deprecated-headers,
8+
modernize-loop-convert,
89
modernize-redundant-void-arg,
910
modernize-replace-random-shuffle,
1011
modernize-return-braced-init-list,
12+
modernize-shrink-to-fit,
1113
modernize-use-auto,
14+
modernize-use-emplace,
1215
modernize-use-equals-default,
1316
modernize-use-equals-delete,
1417
modernize-use-nullptr,

common/include/pcl/point_types_conversion.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ namespace pcl
173173
f[2] /= 1.08883;
174174

175175
// CIEXYZ -> CIELAB
176-
for (int i = 0; i < 3; ++i) {
177-
if (f[i] > 0.008856) {
178-
f[i] = std::pow(f[i], 1.0 / 3.0);
176+
for (float & xyz : f) {
177+
if (xyz > 0.008856) {
178+
xyz = std::pow(xyz, 1.0 / 3.0);
179179
}
180180
else {
181-
f[i] = 7.787 * f[i] + 16.0 / 116.0;
181+
xyz = 7.787 * xyz + 16.0 / 116.0;
182182
}
183183
}
184184

features/include/pcl/features/impl/multiscale_feature_persistence.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ pcl::MultiscaleFeaturePersistence<PointSource, PointFeature>::computeFeaturesAtA
9191
features_at_scale_.reserve (scale_values_.size ());
9292
features_at_scale_vectorized_.clear ();
9393
features_at_scale_vectorized_.reserve (scale_values_.size ());
94-
for (std::size_t scale_i = 0; scale_i < scale_values_.size (); ++scale_i)
94+
for (float & scale_value : scale_values_)
9595
{
9696
FeatureCloudPtr feature_cloud (new FeatureCloud ());
97-
computeFeatureAtScale (scale_values_[scale_i], feature_cloud);
97+
computeFeatureAtScale (scale_value, feature_cloud);
9898
features_at_scale_.push_back(feature_cloud);
9999

100100
// Vectorize each feature and insert it into the vectorized feature storage

features/include/pcl/features/our_cvfh.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ namespace pcl
190190
inline void
191191
getCentroidClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
192192
{
193-
for (std::size_t i = 0; i < centroids_dominant_orientations_.size (); ++i)
194-
centroids.push_back (centroids_dominant_orientations_[i]);
193+
for (const auto & centroids_dominant_orientation : centroids_dominant_orientations_)
194+
centroids.push_back (centroids_dominant_orientation);
195195
}
196196

197197
/** \brief Get the normal centroids used to compute different CVFH descriptors
@@ -200,8 +200,8 @@ namespace pcl
200200
inline void
201201
getCentroidNormalClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
202202
{
203-
for (std::size_t i = 0; i < dominant_normals_.size (); ++i)
204-
centroids.push_back (dominant_normals_[i]);
203+
for (const auto & dominant_normal : dominant_normals_)
204+
centroids.push_back (dominant_normal);
205205
}
206206

207207
/** \brief Sets max. Euclidean distance between points to be added to the cluster

features/src/narf.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud<
376376
schedule(dynamic, 10) \
377377
num_threads(max_no_of_threads)
378378
//!!! nizar 20110408 : for OpenMP sake on MSVC this must be kept signed
379+
// Disable lint since this 'for' is part of the pragma
380+
// NOLINTNEXTLINE(modernize-loop-convert)
379381
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t>(interest_points.size ()); ++idx)
380382
{
381383
const auto& interest_point = interest_points[idx];
@@ -389,7 +391,7 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud<
389391
else {
390392
if (!rotation_invariant)
391393
{
392-
# pragma omp critical
394+
#pragma omp critical
393395
{
394396
feature_list.push_back(feature);
395397
}
@@ -409,7 +411,7 @@ Narf::extractForInterestPoints (const RangeImage& range_image, const PointCloud<
409411
delete feature2;
410412
continue;
411413
}
412-
# pragma omp critical
414+
#pragma omp critical
413415
{
414416
feature_list.push_back(feature2);
415417
}

filters/include/pcl/filters/impl/covariance_sampling.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pcl::CovarianceSampling<PointT, PointNT>::initCompute ()
7575
}
7676

7777
average_norm /= static_cast<double>(scaled_points_.size ());
78-
for (std::size_t p_i = 0; p_i < scaled_points_.size (); ++p_i)
79-
scaled_points_[p_i] /= static_cast<float>(average_norm);
78+
for (auto & scaled_point : scaled_points_)
79+
scaled_point /= static_cast<float>(average_norm);
8080

8181
return (true);
8282
}

filters/include/pcl/filters/impl/crop_hull.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ pcl::CropHull<PointT>::applyFilter3D (Indices &indices)
153153
Eigen::Vector3f(0.856514f, 0.508771f, 0.0868081f)
154154
};
155155

156-
for (std::size_t poly = 0; poly < hull_polygons_.size (); poly++)
156+
for (const auto & hull_polygon : hull_polygons_)
157157
for (std::size_t ray = 0; ray < 3; ray++)
158158
crossings[ray] += rayTriangleIntersect
159-
((*input_)[(*indices_)[index]], rays[ray], hull_polygons_[poly], *hull_cloud_);
159+
((*input_)[(*indices_)[index]], rays[ray], hull_polygon, *hull_cloud_);
160160

161161
bool crosses = (crossings[0]&1) + (crossings[1]&1) + (crossings[2]&1) > 1;
162162
if ((crop_outside_ && crosses) || (!crop_outside_ && !crosses))

filters/include/pcl/filters/impl/local_maximum.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ pcl::LocalMaximum<PointT>::applyFilterIndices (Indices &indices)
154154

155155
// Check to see if a neighbor is higher than the query point
156156
float query_z = (*input_)[iii].z;
157-
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 ">"
157+
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 ">"
158158
{
159-
if ((*input_)[radius_indices[k]].z > query_z)
159+
if ((*input_)[radius_index].z > query_z)
160160
{
161161
// Query point is not the local max, no need to check others
162162
point_is_max[iii] = false;
@@ -168,9 +168,9 @@ pcl::LocalMaximum<PointT>::applyFilterIndices (Indices &indices)
168168
// visited, excluding them from future consideration as local maxima
169169
if (point_is_max[iii])
170170
{
171-
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
171+
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
172172
{
173-
point_is_visited[radius_indices[k]] = true;
173+
point_is_visited[radius_index] = true;
174174
}
175175
}
176176

geometry/include/pcl/geometry/mesh_base.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,25 +323,28 @@ class MeshBase {
323323
}
324324

325325
// Adjust the indices
326-
for (auto it = vertices_.begin(); it != vertices_.end(); ++it) {
327-
if (it->idx_outgoing_half_edge_.isValid()) {
328-
it->idx_outgoing_half_edge_ =
329-
new_half_edge_indices[it->idx_outgoing_half_edge_.get()];
326+
for (auto& vertex : vertices_) {
327+
if (vertex.idx_outgoing_half_edge_.isValid()) {
328+
vertex.idx_outgoing_half_edge_ =
329+
new_half_edge_indices[vertex.idx_outgoing_half_edge_.get()];
330330
}
331331
}
332332

333-
for (auto it = half_edges_.begin(); it != half_edges_.end(); ++it) {
334-
it->idx_terminating_vertex_ =
335-
new_vertex_indices[it->idx_terminating_vertex_.get()];
336-
it->idx_next_half_edge_ = new_half_edge_indices[it->idx_next_half_edge_.get()];
337-
it->idx_prev_half_edge_ = new_half_edge_indices[it->idx_prev_half_edge_.get()];
338-
if (it->idx_face_.isValid()) {
339-
it->idx_face_ = new_face_indices[it->idx_face_.get()];
333+
for (auto& half_edge : half_edges_) {
334+
half_edge.idx_terminating_vertex_ =
335+
new_vertex_indices[half_edge.idx_terminating_vertex_.get()];
336+
half_edge.idx_next_half_edge_ =
337+
new_half_edge_indices[half_edge.idx_next_half_edge_.get()];
338+
half_edge.idx_prev_half_edge_ =
339+
new_half_edge_indices[half_edge.idx_prev_half_edge_.get()];
340+
if (half_edge.idx_face_.isValid()) {
341+
half_edge.idx_face_ = new_face_indices[half_edge.idx_face_.get()];
340342
}
341343
}
342344

343-
for (auto it = faces_.begin(); it != faces_.end(); ++it) {
344-
it->idx_inner_half_edge_ = new_half_edge_indices[it->idx_inner_half_edge_.get()];
345+
for (auto& face : faces_) {
346+
face.idx_inner_half_edge_ =
347+
new_half_edge_indices[face.idx_inner_half_edge_.get()];
345348
}
346349
}
347350

keypoints/include/pcl/keypoints/impl/smoothed_surfaces_keypoint.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pcl::SmoothedSurfacesKeypoint<PointT, PointNT>::addSmoothedPointCloud (const Poi
5252
clouds_.push_back (cloud);
5353
cloud_normals_.push_back (normals);
5454
cloud_trees_.push_back (kdtree);
55-
scales_.push_back (std::pair<float, std::size_t> (scale, scales_.size ()));
55+
scales_.emplace_back(scale, scales_.size ());
5656
}
5757

5858

@@ -115,15 +115,15 @@ pcl::SmoothedSurfacesKeypoint<PointT, PointNT>::detectKeypoints (PointCloudT &ou
115115
if (is_min || is_max)
116116
{
117117
bool passed_min = true, passed_max = true;
118-
for (std::size_t scale_i = 0; scale_i < scales_.size (); ++scale_i)
118+
for (const auto & scale : scales_)
119119
{
120-
std::size_t cloud_i = scales_[scale_i].second;
120+
std::size_t cloud_i = scale.second;
121121
// skip input cloud
122122
if (cloud_i == clouds_.size () - 1)
123123
continue;
124124

125125
nn_indices.clear (); nn_distances.clear ();
126-
cloud_trees_[cloud_i]->radiusSearch (point_i, scales_[scale_i].first * neighborhood_constant_, nn_indices, nn_distances);
126+
cloud_trees_[cloud_i]->radiusSearch (point_i, scale.first * neighborhood_constant_, nn_indices, nn_distances);
127127

128128
bool is_min_other_scale = true, is_max_other_scale = true;
129129
for (const auto &nn_index : nn_indices)
@@ -225,7 +225,7 @@ pcl::SmoothedSurfacesKeypoint<PointT, PointNT>::initCompute ()
225225
}
226226

227227
// Add the input cloud as the last index
228-
scales_.push_back (std::pair<float, std::size_t> (input_scale_, scales_.size ()));
228+
scales_.emplace_back(input_scale_, scales_.size ());
229229
clouds_.push_back (input_);
230230
cloud_normals_.push_back (normals_);
231231
cloud_trees_.push_back (tree_);
@@ -241,7 +241,7 @@ pcl::SmoothedSurfacesKeypoint<PointT, PointNT>::initCompute ()
241241
}
242242

243243
PCL_INFO ("Scales: ");
244-
for (std::size_t i = 0; i < scales_.size (); ++i) PCL_INFO ("(%d %f), ", scales_[i].second, scales_[i].first);
244+
for (const auto & scale : scales_) PCL_INFO ("(%d %f), ", scale.second, scale.first);
245245
PCL_INFO ("\n");
246246

247247
return (true);

keypoints/include/pcl/keypoints/impl/trajkovic_2d.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ TrajkovicKeypoint2D<PointInT, PointOutT, IntensityT>::detectKeypoints (PointClou
246246
shared(height, indices, occupency_map, output, width) \
247247
num_threads(threads_)
248248
#endif
249+
// Disable lint since this 'for' is part of the pragma
250+
// NOLINTNEXTLINE(modernize-loop-convert)
249251
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (indices.size ()); ++i)
250252
{
251253
int idx = indices[i];

ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,15 @@ DecisionTreeTrainer<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::
159159
if (!thresholds_.empty()) {
160160
// compute information gain for each threshold and store threshold with highest
161161
// information gain
162-
for (std::size_t threshold_index = 0; threshold_index < thresholds_.size();
163-
++threshold_index) {
162+
for (const float& threshold : thresholds_) {
164163

165-
const float information_gain =
166-
stats_estimator_->computeInformationGain(data_set_,
167-
examples,
168-
label_data,
169-
feature_results,
170-
flags,
171-
thresholds_[threshold_index]);
164+
const float information_gain = stats_estimator_->computeInformationGain(
165+
data_set_, examples, label_data, feature_results, flags, threshold);
172166

173167
if (information_gain > best_feature_information_gain) {
174168
best_feature_information_gain = information_gain;
175169
best_feature_index = static_cast<int>(feature_index);
176-
best_feature_threshold = thresholds_[threshold_index];
170+
best_feature_threshold = threshold;
177171
}
178172
}
179173
}

people/include/pcl/people/impl/head_based_subcluster.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ pcl::people::HeadBasedSubclustering<PointT>::subcluster (std::vector<pcl::people
270270
}
271271

272272
// Person clusters creation from clusters indices:
273-
for(std::vector<pcl::PointIndices>::const_iterator it = cluster_indices_.begin(); it != cluster_indices_.end(); ++it)
273+
for(const auto & cluster_index : cluster_indices_)
274274
{
275-
pcl::people::PersonCluster<PointT> cluster(cloud_, *it, ground_coeffs_, sqrt_ground_coeffs_, head_centroid_, vertical_); // PersonCluster creation
275+
pcl::people::PersonCluster<PointT> cluster(cloud_, cluster_index, ground_coeffs_, sqrt_ground_coeffs_, head_centroid_, vertical_); // PersonCluster creation
276276
clusters.push_back(cluster);
277277
}
278278

recognition/include/pcl/recognition/3rdparty/metslib/model.hh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#define METS_MODEL_HH_
3737

3838
namespace mets {
39+
// Exempt third-party code from clang-tidy
40+
// NOLINTBEGIN
3941

4042
/// @brief Type of the objective/cost function.
4143
///
@@ -656,7 +658,7 @@ namespace mets {
656658

657659
/// @brief Dtor.
658660
~swap_full_neighborhood() override {
659-
for(auto it = moves_m.begin();
661+
for(auto it = moves_m.begin();
660662
it != moves_m.end(); ++it)
661663
delete *it;
662664
}
@@ -681,7 +683,7 @@ namespace mets {
681683

682684
/// @brief Dtor.
683685
~invert_full_neighborhood() override {
684-
for(auto it = moves_m.begin();
686+
for(auto it = moves_m.begin();
685687
it != moves_m.end(); ++it)
686688
delete *it;
687689
}
@@ -711,7 +713,7 @@ namespace mets {
711713
const Tp r) const
712714
{ return l->operator==(*r); }
713715
};
714-
716+
// NOLINTEND
715717
}
716718

717719
//________________________________________________________________________

recognition/include/pcl/recognition/3rdparty/metslib/tabu-search.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ mets::tabu_list_chain::is_tabu(feasible_solution& sol, /* const */ move& mov) co
497497

498498
inline mets::simple_tabu_list::~simple_tabu_list()
499499
{
500-
for(move_map_type::iterator m = tabu_hash_m.begin();
500+
// Disable lint for third-party code
501+
// NOLINTNEXTLINE(modernize-loop-convert)
502+
for(move_map_type::iterator m = tabu_hash_m.begin();
501503
m!=tabu_hash_m.end(); ++m)
502504
delete m->first;
503505
}

recognition/include/pcl/recognition/impl/hv/hv_go.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ void pcl::GlobalHypothesesVerification<ModelT, SceneT>::SAOptimize(std::vector<i
410410
}
411411

412412
int occupied_multiple = 0;
413-
for(std::size_t i=0; i < complete_cloud_occupancy_by_RM_.size(); i++) {
414-
if(complete_cloud_occupancy_by_RM_[i] > 1) {
415-
occupied_multiple+=complete_cloud_occupancy_by_RM_[i];
413+
for(const auto& i : complete_cloud_occupancy_by_RM_) {
414+
if(i > 1) {
415+
occupied_multiple+=i;
416416
}
417417
}
418418

0 commit comments

Comments
 (0)