OctoMap / octomap

An Efficient Probabilistic 3D Mapping Framework Based on Octrees. Contains the main OctoMap library, the viewer octovis, and dynamicEDT3D.
http://octomap.github.io
1.87k stars 652 forks source link

Map Dynamic Casting fails #390

Open hichamhendy opened 1 year ago

hichamhendy commented 1 year ago

I am trying to process the binary map generated from octo binary; however the dynamic casting keeps failing. The call back function as the following

`void Planner::octomapBinaryCallback(const octomap_msgs::Octomap::ConstPtr& binary_msg)

{

ROS_INFO("Message Resolution is %f", binary_msg->resolution);

std::lock_guard<std::mutex> lock(octomap_mutex); 

ros::Time current = ros::Time::now();

// Update map at a fixed rate. This is useful on setting replanning rates for the planner.

if ((current - last_wp_time_).toSec() < mapupdate_dt_) 
{
    return;
}
last_wp_time_ = ros::Time::now();
octomap::AbstractOcTree* msg_octree = octomap_msgs::msgToMap(*binary_msg);
if (tree_oct) 
{
    delete tree_oct;
}
if (msg_octree)
{
    tree_oct = dynamic_cast<octomap::OcTree*>(msg_octree);  // dynamic casting from octomap::AbstractOcTree to octomap::OcTree

    if(tree_oct == NULL)
    {
        ROS_WARN("Casting failed!I'm out");
        return;
    }

    else
        ROS_WARN("Resolution is %f", tree_oct->getResolution ());
}

if (tree_oct)
{
    ROS_INFO("%s: Octomap received %zu nodes, %f m of resolution", ros::this_node::getName().c_str(), tree_oct->size(), tree_oct->getResolution());
    fcl::OcTree* tree = NULL;
    tree = (new fcl::OcTree(std::shared_ptr<const octomap::OcTree>(tree_oct)));
    // Update the octree used for collision checking
    updateOctotree(std::shared_ptr<fcl::CollisionGeometry>(tree));
    replan();
    delete tree;
    tree_oct->clear();
} 
else
{
    ROS_ERROR("Error by reading OcTree from stream");
    tree_oct->clear();
} 

}`

can anybody see a problem here??

I traced the problem it lies in this critical command tree_oct = dynamic_cast<octomap::OcTree*>(msg_octree);