icr_pointcloud_test.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <sensor_msgs/PointCloud.h>
00003 // PCL specific includes
00004 #include <pcl/ros/conversions.h>
00005 #include <pcl/point_cloud.h>
00006 #include <pcl/point_types.h>
00007 #include "icr/compute_icr.h"
00008 #include <string>
00009 
00010 using std::string;
00011 
00012 ros::Publisher pub;
00013 
00014 int main (int argc, char** argv)
00015 {
00016   // Initialize ROS
00017   ros::init (argc, argv, "my_icr_pcl_test");
00018   ros::NodeHandle nh;
00019   
00020   //let us assume that center points come from somewhere
00021   uint16_t myints[] =  {1838, 4526, 4362, 1083, 793};
00022   uint16_t myints2[] =  {138, 452, 436, 108, 793};
00023   uint16_t myints3[] =  {1000, 4000, 2000, 1083, 93};
00024   std::vector<uint16_t> 
00025     tmpPts(myints, myints + sizeof(myints) / sizeof(uint16_t) );
00026 
00027   //get icrs from icr_server_node
00028   compute_icr_srv.request.centerpoint_ids = tmpPts;
00029   std::vector<uint8_t> tmp_used(5,1);
00030   compute_icr_srv.request.used = tmp_used;
00031 
00032   if (clientComputeICR.call(compute_icr_srv)) {
00033     ROS_INFO("Response: %ld", (long int)compute_icr_srv.response.success);
00034   }
00035 
00036   //convert it to proper point clouds
00037   pub = nh.advertise<sensor_msgs::PointCloud> ("output", 1);
00038   sensor_msgs::PointCloud output_cloud;
00039   plc::PointCloud<plc::PointXYZ>::Ptr cloud(new plc::PointCloud<plc::PointXYZRGB>() ); 
00040 
00041   // unsigned char rgb = {0,0,0};
00042   // for(uint i=0 ; i < cloud->size(); ++i)
00043   //   {
00044   //     cloud->points[i].rgb = *((float*)rgb);
00045   //   }
00046   // main loop
00047   ros::Rate loop_rate(1);
00048   while (ros::ok())
00049     {
00050       // Create a ROS publisher for the output point cloud
00051       if (clientComputeICR.call(compute_icr_srv) 
00052           && compute_icr_srv.response.success == true) 
00053         {
00054           icr2pc(compute_icr_srv.response, cloud);
00055           pub.publish(cloud);
00056           ros::spinOnce();
00057         }
00058       loop_rate.sleep();
00059     }
00060 }
00061 
00062 
00063 bool icr2pc(icr::compute_icr::Response &res_in, plc::PointCloud<plc::PointXYZ>::Ptr cloud) {
00064   ROS_INFO("converting ICR to PointCloud message");
00065   //  pc_out.header 
00066   for (uint j=0; j<res.stx.size();++j) {    
00067     //    cout << "icr " << j << endl;
00068     for(uint i=res.stx[j]; i<res.stx[j]+res.len[j] ;++i) {
00069       //cout << res.all_icrs.at(i) << " ";
00070       plc::PointXYZ pt;
00071       pt.x = rand();
00072       pt.y = rand();
00073       pt.z = rand();
00074       
00075       cloud.points->push_back(pt);
00076     }
00077     cout << endl;
00078   }
00079 
00080   cloud.width = cloud.points.size();
00081   cloud.height = 1;
00082 
00083   return true;
00084 }


icr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:36:10