Convert OctoMap to Voxel Grid

Skip to first unread message

Martin Kerschberger

May 23, 2019, 3:51:44 AM5/23/19
to OctoMap developers and users discussion
Hi everyone,

i want to convert an existing Octomap to a Voxel Grid with fixed size of 32x32x32 voxels.

In my naive approach i assumed that setting a maxDepth of 5 for my treeIterator (begin_tree(5)) i would receive the goal of getting the octomap to represent the 32x32x32 cubes and just need to transform them to my grid.

But so i only get 21 nodes for my testing model, and only about 4 ocupied nodes. I know that unknown nodes are not represented but 21 is very low instead the at maximum 32768 nodes i expceted at this level.

Can anyone please give me a hint what i missunderstood in this concept or what I'm doing wrong?

br Martin

Federico Ferri

May 24, 2019, 4:03:09 AM5/24/19
Hi Martin,

You have to either recursively expand the nodes by calling
OcTreeNode::expandNode(), or take into account the level of the node
you are iterating and fill the voxel grid according to node's size.

Have a look at the src/octree2pointcloud.cpp example I added some time
ago,m where I used the first approach (simpler).

Federico Ferri
> --
> You received this message because you are subscribed to the Google Groups "OctoMap developers
> and users discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To post to this group, send email to
> Visit this group at
> To view this discussion on the web visit
> For more options, visit

Martin Kerschberger

May 27, 2019, 3:04:58 PM5/27/19
to OctoMap developers and users discussion
Hi Frederico,

Thank you very much for your help!

This helped me allready much in understanding, but unfortunatly this did not solve my problem. The nodes get expanded but at the desired level there are still only four occupied nodes.

But i think i now unterstood whats the cause of the problem:
While experimenting i found the node size for the query depth is 102.4. I guess the unit is meters for this value?
And the size of the root node is 3276.8 (meters?).

Since my models are at maximum inside a cube of 10 meters the size of the root node with 3276.8 meters is somehow wide outside the required range.

Is there a way to shrink the tree so its root node fits only existing coordinates, or to shrink the root node to say 10 meters?

Unfortunatly i did not recognise such a function yet...

br Martin

> To unsubscribe from this group and stop receiving emails from it, send an email to

Martin Kerschberger

May 29, 2019, 6:06:20 AM5/29/19
to OctoMap developers and users discussion
Hi everyone,

i think i figured it out now:

* Expand all the nodes as mentioned above.

* Get the size of the actual occoupied part of the model
double maxX, maxY, maxZ;
point3d maxBb = point3d(maxX, maxY, maxZ);
cout << "metric max " << maxBb.x() << "," << maxBb.y() << "," << maxBb.z() << endl;
double minX, minY, minZ;
point3d minBb = point3d(minX, minY, minZ);
cout << "metric min " << minBb.x() << "," << minBb.y() << "," << minBb.z() << endl;

* Query the model inside the bounding box
tree->begin_leafs_bbx(minBb, maxBb, maxDepth)

and "normalize" the occupied nodes into my 32x32x32 cube.

Please let me know if there is an easier/cheaper way...

br Martin
Reply all
Reply to author
0 new messages