PCL Octree Cheat Sheet
The point cloud library (PCL) is a fantastic resource for working with point clouds, however it is a large library and it can take a while to effectively find your way around it. The octree construct is very useful for working with point clouds, but again it can take a while to learn how to interact with octrees. To help me to remember how to interact with them I will include some examples here:
To iterate across the nodes of an octree (depth first):
1 2 3 4 5 6 7 8 9 10 11 | // for (auto it = octree.begin(); it != octree.end(); ++it) { if (it.isBranchNode()) { cout << "branch" << std::endl; } if (it.isLeafNode()) { cout << "leaf" << std::endl; } } // |
To iterate across the leaf nodes:
1 2 3 4 5 | // for (auto it = octree.leaf_begin(); it != octree.leaf_end(); ++it) { } // |
Get a Voxel’s Bounding Region given node iterator:
1 2 3 4 5 6 7 | // // Get iterator to first leaf auto it = octree.leaf_begin(); Eigen::Vector3f voxel_min, voxel_max; octree.getVoxelBounds(it, voxel_min, voxel_max); // |
Get point indices from leaf node iterator
1 2 3 4 5 6 | // auto it = octree.leaf_begin(); std::vector<int> indices; it.getLeafContainer().getPointIndices(indices); // |
Get point indices from leaf node pointer
1 2 3 4 5 6 7 8 9 10 | // std::vector<int> indices; if (node->getNodeType() == LEAF_NODE) { // Nasty down-cast? auto* l = dynamic_cast <const OctreePointCloud<PointXYZ>::LeafNode*>(node); (*l)->getPointIndices(indices); } // |