Program Listing for File tsdf_server.h¶
↰ Return to documentation for file (voxblox_ros/include/voxblox_ros/tsdf_server.h
)
#ifndef VOXBLOX_ROS_TSDF_SERVER_H_
#define VOXBLOX_ROS_TSDF_SERVER_H_
#include <pcl/conversions.h>
#include <pcl/filters/filter.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/point_cloud.h>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <std_srvs/Empty.h>
#include <tf/transform_broadcaster.h>
#include <visualization_msgs/MarkerArray.h>
#include <memory>
#include <queue>
#include <string>
#include <voxblox/alignment/icp.h>
#include <voxblox/core/tsdf_map.h>
#include <voxblox/integrator/tsdf_integrator.h>
#include <voxblox/io/layer_io.h>
#include <voxblox/io/mesh_ply.h>
#include <voxblox/mesh/mesh_integrator.h>
#include <voxblox/utils/color_maps.h>
#include <voxblox_msgs/FilePath.h>
#include <voxblox_msgs/Mesh.h>
#include "voxblox_ros/mesh_vis.h"
#include "voxblox_ros/ptcloud_vis.h"
#include "voxblox_ros/transformer.h"
namespace voxblox {
constexpr float kDefaultMaxIntensity = 100.0;
class TsdfServer {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
TsdfServer(const ros::NodeHandle& nh, const ros::NodeHandle& nh_private);
TsdfServer(const ros::NodeHandle& nh, const ros::NodeHandle& nh_private,
const TsdfMap::Config& config,
const TsdfIntegratorBase::Config& integrator_config);
virtual ~TsdfServer() {}
void getServerConfigFromRosParam(const ros::NodeHandle& nh_private);
void insertPointcloud(const sensor_msgs::PointCloud2::Ptr& pointcloud);
void insertFreespacePointcloud(
const sensor_msgs::PointCloud2::Ptr& pointcloud);
virtual void processPointCloudMessageAndInsert(
const sensor_msgs::PointCloud2::Ptr& pointcloud_msg,
const Transformation& T_G_C, const bool is_freespace_pointcloud);
void integratePointcloud(const Transformation& T_G_C,
const Pointcloud& ptcloud_C, const Colors& colors,
const bool is_freespace_pointcloud = false);
virtual void newPoseCallback(const Transformation& /*new_pose*/) {
// Do nothing.
}
void publishAllUpdatedTsdfVoxels();
void publishTsdfSurfacePoints();
void publishTsdfOccupiedNodes();
virtual void publishSlices();
virtual void updateMesh();
virtual bool generateMesh();
// Publishes all available pointclouds.
virtual void publishPointclouds();
// Publishes the complete map
virtual void publishMap(const bool reset_remote_map = false);
virtual bool saveMap(const std::string& file_path);
virtual bool loadMap(const std::string& file_path);
bool clearMapCallback(std_srvs::Empty::Request& request, // NOLINT
std_srvs::Empty::Response& response); // NOLINT
bool saveMapCallback(voxblox_msgs::FilePath::Request& request, // NOLINT
voxblox_msgs::FilePath::Response& response); // NOLINT
bool loadMapCallback(voxblox_msgs::FilePath::Request& request, // NOLINT
voxblox_msgs::FilePath::Response& response); // NOLINT
bool generateMeshCallback(std_srvs::Empty::Request& request, // NOLINT
std_srvs::Empty::Response& response); // NOLINT
bool publishPointcloudsCallback(
std_srvs::Empty::Request& request, // NOLINT
std_srvs::Empty::Response& response); // NOLINT
bool publishTsdfMapCallback(std_srvs::Empty::Request& request, // NOLINT
std_srvs::Empty::Response& response); // NOLINT
void updateMeshEvent(const ros::TimerEvent& event);
std::shared_ptr<TsdfMap> getTsdfMapPtr() { return tsdf_map_; }
double getSliceLevel() const { return slice_level_; }
void setSliceLevel(double slice_level) { slice_level_ = slice_level; }
bool setPublishSlices() const { return publish_slices_; }
void setPublishSlices(const bool publish_slices) {
publish_slices_ = publish_slices;
}
void setWorldFrame(const std::string& world_frame) {
world_frame_ = world_frame;
}
std::string getWorldFrame() const { return world_frame_; }
virtual void clear();
void tsdfMapCallback(const voxblox_msgs::Layer& layer_msg);
protected:
bool getNextPointcloudFromQueue(
std::queue<sensor_msgs::PointCloud2::Ptr>* queue,
sensor_msgs::PointCloud2::Ptr* pointcloud_msg, Transformation* T_G_C);
ros::NodeHandle nh_;
ros::NodeHandle nh_private_;
bool verbose_;
std::string world_frame_;
std::string icp_corrected_frame_;
std::string pose_corrected_frame_;
double max_block_distance_from_body_;
double slice_level_;
bool use_freespace_pointcloud_;
std::string mesh_filename_;
ColorMode color_mode_;
std::unique_ptr<ColorMap> color_map_;
ros::Duration min_time_between_msgs_;
bool publish_tsdf_info_;
bool publish_slices_;
bool publish_pointclouds_;
bool publish_tsdf_map_;
bool cache_mesh_;
bool enable_icp_;
bool accumulate_icp_corrections_;
ros::Subscriber pointcloud_sub_;
ros::Subscriber freespace_pointcloud_sub_;
int pointcloud_queue_size_;
// Publish markers for visualization.
ros::Publisher mesh_pub_;
ros::Publisher tsdf_pointcloud_pub_;
ros::Publisher surface_pointcloud_pub_;
ros::Publisher tsdf_slice_pub_;
ros::Publisher occupancy_marker_pub_;
ros::Publisher icp_transform_pub_;
ros::Publisher tsdf_map_pub_;
ros::Subscriber tsdf_map_sub_;
// Services.
ros::ServiceServer generate_mesh_srv_;
ros::ServiceServer clear_map_srv_;
ros::ServiceServer save_map_srv_;
ros::ServiceServer load_map_srv_;
ros::ServiceServer publish_pointclouds_srv_;
ros::ServiceServer publish_tsdf_map_srv_;
tf::TransformBroadcaster tf_broadcaster_;
// Timers.
ros::Timer update_mesh_timer_;
// Maps and integrators.
std::shared_ptr<TsdfMap> tsdf_map_;
std::unique_ptr<TsdfIntegratorBase> tsdf_integrator_;
std::shared_ptr<ICP> icp_;
// Mesh accessories.
std::shared_ptr<MeshLayer> mesh_layer_;
std::unique_ptr<MeshIntegrator<TsdfVoxel>> mesh_integrator_;
voxblox_msgs::Mesh cached_mesh_msg_;
Transformer transformer_;
std::queue<sensor_msgs::PointCloud2::Ptr> pointcloud_queue_;
std::queue<sensor_msgs::PointCloud2::Ptr> freespace_pointcloud_queue_;
// Last message times for throttling input.
ros::Time last_msg_time_ptcloud_;
ros::Time last_msg_time_freespace_ptcloud_;
Transformation icp_corrected_transform_;
};
} // namespace voxblox
#endif // VOXBLOX_ROS_TSDF_SERVER_H_