00001 /** 00002 * @file RasterStrategy.h 00003 * 00004 * This file contains the definition of class RasterStrategy. 00005 * 00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00007 */ 00008 #ifndef RASTERSTRATEGY_H 00009 #define RASTERSTRATEGY_H 00010 00011 class RasterStrategy; 00012 00013 #include "RasterImageProcessor.h" 00014 #include "Representations/Perception/ColorTableTSL.h" 00015 #include <vector> 00016 00017 const int Y_VALUE = 0, /**< Relative offset of Y component. */ 00018 U_VALUE = cameraResolutionWidth_ERS7, /**< Relative offset of U component. */ 00019 V_VALUE = 2 * cameraResolutionWidth_ERS7; /**< Relative offset of V component. */ 00020 00021 /** @class RasterStrategy 00022 * Base-class for RasterStrategies. 00023 * 00024 * A RasterStrategy is a object that delegates a collection of specialists. 00025 * And decides what pixels are scanned on the image. 00026 * First the image has to be scanned, than the several post-processings 00027 * of the specialists have to be executed. 00028 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00029 */ 00030 class RasterStrategy 00031 { 00032 public: 00033 00034 /** Keys for the several activities can be made by strategies. */ 00035 enum ActivationKeys{ 00036 preScan = 0, 00037 postScan, 00038 ball, 00039 flag, 00040 goal, 00041 lines, 00042 foes, 00043 numberOfActivationKeys 00044 }; 00045 00046 typedef const unsigned char* I_Pin; 00047 00048 /** True if the strategy scans over a ball.*/ 00049 bool insideBall; 00050 /** True if the strategy scans over a box.*/ 00051 bool insideBox; 00052 /** True if the strategy scans over a bridge beacon.*/ 00053 bool insideBridge; 00054 /** True if the strategy scans over a player.*/ 00055 bool insidePlayer; 00056 /** True if the strategy scans over the field.*/ 00057 bool insideField; 00058 /** True if the strategy scans over a landmark.*/ 00059 bool insideLM; 00060 00061 /** Constructor 00062 * 00063 * @param iProcessor The image processor interfaces. 00064 */ 00065 RasterStrategy(RasterImageProcessor &iProcessor); 00066 /** Destructor */ 00067 virtual ~RasterStrategy(); 00068 00069 /** Initializes a strategy and the related specialists. 00070 * Call this before execute().*/ 00071 virtual void init() = 0; 00072 /** Executes the strategy. */ 00073 virtual void execute() = 0; 00074 00075 protected: 00076 /** The image processor interfaces */ 00077 RasterImageProcessor *rip; 00078 00079 /** Implemented with ColorTable interface. 00080 * Corrects the color before classifying. 00081 * @param v input pixel 00082 * @return The classified color of the pixel. 00083 */ 00084 inline colorClass getColor(Vector2<int> v){ 00085 return getColor(v.x,v.y); 00086 }; 00087 /** Implemented with ColorTable interface. 00088 * Corrects the color before classifying. 00089 * @param x x-coordinate of the requested pixel 00090 * @param y y-coordinate of the requested pixel 00091 * @return The classified color of the pixel.*/ 00092 inline colorClass getColor(int x,int y){ 00093 unsigned char cy = rip->image.image[y][0][x]; 00094 unsigned char cu = rip->image.image[y][1][x]; 00095 unsigned char cv = rip->image.image[y][2][x]; 00096 ColorCorrector::correct(x,y,cy,cu,cv); 00097 return rip->colorTable.getColorClass(cy,cu,cv); 00098 }; 00099 /** Implemented with ColorTable interface. 00100 * @param x X-coordinate of the requested pixel. 00101 * @param y Y-coordinate of the requested pixel. 00102 * @param color The color class to match. 00103 * @return True if color equals getColor(x,y). 00104 */ 00105 inline bool checkColor(int x,int y,colorClass color){ 00106 return color == getColor(x,y); 00107 }; 00108 /** Implemented with ColorTable interface. 00109 * @param v The requested pixel. 00110 * @param color The color class to match. 00111 * @return True if color equals getColor(x,y). 00112 */ 00113 inline bool checkColor(Vector2<int> v,colorClass color){ 00114 return color == getColor(v.x,v.y); 00115 }; 00116 /** The theta function. 00117 * @param dx first vector of the difference 00118 * @param dy second vector of the difference 00119 * @return a number between 0 and 360 with the same order as v.angle()*/ 00120 inline double theta(int dx,int dy){ 00121 double t = 0; 00122 int ax = abs(dx); 00123 int ay = abs(dy); 00124 if (dx == 0 && dy == 0) t = 0; 00125 else t = (double)dy /(double)(ax + ay); 00126 if (dx < 0) t = 2 - t; 00127 else if (dy < 0) t = 4 + t; 00128 return t*90; // multiplication with 90 is not really needed for correct ordering 00129 } 00130 00131 }; 00132 00133 #endif // !defined(AFX_RASTERSTRATEGY_H__E73419DC_85CE_4D73_87C1_DEBCEC21740B__INCLUDED_) 00134 00135 /* 00136 * Change log : 00137 * 00138 * $Log: RasterStrategy.h,v $ 00139 * Revision 1.5 2004/09/06 12:02:26 schmidtb 00140 * commented almost all members, removed warnings in documentation 00141 00142 * did further code clean up 00143 * 00144 * Revision 1.4 2004/09/03 11:32:14 nistico 00145 * References to MSH2004ColorCorrector removed, now uses the unified ColorCorrector 00146 * 00147 * Revision 1.3 2004/09/02 07:59:29 schmidtb 00148 * Added RasterImageProcessor to repository, because we used it for the OpenChallenge. 00149 * 00150 * Revision 1.16 2004/05/27 11:18:48 schmidtb 00151 * new version with further work for open challenge 00152 * 00153 * Revision 1.15 2004/05/25 13:27:34 schmidtb 00154 * modified version of rip for open-challenge 00155 * 00156 * Revision 1.16 2004/05/22 16:01:49 pg_besc 00157 * -modified version of rip for bridge-recognition 00158 * 00159 * Revision 1.15 2004/05/18 10:52:14 pg_besc 00160 * version of the last game at US-Open 00161 * 00162 * Revision 1.14 2004/04/15 19:09:02 pg_besc 00163 * merged code 00164 * 00165 * Revision 1.13 2004/03/17 17:06:09 koh 00166 * added enemyOnlySpecialist; 00167 * added enemySpecialist2; 00168 * added some int and bool variables 00169 * 00170 * Revision 1.12 2004/03/11 20:34:01 schmidtb 00171 * new version of rip 00172 * 00173 * Revision 1.11 2004/03/04 09:54:52 schmidtb 00174 * color correction integrated 00175 * 00176 * Revision 1.10 2004/03/03 12:53:22 schmidtb 00177 * color correction integrated 00178 * 00179 * Revision 1.9 2004/03/01 14:17:26 koh 00180 * added new strategy "RFlexibleStrategy" + new specialist "EnemyOnlySpecialist"; 00181 * changed references to "RDefaultStrategy" to references to "RasterStrategy" in RFieldSpecialist 00182 * added Geometry::Line horizon to "RasterStrategy" 00183 * 00184 * Revision 1.8 2004/02/02 13:42:12 schmidtb 00185 * merged sources of RIP. added som functions. 00186 * 00187 * Revision 1.7 2004/01/23 15:44:01 deom 00188 * New specialist :: BoxSpecialist 00189 * Recognizes both landmarks and goals 00190 * 00191 * Revision 1.6 2003/12/15 13:55:33 schmidtb 00192 * Merged and patched new version of RasterImageProcessor. 00193 * 00194 * Revision 1.5 2003/12/02 21:59:02 schmidtb 00195 * New version of RasterImageProcessor 00196 * 00197 * Revision 1.4 2003/12/02 12:45:44 neubach 00198 * new EnemySpecialist added 00199 * 00200 * Revision 1.3 2003/11/20 10:26:56 schmidtb 00201 * Ball Detection added 00202 * 00203 * Revision 1.2 2003/11/13 10:41:29 schmidtb 00204 * renewed RBallSpeciaslist and Strategy 00205 * 00206 * Revision 1.1 2003/11/12 13:13:20 schmidtb 00207 * new RasterImageProcessor added 00208 * 00209 * 00210 */