Skip to content

Commit da4c408

Browse files
authored
Added the ability to redirect logging to a callable. (#6244)
* Added the ability to redirect logging to a callable. * Use formatted string instead of temporary stringstream. * Add includes. * cleanup * Test for undefined symbol. * Fix copy paste error. * Fix ODR of OctreeKey::maxdepth. * Remove unnecessary c_str(). * Wrap static member variables in a getter method. * Add wrapper function for easier setting the callback. * Address parsing in the string from the LogRecord to reduce copying. * Revert removal of c_str() * Revert direct removal of the two static variables, but added deprecrecation notice. * Added more documentation for usage of the setCallback and how to reset logging to console * Fix missing field in initializer * Address suggestions from copilot. * Added checks if verbosity level is enabled before to_string. Replaced Logrecorder with stringstream directly and added as a member to Logger, to reuse it fore the entire lifetime of the application. Added doc strings. Added constructors to LogRecord. * For now have a stringstream per PCL_LOG_STREAM. * Only reset_text_color on L_DEBUG, L_WARN and L_ERROR.
1 parent 0290ff7 commit da4c408

File tree

14 files changed

+510
-339
lines changed

14 files changed

+510
-339
lines changed

common/include/pcl/console/print.h

Lines changed: 265 additions & 72 deletions
Large diffs are not rendered by default.

common/src/print.cpp

Lines changed: 93 additions & 244 deletions
Large diffs are not rendered by default.

examples/segmentation/example_cpc_segmentation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ CPCSegmentation Parameters: \n\
211211
pcl::PCLPointCloud2 input_pointcloud2;
212212
if (pcl::io::loadPCDFile (pcd_filename, input_pointcloud2))
213213
{
214-
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str ());
214+
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str());
215215
return (3);
216216
}
217217
pcl::fromPCLPointCloud2 (input_pointcloud2, *input_cloud_ptr);
@@ -362,9 +362,8 @@ CPCSegmentation Parameters: \n\
362362
PCL_INFO ("Refining supervoxels\n");
363363
super.refineSupervoxels (2, supervoxel_clusters);
364364
}
365-
std::stringstream temp;
366-
temp << " Nr. Supervoxels: " << supervoxel_clusters.size () << "\n";
367-
PCL_INFO (temp.str ().c_str ());
365+
366+
PCL_INFO(" Nr. Supervoxels: %zu\n", supervoxel_clusters.size());
368367

369368
PCL_INFO ("Getting supervoxel adjacency\n");
370369
std::multimap<std::uint32_t, std::uint32_t>supervoxel_adjacency;

examples/segmentation/example_lccp_segmentation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ LCCPSegmentation Parameters: \n\
182182
pcl::PCLPointCloud2 input_pointcloud2;
183183
if (pcl::io::loadPCDFile (pcd_filename, input_pointcloud2))
184184
{
185-
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str ());
185+
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str());
186186
return (3);
187187
}
188188
pcl::fromPCLPointCloud2 (input_pointcloud2, *input_cloud_ptr);
@@ -289,9 +289,8 @@ LCCPSegmentation Parameters: \n\
289289
PCL_INFO ("Refining supervoxels\n");
290290
super.refineSupervoxels (2, supervoxel_clusters);
291291
}
292-
std::stringstream temp;
293-
temp << " Nr. Supervoxels: " << supervoxel_clusters.size () << "\n";
294-
PCL_INFO (temp.str ().c_str ());
292+
293+
PCL_INFO(" Nr. Supervoxels: %zu\n", supervoxel_clusters.size());
295294

296295
PCL_INFO ("Getting supervoxel adjacency\n");
297296
std::multimap<std::uint32_t, std::uint32_t> supervoxel_adjacency;

octree/include/pcl/octree/impl/octree2buf_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Octree2BufBase<LeafContainerT, BranchContainerT>::setMaxVoxelIndex(
7373

7474
// tree depth == amount of bits of maxVoxels
7575
treeDepth =
76-
std::max<uindex_t>(std::min<uindex_t>(OctreeKey::maxDepth,
76+
std::max<uindex_t>(std::min<uindex_t>(OctreeKey::getMaxDepth(),
7777
std::ceil(std::log2(max_voxel_index_arg))),
7878
0);
7979

octree/include/pcl/octree/impl/octree_base.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#ifndef PCL_OCTREE_BASE_HPP
4040
#define PCL_OCTREE_BASE_HPP
4141

42+
#include <pcl/octree/octree_base.h>
43+
#include <pcl/octree/octree_key.h>
44+
4245
#include <vector>
4346

4447
namespace pcl {
@@ -75,7 +78,7 @@ OctreeBase<LeafContainerT, BranchContainerT>::setMaxVoxelIndex(
7578

7679
// tree depth == bitlength of maxVoxels
7780
tree_depth =
78-
std::min(static_cast<uindex_t>(OctreeKey::maxDepth),
81+
std::min(static_cast<uindex_t>(OctreeKey::getMaxDepth()),
7982
static_cast<uindex_t>(std::ceil(std::log2(max_voxel_index_arg))));
8083

8184
setTreeDepth(tree_depth);
@@ -91,11 +94,11 @@ OctreeBase<LeafContainerT, BranchContainerT>::setTreeDepth(uindex_t depth_arg)
9194
depth_arg);
9295
return;
9396
}
94-
if (depth_arg > OctreeKey::maxDepth) {
97+
if (depth_arg > OctreeKey::getMaxDepth()) {
9598
PCL_ERROR("[pcl::octree::OctreeBase::setTreeDepth] Tree depth (%lu) must be <= max "
9699
"depth(%lu)!\n",
97100
depth_arg,
98-
OctreeKey::maxDepth);
101+
OctreeKey::getMaxDepth());
99102
return;
100103
}
101104

octree/include/pcl/octree/impl/octree_pointcloud.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>
713713

714714
// tree depth == amount of bits of max_voxels
715715
this->octree_depth_ = std::max<uindex_t>(
716-
std::min<uindex_t>(OctreeKey::maxDepth,
716+
std::min<uindex_t>(OctreeKey::getMaxDepth(),
717717
std::ceil(std::log2(max_voxels) - minValue)),
718718
0);
719719

octree/include/pcl/octree/octree_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@
4343
#include <pcl/octree/impl/octree_iterator.hpp>
4444
#include <pcl/octree/impl/octree_pointcloud.hpp>
4545
#include <pcl/octree/impl/octree_search.hpp>
46-
#include <pcl/octree/octree.h>

octree/include/pcl/octree/octree_key.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,19 @@ class OctreeKey {
138138
(!!(this->z & depthMask)));
139139
}
140140

141-
/* \brief maximum depth that can be addressed */
141+
PCL_DEPRECATED(1, 18, "Use getMaxDepth() instead.")
142142
static const unsigned char maxDepth =
143143
static_cast<unsigned char>(sizeof(uindex_t) * 8);
144144

145+
static unsigned char
146+
getMaxDepth()
147+
{
148+
/* \brief maximum depth that can be addressed */
149+
static const unsigned char maxDepth{
150+
static_cast<unsigned char>(sizeof(uindex_t) * 8)};
151+
return maxDepth;
152+
}
153+
145154
// Indices addressing a voxel at (X, Y, Z)
146155
// NOLINTBEGIN(modernize-use-default-member-init)
147156
union {

octree/src/octree_inst.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <pcl/octree/octree.h>
3838
#include <pcl/octree/octree_impl.h>
39+
#include <pcl/octree/octree_key.h>
3940

4041
// Instantiations of specific point types
4142

0 commit comments

Comments
 (0)