Hi Sunando,
>
> I am a to the ocomap framework. I wanted to find all the neighbours of
> a node in a map that are occupied. It might be quite stupid question,
> but any help will be greatly appreciated
>
> I am currently generating the tree with few nodes
> octomap::OcTreeKey key = octree.coordToKey(octomap::point3d(1, 1, 1));
> octree.updateNode(octomap::point3d(1, 1, 1), true);
>
> now I want to find the neighbors of this node
>
> lut.genNeighborKey(key, OcTreeLUT::T, neighbor_key);
> p = octree.keyToCoord(neighbor_key);
Only use the LUT if you really know what you're doing, that code is not
really maintained anymore and we haven't used it for some time.
If you know that you are working on voxel keys of size "res" (lowest
octree level), you can find the neighbors directly with the keys:
neighborkey = key;
neighborkey[0] +=1; // neighbor in pos. x-direction
OcTreeNode* result = octree.search(neighborkey);
>
> I search if this node is in the graph
> OcTreeNode* result = octree.search(p.x()+.01,p.y()+.01,p.z()+.01);
>
> however I getting a seg fault over here
> octree.isNodeOccupied(result)
>
"search" may return a pointer to a node, or NULL of the node does not
exist (since x,y,z could be in unknown space). Check the documentation
of search:
http://octomap.github.com/octomap/doc/classoctomap_1_1OcTreeBaseImpl.html#a6db68c9dd1eef46e6343edcc9448a5ce
Thus, you need to check first if the node exists:
if (result != NULL){
octree.isNodeOccupied(result);
...
}
Best regards,
--
Armin Hornung
Humanoid Robots Lab, Albert-Ludwigs-Universit�t Freiburg
Contact:
http://www.informatik.uni-freiburg.de/~hornunga