-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[OCTREE] Compute accurately the centroids of octree in 'pcl_octree_viewer' #1981
[OCTREE] Compute accurately the centroids of octree in 'pcl_octree_viewer' #1981
Conversation
I do not think that it makes sense to align cubes with centroids. This viewer visualizes the hierarchical nested structure of an octree, illustrates how the space is partitioned into a regular 3D grid. However, I agree that this will serve as an example of handling octree branches/leaves and also that visualization of centroids may be insightful. Therefore, I propose to just add centroid visualization capability alongside with cubes display. |
Sorry, I didn't realise that I screw up the cube visualization... I completely agree with you. I prepare a fix. |
d32afd4
to
9fb4686
Compare
Cubes visualization: fixed. |
Hi, thanks for the edits, works mostly fine on my side. However, I noticed that when the viewer is in the "point representation", it is not possible to toggle display of the original point cloud (i.e. "x" key has no effect). Further, when we are in "cube representation", it is possible to show the original cloud, but then it is impossible to rotate the camera anymore because "x" shortcut coincidentally switches on point selection mode. Thus I have a couple of proposals. First, right now we have three different visualization objects: original point cloud, voxel centroid cloud, and voxel boxes. What if we allow to toggle them independently? Second, let's change the shortcuts, in particular avoid using "x". Finally, I think it makes sense to have the cube visualization on by default, that's the whole point of having this viewer, after all. |
I completly agree with your previous remarks. All remarks have been taken into accompt . I let you check it. |
Hi, sorry for the delay. I tried to run it on my machine, works fine. Only problem I noticed is that the lines for Also, I wonder if we need that Could you please do me a favor and rebase this pull request branch onto the current master? This will remove the commits that have been merged already making it easier for me to review only the new changes. |
Thanks for the explanation, makes sense.
Very good point. The size is also reset when toggling visibility of the points, would be nice to preserve this. |
Nice, it's done in the last commit. |
Thanks, works great. So functionality-wise I'd say with PR is complete. Could you please rebase as I requested before so that we can do a quick code review and be ready to merge? |
c361bdc
to
4d6e875
Compare
This branch is now rebase onto |
tools/octree_viewer.cpp
Outdated
show_centroids_ (false), | ||
show_original_points_ (false), | ||
point_size_ (1.0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bracket is over-indented.
tools/octree_viewer.cpp
Outdated
@@ -197,26 +229,30 @@ class OctreeViewer | |||
/* \brief Helper function that draw info for the user on the viewer | |||
* | |||
*/ | |||
void showLegend(bool showCubes) | |||
void showLegend() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space
tools/octree_viewer.cpp
Outdated
viz.addText (level, 0, 30, 1.0, 0.0, 0.0, "level_t1"); | ||
|
||
viz.removeShape ("level_t2"); | ||
sprintf (level, "Voxel size: %.4fm [%lu voxels]", sqrt(octree.getVoxelSquaredSideLen(displayedDepth)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces. Also, please use std::sqrt
.
tools/octree_viewer.cpp
Outdated
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color_handler(cloud, "z"); | ||
viz.addPointCloud(cloud, color_handler, "cloud"); | ||
} | ||
showCubes (sqrt (octree.getVoxelSquaredSideLen (displayedDepth))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::sqrt
tools/octree_viewer.cpp
Outdated
cloudVoxel->points.push_back (pt_voxel_center); | ||
|
||
// If the asked depth is the depth of the octree, retrieve the centroid at this LeafNode | ||
if ( octree.getTreeDepth() == depth ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces inside braces, missing space after getTreeDepth
, opening curly bracket should go on a separate line.
tools/octree_viewer.cpp
Outdated
if ( octree.getTreeDepth() == depth ){ | ||
pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::LeafNode* container = static_cast<pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::LeafNode*> (tree_it.getCurrentOctreeNode ()); | ||
|
||
container->getContainer().getCentroid (pt_centroid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space
tools/octree_viewer.cpp
Outdated
container->getContainer().getCentroid (pt_centroid); | ||
} | ||
// Else, compute the centroid of the LeafNode under the current BranchNode | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
on a new line
pcl::PointCloud<pcl::PointXYZ>::VectorType voxelCentroids; | ||
octree.getVoxelCentroidsRecursive (static_cast<pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::BranchNode*> (*tree_it), dummy_key, voxelCentroids); | ||
|
||
// Iterate over the leafs to compute the centroid of all of them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a dedicated utility class for this: CentroidPoint
.
// Add this include
#include <pcl/common/centroid.h>
// Utility class, instantiate before the loop
CentroidPoint<pcl::PointXYZ> centroid;
// Inside the loop add points
centroid.add (voxelCentroids[j]);
// Fetch centroid after the loop
centroid.get (pt_centroid);
Note that the line 410 is not necessary.
Every comment has been taken into account in the last commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides from one minor style problem everything looks alright for me. When you fix it please also squash the commits and we will be ready to merge.
tools/octree_viewer.cpp
Outdated
cloudVoxel->points.push_back (pt_voxel_center); | ||
|
||
// If the asked depth is the depth of the octree, retrieve the centroid at this LeafNode | ||
if (octree.getTreeDepth() == depth){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still style problems here: missing space and {
should go to a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed !
Should I squash every commit in a single commit? |
@SergioRAgostinho : The Travis check failed because a job timeout. Can you handle that please? |
I restarted the failed job. |
Use the method 'getVoxelCentroidsRecursive' to retrieve every centroids under a given BranchNode and compute the correct global centroid.
6e2e1fc
to
6dadd0b
Compare
I restarted it before as well. So it means it didn't complete again :/ it might not get through…
|
The squash of commit is done. Hope the Travis check will be ok, but let see ^^' |
Use the method
getVoxelCentroidsRecursive()
to retrieve every centroid under a givenBranchNode
and compute the correct global centroid.This pull request improves the accuracy of
pcl_octree_viewer
. The code itself is useful as example to show how to handle the octree classes.Nota Bene: This merge request relies on top of the pull request #1973