dummy_mofa_bridge.cpp
Go to the documentation of this file.
00001 #include "dummy_mofa_bridge.h"
00002 
00003 DummyMofaBridge::DummyMofaBridge() {
00004 
00005   srand((unsigned)time(0)); 
00006 
00007   //init class attributes if necessary
00008   idx = 0;
00009   this->nc=0;
00010   this->nr=0;
00011 
00012   //string for port names
00013   std::string pcl2_sub_name                    = "/mofa_bridge/input/pcl2/raw";
00014   std::string labeled_pcl2_sub_name            = "/mofa_bridge/output/pcl2/segmented";
00015   std::string request_observation_sub_name     = "/mofa_bridge/srv/request_observation";
00016 
00017   // [init subscribers]
00018   this->pcl2_sub = this->nh.subscribe(pcl2_sub_name, 1, &DummyMofaBridge::pcl2_sub_callback, this);
00019   
00020   // [init publishers]
00021   this->labeled_pcl2_publisher = this->nh.advertise< pcl::PointCloud<pcl::PointXYZRGB> > (labeled_pcl2_sub_name, 5);
00022 
00023   // [init services]
00024   this->obs_request = this->nh.advertiseService(request_observation_sub_name, &DummyMofaBridge::obs_request_callback, this);
00025 
00026   
00027   // [init clients]
00028   
00029   // [init action servers]
00030   
00031   // [init action clients]
00032   ROS_INFO("Starting mofaBridge Node");
00033   ROS_INFO("Use [ rosservice call /request_observation ] to store current range image and compute observation");
00034 }
00035 
00036 DummyMofaBridge::~DummyMofaBridge(){
00037 
00038 }
00039 
00040 void DummyMofaBridge::close(){
00041 
00042 }
00043 
00044 void DummyMofaBridge::open(){
00045                 
00046 }
00047 
00048 /*  [subscriber callbacks] */
00049 void DummyMofaBridge::pcl2_sub_callback(const sensor_msgs::PointCloud2ConstPtr& msg) 
00050 { 
00051   pcl::fromROSMsg(*msg, this->pcl_xyzrgb);
00052 
00053   this->nc=msg->width;
00054   this->nr=msg->height;
00055 
00056 }
00057 
00058 /*  [service callback] */
00059 bool DummyMofaBridge::obs_request_callback(iri_wam_common_msgs::obs_request::Request &req, iri_wam_common_msgs::obs_request::Response &res){
00060 
00061     /*
00062   // [xyzRGB matlab file name]
00063   std::stringstream matlab_xyzrgb_fn;
00064   //matlab_xyzrgb_fn << "frameXYZRGB" << std::setw(2) << std::setfill('0') << this->idx << ".dat";
00065   matlab_xyzrgb_fn << "last_image.dat";
00066 
00067   // [open xyzRGB matlab file]
00068   matlab_xyzrgb.open(matlab_xyzrgb_fn.str().c_str(), std::ios::out);
00069 
00070   RGBValue color;
00071   // [store xyzRGB matlab file]
00072   pcl::PointCloud<pcl::PointXYZRGB>::iterator pt_iter = this->pcl_xyzrgb.begin();
00073   for (int rr = 0; rr < (int)pcl_xyzrgb.height; ++rr) {
00074     for (int cc = 0; cc < (int)pcl_xyzrgb.width; ++cc, ++pt_iter) {
00075       pcl::PointXYZRGB &pt = *pt_iter;
00076       color.float_value= pt.rgb;
00077       matlab_xyzrgb << rr << " " << cc << " " << pt.x*1000 << " " << pt.y*1000 << " " << pt.z*1000 << " " << (int)color.Red << " " << (int)color.Green << " " << (int)color.Blue << std::endl;
00078     }
00079   }
00080 
00081   // [close range image file]
00082   matlab_xyzrgb.close();
00083   std::cout << "Saved XYZRGB image " << matlab_xyzrgb_fn.str() << std::endl;
00084 
00085   // DUMMY SAVE
00086   std::stringstream matlab_xyzrgb_fn_labeled;
00087   matlab_xyzrgb_fn_labeled << "last_image_labeled.dat";
00088   matlab_xyzrgb.open(matlab_xyzrgb_fn_labeled.str().c_str(), std::ios::out);
00089 
00090   pt_iter = this->pcl_xyzrgb.begin();
00091   for (int rr = 0; rr < (int)pcl_xyzrgb.height; ++rr) {
00092     for (int cc = 0; cc < (int)pcl_xyzrgb.width; ++cc, ++pt_iter) {
00093       pcl::PointXYZRGB &pt2 = *pt_iter;
00094       color.float_value= pt2.rgb;
00095       matlab_xyzrgb << rr << " " << cc << " " << pt2.x*1000 << " " << pt2.y*1000 << " " << pt2.z*1000 << " " << 150 << " " << (int)color.Green << " " << (int)color.Blue << std::endl;
00096     }
00097   }
00098 
00099   matlab_xyzrgb.close();
00100   std::cout << "Saved XYZRGB image " << matlab_xyzrgb_fn_labeled.str() << std::endl;
00101   reloadRGB();
00102 */
00103   res.num_objectsA = rand()%5;
00104   res.num_objectsB = rand()%2;
00105   res.num_objects = res.num_objectsA + res.num_objectsB;
00106   this->labeled_pcl2_publisher.publish(this->pcl_xyzrgb);
00107 
00108   return true;
00109 }
00110 
00111 void DummyMofaBridge::reloadRGB(){
00112     int x, y, z;
00113     int red_label, green_label, blue_label;
00114     RGBValue color;
00115     // [xyzRGB matlab file name]
00116     std::stringstream matlab_xyzrgb_fn;
00117     matlab_xyzrgb_fn << "last_image_labelled.dat";
00118 
00119   // [open xyzRGB matlab file]
00120   matlab_xyzrgb_in.open(matlab_xyzrgb_fn.str().c_str(), std::ios::in);
00121 
00122   // [store xyzRGB matlab file]
00123   pcl::PointCloud<pcl::PointXYZRGB>::iterator pt_iter = this->pcl_xyzrgb.begin();
00124   for (int rr = 0; rr < (int)pcl_xyzrgb.height; ++rr) {
00125     for (int cc = 0; cc < (int)pcl_xyzrgb.width; ++cc, ++pt_iter) {
00126       pcl::PointXYZRGB &pt = *pt_iter;
00127       
00128       matlab_xyzrgb_in >> x;
00129       matlab_xyzrgb_in >> y;
00130       matlab_xyzrgb_in >> z;
00131 
00132       matlab_xyzrgb_in >> red_label;
00133       matlab_xyzrgb_in >> green_label;
00134       matlab_xyzrgb_in >> blue_label;
00135 
00136       color.Red = red_label;
00137       color.Green = green_label;
00138       color.Blue = blue_label;
00139       pt.rgb = color.float_value;
00140 
00141     }
00142   }
00143 
00144   // [close range image file]
00145   matlab_xyzrgb.close();
00146   std::cout << "Loaded pcl image " << matlab_xyzrgb_fn.str() << std::endl;
00147 
00148 
00149 }
00150 
00151 int main(int argc, char** argv)
00152 {
00153   ros::init(argc, argv, "mofa_bridge");
00154   DummyMofaBridge mofa_bridge;
00155   mofa_bridge.open();
00156   ros::spin();
00157   return 0;
00158 }


iri_pcl_filters
Author(s): Sergi Foix
autogenerated on Fri Dec 6 2013 20:44:42