I'm trying to build an octree to manage my point cloud data loaded from pcd file. I want to get the correspondent point indices in each voxel at a given depth of the octree...But I don't seem to find any method or example in the official documents.
I've tried to use FixedDepthIterator to traverse the tree and use "tree it.getLeafContainer().getPointIndices(vector)"something like this to get them.
But I don't know if I comprehend the usage properly and it's been a problem hard to solve before I can get the result and perform further study on region growth algorithms based on Octree.
Expected Behavior
Current Behavior
Code to Reproduce
This is the relevant codes I used after referring to the source codes of Class octreeViewer in Octree_viewer.cpp
void traverseOctree::getLeafNodesAtDepth(int depth){
//voxelCentercloud->clear();
pcl::PointXYZ pt_voxel_center;
vector point_idx_data;
for (pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>::FixedDepthIterator tree_it = octree.fixed_depth_begin (depth);
tree_it != octree.fixed_depth_end ();
++tree_it)
{
// Compute the point at the center of the voxel which represents the current OctreeNode
Eigen::Vector3f voxel_min, voxel_max;
octree.getVoxelBounds (tree_it, voxel_min, voxel_max);
pt_voxel_center.x = (voxel_min.x () + voxel_max.x ()) / 2.0f;
pt_voxel_center.y = (voxel_min.y () + voxel_max.y ()) / 2.0f;
pt_voxel_center.z = (voxel_min.z () + voxel_max.z ()) / 2.0f;
voxelCentercloud->points.push_back (pt_voxel_center);
voxelCenters.push_back(pt_voxel_center);
cloud->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 () == (unsigned int) depth)
{
pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::LeafNode* container = static_cast<pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::LeafNode*> (tree_it.getCurrentOctreeNode ());
tree_it.getLeafContainer().getPointIndices(point_idx_data);
}
// Else, compute the centroid of the LeafNode under the current BranchNode
else
{
// Retrieve every centroid under the current BranchNode
tree_it.getBranchContainer().getPointIndices(point_idx_data);
pcl::octree::OctreeKey dummy_key;
pcl::PointCloud<pcl::PointXYZ>::VectorType voxelCentroids;
for(size_t i=0;i<point_idx_data.size();++i){
cout<<" "<<point_idx_data[i]<<" "<<endl;
}
}
Your Environment
Context
I'm trying to build an octree to manage my point cloud data loaded from pcd file. I want to get the correspondent point indices in each voxel at a given depth of the octree...But I don't seem to find any method or example in the official documents. I've tried to use FixedDepthIterator to traverse the tree and use "tree it.getLeafContainer().getPointIndices(vector)"something like this to get them.
But I don't know if I comprehend the usage properly and it's been a problem hard to solve before I can get the result and perform further study on region growth algorithms based on Octree.
Expected Behavior
Current Behavior
Code to Reproduce
This is the relevant codes I used after referring to the source codes of Class octreeViewer in Octree_viewer.cpp void traverseOctree::getLeafNodesAtDepth(int depth){ //voxelCentercloud->clear(); pcl::PointXYZ pt_voxel_center; vector point_idx_data;
}
Possible Solution