Skip to content

Commit

Permalink
Merge pull request #2950 from SunBlack/log2
Browse files Browse the repository at this point in the history
Use std::log2 instead of custom implementation
  • Loading branch information
taketwo authored Mar 28, 2019
2 parents 499bc6f + ce0e5fc commit d009887
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
7 changes: 3 additions & 4 deletions features/include/pcl/features/impl/brisk_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ pcl::BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::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<KeypointT, Eigen::aligned_allocator<KeypointT> >::iterator beginning = keypoints_->points.begin ();
std::vector<int>::iterator beginningkscales = kscales.begin ();
Expand All @@ -479,14 +478,14 @@ pcl::BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::compute (
unsigned int basicscale = 0;

if (!scale_invariance_enabled_)
basicscale = std::max (static_cast<int> (float (scales_) / lb_scalerange * (log (1.45f * basic_size_ / (basic_size_06)) / log2) + 0.5f), 0);
basicscale = std::max (static_cast<int> (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<int> (float (scales_) / lb_scalerange * (log (keypoints_->points[k].size / (basic_size_06)) / log2) + 0.5f), 0);
scale = std::max (static_cast<int> (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;
Expand Down
3 changes: 2 additions & 1 deletion io/include/pcl/compression/entropy_range_coder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion io/include/pcl/compression/impl/entropy_range_coder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pcl::StaticRangeCoder::encodeIntVectorToStream (std::vector<unsigned int>& input

// calculate amount of bytes per frequency table entry
uint8_t frequencyTableByteSize = static_cast<uint8_t> (ceil (
Log2 (static_cast<double> (cFreqTable_[static_cast<std::size_t> (frequencyTableSize - 1)])) / 8.0));
std::log2 (static_cast<double> (cFreqTable_[static_cast<std::size_t> (frequencyTableSize - 1)])) / 8.0));

// write size of frequency table to output stream
outputByteStream_arg.write (reinterpret_cast<const char*> (&frequencyTableSize), sizeof(frequencyTableSize));
Expand Down
2 changes: 1 addition & 1 deletion octree/include/pcl/octree/impl/octree2buf_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace pcl

// tree depth == amount of bits of maxVoxels
treeDepth = std::max ((std::min (static_cast<unsigned int> (OctreeKey::maxDepth),
static_cast<unsigned int> (std::ceil (Log2 (max_voxel_index_arg))))),
static_cast<unsigned int> (std::ceil (std::log2 (max_voxel_index_arg))))),
static_cast<unsigned int> (0));

// define depthMask_ by setting a single bit to 1 at bit position == tree depth
Expand Down
2 changes: 1 addition & 1 deletion octree/include/pcl/octree/impl/octree_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace pcl
assert(max_voxel_index_arg>0);

// tree depth == bitlength of maxVoxels
tree_depth = std::min (static_cast<unsigned int> (OctreeKey::maxDepth), static_cast<unsigned int> (std::ceil (Log2 (max_voxel_index_arg))));
tree_depth = std::min (static_cast<unsigned int> (OctreeKey::maxDepth), static_cast<unsigned int> (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));
Expand Down
2 changes: 1 addition & 1 deletion octree/include/pcl/octree/impl/octree_pointcloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>


// tree depth == amount of bits of max_voxels
this->octree_depth_ = std::max ((std::min (static_cast<unsigned int> (OctreeKey::maxDepth), static_cast<unsigned int> (ceil (this->Log2 (max_voxels)-minValue)))),
this->octree_depth_ = std::max ((std::min (static_cast<unsigned int> (OctreeKey::maxDepth), static_cast<unsigned int> (std::ceil (std::log2 (max_voxels) - minValue)))),
static_cast<unsigned int> (0));

octree_side_len = static_cast<double> (1 << this->octree_depth_) * resolution_;
Expand Down
3 changes: 2 additions & 1 deletion octree/include/pcl/octree/octree2buf_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion octree/include/pcl/octree/octree_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion outofcore/include/pcl/outofcore/impl/octree_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ namespace pcl
if (side_length < leaf_resolution)
return (0);

boost::uint64_t res = static_cast<boost::uint64_t> (std::ceil (log2f (static_cast<float> (side_length / leaf_resolution))));
boost::uint64_t res = static_cast<boost::uint64_t> (std::ceil (std::log2 (side_length / leaf_resolution)));

PCL_DEBUG ("[pcl::outofcore::OutofcoreOctreeBase::calculateDepth] Setting depth to %d\n",res);
return (res);
Expand Down

0 comments on commit d009887

Please sign in to comment.