How to get all unknown voxels from octomap

2,368 views
Skip to first unread message

Victor M

unread,
Sep 4, 2014, 1:24:23 PM9/4/14
to oct...@googlegroups.com
Hello: I am new to Octomap and trying to get all the unknown voxels. I have gone through the recent octomap paper (Armin et al, Autonomous Robots 2013) and came to know that all voxels (cells) that exist in octomap are either free or occupied. Unknown space is encoded implicitly by non-existing nodes.

Can anyone please tell me how can I iterate through all nodes (or just leaf nodes ?)  and then find all the unknown voxels, their center and size of voxel?

Thanks in advance!

Armin Hornung

unread,
Sep 13, 2014, 9:30:58 AM9/13/14
to oct...@googlegroups.com
You can iterate through all leafs with a leaf iterator:
http://octomap.github.io/octomap/doc/classleaf__iterator.html#details

You could use that information (center and size as shown in the example)
to "carve" the known space out from unknown.

If you are only interested in a small bounding box, you could iterate
over all OcTreeKeys in the bounding box, then call search() on each key
and check if the return value is NULL.

Best regards,
Armin

shehroze bhatti

unread,
Apr 15, 2015, 7:55:34 PM4/15/15
to oct...@googlegroups.com
Hi Armin

I actually need unknown voxels as well and I was just wondering what do you mean by "carve the known space out from unknown " ???


Regards
Shehroze

Miguel Armando Riem de Oliveira

unread,
Apr 16, 2015, 11:48:48 AM4/16/15
to oct...@googlegroups.com
Hello Armin,

I am starting to use the octomap. My goal is to compute the unknown space using an octree representation. 

I have tried to implement your second suggestion but without any good results. 
Do you have any suggestion as to what I am doing wrong? Here is my code:

//msg comes from a ros message ...

AbstractOcTree* tree = msgToMap(*msg);
OcTree* octree = dynamic_cast<OcTree*>(tree); 

//Define a bouding box
point3d min; min.x() = -1; min.y() = -1; min.z() = -1;
point3d max; max.x() = 1; max.y() = 1; max.z() = 1;

for(OcTree::leaf_bbx_iterator it = octree->begin_leafs_bbx(min,max), end=octree->end_leafs_bbx(); it!= end; ++it)
{
        //if (octree->search(it.getX(), it.getY(), it.getZ()) == NULL)
        if (octree->search(it.getKey()) == NULL)
        {   
            cout << "Found an unknown" << endl;
        }   
}           

So my problem is that I never get a print saying "Found unknown".

Thanks for the help.

Miguel

Armin Hornung

unread,
Apr 20, 2015, 12:38:07 PM4/20/15
to oct...@googlegroups.com, Miguel Armando Riem de Oliveira
The problem is that you iterate over nodes in the tree, which are always either free or occupied. Unknown space is only implicitly represented in octomap by missing information.

So you need to iterate over all coordinates or keys in the bounding box and then check if the corresponding node exist.

Miguel Armando Riem de Oliveira

unread,
Jun 9, 2015, 10:00:15 AM6/9/15
to oct...@googlegroups.com
Hi Vitor,

this is how I do it:

point3d min; min.x() = 0.6; min.y() = -.7; min.z() = 0.6;
cout << min << endl;
point3d max; max.x() = 1.4; max.y() = 0.7; max.z() = 2.0;
cout << max << endl;
double resolution = 0.05;

for (double ix = min.x(); ix < max.x(); ix += resolution)
   for (double iy = min.y(); iy < max.y(); iy += resolution)
         for (double iz = min.z(); iz < max.z(); iz += resolution)
         {
              if (!octree->search(ix,iy,iz))
              {
                    //This cell is unknown
              }
         }


Basically, I iterate over a 3d grid of points, and for each check if there is a valid octree cell, if there is not, then that cell is unknown

Hope it helps,

Miguel
Reply all
Reply to author
Forward
0 new messages