From ce0e5fc682422afb9d0c0eb503ee5ab3ab42606f Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Wed, 27 Mar 2019 16:17:22 +0100 Subject: [PATCH] Use std::log2 instead of custom implementation --- features/include/pcl/features/impl/brisk_2d.hpp | 7 +++---- io/include/pcl/compression/entropy_range_coder.h | 3 ++- io/include/pcl/compression/impl/entropy_range_coder.hpp | 2 +- octree/include/pcl/octree/impl/octree2buf_base.hpp | 2 +- octree/include/pcl/octree/impl/octree_base.hpp | 2 +- octree/include/pcl/octree/impl/octree_pointcloud.hpp | 2 +- octree/include/pcl/octree/octree2buf_base.h | 3 ++- octree/include/pcl/octree/octree_base.h | 3 ++- outofcore/include/pcl/outofcore/impl/octree_base.hpp | 2 +- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/features/include/pcl/features/impl/brisk_2d.hpp b/features/include/pcl/features/impl/brisk_2d.hpp index d010803fc87..9ff27dd847a 100644 --- a/features/include/pcl/features/impl/brisk_2d.hpp +++ b/features/include/pcl/features/impl/brisk_2d.hpp @@ -469,8 +469,7 @@ pcl::BRISK2DEstimation::compute ( kscales.resize (ksize); // initialize constants - static const float log2 = 0.693147180559945f; - static const float lb_scalerange = std::log (scalerange_) / (log2); + static const float lb_scalerange = std::log2 (scalerange_); typename std::vector >::iterator beginning = keypoints_->points.begin (); std::vector::iterator beginningkscales = kscales.begin (); @@ -479,14 +478,14 @@ pcl::BRISK2DEstimation::compute ( unsigned int basicscale = 0; if (!scale_invariance_enabled_) - basicscale = std::max (static_cast (float (scales_) / lb_scalerange * (log (1.45f * basic_size_ / (basic_size_06)) / log2) + 0.5f), 0); + basicscale = std::max (static_cast (float (scales_) / lb_scalerange * (std::log2 (1.45f * basic_size_ / (basic_size_06))) + 0.5f), 0); for (size_t k = 0; k < ksize; k++) { unsigned int scale; if (scale_invariance_enabled_) { - scale = std::max (static_cast (float (scales_) / lb_scalerange * (log (keypoints_->points[k].size / (basic_size_06)) / log2) + 0.5f), 0); + scale = std::max (static_cast (float (scales_) / lb_scalerange * (std::log2 (keypoints_->points[k].size / (basic_size_06))) + 0.5f), 0); // saturate if (scale >= scales_) scale = scales_ - 1; kscales[k] = scale; diff --git a/io/include/pcl/compression/entropy_range_coder.h b/io/include/pcl/compression/entropy_range_coder.h index 86496b32640..1f3c8aa3979 100644 --- a/io/include/pcl/compression/entropy_range_coder.h +++ b/io/include/pcl/compression/entropy_range_coder.h @@ -168,10 +168,11 @@ namespace pcl * \param n_arg: some value * \return binary logarithm (log2) of argument n_arg */ + [[deprecated("use std::log2 instead")]] inline double Log2 (double n_arg) { - return log (n_arg) / log (2.0); + return std::log2 (n_arg); } private: diff --git a/io/include/pcl/compression/impl/entropy_range_coder.hpp b/io/include/pcl/compression/impl/entropy_range_coder.hpp index 88bbafa856c..1c43a427f46 100644 --- a/io/include/pcl/compression/impl/entropy_range_coder.hpp +++ b/io/include/pcl/compression/impl/entropy_range_coder.hpp @@ -294,7 +294,7 @@ pcl::StaticRangeCoder::encodeIntVectorToStream (std::vector& input // calculate amount of bytes per frequency table entry uint8_t frequencyTableByteSize = static_cast (ceil ( - Log2 (static_cast (cFreqTable_[static_cast (frequencyTableSize - 1)])) / 8.0)); + std::log2 (static_cast (cFreqTable_[static_cast (frequencyTableSize - 1)])) / 8.0)); // write size of frequency table to output stream outputByteStream_arg.write (reinterpret_cast (&frequencyTableSize), sizeof(frequencyTableSize)); diff --git a/octree/include/pcl/octree/impl/octree2buf_base.hpp b/octree/include/pcl/octree/impl/octree2buf_base.hpp index ff79381bbc3..f04e0c91f77 100644 --- a/octree/include/pcl/octree/impl/octree2buf_base.hpp +++ b/octree/include/pcl/octree/impl/octree2buf_base.hpp @@ -77,7 +77,7 @@ namespace pcl // tree depth == amount of bits of maxVoxels treeDepth = std::max ((std::min (static_cast (OctreeKey::maxDepth), - static_cast (std::ceil (Log2 (max_voxel_index_arg))))), + static_cast (std::ceil (std::log2 (max_voxel_index_arg))))), static_cast (0)); // define depthMask_ by setting a single bit to 1 at bit position == tree depth diff --git a/octree/include/pcl/octree/impl/octree_base.hpp b/octree/include/pcl/octree/impl/octree_base.hpp index 644a0680cfb..7cce06399c2 100644 --- a/octree/include/pcl/octree/impl/octree_base.hpp +++ b/octree/include/pcl/octree/impl/octree_base.hpp @@ -79,7 +79,7 @@ namespace pcl assert(max_voxel_index_arg>0); // tree depth == bitlength of maxVoxels - tree_depth = std::min (static_cast (OctreeKey::maxDepth), static_cast (std::ceil (Log2 (max_voxel_index_arg)))); + tree_depth = std::min (static_cast (OctreeKey::maxDepth), static_cast (std::ceil (std::log2 (max_voxel_index_arg)))); // define depthMask_ by setting a single bit to 1 at bit position == tree depth depth_mask_ = (1 << (tree_depth - 1)); diff --git a/octree/include/pcl/octree/impl/octree_pointcloud.hpp b/octree/include/pcl/octree/impl/octree_pointcloud.hpp index 68caa31f232..43999a74c89 100644 --- a/octree/include/pcl/octree/impl/octree_pointcloud.hpp +++ b/octree/include/pcl/octree/impl/octree_pointcloud.hpp @@ -635,7 +635,7 @@ pcl::octree::OctreePointCloud // tree depth == amount of bits of max_voxels - this->octree_depth_ = std::max ((std::min (static_cast (OctreeKey::maxDepth), static_cast (ceil (this->Log2 (max_voxels)-minValue)))), + this->octree_depth_ = std::max ((std::min (static_cast (OctreeKey::maxDepth), static_cast (std::ceil (std::log2 (max_voxels) - minValue)))), static_cast (0)); octree_side_len = static_cast (1 << this->octree_depth_) * resolution_; diff --git a/octree/include/pcl/octree/octree2buf_base.h b/octree/include/pcl/octree/octree2buf_base.h index baf1ee5d805..8c47a6832a8 100644 --- a/octree/include/pcl/octree/octree2buf_base.h +++ b/octree/include/pcl/octree/octree2buf_base.h @@ -885,9 +885,10 @@ namespace pcl * \param n_arg: some value * \return binary logarithm (log2) of argument n_arg */ + [[deprecated("use std::log2 instead")]] inline double Log2 (double n_arg) { - return log (n_arg) / log (2.0); + return std::log2 (n_arg); } /** \brief Test if octree is able to dynamically change its depth. This is required for adaptive bounding box adjustment. diff --git a/octree/include/pcl/octree/octree_base.h b/octree/include/pcl/octree/octree_base.h index c2a1711f6f5..d6a4e7661f0 100644 --- a/octree/include/pcl/octree/octree_base.h +++ b/octree/include/pcl/octree/octree_base.h @@ -654,10 +654,11 @@ namespace pcl * \param n_arg: some value * \return binary logarithm (log2) of argument n_arg */ + [[deprecated("use std::log2 instead")]] double Log2 (double n_arg) { - return log( n_arg ) / log( 2.0 ); + return std::log2( n_arg ); } /** \brief Test if octree is able to dynamically change its depth. This is required for adaptive bounding box adjustment. diff --git a/outofcore/include/pcl/outofcore/impl/octree_base.hpp b/outofcore/include/pcl/outofcore/impl/octree_base.hpp index 743cf658a53..bb73d7c2d76 100644 --- a/outofcore/include/pcl/outofcore/impl/octree_base.hpp +++ b/outofcore/include/pcl/outofcore/impl/octree_base.hpp @@ -734,7 +734,7 @@ namespace pcl if (side_length < leaf_resolution) return (0); - boost::uint64_t res = static_cast (std::ceil (log2f (static_cast (side_length / leaf_resolution)))); + boost::uint64_t res = static_cast (std::ceil (std::log2 (side_length / leaf_resolution))); PCL_DEBUG ("[pcl::outofcore::OutofcoreOctreeBase::calculateDepth] Setting depth to %d\n",res); return (res);