Ask Your Question
1

Is there an existing implementation to save an Octomap octree as a PCD file?

asked 2011-03-09 23:51:50 -0600

raphael favier gravatar image

updated 2011-03-09 23:56:26 -0600

Hello,

I am wondering if there is already a way to save an octree generated with Octomap as a pcd file?

Raph

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-03-10 04:01:42 -0600

raphael favier gravatar image

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

edit flag offensive delete link more

Comments

1
You might want to structure this more in a public package.
KoenBuys gravatar imageKoenBuys ( 2011-03-10 06:24:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-03-09 23:51:50 -0600

Seen: 1,682 times

Last updated: Mar 10 '11