mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-04 00:37:46 +08:00
MapCloud: auto refresh clouds when rtabmap is reset
This commit is contained in:
@@ -272,58 +272,56 @@ void MapCloudDisplay::processMapData(const rtabmap_ros::MapData& map)
|
|||||||
for(unsigned int i=0; i<map.nodes.size() && i<map.nodes.size(); ++i)
|
for(unsigned int i=0; i<map.nodes.size() && i<map.nodes.size(); ++i)
|
||||||
{
|
{
|
||||||
int id = map.nodes[i].id;
|
int id = map.nodes[i].id;
|
||||||
if(poses.find(id) != poses.end() &&
|
|
||||||
cloud_infos_.find(id) == cloud_infos_.end())
|
// Always refresh the cloud if there are data
|
||||||
|
rtabmap::Signature s = rtabmap_ros::nodeDataFromROS(map.nodes[i]);
|
||||||
|
if(!s.sensorData().imageCompressed().empty() &&
|
||||||
|
!s.sensorData().depthOrRightCompressed().empty() &&
|
||||||
|
(s.sensorData().cameraModels().size() || s.sensorData().stereoCameraModel().isValidForProjection()))
|
||||||
{
|
{
|
||||||
// Cloud not added to RVIZ, add it!
|
cv::Mat image, depth;
|
||||||
rtabmap::Signature s = rtabmap_ros::nodeDataFromROS(map.nodes[i]);
|
s.sensorData().uncompressData(&image, &depth, 0);
|
||||||
if(!s.sensorData().imageCompressed().empty() &&
|
|
||||||
!s.sensorData().depthOrRightCompressed().empty() &&
|
|
||||||
(s.sensorData().cameraModels().size() || s.sensorData().stereoCameraModel().isValidForProjection()))
|
if(!s.sensorData().imageRaw().empty() && !s.sensorData().depthOrRightRaw().empty())
|
||||||
{
|
{
|
||||||
cv::Mat image, depth;
|
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
||||||
s.sensorData().uncompressData(&image, &depth, 0);
|
pcl::IndicesPtr validIndices(new std::vector<int>);
|
||||||
|
cloud = rtabmap::util3d::cloudRGBFromSensorData(
|
||||||
|
s.sensorData(),
|
||||||
|
cloud_decimation_->getInt(),
|
||||||
|
cloud_max_depth_->getFloat(),
|
||||||
|
cloud_min_depth_->getFloat(),
|
||||||
|
validIndices.get());
|
||||||
|
|
||||||
|
if(cloud_voxel_size_->getFloat())
|
||||||
if(!s.sensorData().imageRaw().empty() && !s.sensorData().depthOrRightRaw().empty())
|
|
||||||
{
|
{
|
||||||
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
cloud = rtabmap::util3d::voxelize(cloud, validIndices, cloud_voxel_size_->getFloat());
|
||||||
pcl::IndicesPtr validIndices(new std::vector<int>);
|
}
|
||||||
cloud = rtabmap::util3d::cloudRGBFromSensorData(
|
|
||||||
s.sensorData(),
|
|
||||||
cloud_decimation_->getInt(),
|
|
||||||
cloud_max_depth_->getFloat(),
|
|
||||||
cloud_min_depth_->getFloat(),
|
|
||||||
validIndices.get());
|
|
||||||
|
|
||||||
if(cloud_voxel_size_->getFloat())
|
if(cloud->size())
|
||||||
|
{
|
||||||
|
if(cloud_filter_floor_height_->getFloat() > 0.0f || cloud_filter_ceiling_height_->getFloat() > 0.0f)
|
||||||
{
|
{
|
||||||
cloud = rtabmap::util3d::voxelize(cloud, validIndices, cloud_voxel_size_->getFloat());
|
cloud = rtabmap::util3d::passThrough(cloud, "z",
|
||||||
|
cloud_filter_floor_height_->getFloat()>0.0f?cloud_filter_floor_height_->getFloat():-999.0f,
|
||||||
|
cloud_filter_ceiling_height_->getFloat()>0.0f && (cloud_filter_floor_height_->getFloat()<=0.0f || cloud_filter_ceiling_height_->getFloat()>cloud_filter_floor_height_->getFloat())?cloud_filter_ceiling_height_->getFloat():999.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cloud->size())
|
sensor_msgs::PointCloud2::Ptr cloudMsg(new sensor_msgs::PointCloud2);
|
||||||
|
pcl::toROSMsg(*cloud, *cloudMsg);
|
||||||
|
cloudMsg->header = map.header;
|
||||||
|
|
||||||
|
CloudInfoPtr info(new CloudInfo);
|
||||||
|
info->message_ = cloudMsg;
|
||||||
|
info->pose_ = rtabmap::Transform::getIdentity();
|
||||||
|
info->id_ = id;
|
||||||
|
|
||||||
|
if (transformCloud(info, true))
|
||||||
{
|
{
|
||||||
if(cloud_filter_floor_height_->getFloat() > 0.0f || cloud_filter_ceiling_height_->getFloat() > 0.0f)
|
boost::mutex::scoped_lock lock(new_clouds_mutex_);
|
||||||
{
|
new_cloud_infos_.erase(id);
|
||||||
cloud = rtabmap::util3d::passThrough(cloud, "z",
|
new_cloud_infos_.insert(std::make_pair(id, info));
|
||||||
cloud_filter_floor_height_->getFloat()>0.0f?cloud_filter_floor_height_->getFloat():-999.0f,
|
|
||||||
cloud_filter_ceiling_height_->getFloat()>0.0f && (cloud_filter_floor_height_->getFloat()<=0.0f || cloud_filter_ceiling_height_->getFloat()>cloud_filter_floor_height_->getFloat())?cloud_filter_ceiling_height_->getFloat():999.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
sensor_msgs::PointCloud2::Ptr cloudMsg(new sensor_msgs::PointCloud2);
|
|
||||||
pcl::toROSMsg(*cloud, *cloudMsg);
|
|
||||||
cloudMsg->header = map.header;
|
|
||||||
|
|
||||||
CloudInfoPtr info(new CloudInfo);
|
|
||||||
info->message_ = cloudMsg;
|
|
||||||
info->pose_ = rtabmap::Transform::getIdentity();
|
|
||||||
info->id_ = id;
|
|
||||||
|
|
||||||
if (transformCloud(info, true))
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock lock(new_clouds_mutex_);
|
|
||||||
new_cloud_infos_.insert(std::make_pair(id, info));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -633,6 +631,7 @@ void MapCloudDisplay::update( float wall_dt, float ros_dt )
|
|||||||
cloud_info->scene_node_->attachObject( cloud_info->cloud_.get() );
|
cloud_info->scene_node_->attachObject( cloud_info->cloud_.get() );
|
||||||
cloud_info->scene_node_->setVisible(false);
|
cloud_info->scene_node_->setVisible(false);
|
||||||
|
|
||||||
|
cloud_infos_.erase(it->first);
|
||||||
cloud_infos_.insert(*it);
|
cloud_infos_.insert(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user