pointCloudToVtk.cpp
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         string cloudTopic;
00032         string mapFrame;
00033 
00034         tf::TransformListener tf_listener;
00035         std::shared_ptr<PM::Transformation> transformation;
00036 
00037 public:
00038         ExportVtk(ros::NodeHandle& n);
00039         void gotCloud(const sensor_msgs::PointCloud2& cloudMsg);
00040 };
00041 
00042 ExportVtk::ExportVtk(ros::NodeHandle& n):
00043         n(n),
00044         transformation(PM::get().TransformationRegistrar.create("RigidTransformation"))
00045 {
00046         // ROS initialization
00047         cloudTopic = getParam<string>("cloudTopic", "/static_point_cloud");
00048         cloudSub = n.subscribe(cloudTopic, 100, &ExportVtk::gotCloud, this);
00049         
00050         // Parameters for 3D map
00051         mapFrame= getParam<string>("mapFrameId", "/map");
00052 }
00053 
00054 
00055 void ExportVtk::gotCloud(const sensor_msgs::PointCloud2& cloudMsgIn)
00056 {
00057         const DP inCloud(PointMatcher_ros::rosMsgToPointMatcherCloud<float>(cloudMsgIn));
00058         
00059         const PM::TransformationParameters tr(PointMatcher_ros::transformListenerToEigenMatrix<float>(tf_listener, cloudMsgIn.header.frame_id, mapFrame, cloudMsgIn.header.stamp));
00060         
00061         const DP outCloud(transformation->compute(inCloud, tr));
00062         
00063         if (outCloud.features.cols() == 0)
00064         {
00065                 ROS_ERROR("I found no good points in the cloud");
00066                 return;
00067         }
00068         else
00069         {
00070                 ROS_INFO("Saving cloud");
00071         }
00072         
00073         stringstream nameStream;
00074         nameStream << "." << cloudTopic << "_" << cloudMsgIn.header.seq << ".vtk";
00075         outCloud.save(nameStream.str());
00076 }
00077 
00078 // Main function supporting the ExportVtk class
00079 int main(int argc, char **argv)
00080 {
00081         ros::init(argc, argv, "pointCloudToVtk_node");
00082         ros::NodeHandle n;
00083         ExportVtk exporter(n);
00084         ros::spin();
00085         
00086         return 0;
00087 }


ethzasl_point_cloud_vtk_tools
Author(s): François Pomerleau and Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:16:38