finding occupied neighbours

1,157 views
Skip to first unread message

Sunando Sengupta

unread,
Mar 27, 2013, 2:36:32 AM3/27/13
to oct...@googlegroups.com
Hi,

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);

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)

Am I doing some mistake?

Armin Hornung

unread,
Mar 27, 2013, 6:49:45 AM3/27/13
to oct...@googlegroups.com
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

Christian Dornhege

unread,
Mar 27, 2013, 11:52:40 AM3/27/13
to oct...@googlegroups.com
Hi,
Am 27.03.2013 03:49, schrieb Armin Hornung:
> 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);

Actually as far as I know this is the only thing that the LUT currently
does, just more complicated.

Best,
Christian

Sunando Sengupta

unread,
Apr 6, 2013, 3:37:47 AM4/6/13
to oct...@googlegroups.com
Thanks a lot Armin.

This helped :)

jess

unread,
Jul 28, 2014, 5:39:52 PM7/28/14
to oct...@googlegroups.com
Hi Armin,
I'm also trying to find the neighbors of cells so I'm using the coordToKey and keyToCoord a lot. But I noticed that after I transform a coord to a key, then the key to coord, the resulting coord is not exactly the same as the original one, as the y axis is res/2 less. Is this coming from the implementation of the functions or am I using them wrong?
Thanks!

Armin Hornung

unread,
Aug 7, 2014, 3:36:02 PM8/7/14
to oct...@googlegroups.com
Am 28.07.2014 23:39, schrieb jess:
> Hi Armin,
> I'm also trying to find the neighbors of cells so I'm using the
> coordToKey and keyToCoord a lot. But I noticed that after I transform
> a coord to a key, then the key to coord, the resulting coord is not
> exactly the same as the original one, as the y axis is res/2 less. Is
> this coming from the implementation of the functions or am I using
> them wrong?

Yes, this is generally the expected behavior. You first convert from
float coordinates into discrete keys and then back into floats. The last
step uses to center coordinate of the cell. If you would convert once
into keys and then back again the values should remain constant.

Cheers,
Armin

--
Dr. Armin Hornung
Humanoid Robots Lab, Albert-Ludwigs-Universität Freiburg
Contact: http://www.informatik.uni-freiburg.de/~hornunga

Rang

unread,
Nov 14, 2014, 11:47:46 AM11/14/14
to oct...@googlegroups.com
Hi Armin,
 
What did you mean by
 
"If you would convert once  into keys and then back again the values should remain constant." ?
 
I am also suffering from the same problem that output from keytocoord is not the same as that of
coordtokey. Would you please tell the solution? 

Christian Dornhege

unread,
Nov 14, 2014, 11:57:30 AM11/14/14
to oct...@googlegroups.com
Hi,

I think he means: Once you did coordToKey and keyToCoord any more
iterative applications of the same will not change the coord any more.

The first time the coord will most likely change, and this is expected
behavior. A key represents an octree cell, i.e. all coords within that
voxel. Once you convert coordToKey you thus loose information. There is
also no way around that. If this is a problem you might want to rethink
what you are actually trying to solve.

Best,
Christian
> <http://www.informatik.uni-freiburg.de/~hornunga>
>
> --
> 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
> <mailto:octomap+u...@googlegroups.com>.
> To post to this group, send email to oct...@googlegroups.com
> <mailto:oct...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/octomap.
> For more options, visit https://groups.google.com/d/optout.

Rang

unread,
Nov 20, 2014, 10:52:46 AM11/20/14
to oct...@googlegroups.com
Many thanks Christian.
Reply all
Reply to author
Forward
0 new messages