Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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