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

[OCTREE] Compute accurately the centroids of octree in 'pcl_octree_viewer' #1981

Merged

Conversation

frozar
Copy link
Contributor

@frozar frozar commented Sep 1, 2017

Use the method getVoxelCentroidsRecursive() to retrieve every centroid under a given BranchNode 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

@taketwo taketwo added this to the pcl-1.9.0 milestone Sep 1, 2017
@taketwo
Copy link
Member

taketwo commented Sep 1, 2017

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.

@frozar
Copy link
Contributor Author

frozar commented Sep 1, 2017

Sorry, I didn't realise that I screw up the cube visualization... I completely agree with you. I prepare a fix.

@frozar frozar force-pushed the octree_voxel_centroid branch from d32afd4 to 9fb4686 Compare September 1, 2017 10:06
@frozar
Copy link
Contributor Author

frozar commented Sep 1, 2017

Cubes visualization: fixed.

@taketwo
Copy link
Member

taketwo commented Sep 2, 2017

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.

@taketwo taketwo added the needs: author reply Specify why not closed/merged yet label Sep 2, 2017
@frozar
Copy link
Contributor Author

frozar commented Sep 3, 2017

I completly agree with your previous remarks. All remarks have been taken into accompt . I let you check it.

@taketwo taketwo added needs: code review Specify why not closed/merged yet and removed needs: author reply Specify why not closed/merged yet labels Sep 3, 2017
@taketwo taketwo self-assigned this Sep 3, 2017
@taketwo
Copy link
Member

taketwo commented Sep 6, 2017

Hi, sorry for the delay. I tried to run it on my machine, works fine. Only problem I noticed is that the lines for v anb b key are overlapping:

image

Also, I wonder if we need that s/w switch. PCL Visualizer provides these hotkeys by default (as can be seen in the console output when pressing h for help). So probably s/w in this app is just a duplicate and can be removed.

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.

@taketwo taketwo added needs: author reply Specify why not closed/merged yet needs: code review Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Sep 6, 2017
@frozar
Copy link
Contributor Author

frozar commented Sep 7, 2017

Happy to see your answer. You were right, there was some legend overlap. Also I remove the "s/w" line in the legend, but in the code, the bool wireframe is still present.

The reason for that is when you don't save this information, the default behavior of the camera is to display the octree cubes with surfaces visible. When you toggle to the wireframe view at a given depth, is works, OK, but when you change the depth, you get back to the "surface visible" view. I try to show it in this animation:
pcl_review

So to keep the wireframe/surface visible state, you have to save it.

I realises that it's the same with the "+/-" event which change the size of point when point cloud are displayed. I this it's the good time to introduce another parameter, let say point_size_, to keep the point size when one changes the depth of the representation.

What do you think about it?

@taketwo
Copy link
Member

taketwo commented Sep 7, 2017

Thanks for the explanation, makes sense.

I this it's the good time to introduce another parameter, let say point_size_, to keep the point size when one changes the depth of the representation.

Very good point. The size is also reset when toggling visibility of the points, would be nice to preserve this.

@frozar
Copy link
Contributor Author

frozar commented Sep 7, 2017

Nice, it's done in the last commit.

@taketwo
Copy link
Member

taketwo commented Sep 7, 2017

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?

@frozar frozar force-pushed the octree_voxel_centroid branch from c361bdc to 4d6e875 Compare September 7, 2017 11:10
@frozar
Copy link
Contributor Author

frozar commented Sep 7, 2017

This branch is now rebase onto master. I didn't rewrite the history, but I can if you want.

show_centroids_ (false),
show_original_points_ (false),
point_size_ (1.0)
{
Copy link
Member

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.

@@ -197,26 +229,30 @@ class OctreeViewer
/* \brief Helper function that draw info for the user on the viewer
*
*/
void showLegend(bool showCubes)
void showLegend()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space

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)),
Copy link
Member

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.

pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color_handler(cloud, "z");
viz.addPointCloud(cloud, color_handler, "cloud");
}
showCubes (sqrt (octree.getVoxelSquaredSideLen (displayedDepth)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::sqrt

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 ){
Copy link
Member

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.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space

container->getContainer().getCentroid (pt_centroid);
}
// Else, compute the centroid of the LeafNode under the current BranchNode
else {
Copy link
Member

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
Copy link
Member

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.

@taketwo taketwo removed the needs: code review Specify why not closed/merged yet label Sep 7, 2017
@frozar
Copy link
Contributor Author

frozar commented Sep 8, 2017

Every comment has been taken into account in the last commit.

Copy link
Member

@taketwo taketwo left a 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.

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){
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed !

@frozar
Copy link
Contributor Author

frozar commented Sep 8, 2017

Should I squash every commit in a single commit?

@frozar
Copy link
Contributor Author

frozar commented Sep 9, 2017

@SergioRAgostinho : The Travis check failed because a job timeout. Can you handle that please?

@taketwo
Copy link
Member

taketwo commented Sep 9, 2017

I restarted the failed job.
I'd say the point size commit can remain on its own, and the rest can be squashed.

frozar added 2 commits September 9, 2017 19:32
Use the method 'getVoxelCentroidsRecursive' to retrieve every centroids under a given BranchNode and compute the correct global centroid.
@frozar frozar force-pushed the octree_voxel_centroid branch from 6e2e1fc to 6dadd0b Compare September 9, 2017 17:33
@SergioRAgostinho
Copy link
Member

SergioRAgostinho commented Sep 9, 2017 via email

@frozar
Copy link
Contributor Author

frozar commented Sep 9, 2017

The squash of commit is done.

Hope the Travis check will be ok, but let see ^^'

@taketwo taketwo added status: ready to merge and removed needs: author reply Specify why not closed/merged yet labels Sep 11, 2017
@SergioRAgostinho SergioRAgostinho merged commit fa9b816 into PointCloudLibrary:master Sep 21, 2017
@frozar frozar deleted the octree_voxel_centroid branch September 27, 2017 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants