personalrobotics / or_octomap

or_octomap is a collision checker and sensor system plugin for OpenRAVE, intended to allow OpenRAVE meshes to be collision checked against octrees.
1 stars 2 forks source link

invalid conversion from AbstractOctree* to Octree* #2

Open jontromanab opened 7 years ago

jontromanab commented 7 years ago

Hello,

When I was trying to build the package, I got this error:

/src/OctomapClientInterface.cpp:129:12: error: invalid conversion from ‘octomap::AbstractOcTree’ to ‘octomap::OcTree’ [-fpermissive]

The line is:

  1. m_octree = octomap_msgs::binaryMsgToMap(m_octomapMsg.response.map);

where m_octree is a octomap::OcTree, but found out the binaryMsgToMap() returns a octomap::AbstractOcTree I have changed the code like this:

octomap::AbstractOcTree tree = octomap_msgs::binaryMsgToMap(m_octomapMsg.response.map); m_octree = (octomap::OcTree)tree;

which is building fine. Is this casting right?

Thank you.

indraneelpatil commented 5 years ago

@jontromanab I am aware that this is an extremely old question, but for whoever faces this problem in the future, I can safely confirm this solution:

    octomap::OcTree* octTree = new octomap::OcTree(0.1);
   octomap::AbstractOcTree* tree = octomap_msgs::fullMsgToMap(*msg);
    octTree = dynamic_cast<octomap::OcTree*>(tree);
HZhang1003 commented 2 years ago

@jontromanab I am aware that this is an extremely old question, but for whoever faces this problem in the future, I can safely confirm this solution:

    octomap::OcTree* octTree = new octomap::OcTree(0.1);
   octomap::AbstractOcTree* tree = octomap_msgs::fullMsgToMap(*msg);
    octTree = dynamic_cast<octomap::OcTree*>(tree);

thank you very much for your answer. You solved the problem that bothered me for a long time!!!!!

hichamhendy commented 1 year ago

Hello,

When I was trying to build the package, I got this error:

_/src/OctomapClientInterface.cpp:129:12: error: invalid conversion from ‘octomap::AbstractOcTree’ to ‘octomap::OcTree_’ [-fpermissive]**

The line is: 129. m_octree = octomap_msgs::binaryMsgToMap(m_octomapMsg.response.map);

where m_octree is a octomap::OcTree, but found out the binaryMsgToMap() returns a octomap::AbstractOcTree I have changed the code like this:

octomap::AbstractOcTree tree = octomap_msgs::binaryMsgToMap(m_octomapMsg.response.map); m_octree = (octomap::OcTree)tree;

which is building fine. Is this casting right?

Thank you.

I was facing troubles because of the dynamic casting actually and for some reason, the regular casting works fine. I know that makes no sense but it's worth mentioning if someone has some memory leaks because of memory management!