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

color drop when dereference pointer to octomap::ColorOcTree object #401

Open SDADEEC opened 11 months ago

SDADEEC commented 11 months ago

Hi,

I have a callback function to handle octomap_msgs::Octomap messages. It will receive a message and convert it into octomap::ColorOcTree object then write it to local.

I found when I convert the message to octomap::ColorOcTree pointer and write it to file, the color of the octomap is correct. But when I dereference it and write the object to file, all the color drops. I'm wondering if there is any proper way to dereference pointer to octomap::ColorOcTree object?

The callback function is like

void className::oct_Callback(const octomap_msgs::Octomap::ConstPtr& oct_msg)
{

    octomap::AbstractOcTree* ptr_oc_temp = octomap_msgs::fullMsgToMap(*oct_msg);
    octomap::ColorOcTree* ptr_color_oc_temp = dynamic_cast<octomap::ColorOcTree*>(ptr_oc_temp);

    // Save by pointer
    std::string oct_path = re_path1 + std::to_string(oct_msg->header.stamp.sec) + "_" + std::to_string(oct_msg->header.stamp.nsec)+ ".ot";
    octomap::ColorOcTree oc_c = *ptr_color_oc_temp;
    oc_c.write(oct_path);

    // Save by object
    std::string octptr_path = re_path2 + std::to_string(oct_msg->header.stamp.sec) + "_" + std::to_string(oct_msg->header.stamp.nsec)+ ".ot";
    ptr_color_oc_temp->write(octptr_path);

    delete ptr_color_oc_temp;

}

The 're_path1' and 're_path2' are two std::string to specify the paths to save the octomap files

The octomap saved by pointer is like image

The octomap saved by object is like image