Convert OctoMap to Voxel Grid

264 views
Skip to first unread message

Martin Kerschberger

unread,
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

unread,
May 24, 2019, 4:03:09 AM5/24/19
to oct...@googlegroups.com
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).

Cheers,
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 octomap+u...@googlegroups.com.
> To post to this group, send email to oct...@googlegroups.com.
> Visit this group at https://groups.google.com/group/octomap.
> To view this discussion on the web visit https://groups.google.com/d/msgid/octomap/8610cef1-f1a6-443d-ab9d-776c7c421f31%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Martin Kerschberger

unread,
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 oct...@googlegroups.com.

Martin Kerschberger

unread,
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;
  tree->getMetricMax(maxX,maxY,maxZ);
point3d maxBb = point3d(maxX, maxY, maxZ);
cout << "metric max " << maxBb.x() << "," << maxBb.y() << "," << maxBb.z() << endl;
double minX, minY, minZ;
  tree->getMetricMin(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
Forward
0 new messages