Hello,
I am wondering if there is already a way to save an octree generated with Octomap as a pcd file?
Raph
Originally posted by raphael favier on ROS Answers with karma: 1382 on 2011-03-10
Post score: 1
Hello,
I am wondering if there is already a way to save an octree generated with Octomap as a pcd file?
Raph
Originally posted by raphael favier on ROS Answers with karma: 1382 on 2011-03-10
Post score: 1
I made it myself, inspired by the code from octomap_server:
#include <octomap/octomap.h>
#include <octomap/OcTreeLabeled.h>
#include "pcl/io/pcd_io.h"
#include "pcl/point_types.h"
...
void buildCloud(OcTree tree)
{
//how many occupied cells do we have in the tree?
std::list<octomap::OcTreeVolume> occupiedCells;
tree.getOccupied(occupiedCells);
//cloud to store the points
pcl::PointCloud<pcl::PointXYZ> cloud;
cloud.points.resize(occupiedCells.size());
std::list<octomap::OcTreeVolume>::iterator it;
int i=0;
for (it = occupiedCells.begin(); it != occupiedCells.end(); ++it, i++)
{
//add point in point cloud
cloud.points[i].x = it->first.x();
cloud.points[i].y = it->first.y();
cloud.points[i].z = it->first.z();
}
//save cloud
pcl::io::savePCDFileASCII ("file.pcd", cloud);
}
Raph
Originally posted by raphael favier with karma: 1382 on 2011-03-10
This answer was ACCEPTED on the original site
Post score: 4
Comment by KoenBuys on 2011-03-10:
You might want to structure this more in a public package.