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

Prefer C++ method std::abs over C method abs #3271

Merged
merged 1 commit into from
Aug 8, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace pcl
PCL_ERROR("Eigen sum is not finite\n");
}

if ((fabs (eigenValues[0] - eigenValues[1]) < 1.5e-4) || (eigsum != 0 && fabs (eigenValues[0] / eigsum) > 1.e-2))
if ((std::abs (eigenValues[0] - eigenValues[1]) < 1.5e-4) || (eigsum != 0 && std::abs (eigenValues[0] / eigsum) > 1.e-2))
{
//region is not planar, add to filtered keypoint
keypoints_cloud->points[good] = keypoints_cloud->points[i];
Expand Down
4 changes: 2 additions & 2 deletions apps/point_cloud_editor/src/select2DTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ Select2DTool::drawRubberBand (GLint* viewport) const
void
Select2DTool::highlightPoints (GLint* viewport) const
{
double width = abs(origin_x_ - final_x_);
double height = abs(origin_y_ - final_y_);
double width = std::abs(origin_x_ - final_x_);
double height = std::abs(origin_y_ - final_y_);
glPushAttrib(GL_SCISSOR_BIT);
{
glEnable(GL_SCISSOR_TEST);
Expand Down
6 changes: 3 additions & 3 deletions apps/src/openni_tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ class OpenNISegmentTracking
for (size_t i = 0; i < cloud->points.size (); i++)
{
PointType point = cloud->points[i];
if (!(fabs(point.x) < 0.01 &&
fabs(point.y) < 0.01 &&
fabs(point.z) < 0.01) &&
if (!(std::abs(point.x) < 0.01 &&
std::abs(point.y) < 0.01 &&
std::abs(point.z) < 0.01) &&
!std::isnan(point.x) &&
!std::isnan(point.y) &&
!std::isnan(point.z))
Expand Down
4 changes: 2 additions & 2 deletions apps/src/organized_segmentation_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ compareClusterToRegion (pcl::PlanarRegion<PointT>& region, pcl::PointCloud<Point

for (const auto &point : cluster.points)
{
double ptp_dist = fabs (model[0] * point.x +
double ptp_dist = std::abs (model[0] * point.x +
model[1] * point.y +
model[2] * point.z +
model[3]);
Expand All @@ -156,7 +156,7 @@ comparePointToRegion (PointT& pt, pcl::ModelCoefficients& model, pcl::PointCloud
{
//bool dist_ok;

double ptp_dist = fabs (model.values[0] * pt.x +
double ptp_dist = std::abs (model.values[0] * pt.x +
model.values[1] * pt.y +
model.values[2] * pt.z +
model.values[3]);
Expand Down
2 changes: 1 addition & 1 deletion apps/src/render_views_tesselated_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews() {
//If the view up is parallel to ray cam_pos - focalPoint then the transformation
//is singular and no points are rendered...
//make sure it is perpendicular
if (fabs (cam_pos_3f.dot (test)) == 1)
if (std::abs (cam_pos_3f.dot (test)) == 1)
{
//parallel, create
test = cam_pos_3f.cross (Eigen::Vector3f::UnitX ());
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/common/impl/bivariate_polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pcl::operator<< (std::ostream& os, const pcl::BivariatePolynomialT<real>& p)
if (!first)
{
os << (currentParameter<0.0?" - ":" + ");
currentParameter = fabs (currentParameter);
currentParameter = std::abs (currentParameter);
}
os << currentParameter;
if (xDegree>0)
Expand Down
6 changes: 3 additions & 3 deletions common/include/pcl/common/impl/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pcl::computeRoots (const Matrix& m, Roots& roots)
m (1, 2) * m (1, 2);
Scalar c2 = m (0, 0) + m (1, 1) + m (2, 2);

if (fabs (c0) < Eigen::NumTraits < Scalar > ::epsilon ()) // one root is 0 -> quadratic equation
if (std::abs (c0) < Eigen::NumTraits < Scalar > ::epsilon ()) // one root is 0 -> quadratic equation
computeRoots2 (c2, c1, roots);
else
{
Expand Down Expand Up @@ -127,7 +127,7 @@ pcl::eigen22 (const Matrix& mat, typename Matrix::Scalar& eigenvalue, Vector& ei
{
// if diagonal matrix, the eigenvalues are the diagonal elements
// and the eigenvectors are not unique, thus set to Identity
if (fabs (mat.coeff (1)) <= std::numeric_limits<typename Matrix::Scalar>::min ())
if (std::abs (mat.coeff (1)) <= std::numeric_limits<typename Matrix::Scalar>::min ())
{
if (mat.coeff (0) < mat.coeff (2))
{
Expand Down Expand Up @@ -166,7 +166,7 @@ pcl::eigen22 (const Matrix& mat, Matrix& eigenvectors, Vector& eigenvalues)
{
// if diagonal matrix, the eigenvalues are the diagonal elements
// and the eigenvectors are not unique, thus set to Identity
if (fabs (mat.coeff (1)) <= std::numeric_limits<typename Matrix::Scalar>::min ())
if (std::abs (mat.coeff (1)) <= std::numeric_limits<typename Matrix::Scalar>::min ())
{
if (mat.coeff (0) < mat.coeff (3))
{
Expand Down
6 changes: 3 additions & 3 deletions common/include/pcl/common/impl/intersections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pcl::planeWithPlaneIntersection (const Eigen::Matrix<Scalar, 4, 1> &plane_a,

// Test if planes are parallel
double test_cos = plane_a_norm.dot (plane_b_norm);
double tolerance_cos = 1 - sin (fabs (angular_tolerance));
double tolerance_cos = 1 - sin (std::abs (angular_tolerance));

if (fabs (test_cos) > tolerance_cos)
if (std::abs (test_cos) > tolerance_cos)
{
PCL_DEBUG ("Plane A and Plane B are parallel.\n");
return (false);
Expand Down Expand Up @@ -142,7 +142,7 @@ pcl::threePlanesIntersection (const Eigen::Matrix<Scalar, 4, 1> &plane_a,
}

Scalar determinant = normals_in_lines.determinant ();
if (fabs (determinant) < determinant_tolerance)
if (std::abs (determinant) < determinant_tolerance)
{
// det ~= 0
PCL_DEBUG ("At least two planes are parallel.\n");
Expand Down
8 changes: 4 additions & 4 deletions common/include/pcl/common/impl/norms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ L1_Norm (FloatVectorT a, FloatVectorT b, int dim)
{
float norm = 0.0f;
for (int i = 0; i < dim; ++i)
norm += fabsf(a[i] - b[i]);
norm += std::abs(a[i] - b[i]);
return norm;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ Linf_Norm (FloatVectorT a, FloatVectorT b, int dim)
{
float norm = 0.0;
for (int i = 0; i < dim; ++i)
norm = (std::max)(fabsf(a[i] - b[i]), norm);
norm = (std::max)(std::abs(a[i] - b[i]), norm);
return norm;
}

Expand Down Expand Up @@ -158,7 +158,7 @@ Sublinear_Norm (FloatVectorT a, FloatVectorT b, int dim)
float norm = 0.0;

for (int i = 0; i < dim; ++i)
norm += std::sqrt (fabsf (a[i] - b[i]));
norm += std::sqrt (std::abs (a[i] - b[i]));

return norm;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ K_Norm (FloatVectorT a, FloatVectorT b, int dim, float P1, float P2)
float norm = 0.0;

for (int i = 0; i < dim; ++i)
norm += fabsf (P1 * a[i] - P2 * b[i]);
norm += std::abs (P1 * a[i] - P2 * b[i]);
return norm;
}

Expand Down
4 changes: 2 additions & 2 deletions common/include/pcl/common/impl/polynomial_calculations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ inline void
{
real x=roots[i], x2=x*x, x3=x2*x;
real result = a*x3 + b*x2 + c*x + d;
if (fabs (result) > 1e-4)
if (std::abs (result) > 1e-4)
{
cout << "Something went wrong:\n";
//roots.clear ();
Expand Down Expand Up @@ -395,7 +395,7 @@ inline void
{
real x=roots[i], x2=x*x, x3=x2*x, x4=x2*x2;
real result = a*x4 + b*x3 + c*x2 + d*x + e;
if (fabs (result) > 1e-4)
if (std::abs (result) > 1e-4)
{
cout << "Something went wrong:\n";
//roots.clear ();
Expand Down
8 changes: 4 additions & 4 deletions common/include/pcl/common/polynomial_calculations.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ namespace pcl

protected:
// =====PROTECTED METHODS=====
//! check if fabs(d)<zeroValue
//! check if std::abs(d)<zeroValue
inline bool
isNearlyZero (real d) const
{
return (fabs (d) < parameters_.zero_value);
return (std::abs (d) < parameters_.zero_value);
}

//! check if sqrt(fabs(d))<zeroValue
//! check if sqrt(std::abs(d))<zeroValue
inline bool
sqrtIsNearlyZero (real d) const
{
return (fabs (d) < parameters_.sqr_zero_value);
return (std::abs (d) < parameters_.sqr_zero_value);
}

// =====PROTECTED MEMBERS=====
Expand Down
6 changes: 3 additions & 3 deletions common/include/pcl/range_image/impl/range_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RangeImage::atan2LookUp (float y, float x)
if (x==0 && y==0)
return 0;
float ret;
if (fabsf (x) < fabsf (y))
if (std::abs (x) < std::abs (y))
{
ret = atan_lookup_table[
static_cast<int> (
Expand All @@ -85,7 +85,7 @@ RangeImage::atan2LookUp (float y, float x)
inline float
RangeImage::cosLookUp (float value)
{
int cell_idx = static_cast<int> (pcl_lrintf ( (static_cast<float> (lookup_table_size-1)) * fabsf (value) / (2.0f * static_cast<float> (M_PI))));
int cell_idx = static_cast<int> (pcl_lrintf ( (static_cast<float> (lookup_table_size-1)) * std::abs (value) / (2.0f * static_cast<float> (M_PI))));
return (cos_lookup_table[cell_idx]);
}

Expand Down Expand Up @@ -654,7 +654,7 @@ RangeImage::getAcutenessValue (const PointWithRange& point1, const PointWithRang
float ret = 1.0f - float (std::fabs (impact_angle)/ (0.5f*M_PI));
if (impact_angle < 0.0f)
ret = -ret;
//if (fabs (ret)>1)
//if (std::abs (ret)>1)
//std::cout << PVARAC (impact_angle)<<PVARN (ret);
return ret;
}
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 @@ -495,12 +495,12 @@ RangeImage::getInterpolatedSurfaceProjection (const Eigen::Affine3f& pose, int p
continue;
getPoint (x, y, point1);
point1 = pose*point1;
if (fabs (point1[2]) > max_dist)
if (std::abs (point1[2]) > max_dist)
continue;

getPoint (x+1, y+1, point2);
point2 = pose*point2;
if (fabs (point2[2]) > max_dist)
if (std::abs (point2[2]) > max_dist)
continue;

for (int triangle_idx=0; triangle_idx<=1; ++triangle_idx)
Expand All @@ -518,7 +518,7 @@ RangeImage::getInterpolatedSurfaceProjection (const Eigen::Affine3f& pose, int p
getPoint (x+1, y, point3);
}
point3 = pose*point3;
if (fabs (point3[2]) > max_dist)
if (std::abs (point3[2]) > max_dist)
continue;

// Are all the points either left, right, on top or below the bottom of the surface patch?
Expand Down
2 changes: 1 addition & 1 deletion common/src/range_image_planar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace pcl

//float image_x, image_y;
//getImagePoint (point.getVector3fMap (), image_x, image_y);
//if (fabsf (image_x-x)+fabsf (image_y-y)>1e-4)
//if (std::abs (image_x-x)+std::abs (image_y-y)>1e-4)
//cerr << PVARC (x)<<PVARC (y)<<PVARC (image_x)<<PVARN (image_y);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cuda/common/include/pcl/cuda/common/eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace pcl
float c2 = m.data[0].x + m.data[1].y + m.data[2].z;


if (fabs(c0) < FLT_EPSILON) // one root is 0 -> quadratic equation
if (std::abs(c0) < FLT_EPSILON) // one root is 0 -> quadratic equation
computeRoots2 (c2, c1, roots);
else
{
Expand Down
12 changes: 6 additions & 6 deletions cuda/features/include/pcl/cuda/features/normal_3d_kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ namespace pcl
int yIdx = idx / width_;

// are we at a border? are our neighbor valid points?
bool west_valid = (xIdx > 1) && !isnan (points_[idx-1].z) && fabs (points_[idx-1].z - query_pt.z) < 200;
bool east_valid = (xIdx < width_-1) && !isnan (points_[idx+1].z) && fabs (points_[idx+1].z - query_pt.z) < 200;
bool north_valid = (yIdx > 1) && !isnan (points_[idx-width_].z) && fabs (points_[idx-width_].z - query_pt.z) < 200;
bool south_valid = (yIdx < height_-1) && !isnan (points_[idx+width_].z) && fabs (points_[idx+width_].z - query_pt.z) < 200;
bool west_valid = (xIdx > 1) && !isnan (points_[idx-1].z) && std::abs (points_[idx-1].z - query_pt.z) < 200;
bool east_valid = (xIdx < width_-1) && !isnan (points_[idx+1].z) && std::abs (points_[idx+1].z - query_pt.z) < 200;
bool north_valid = (yIdx > 1) && !isnan (points_[idx-width_].z) && std::abs (points_[idx-width_].z - query_pt.z) < 200;
bool south_valid = (yIdx < height_-1) && !isnan (points_[idx+width_].z) && std::abs (points_[idx+width_].z - query_pt.z) < 200;

float3 horiz, vert;
if (west_valid & east_valid)
Expand All @@ -139,7 +139,7 @@ namespace pcl
float3 normal = cross (horiz, vert);

float curvature = length (normal);
curvature = fabs(horiz.z) > 0.04 | fabs(vert.z) > 0.04 | !west_valid | !east_valid | !north_valid | !south_valid;
curvature = std::abs(horiz.z) > 0.04 | std::abs(vert.z) > 0.04 | !west_valid | !east_valid | !north_valid | !south_valid;

float3 mc = normalize (normal);
if ( dot (query_pt, mc) > 0 )
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace pcl
normal.z * (query_pt.z - centroid.z) / sqrt(sqr_radius_) ;


//return make_float4 (normal.x*proj, normal.y*proj, normal.z*proj, clamp (fabs (proj), 0.0f, 1.0f));
//return make_float4 (normal.x*proj, normal.y*proj, normal.z*proj, clamp (std::abs (proj), 0.0f, 1.0f));
return make_float4 (
(centroid.x - query_pt.x) / sqrt(sqr_radius_) ,
(centroid.y - query_pt.y) / sqrt(sqr_radius_) ,
Expand Down
2 changes: 1 addition & 1 deletion cuda/io/include/pcl/cuda/io/kinect_smoothing.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace pcl
// ignore invalid points
if (otherDepth == 0)
continue;
if (fabs(otherDepth - depth) > 200)
if (std::abs(otherDepth - depth) > 200)
continue;

++counter;
Expand Down
22 changes: 11 additions & 11 deletions cuda/sample_consensus/src/sac_model_1point_plane.cu
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ namespace pcl

//TODO: make threshold adaptive, depending on z

return (fabs (thrust::raw_reference_cast(thrust::get<0>(t)).x * coefficients.x +
return (std::abs (thrust::raw_reference_cast(thrust::get<0>(t)).x * coefficients.x +
thrust::raw_reference_cast(thrust::get<0>(t)).y * coefficients.y +
thrust::raw_reference_cast(thrust::get<0>(t)).z * coefficients.z + coefficients.w) < threshold);
}
Expand All @@ -405,7 +405,7 @@ namespace pcl
if (isnan (p.x))
return -1;

if (fabs (p.x * coefficients.x +
if (std::abs (p.x * coefficients.x +
p.y * coefficients.y +
p.z * coefficients.z + coefficients.w) < threshold)
// If inlier, return its position in the vector
Expand All @@ -432,7 +432,7 @@ namespace pcl

//TODO: make threshold adaptive, depending on z

if (fabs (dot (pt, coefficients)) < threshold)
if (std::abs (dot (pt, coefficients)) < threshold)
// If inlier, return its position in the vector
return (thrust::get<1>(t));
else
Expand All @@ -456,7 +456,7 @@ namespace pcl
float orig_disparity = b * f / pt.z;
float actual_disparity = orig_disparity * length_pt / (length_pt + D);

if ((fabs (actual_disparity - orig_disparity) <= 1.0/6.0) & idx != -1)
if ((std::abs (actual_disparity - orig_disparity) <= 1.0/6.0) & idx != -1)
return (idx);
else
return -1;
Expand All @@ -482,12 +482,12 @@ namespace pcl
float orig_disparity = b * f / pt.z;
float actual_disparity = orig_disparity * length_pt / (length_pt + D);

if ((fabs (actual_disparity - orig_disparity) <= 1.0/2.0) & (idx != -1)
if ((std::abs (actual_disparity - orig_disparity) <= 1.0/2.0) & (idx != -1)
&
(
fabs (std::acos (normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z)) < angle_threshold
std::abs (std::acos (normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z)) < angle_threshold
|
fabs (std::acos (-(normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z))) < angle_threshold
std::abs (std::acos (-(normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z))) < angle_threshold
)
)
return (idx);
Expand All @@ -505,14 +505,14 @@ namespace pcl
float4 &normal = thrust::get<1>(t);
//TODO: make threshold adaptive, depending on z

if (fabs (pt.x * coefficients.x +
if (std::abs (pt.x * coefficients.x +
pt.y * coefficients.y +
pt.z * coefficients.z + coefficients.w) < threshold
&
(
fabs (std::acos (normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z)) < angle_threshold
std::abs (std::acos (normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z)) < angle_threshold
|
fabs (std::acos (-(normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z))) < angle_threshold
std::abs (std::acos (-(normal.x*coefficients.x + normal.y*coefficients.y + normal.z*coefficients.z))) < angle_threshold
)
)
// If inlier, return its position in the vector
Expand All @@ -531,7 +531,7 @@ namespace pcl

//TODO: make threshold adaptive, depending on z

if (fabs (pt.x * coefficients.x +
if (std::abs (pt.x * coefficients.x +
pt.y * coefficients.y +
pt.z * coefficients.z + coefficients.w) < threshold)
// If inlier, return its position in the vector
Expand Down
Loading