2
* @file movement_from_image.cpp
3
* @author Ugo Cupcic <ugo@shadowrobot.com>
4
* @date Tue Sep 27 10:05:01 2011
7
* Copyright 2011 Shadow Robot Company Ltd.
9
* This program is free software: you can redistribute it and/or modify it
10
* under the terms of the GNU General Public License as published by the Free
11
* Software Foundation, either version 2 of the License, or (at your option)
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19
* You should have received a copy of the GNU General Public License along
20
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
* @brief Reads a png file and creates a movement from it.
28
#include "sr_movements/movement_from_image.hpp"
34
MovementFromImage::MovementFromImage(std::string image_path)
37
png::image< png::rgb_pixel > image( image_path );
39
generate_movement(image);
42
MovementFromImage::~MovementFromImage()
46
void MovementFromImage::generate_movement( png::image<png::rgb_pixel> image )
48
png::byte empty_byte(0);
49
double img_height = static_cast<double>( image.get_width() );
50
for (size_t y = 0; y < image.get_height(); ++y)
53
for (size_t x = 0; x < image.get_width(); ++x)
55
if( (image[x][y].red == empty_byte) && (image[x][y].green == empty_byte)
56
&& (image[x][y].blue == empty_byte) )
59
steps.push_back( 1.0 - static_cast<double>(x) / img_height);
65
//not sending any targets for this point.
66
steps.push_back( -1.0 );
72
/* For the emacs weenies in the crowd.