8 #include <sensor_msgs/Image.h> 9 #include <sensor_msgs/CameraInfo.h> 10 #include <sensor_msgs/PointCloud2.h> 13 #include <geometry_msgs/PointStamped.h> 14 #include <geometry_msgs/PolygonStamped.h> 40 rect_sub_.
subscribe (pnode_,
"rect", queue_size);
41 point_sub_.
subscribe (pnode_,
"point", queue_size);
42 points_sub_.
subscribe (pnode_,
"points", queue_size);
44 sync_a_polygon_ = boost::make_shared < message_filters::Synchronizer< PolygonApproxSyncPolicy > > (
queue_size);
45 sync_a_polygon_->connectInput (points_sub_, rect_sub_);
48 sync_a_point_ = boost::make_shared < message_filters::Synchronizer< PointApproxSyncPolicy > > (
queue_size);
49 sync_a_point_->connectInput (points_sub_, point_sub_);
52 pub_ = pnode_.
advertise< sensor_msgs::PointCloud2 > (
"output", 1);
56 const geometry_msgs::PointStampedConstPtr& array_ptr) {
62 int wd = points_ptr->width;
63 int ht = points_ptr->height;
64 int rstep = points_ptr->row_step;
65 int pstep = points_ptr->point_step;
66 if (st_x < 0) st_x = 0;
67 if (st_y < 0) st_x = 0;
68 if (ed_x >= wd) ed_x = wd - 1;
69 if (ed_y >= ht) ed_y = ht - 1;
71 sensor_msgs::PointCloud2 pt;
72 pt.header = points_ptr->header;
73 pt.width = ed_x - st_x + 1;
74 pt.height = ed_y - st_y + 1;
75 pt.row_step = pt.width * pstep;
76 pt.point_step = pstep;
77 pt.is_bigendian =
false;
78 pt.fields = points_ptr->fields;
80 pt.data.resize(pt.row_step * pt.height);
82 unsigned char * dst_ptr = &(pt.data[0]);
84 for (
size_t idx_y = st_y; idx_y <= ed_y; idx_y++) {
85 for (
size_t idx_x = st_x; idx_x <= ed_x; idx_x++) {
86 const unsigned char * src_ptr = &(points_ptr->data[idx_y * rstep + idx_x * pstep]);
87 memcpy(dst_ptr, src_ptr, pstep);
95 const geometry_msgs::PolygonStampedConstPtr& array_ptr) {
100 ROS_INFO(
"number of subscribers is 0, ignoring image");
105 if (array_ptr->polygon.points.size() > 1) {
106 int st_x = array_ptr->polygon.points[0].x;
107 int st_y = array_ptr->polygon.points[0].y;
108 int ed_x = array_ptr->polygon.points[1].x;
109 int ed_y = array_ptr->polygon.points[1].y;
110 int wd = points_ptr->width;
111 int ht = points_ptr->height;
112 int rstep = points_ptr->row_step;
113 int pstep = points_ptr->point_step;
115 sensor_msgs::PointCloud2 pt;
116 pt.header = points_ptr->header;
117 pt.width = ed_x - st_x + 1;
118 pt.height = ed_y - st_y + 1;
119 pt.row_step = pt.width * pstep;
120 pt.point_step = pstep;
121 pt.is_bigendian =
false;
122 pt.fields = points_ptr->fields;
124 pt.data.resize(pt.row_step * pt.height);
126 unsigned char * dst_ptr = &(pt.data[0]);
128 for (
size_t idx_y = st_y; idx_y <= ed_y; idx_y++) {
129 for (
size_t idx_x = st_x; idx_x <= ed_x; idx_x++) {
130 const unsigned char * src_ptr = &(points_ptr->data[idx_y * rstep + idx_x * pstep]);
131 memcpy(dst_ptr, src_ptr, pstep);
140 int main (
int argc,
char **argv)
142 ros::init (argc, argv,
"points_rectangle_extractor");
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
uint32_t getNumSubscribers() const
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)