movement_from_image.cpp
Go to the documentation of this file.
00001 
00028 #include "sr_movements/movement_from_image.hpp"
00029 #include <ros/ros.h>
00030 
00031 #include <iostream>
00032 
00033 namespace shadowrobot
00034 {
00035   MovementFromImage::MovementFromImage(std::string image_path)
00036     : PartialMovement()
00037   {
00038     image_ = boost::shared_ptr<Magick::Image>( new Magick::Image() );
00039     image_->read( image_path );
00040 
00041     nb_cols_ = image_->columns();
00042     nb_rows_ = image_->rows();
00043 
00044     generate_movement_();
00045   }
00046 
00047   MovementFromImage::~MovementFromImage()
00048   {}
00049 
00050 
00051   void MovementFromImage::generate_movement_()
00052   {
00053     const Magick::PixelPacket* pixel_cache = image_->getConstPixels(0,0,nb_cols_, nb_rows_);
00054 
00055     for( ssize_t col = 0; col < nb_cols_; ++col)
00056     {
00057       bool no_pixel = true;
00058       for( ssize_t row=0; row < nb_rows_; ++row)
00059       {
00060         const Magick::PixelPacket* tmp_pixel = pixel_cache + row * nb_cols_ + col;
00061         if( tmp_pixel->red != 0xFFFF && tmp_pixel->green != 0xFFFF
00062             && tmp_pixel->blue != 0xFFFF)
00063         {
00064           no_pixel = false;
00065           steps.push_back( 1.0 - static_cast<double>(row) / static_cast<double>(nb_rows_) );
00066           break;
00067         }
00068       }
00069       if(no_pixel)
00070       {
00071         //not sending any targets for this point.
00072         steps.push_back( -1.0 );
00073       }
00074     }
00075   }
00076 }
00077 
00078 /* For the emacs weenies in the crowd.
00079 Local Variables:
00080    c-basic-offset: 2
00081 End:
00082 */
00083 


sr_movements
Author(s): Ugo Cupcic
autogenerated on Fri Aug 28 2015 13:09:30