-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscriber.cpp
More file actions
executable file
·58 lines (54 loc) · 1.65 KB
/
subscriber.cpp
File metadata and controls
executable file
·58 lines (54 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <boost/foreach.hpp>
#include <fstream>
#include <nav_msgs/Path.h>
#include <geometry_msgs/PoseStamped.h>
typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloud;
std::vector<pcl::PointXYZRGB> points;
void pcd_callback(const PointCloud::ConstPtr& msg)
{
printf ("Cloud: width = %d, height = %d\n", msg->width, msg->height);
points.clear();
BOOST_FOREACH (pcl::PointXYZRGB pt, msg->points)
{
points.push_back(pt);
}
}
int main(int argc, char** argv)
{
char* pcd_topic = argv[1];
<<<<<<< HEAD
=======
char* path_topic = "/mapPath";
>>>>>>> 607468dfaa1cce6b1255b0bb6bfd910f09b888fb
std::cout << "subscribing to " << pcd_topic << std::endl;
ros::init(argc, argv, "sub_pcl");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe<PointCloud>(pcd_topic, 1, pcd_callback);
ros::spin();
// save pointcloud
std::cout << "Saving pointcloud..." << std::endl;
std::ofstream points_output(argv[2]);
std::ofstream rgbs_output(argv[3]);
// write pointcloud file cap
points_output << \
"VERSION .5\n\
FIELDS x y z\n\
SIZE 4 4 4\n\
TYPE F F F\n\
COUNT 1 1 1\n\
WIDTH " << points.size() << std::endl << \
"HEIGHT 1\n\
POINTS " << points.size() << std::endl << \
"DATA ascii" << std::endl;
// write pointcloud file data
for (int i = 0; i < points.size(); i++)
{
points_output << points[i].x << ' ' << points[i].y << ' ' << points[i].z << std::endl;
rgbs_output << (int)points[i].r << ' ' << (int)points[i].g << ' ' << (int)points[i].b << std::endl;
}
points_output.close();
rgbs_output.close();
}