Go to the documentation of this file.00001 #include <fstream>
00002 #include <memory>
00003
00004 #include "ros/ros.h"
00005 #include "ros/console.h"
00006
00007 #include "pointmatcher/PointMatcher.h"
00008
00009 #include "pointmatcher_ros/point_cloud.h"
00010 #include "pointmatcher_ros/transform.h"
00011 #include "pointmatcher_ros/get_params_from_server.h"
00012 #include "pointmatcher_ros/ros_logger.h"
00013
00014 #include "geometry_msgs/PoseWithCovarianceStamped.h"
00015 #include "nav_msgs/Odometry.h"
00016 #include "tf/transform_broadcaster.h"
00017 #include "tf_conversions/tf_eigen.h"
00018 #include "tf/transform_listener.h"
00019
00020 using namespace std;
00021 using namespace PointMatcherSupport;
00022
00023 class ExportVtk
00024 {
00025 typedef PointMatcher<float> PM;
00026 typedef PM::DataPoints DP;
00027
00028 ros::NodeHandle& n;
00029
00030 ros::Subscriber cloudSub;
00031 const string cloudTopic;
00032 const string mapFrame;
00033 const bool recordOnce;
00034
00035 tf::TransformListener tf_listener;
00036 std::shared_ptr<PM::Transformation> transformation;
00037
00038 public:
00039 ExportVtk(ros::NodeHandle& n);
00040 void gotCloud(const sensor_msgs::PointCloud2& cloudMsg);
00041 };
00042
00043 ExportVtk::ExportVtk(ros::NodeHandle& n):
00044 n(n),
00045 cloudTopic(getParam<string>("cloudTopic", "/static_point_cloud")),
00046 mapFrame(getParam<string>("mapFrameId", "/map")),
00047 recordOnce(getParam<bool>("recordOnce", "false")),
00048 transformation(PM::get().TransformationRegistrar.create("RigidTransformation"))
00049 {
00050
00051 cloudSub = n.subscribe(cloudTopic, 100, &ExportVtk::gotCloud, this);
00052
00053
00054 }
00055
00056
00057 void ExportVtk::gotCloud(const sensor_msgs::PointCloud2& cloudMsgIn)
00058 {
00059 const DP inCloud(PointMatcher_ros::rosMsgToPointMatcherCloud<float>(cloudMsgIn));
00060
00061 try
00062 {
00063 const PM::TransformationParameters tr(PointMatcher_ros::transformListenerToEigenMatrix<float>(tf_listener, mapFrame, cloudMsgIn.header.frame_id, cloudMsgIn.header.stamp));
00064
00065 const DP outCloud(transformation->compute(inCloud, tr));
00066
00067 if (outCloud.features.cols() == 0)
00068 {
00069 ROS_ERROR("I found no good points in the cloud");
00070 return;
00071 }
00072 else
00073 {
00074 ROS_INFO("Saving cloud");
00075 }
00076
00077 stringstream nameStream;
00078 nameStream << "." << cloudTopic << "_" << cloudMsgIn.header.seq << ".vtk";
00079 outCloud.save(nameStream.str());
00080 if(recordOnce)
00081 {
00082 ros::shutdown();
00083 }
00084 }
00085 catch (tf::ExtrapolationException e)
00086 {
00087 ROS_WARN("Still build tf tree, skipping that scan");
00088 }
00089 }
00090
00091
00092 int main(int argc, char **argv)
00093 {
00094 ros::init(argc, argv, "pointCloudToVtk_node");
00095 ros::NodeHandle n;
00096 ExportVtk exporter(n);
00097 ros::spin();
00098
00099
00100 while(ros::ok()){}
00101
00102 return 0;
00103 }