00001 // Copyright (C) 2010-2011 Institut de Robotica i Informatica Industrial, CSIC-UPC. 00002 // Author 00003 // All rights reserved. 00004 // 00005 // This file is part of iri-ros-pkg 00006 // iri-ros-pkg is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 // IMPORTANT NOTE: This code has been generated through a script from the 00020 // iri_ros_scripts. Please do NOT delete any comments to guarantee the correctness 00021 // of the scripts. ROS topics can be easly add by using those scripts. Please 00022 // refer to the IRI wiki page for more information: 00023 // http://wikiri.upc.es/index.php/Robotics_Lab 00024 00025 #ifndef _screen_information_alg_h_ 00026 #define _screen_information_alg_h_ 00027 00028 #include <iri_screen_information/ScreenInformationConfig.h> 00029 #include "mutex.h" 00030 00031 //OpenCV 00032 #include<opencv/cv.h> 00033 #include <opencv/cvwimage.h> 00034 #include <opencv/highgui.h> 00035 00036 //include screen_information_alg main library 00037 static const char WINDOW[] = "Image window"; 00038 00044 class ScreenInformationAlgorithm 00045 { 00046 protected: 00053 CMutex alg_mutex_; 00054 00055 // private attributes and methods 00056 int code; 00057 int lastCode; 00058 int ownX; 00059 int ownY; 00060 cv::Mat image; 00061 std::string answer; 00062 00063 std::vector<cv::Mat> images; 00064 std::vector<std::string> texts; 00065 std::vector<CvScalar> colors; 00066 cv::Mat loadImage(std::string const path, int mode); 00067 void createWindow(const std::string& window); 00068 void showImage(const std::string& window, cv::Mat image); 00069 int getImageIndex(int code); 00070 void addText(int i, int code); 00071 void addOwnLocation(int x, int y); 00072 void addLocationWithCode(int code); 00073 void drawCircle(int x, int y, int r, CvScalar color); 00074 00075 public: 00082 typedef iri_screen_information::ScreenInformationConfig Config; 00083 00090 Config config_; 00091 00100 ScreenInformationAlgorithm(void); 00101 00107 void lock(void) { alg_mutex_.enter(); }; 00108 00114 void unlock(void) { alg_mutex_.exit(); }; 00115 00123 bool try_enter(void) { return alg_mutex_.try_enter(); }; 00124 00136 void config_update(Config& new_cfg, uint32_t level=0); 00137 00138 // here define all screen_information_alg interface methods to retrieve and set 00139 // the driver parameters 00140 std::string path; 00141 00142 void initialize(); 00143 void iteration(); 00144 00145 void setCode(int newCode); 00146 void setAnswer(std::string newAnswer); 00147 00154 ~ScreenInformationAlgorithm(void); 00155 }; 00156 00157 #endif