og_to_pc.cpp
Go to the documentation of this file.
00001 
00002 #include <ros/ros.h>
00003 #include <sensor_msgs/PointCloud.h>
00004 
00005 #include "point_cloud_ros/occupancy_grid.h"
00006 #include "point_cloud_ros/OccupancyGrid.h" // ROS Message
00007 
00008 using namespace std;
00009 
00010 class OccupancyGridToPointCloud 
00011 {
00012     private:
00013         // ROS
00014         ros::NodeHandle nh_;
00015         ros::Subscriber sub_og_;
00016         ros::Publisher pub_points_;
00017 
00018         int queue_size_;
00019         string og_in_, points_out_;
00020 
00021     public:
00023         OccupancyGridToPointCloud () : nh_ ("~"), queue_size_ (1), og_in_ ("/og_in"), points_out_ ("/points_out")
00024         {
00025             pub_points_ = nh_.advertise<sensor_msgs::PointCloud> (points_out_, queue_size_);
00026             sub_og_ = nh_.subscribe (og_in_, queue_size_, &OccupancyGridToPointCloud::cloud_cb_og, this);
00027             ROS_INFO ("OccupancyGridToPointCloud initialized to transform from OccupancyGrid (%s) to PointCloud (%s).", nh_.resolveName (og_in_).c_str (), nh_.resolveName (points_out_).c_str ());
00028         }
00029 
00031 
00032         void cloud_cb_og(const point_cloud_ros::OccupancyGridConstPtr &msg)
00033         {
00034             ROS_INFO("cloud_cb_og called");
00035             if (pub_points_.getNumSubscribers () <= 0)
00036             {
00037                 ROS_DEBUG ("[occupancy_grid_converter] Got an OccuancyGrid but no subscribers.");
00038                 return;
00039             }
00040 
00041             float cx = msg->center.x;
00042             float cy = msg->center.y;
00043             float cz = msg->center.z;
00044 
00045             float rx = msg->resolution.x;
00046             float ry = msg->resolution.y;
00047             float rz = msg->resolution.z;
00048 
00049             float sx = msg->grid_size.x;
00050             float sy = msg->grid_size.y;
00051             float sz = msg->grid_size.z;
00052 
00053             occupancy_grid::OccupancyGrid *v = new
00054                 occupancy_grid::OccupancyGrid(cx, cy, cz, sx, sy, sz, rx, ry, rz);
00055 
00056             uint32_t* d = v->getData();
00057             int nCells = v->nX() * v->nY() * v->nZ();
00058             for (int i=0; i<nCells; i++)
00059                 d[i] = msg->data[i];
00060 
00061             sensor_msgs::PointCloud pc = v->gridToPoints();
00062             pc.header = msg->header;
00063             pub_points_.publish(pc);
00064 
00065             delete v;
00066         }
00067 };
00068 
00069 
00070 int main (int argc, char** argv)
00071 {
00072     // ROS init
00073     ros::init (argc, argv, "og_to_pc", ros::init_options::AnonymousName);
00074     OccupancyGridToPointCloud p;
00075     ros::spin();
00076 
00077     return (0);
00078 }
00079 
00080 


point_cloud_ros
Author(s): Advait Jain (Healthcare Robotics Lab, Georgia Tech)
autogenerated on Wed Nov 27 2013 12:16:42