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

Review casts in PCL, Part B #5508

4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
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,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-type-promotion-in-math-fn,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-static-cast-downcast'
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,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-type-promotion-in-math-fn,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-static-cast-downcast'
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,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-type-promotion-in-math-fn,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-static-cast-downcast,google-readability-casting'
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,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-type-promotion-in-math-fn,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-static-cast-downcast,google-readability-casting'
CheckOptions:
- {key: modernize-use-auto.MinTypeNameLength, value: 7}
2 changes: 1 addition & 1 deletion 2d/include/pcl/2d/impl/edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Edge<PointInT, PointOutT>::suppressNonMaxima(

// maxima (j, i).intensity = 0;

switch (int(ptedge.direction)) {
switch (static_cast<int>(ptedge.direction)) {
case 0: {
if (ptedge.magnitude >= edges(j - 1, i).magnitude &&
ptedge.magnitude >= edges(j + 1, i).magnitude)
Expand Down
9 changes: 5 additions & 4 deletions 2d/include/pcl/2d/impl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ kernel<PointT>::gaussianKernel(pcl::PointCloud<PointT>& kernel)
for (int j = 0; j < kernel_size_; j++) {
int iks = (i - kernel_size_ / 2);
int jks = (j - kernel_size_ / 2);
kernel(j, i).intensity =
std::exp(float(-double(iks * iks + jks * jks) / sigma_sqr));
sum += float(kernel(j, i).intensity);
kernel(j, i).intensity = std::exp(
static_cast<float>(-static_cast<double>(iks * iks + jks * jks) / sigma_sqr));
sum += (kernel(j, i).intensity);
}
}

Expand All @@ -132,7 +132,8 @@ 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);
float temp =
static_cast<float>(static_cast<double>(iks * iks + jks * jks) / sigma_sqr);
kernel(j, i).intensity = (1.0f - temp) * std::exp(-temp);
sum += kernel(j, i).intensity;
}
Expand Down
12 changes: 6 additions & 6 deletions common/include/pcl/common/impl/bivariate_polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ BivariatePolynomialT<real>::findCriticalPoints (std::vector<real>& x_values, std

if (degree == 2)
{
real x = (real(2)*parameters[2]*parameters[3] - parameters[1]*parameters[4]) /
(parameters[1]*parameters[1] - real(4)*parameters[0]*parameters[3]),
y = (real(-2)*parameters[0]*x - parameters[2]) / parameters[1];
real x = (static_cast<real>(2)*parameters[2]*parameters[3] - parameters[1]*parameters[4]) /
(parameters[1]*parameters[1] - static_cast<real>(4)*parameters[0]*parameters[3]),
y = (static_cast<real>(-2)*parameters[0]*x - parameters[2]) / parameters[1];

if (!std::isfinite(x) || !std::isfinite(y))
return;

int type = 2;
real det_H = real(4)*parameters[0]*parameters[3] - parameters[1]*parameters[1];
real det_H = static_cast<real>(4)*parameters[0]*parameters[3] - parameters[1]*parameters[1];
//std::cout << "det(H) = "<<det_H<<"\n";
if (det_H > real(0)) // Check Hessian determinant
if (det_H > static_cast<real>(0)) // Check Hessian determinant
{
if (parameters[0]+parameters[3] < real(0)) // Check Hessian trace
if (parameters[0]+parameters[3] < static_cast<real>(0)) // Check Hessian trace
type = 0;
else
type = 1;
Expand Down
8 changes: 4 additions & 4 deletions common/include/pcl/common/impl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pcl::getPointsInBox (const pcl::PointCloud<PointT> &cloud,
continue;
if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
continue;
indices[l++] = int (i);
indices[l++] = static_cast<int>(i);
}
}
// NaN or Inf values could exist => check for them
Expand All @@ -186,7 +186,7 @@ pcl::getPointsInBox (const pcl::PointCloud<PointT> &cloud,
continue;
if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
continue;
indices[l++] = int (i);
indices[l++] = static_cast<int>(i);
}
}
indices.resize (l);
Expand All @@ -210,7 +210,7 @@ pcl::getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f
dist = (pivot_pt3 - pt).norm ();
if (dist > max_dist)
{
max_idx = int (i);
max_idx = static_cast<int>(i);
max_dist = dist;
}
}
Expand All @@ -227,7 +227,7 @@ pcl::getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f
dist = (pivot_pt3 - pt).norm ();
if (dist > max_dist)
{
max_idx = int (i);
max_idx = static_cast<int>(i);
max_dist = dist;
}
}
Expand Down
12 changes: 6 additions & 6 deletions common/include/pcl/common/impl/pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ PCA<PointT>::initCompute ()
demeanPointCloud (*input_, *indices_, mean_, cloud_demean);
assert (cloud_demean.cols () == int (indices_->size ()));
// Compute the product cloud_demean * cloud_demean^T
const Eigen::Matrix3f alpha = (1.f / (float (indices_->size ()) - 1.f))
const Eigen::Matrix3f alpha = (1.f / (static_cast<float>(indices_->size ()) - 1.f))
* cloud_demean.topRows<3> () * cloud_demean.topRows<3> ().transpose ();

// Compute eigen vectors and values
Expand Down Expand Up @@ -102,7 +102,7 @@ PCA<PointT>::update (const PointT& input_point, FLAG flag)

Eigen::Vector3f input (input_point.x, input_point.y, input_point.z);
const std::size_t n = eigenvectors_.cols ();// number of eigen vectors
Eigen::VectorXf meanp = (float(n) * (mean_.head<3>() + input)) / float(n + 1);
Eigen::VectorXf meanp = (static_cast<float>(n) * (mean_.head<3>() + input)) / static_cast<float>(n + 1);
Eigen::VectorXf a = eigenvectors_.transpose() * (input - mean_.head<3>());
Eigen::VectorXf y = (eigenvectors_ * a) + mean_.head<3>();
Eigen::VectorXf h = y - input;
Expand All @@ -113,12 +113,12 @@ PCA<PointT>::update (const PointT& input_point, FLAG flag)
float gamma = h.dot(input - mean_.head<3>());
Eigen::MatrixXf D = Eigen::MatrixXf::Zero (a.size() + 1, a.size() + 1);
D.block(0,0,n,n) = a * a.transpose();
D /= float(n)/float((n+1) * (n+1));
D /= static_cast<float>(n)/static_cast<float>((n+1) * (n+1));
for(std::size_t i=0; i < a.size(); i++) {
D(i,i)+= float(n)/float(n+1)*eigenvalues_(i);
D(D.rows()-1,i) = float(n) / float((n+1) * (n+1)) * gamma * a(i);
D(i,i)+= static_cast<float>(n)/static_cast<float>(n+1)*eigenvalues_(i);
D(D.rows()-1,i) = static_cast<float>(n) / static_cast<float>((n+1) * (n+1)) * gamma * a(i);
D(i,D.cols()-1) = D(D.rows()-1,i);
D(D.rows()-1,D.cols()-1) = float(n)/float((n+1) * (n+1)) * gamma * gamma;
D(D.rows()-1,D.cols()-1) = static_cast<float>(n)/static_cast<float>((n+1) * (n+1)) * gamma * gamma;
}

Eigen::MatrixXf R(D.rows(), D.cols());
Expand Down
8 changes: 4 additions & 4 deletions common/include/pcl/impl/cloud_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ namespace pcl

unsigned getCurrentPointIndex () const override
{
return (unsigned (iterator_ - cloud_.begin ()));
return (static_cast<unsigned>(iterator_ - cloud_.begin ()));
}

unsigned getCurrentIndex () const override
{
return (unsigned (iterator_ - cloud_.begin ()));
return (static_cast<unsigned>(iterator_ - cloud_.begin ()));
}

std::size_t size () const override
Expand Down Expand Up @@ -292,12 +292,12 @@ namespace pcl

unsigned getCurrentPointIndex () const override
{
return (unsigned (*iterator_));
return (static_cast<unsigned>(*iterator_));
}

unsigned getCurrentIndex () const override
{
return (unsigned (iterator_ - indices_.begin ()));
return (static_cast<unsigned>(iterator_ - indices_.begin ()));
}

std::size_t size () const override
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 @@ -661,7 +661,7 @@ RangeImage::getAcutenessValue (const PointWithRange& point1, const PointWithRang
float impact_angle = getImpactAngle (point1, point2);
if (std::isinf (impact_angle))
return -std::numeric_limits<float>::infinity ();
float ret = 1.0f - float (std::fabs (impact_angle)/ (0.5f*M_PI));
float ret = 1.0f - static_cast<float>(std::fabs (impact_angle)/ (0.5f*M_PI));
if (impact_angle < 0.0f)
ret = -ret;
//if (std::abs (ret)>1)
Expand Down
18 changes: 7 additions & 11 deletions common/src/PCLPointCloud2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ pcl::PCLPointCloud2::concatenate (pcl::PCLPointCloud2 &cloud1, const pcl::PCLPoi
const auto size1 = cloud1.width * cloud1.height;
const auto size2 = cloud2.width * cloud2.height;
//if one input cloud has no points, but the other input does, just select the cloud with points
switch ((bool (size1) << 1) + bool (size2))
{
case 1:
cloud1 = cloud2;
PCL_FALLTHROUGH
case 0:
case 2:
cloud1.header.stamp = std::max (cloud1.header.stamp, cloud2.header.stamp);
return (true);
default:
break;
if ((size1 == 0) && (size2 != 0)) {
cloud1 = cloud2;
}

if ((size1 == 0) || (size2 == 0)) {
cloud1.header.stamp = std::max (cloud1.header.stamp, cloud2.header.stamp);
return true;
}

// Ideally this should be in PCLPointField class since this is global behavior
Expand Down
2 changes: 1 addition & 1 deletion common/src/bearing_angle_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ BearingAngleImage::generateBAImage (PointCloud<PointXYZ>& point_cloud)
points[(i + 1) * width + j].y = point_cloud.at (j, i + 1).y;
points[(i + 1) * width + j].z = point_cloud.at (j, i + 1).z;
// set the gray value for every pixel point
points[(i + 1) * width + j].rgba = ((int)r) << 24 | ((int)g) << 16 | ((int)b) << 8 | 0xff;
points[(i + 1) * width + j].rgba = (static_cast<int>(r)) << 24 | (static_cast<int>(g)) << 16 | (static_cast<int>(b)) << 8 | 0xff;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/src/colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ pcl::getRandomColor (double min, double max)
}
while (sum <= min || sum >= max);
pcl::RGB color;
color.r = std::uint8_t (r * 255.0);
color.g = std::uint8_t (g * 255.0);
color.b = std::uint8_t (b * 255.0);
color.r = static_cast<std::uint8_t>(r * 255.0);
color.g = static_cast<std::uint8_t>(g * 255.0);
color.b = static_cast<std::uint8_t>(b * 255.0);
return (color);
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/gaussian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pcl::GaussianKernel::compute (float sigma,
kernel.resize (kernel_width);
derivative.resize (kernel_width);
const float factor = 0.01f;
float max_gauss = 1.0f, max_deriv = float (sigma * std::exp (-0.5));
float max_gauss = 1.0f, max_deriv = static_cast<float>(sigma * std::exp (-0.5));
int hw = kernel_width / 2;

float sigma_sqr = 1.0f / (2.0f * sigma * sigma);
Expand Down
36 changes: 18 additions & 18 deletions common/src/range_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ float*
RangeImage::getInterpolatedSurfaceProjection (const Eigen::Affine3f& pose, int pixel_size, float world_size) const
{
float max_dist = 0.5f*world_size,
cell_size = world_size/float (pixel_size);
cell_size = world_size/static_cast<float>(pixel_size);
float world2cell_factor = 1.0f/cell_size,
world2cell_offset = 0.5f*float (pixel_size)-0.5f;
world2cell_offset = 0.5f*static_cast<float>(pixel_size)-0.5f;
float cell2world_factor = cell_size,
cell2world_offset = -max_dist + 0.5f*cell_size;
Eigen::Affine3f inverse_pose = pose.inverse (Eigen::Isometry);
Expand Down Expand Up @@ -537,11 +537,11 @@ RangeImage::getInterpolatedSurfaceProjection (const Eigen::Affine3f& pose, int p
cell3_y = world2cell_factor*point3[1] + world2cell_offset,
cell3_z = point3[2];

int min_cell_x = (std::max) (0, int (pcl_lrint (std::ceil ( (std::min) (cell1_x, (std::min) (cell2_x, cell3_x)))))),
max_cell_x = (std::min) (pixel_size-1, int (pcl_lrint (std::floor ( (std::max) (cell1_x,
int min_cell_x = (std::max) (0, static_cast<int>(pcl_lrint (std::ceil ( (std::min) (cell1_x, (std::min) (cell2_x, cell3_x)))))),
max_cell_x = (std::min) (pixel_size-1, static_cast<int>(pcl_lrint (std::floor ( (std::max) (cell1_x,
(std::max) (cell2_x, cell3_x)))))),
min_cell_y = (std::max) (0, int (pcl_lrint (std::ceil ( (std::min) (cell1_y, (std::min) (cell2_y, cell3_y)))))),
max_cell_y = (std::min) (pixel_size-1, int (pcl_lrint (std::floor ( (std::max) (cell1_y,
min_cell_y = (std::max) (0, static_cast<int>(pcl_lrint (std::ceil ( (std::min) (cell1_y, (std::min) (cell2_y, cell3_y)))))),
max_cell_y = (std::min) (pixel_size-1, static_cast<int>(pcl_lrint (std::floor ( (std::max) (cell1_y,
(std::max) (cell2_y, cell3_y))))));
if (max_cell_x<min_cell_x || max_cell_y<min_cell_y)
continue;
Expand Down Expand Up @@ -720,9 +720,9 @@ RangeImage::getSurfaceAngleChangeImages (int radius, float*& angle_change_image_
int size = width*height;
angle_change_image_x = new float[size];
angle_change_image_y = new float[size];
for (int y=0; y<int (height); ++y)
for (int y=0; y<static_cast<int>(height); ++y)
{
for (int x=0; x<int (width); ++x)
for (int x=0; x<static_cast<int>(width); ++x)
{
int index = y*width+x;
getSurfaceAngleChange (x, y, radius, angle_change_image_x[index], angle_change_image_y[index]);
Expand All @@ -739,9 +739,9 @@ RangeImage::getAcutenessValueImages (int pixel_distance, float*& acuteness_value
int size = width*height;
acuteness_value_image_x = new float[size];
acuteness_value_image_y = new float[size];
for (int y=0; y<int (height); ++y)
for (int y=0; y<static_cast<int>(height); ++y)
{
for (int x=0; x<int (width); ++x)
for (int x=0; x<static_cast<int>(width); ++x)
{
int index = y*width+x;
acuteness_value_image_x[index] = getAcutenessValue (x, y, x+pixel_distance, y);
Expand All @@ -757,9 +757,9 @@ RangeImage::getImpactAngleImageBasedOnLocalNormals (int radius) const
MEASURE_FUNCTION_TIME;
int size = width*height;
float* impact_angle_image = new float[size];
for (int y=0; y<int (height); ++y)
for (int y=0; y<static_cast<int>(height); ++y)
{
for (int x=0; x<int (width); ++x)
for (int x=0; x<static_cast<int>(width); ++x)
{
impact_angle_image[y*width+x] = getImpactAngleBasedOnLocalNormal (x, y, radius);
}
Expand All @@ -776,9 +776,9 @@ RangeImage::getRangeImageWithSmoothedSurface (int radius, RangeImage& smoothed_r

smoothed_range_image = *this;
Eigen::Vector3f sensor_pos = getSensorPos ();
for (int y=0; y<int (height); ++y)
for (int y=0; y<static_cast<int>(height); ++y)
{
for (int x=0; x<int (width); ++x)
for (int x=0; x<static_cast<int>(width); ++x)
{
PointWithRange& point = smoothed_range_image.getPoint (x, y);
if (std::isinf (point.range))
Expand Down Expand Up @@ -874,9 +874,9 @@ RangeImage::getOverlap (const RangeImage& other_range_image, const Eigen::Affine
reduction(+ : valid_points_counter) \
reduction(+ : hits_counter) \
num_threads(max_no_of_threads)
for (int other_y=0; other_y<int (other_range_image.height); other_y+=pixel_step)
for (int other_y=0; other_y<static_cast<int>(other_range_image.height); other_y+=pixel_step)
{
for (int other_x=0; other_x<int (other_range_image.width); other_x+=pixel_step)
for (int other_x=0; other_x<static_cast<int>(other_range_image.width); other_x+=pixel_step)
{
const PointWithRange& point = other_range_image.getPoint (other_x, other_y);
if (!std::isfinite (point.range))
Expand Down Expand Up @@ -920,9 +920,9 @@ RangeImage::getBlurredImageUsingIntegralImage (int blur_radius, float* integral_
RangeImage& blurred_image) const
{
this->copyTo(blurred_image);
for (int y=0; y<int (height); ++y)
for (int y=0; y<static_cast<int>(height); ++y)
{
for (int x=0; x<int (width); ++x)
for (int x=0; x<static_cast<int>(width); ++x)
{
const PointWithRange& old_point = getPoint (x, y);
PointWithRange& new_point = blurred_image.getPoint (x, y);
Expand Down
2 changes: 1 addition & 1 deletion examples/features/example_difference_of_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main (int argc, char *argv[])

// Create downsampled point cloud for DoN NN search with large scale
large_cloud_downsampled = PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>);
constexpr float largedownsample = float(scale2 / decimation);
constexpr float largedownsample = static_cast<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
20 changes: 10 additions & 10 deletions examples/segmentation/example_cpc_segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,39 @@ keyboardEventOccurred (const pcl::visualization::KeyboardEvent& event_arg,
if (event_arg.keyUp ())
switch (key)
{
case (int) '1':
case static_cast<int>('1'):
show_normals = !show_normals;
normals_changed = true;
break;
case (int) '2':
case static_cast<int>('2'):
show_adjacency = !show_adjacency;
break;
case (int) '3':
case static_cast<int>('3'):
show_supervoxels = !show_supervoxels;
break;
case (int) '4':
case static_cast<int>('4'):
show_segmentation = !show_segmentation;
break;
case (int) '5':
case static_cast<int>('5'):
normals_scale *= 1.25;
normals_changed = true;
break;
case (int) '6':
case static_cast<int>('6'):
normals_scale *= 0.8;
normals_changed = true;
break;
case (int) '7':
case static_cast<int>('7'):
line_width += 0.5;
line_changed = true;
break;
case (int) '8':
case static_cast<int>('8'):
if (line_width <= 1)
break;
line_width -= 0.5;
line_changed = true;
break;
case (int) 'd':
case (int) 'D':
case static_cast<int>('d'):
case static_cast<int>('D'):
show_help = !show_help;
break;
default:
Expand Down
Loading