Skip to content

Instantly share code, notes, and snippets.

@najlepsiwebdesigner
Created May 30, 2019 09:32
Show Gist options
  • Save najlepsiwebdesigner/979cf07c234f85c149091599ec3554ec to your computer and use it in GitHub Desktop.
Save najlepsiwebdesigner/979cf07c234f85c149091599ec3554ec to your computer and use it in GitHub Desktop.
This converts pcl pointcloud to octomap instance
octomap::OcTree pcl2octomap(const pcl::PointCloud<pcl::PointXYZRGB>::Ptr input_cloud, double resolution = 5) {
// create pcl octree - ultra fast
pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZRGB> octree(resolution);
octree.setInputCloud(input_cloud);
octree.addPointsFromInputCloud();
std::vector< pcl::PointXYZRGB, Eigen::aligned_allocator<pcl::PointXYZRGB> > voxel_centers;
octree.getOccupiedVoxelCenters(voxel_centers);
// create octomap instance from pcl octree
OcTree final_octree(resolution);
for (const auto & voxel_center: voxel_centers) {
final_octree.updateNode(voxel_center.x,voxel_center.y,voxel_center.z,true,false);
}
final_octree.updateInnerOccupancy();
return final_octree;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment