How to Track the updated Octree in OctoMap
- Octree disables the detection of changement as default, which is same with
enableChangeDetection(false)
- To track the update/change of Octree,
enableChangeDetection(true)
should be called once, after its construction. - Important After detection of change, it must be reset via
resetChangeDetection()
- Code Example
#include <octomap/OccupancyOcTreeBase.h>
#include <octomap/OcTree.h>
#include <octomap/octomap.h>
#include <octomap/math/Utils.h>
octomap::OcTree *m_octree;
m_octree = new octomap::OcTree(octomap_resolution);
m_octree->setProbHit(octomap_hit);
m_octree->setProbMiss(octomap_miss);
m_octree->enableChangeDetection(true); // important!!!
//m_octree->enableChangeDetection(false);
void track_changed_octree(octomap::OcTree *octree){
octomap::KeyBoolMap::const_iterator it;
for (it=octree->changedKeysBegin(); it!=octree->changedKeysEnd(); it++) {
octomap::OcTreeNode* node = octree->search(it->first); // it->first is now key, since KeyBoolMap is structure.
if (node){ // ----> has value
if (octree->isNodeOccupied(node)){
// occupied....
}
else{
// free...
}
}
else{ // does not have value, unknown -----> missing
// missing...
}
}
octree->resetChangeDetection(); //important!!!!
}