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

Add modernize-use-auto to clang-tidy checks #5394

Closed
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 .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
Checks: '-*,modernize-deprecated-headers,modernize-redundant-void-arg,modernize-replace-random-shuffle,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,modernize-use-using'
WarningsAsErrors: '-*,modernize-deprecated-headers,modernize-redundant-void-arg,modernize-replace-random-shuffle,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,modernize-use-using'
Checks: '-*,modernize-use-auto,modernize-deprecated-headers,modernize-redundant-void-arg,modernize-replace-random-shuffle,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,modernize-use-using'
WarningsAsErrors: '-*,modernize-use-auto,modernize-deprecated-headers,modernize-redundant-void-arg,modernize-replace-random-shuffle,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,modernize-use-using'
2 changes: 1 addition & 1 deletion 2d/include/pcl/2d/impl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ kernel<PointT>::loGKernel(pcl::PointCloud<PointT>& kernel)
for (int j = 0; j < kernel_size_; j++) {
int iks = (i - kernel_size_ / 2);
int jks = (j - kernel_size_ / 2);
float temp = float(double(iks * iks + jks * jks) / sigma_sqr);
auto temp = float(double(iks * iks + jks * jks) / sigma_sqr);
kernel(j, i).intensity = (1.0f - temp) * std::exp(-temp);
sum += kernel(j, i).intensity;
}
Expand Down
6 changes: 3 additions & 3 deletions common/include/pcl/common/impl/spring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ duplicateColumns (const PointCloud<PointT>& input, PointCloud<PointT>& output,
for (std::size_t j = 0; j < old_height; ++j)
for(std::size_t i = 0; i < amount; ++i)
{
typename PointCloud<PointT>::iterator start = output.begin () + (j * new_width);
auto start = output.begin () + (j * new_width);
output.insert (start, *start);
start = output.begin () + (j * new_width) + old_width + i;
output.insert (start, *start);
Expand Down Expand Up @@ -182,7 +182,7 @@ mirrorColumns (const PointCloud<PointT>& input, PointCloud<PointT>& output,
for (std::size_t j = 0; j < old_height; ++j)
for(std::size_t i = 0; i < amount; ++i)
{
typename PointCloud<PointT>::iterator start = output.begin () + (j * new_width);
auto start = output.begin () + (j * new_width);
output.insert (start, *(start + 2*i));
start = output.begin () + (j * new_width) + old_width + 2*i;
output.insert (start+1, *(start - 2*i));
Expand Down Expand Up @@ -254,7 +254,7 @@ deleteCols (const PointCloud<PointT>& input, PointCloud<PointT>& output,
std::uint32_t new_width = old_width - 2 * amount;
for(std::size_t j = 0; j < old_height; j++)
{
typename PointCloud<PointT>::iterator start = output.begin () + j * new_width;
auto start = output.begin () + j * new_width;
output.erase (start, start + amount);
start = output.begin () + (j+1) * new_width;
output.erase (start, start + amount);
Expand Down
10 changes: 5 additions & 5 deletions common/include/pcl/point_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace pcl

if (trivial_)
{
const float* temp = reinterpret_cast<const float*>(&p);
const auto* temp = reinterpret_cast<const float*>(&p);

for (int i = 0; i < nr_dimensions_; ++i)
{
Expand All @@ -120,7 +120,7 @@ namespace pcl
}
else
{
float *temp = new float[nr_dimensions_];
auto *temp = new float[nr_dimensions_];
copyToFloatArray (p, temp);

for (int i = 0; i < nr_dimensions_; ++i)
Expand All @@ -143,7 +143,7 @@ namespace pcl
template <typename OutputType> void
vectorize (const PointT &p, OutputType &out) const
{
float *temp = new float[nr_dimensions_];
auto *temp = new float[nr_dimensions_];
copyToFloatArray (p, temp);
if (alpha_.empty ())
{
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace pcl
copyToFloatArray (const PointDefault &p, float * out) const override
{
// If point type is unknown, treat it as a struct/array of floats
const float* ptr = reinterpret_cast<const float*> (&p);
const auto* ptr = reinterpret_cast<const float*> (&p);
std::copy_n(ptr, nr_dimensions_, out);
}
};
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace pcl
const std::uint8_t * data_ptr = reinterpret_cast<const std::uint8_t *> (&p1) +
pcl::traits::offset<PointDefault, Key>::value;
int nr_dims = NrDims;
const FieldT * array = reinterpret_cast<const FieldT *> (data_ptr);
const auto * array = reinterpret_cast<const FieldT *> (data_ptr);
for (int i = 0; i < nr_dims; ++i)
{
p2[f_idx++] = array[i];
Expand Down
4 changes: 2 additions & 2 deletions common/include/pcl/point_types_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace pcl
return;
}

const float diff = static_cast <float> (max - min);
const auto diff = static_cast <float> (max - min);
out.s = diff / static_cast <float> (max);

if (min == max) // diff == 0 -> division by zero
Expand Down Expand Up @@ -209,7 +209,7 @@ namespace pcl
return;
}

const float diff = static_cast <float> (max - min);
const auto diff = static_cast <float> (max - min);
out.s = diff / static_cast <float> (max);

if (min == max) // diff == 0 -> division by zero
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/range_image/impl/range_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ RangeImage::getImpactAngle (const PointWithRange& point1, const PointWithRange&

float r1 = (std::min) (point1.range, point2.range),
r2 = (std::max) (point1.range, point2.range);
float impact_angle = static_cast<float> (0.5f * M_PI);
auto impact_angle = static_cast<float> (0.5f * M_PI);

if (std::isinf (r2))
{
Expand Down
2 changes: 1 addition & 1 deletion common/src/feature_histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pcl::FeatureHistogram::addValue (float value)
++number_of_elements_;

// Increase the bin.
std::size_t bin_number = static_cast<std::size_t> ((value - threshold_min_) / step_);
auto bin_number = static_cast<std::size_t> ((value - threshold_min_) / step_);
++histogram_[bin_number];
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pcl::console::parse_multiple_arguments (int argc, const char * const * argv, con
// Search for the string
if ((strcmp (argv[i], str) == 0) && (++i < argc))
{
float val = static_cast<float> (atof (argv[i]));
auto val = static_cast<float> (atof (argv[i]));
values.push_back (val);
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/src/range_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ float*
RangeImage::getRangesArray () const
{
int arraySize = width * height;
float* ranges = new float[arraySize];
auto* ranges = new float[arraySize];
for (int i=0; i<arraySize; ++i)
ranges[i] = points[i].range;
return ranges;
Expand Down Expand Up @@ -465,7 +465,7 @@ RangeImage::getInterpolatedSurfaceProjection (const Eigen::Affine3f& pose, int p
Eigen::Affine3f inverse_pose = pose.inverse (Eigen::Isometry);

int no_of_pixels = pixel_size*pixel_size;
float* surface_patch = new float[no_of_pixels];
auto* surface_patch = new float[no_of_pixels];
SET_ARRAY (surface_patch, -std::numeric_limits<float>::infinity (), no_of_pixels);

Eigen::Vector3f position = inverse_pose.translation ();
Expand Down Expand Up @@ -754,7 +754,7 @@ RangeImage::getImpactAngleImageBasedOnLocalNormals (int radius) const
{
MEASURE_FUNCTION_TIME;
int size = width*height;
float* impact_angle_image = new float[size];
auto* impact_angle_image = new float[size];
for (int y=0; y<int (height); ++y)
{
for (int x=0; x<int (width); ++x)
Expand Down
4 changes: 2 additions & 2 deletions examples/features/example_difference_of_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ int main (int argc, char *argv[])

// Create downsampled point cloud for DoN NN search with small scale
small_cloud_downsampled = PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>);
float smalldownsample = static_cast<float> (scale1 / decimation);
auto smalldownsample = static_cast<float> (scale1 / decimation);
sor.setLeafSize (smalldownsample, smalldownsample, smalldownsample);
sor.filter (*small_cloud_downsampled);
std::cout << "Using leaf size of " << smalldownsample << " for small scale, " << small_cloud_downsampled->size() << " points" << std::endl;

// Create downsampled point cloud for DoN NN search with large scale
large_cloud_downsampled = PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>);
const float largedownsample = float (scale2/decimation);
const auto largedownsample = float (scale2/decimation);
sor.setLeafSize (largedownsample, largedownsample, largedownsample);
sor.filter (*large_cloud_downsampled);
std::cout << "Using leaf size of " << largedownsample << " for large scale, " << large_cloud_downsampled->size() << " points" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion examples/segmentation/example_cpc_segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ CPCSegmentation Parameters: \n\

// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New ();
for (VertexIterator itr = vertex_iterator_range.first; itr != vertex_iterator_range.second; ++itr)
for (auto itr = vertex_iterator_range.first; itr != vertex_iterator_range.second; ++itr)
{
const std::uint32_t sv_label = sv_adjacency_list[*itr];
std::pair<AdjacencyIterator, AdjacencyIterator> neighbors = boost::adjacent_vertices (*itr, sv_adjacency_list);
Expand Down
2 changes: 1 addition & 1 deletion examples/segmentation/example_lccp_segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ LCCPSegmentation Parameters: \n\

// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New ();
for (VertexIterator itr = vertex_iterator_range.first; itr != vertex_iterator_range.second; ++itr)
for (auto itr = vertex_iterator_range.first; itr != vertex_iterator_range.second; ++itr)
{
const std::uint32_t sv_label = sv_adjacency_list[*itr];
std::pair<AdjacencyIterator, AdjacencyIterator> neighbors = boost::adjacent_vertices (*itr, sv_adjacency_list);
Expand Down
12 changes: 6 additions & 6 deletions features/include/pcl/features/impl/brisk_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::generateKernel (
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<unsigned int> (std::ceil (((scale_list_[scale] * radius_list[ring]) + pattern_iterator->sigma)) + 1);
const auto 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 Down Expand Up @@ -453,8 +453,8 @@ BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::compute (
}

// image size
const index_t width = static_cast<index_t>(input_cloud_->width);
const index_t height = static_cast<index_t>(input_cloud_->height);
const auto width = static_cast<index_t>(input_cloud_->width);
const auto height = static_cast<index_t>(input_cloud_->height);

// destination for intensity data; will be forwarded to BRISK
std::vector<unsigned char> image_data (width*height);
Expand All @@ -470,8 +470,8 @@ BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::compute (
// initialize constants
static const float lb_scalerange = std::log2 (scalerange_);

typename std::vector<KeypointT, Eigen::aligned_allocator<KeypointT> >::iterator beginning = keypoints_->points.begin ();
std::vector<int>::iterator beginningkscales = kscales.begin ();
auto beginning = keypoints_->points.begin ();
auto beginningkscales = kscales.begin ();

static const float basic_size_06 = basic_size_ * 0.6f;
unsigned int basicscale = 0;
Expand Down Expand Up @@ -636,7 +636,7 @@ BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::compute (
#endif

// now iterate through all the pairings
UINT32_ALIAS* ptr2 = reinterpret_cast<UINT32_ALIAS*> (ptr);
auto* ptr2 = reinterpret_cast<UINT32_ALIAS*> (ptr);
const BriskShortPair* max = short_pairs_ + no_short_pairs_;

for (BriskShortPair* iter = short_pairs_; iter < max; ++iter)
Expand Down
4 changes: 2 additions & 2 deletions features/include/pcl/features/impl/integral_image2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ IntegralImage2D<DataType, Dimension>::computeIntegralImages (
{
current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
const InputType* element = reinterpret_cast <const InputType*> (&data [valIdx]);
const auto* element = reinterpret_cast <const InputType*> (&data [valIdx]);
if (std::isfinite (element->sum ()))
{
current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
Expand Down Expand Up @@ -208,7 +208,7 @@ IntegralImage2D<DataType, Dimension>::computeIntegralImages (
so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];

const InputType* element = reinterpret_cast <const InputType*> (&data [valIdx]);
const auto* element = reinterpret_cast <const InputType*> (&data [valIdx]);
if (std::isfinite (element->sum ()))
{
current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
Expand Down
34 changes: 17 additions & 17 deletions features/include/pcl/features/impl/integral_image_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::initSimple3DGradientMet
// number of DataType entries per row (equal or bigger than element_stride number of elements per row)
int row_stride = element_stride * input_->width;

const float *data_ = reinterpret_cast<const float*> (&(*input_)[0]);
const auto *data_ = reinterpret_cast<const float*> (&(*input_)[0]);

integral_image_XYZ_.setSecondOrderComputation (false);
integral_image_XYZ_.setInput (data_, input_->width, input_->height, element_stride, row_stride);
Expand All @@ -127,7 +127,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::initCovarianceMatrixMet
// number of DataType entries per row (equal or bigger than element_stride number of elements per row)
int row_stride = element_stride * input_->width;

const float *data_ = reinterpret_cast<const float*> (&(*input_)[0]);
const auto *data_ = reinterpret_cast<const float*> (&(*input_)[0]);

integral_image_XYZ_.setSecondOrderComputation (true);
integral_image_XYZ_.setInput (data_, input_->width, input_->height, element_stride, row_stride);
Expand Down Expand Up @@ -196,7 +196,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::initAverageDepthChangeM
// number of DataType entries per row (equal or bigger than element_stride number of elements per row)
int row_stride = element_stride * input_->width;

const float *data_ = reinterpret_cast<const float*> (&(*input_)[0]);
const auto *data_ = reinterpret_cast<const float*> (&(*input_)[0]);

// integral image over the z - value
integral_image_depth_.setInput (&(data_[2]), input_->width, input_->height, element_stride, row_stride);
Expand Down Expand Up @@ -278,9 +278,9 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computePointNormal (

normal_vector /= sqrt (normal_length);

float nx = static_cast<float> (normal_vector [0]);
float ny = static_cast<float> (normal_vector [1]);
float nz = static_cast<float> (normal_vector [2]);
auto nx = static_cast<float> (normal_vector [0]);
auto ny = static_cast<float> (normal_vector [1]);
auto nz = static_cast<float> (normal_vector [2]);

flipNormalTowardsViewpoint ((*input_)[point_index], vpx_, vpy_, vpz_, nx, ny, nz);

Expand All @@ -307,10 +307,10 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computePointNormal (
return;
}

float mean_L_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_2_, pos_y - rect_height_4_, rect_width_2_, rect_height_2_) / count_L_z);
float mean_R_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x + 1 , pos_y - rect_height_4_, rect_width_2_, rect_height_2_) / count_R_z);
float mean_U_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_4_, pos_y - rect_height_2_, rect_width_2_, rect_height_2_) / count_U_z);
float mean_D_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_4_, pos_y + 1 , rect_width_2_, rect_height_2_) / count_D_z);
auto mean_L_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_2_, pos_y - rect_height_4_, rect_width_2_, rect_height_2_) / count_L_z);
auto mean_R_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x + 1 , pos_y - rect_height_4_, rect_width_2_, rect_height_2_) / count_R_z);
auto mean_U_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_4_, pos_y - rect_height_2_, rect_width_2_, rect_height_2_) / count_U_z);
auto mean_D_z = static_cast<float> (integral_image_depth_.getFirstOrderSum (pos_x - rect_width_4_, pos_y + 1 , rect_width_2_, rect_height_2_) / count_D_z);

PointInT pointL = (*input_)[point_index - rect_width_4_ - 1];
PointInT pointR = (*input_)[point_index + rect_width_4_ + 1];
Expand Down Expand Up @@ -371,9 +371,9 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computePointNormal (

normal_vector /= sqrt (normal_length);

float nx = static_cast<float> (normal_vector [0]);
float ny = static_cast<float> (normal_vector [1]);
float nz = static_cast<float> (normal_vector [2]);
auto nx = static_cast<float> (normal_vector [0]);
auto ny = static_cast<float> (normal_vector [1]);
auto nz = static_cast<float> (normal_vector [2]);

flipNormalTowardsViewpoint ((*input_)[point_index], vpx_, vpy_, vpz_, nx, ny, nz);

Expand Down Expand Up @@ -585,9 +585,9 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computePointNormalMirro

normal_vector /= sqrt (normal_length);

float nx = static_cast<float> (normal_vector [0]);
float ny = static_cast<float> (normal_vector [1]);
float nz = static_cast<float> (normal_vector [2]);
auto nx = static_cast<float> (normal_vector [0]);
auto ny = static_cast<float> (normal_vector [1]);
auto nz = static_cast<float> (normal_vector [2]);

flipNormalTowardsViewpoint ((*input_)[point_index], vpx_, vpy_, vpz_, nx, ny, nz);

Expand Down Expand Up @@ -738,7 +738,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeature (PointCl
float bad_point = std::numeric_limits<float>::quiet_NaN ();

// compute depth-change map
unsigned char * depthChangeMap = new unsigned char[input_->size ()];
auto * depthChangeMap = new unsigned char[input_->size ()];
memset (depthChangeMap, 255, input_->size ());

unsigned index = 0;
Expand Down
Loading