Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SDADEEC opened this issue Jul 11, 2023 · 0 comments
Open

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

SDADEEC opened this issue Jul 11, 2023 · 0 comments

Comments

@SDADEEC
Copy link

SDADEEC commented Jul 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant