Making a Copy of an Octomap

188 views
Skip to first unread message

David Sestak

unread,
Oct 23, 2019, 11:04:32 AM10/23/19
to OctoMap developers and users discussion
Hello,

I tried searching for this issue of mine on the internet, but I was not clear on the answers.

In my code, I initialize an octomap of an environment and with my current method of calculating information gain I try to use a copy of the original octomap I initialized to cross check which nodes have been checked already, are unknown, or haven't been checked using ray-casting at a candidate goal point (I'm working on an Exploration Problem).

I construct the original map as a pointer as follows:

m_octree = reinterpret_cast<octomap::OcTree*>(octree_in);

Then to "copy" it, I merely make a copy of the pointer:

octree_tmp = m_octree;

Then, during the information gain calculation function, after cross checking with the maps, for each node, I perform:

octree_tmp->deleteNode(ray[i].x(),ray[i].y(),ray[i].z())

I realize now, that this is merely a pointer to the original and I am actually deleting the nodes of the original map (there by losing data and ruining the rest of the iterations), so at the end of the iteration it is certainly not enough to simply do:

octree_tmp = m_octree;

to reinitialize the temporary map as the original for the next iteration.

Maybe there is a better way to perform the information gain calculation, but it also seems to me there there should be an easier way (and more importantly more computationally efficient way) to get the data of the original map to the temporary map after each iteration than by initializing the map every iteration with:

octomap::AbstractOcTree* readTreeAbstract = octomap::AbstractOcTree::read(*filenameOt);
octomap::OcTree* readTreeOt = dynamic_cast<octomap::OcTree*>(readTreeAbstract);
m_octree = reinterpret_cast<octomap::OcTree*>(readTreeOt);

Ideally, I just want to initialize the octomap once and copy the values to another "temporary" octomap which I perform changes on without altering the original. I would appreciate any advice in this because I tried de-referencing the pointers to get at its value rather than just the memory address, and a few other combinations. I am not so strong with C++ yet, so I apologize if this exact question does not belong here.

Thank you and kind regards,
David Sestak

Armin Hornung

unread,
Nov 8, 2019, 10:39:26 AM11/8/19
to oct...@googlegroups.com

Hi David,

both OcTree classes and the actual nodes have a deep copy operation in the copy constructor. Could those help you either by storing a complete octree copy or by storing parts of it?

You can use it like this:


OcTree tree (0.1);
//...

OcTree* treeCopyPtr = new OcTree(tree);
// or
OcTree treeCopy2(tree);


Best regards,

Armin


Reply all
Reply to author
Forward
0 new messages