color drop when dereference pointer to octomap::ColorOcTree object
SDADEEC opened this issue · 0 comments
SDADEEC commented
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