Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/ImageProcessor/RasterImageProcessor/RasterImageProcessor.cpp

Go to the documentation of this file.
00001 /**
00002 * @file RasterImageProcessor.cpp
00003 * 
00004 * This file contains the implementation of class RasterImageProcessor.
00005 *
00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a>
00007 */
00008 #include "RasterImageProcessor.h"
00009 #include "Tools/Math/Common.h"
00010 #include "Tools/Debugging/GenericDebugData.h"
00011 #include "Tools/FieldDimensions.h"
00012 #include "Tools/RingBuffer.h"
00013 #include "Representations/Perception/ColorTable64.h"
00014 #include "RDefaultStrategy.h"
00015 
00016 #include <time.h>
00017 
00018 using namespace std;
00019 
00020 
00021 RasterImageProcessor::RasterImageProcessor(const ImageProcessorInterfaces& interfaces)
00022 : ImageProcessor(interfaces), 
00023   corrector(),
00024   edgeDetector(10)
00025 { 
00026   for (int i=0;i < maxRasterSpecialists; i++)
00027     specials[i] = NULL;
00028     
00029   minX = 0;
00030   minY = 0;
00031   maxX = image.cameraInfo.resolutionWidth -1;
00032   maxY = image.cameraInfo.resolutionHeight -1;
00033 
00034 
00035   strategy = new RDefaultStrategy(*this);
00036   waitingStrategy = NULL;
00037 
00038   
00039 }
00040 
00041 RasterImageProcessor::~RasterImageProcessor()
00042 {
00043   delete strategy;  
00044 }
00045 
00046 void RasterImageProcessor::execute()
00047 {
00048   //INIT_DEBUG_IMAGE(imageProcessorScanLines, image);
00049   //Image emptyImage;
00050   INIT_DEBUG_IMAGE(imageProcessorBall,image);
00051   INIT_DEBUG_IMAGE(imageProcessorObstacles,image);
00052   INIT_DEBUG_IMAGE(imageProcessorFlagsAndGoals, image);
00053   INIT_DEBUG_IMAGE(imageProcessorGround, image);
00054   INIT_DEBUG_IMAGE(imageProcessorGeneral, image);
00055 
00056   
00057   
00058   //INIT_DEBUG_IMAGE(classificationY, emptyImage);
00059   //INIT_DEBUG_IMAGE(classificationU, emptyImage);
00060   //INIT_DEBUG_IMAGE(classificationV, emptyImage);
00061 //  clock_t t1 = clock();
00062 
00063   init();
00064 
00065   strategy->execute();
00066 //  clock_t t2 = clock();
00067 
00068   //OUTPUT(idText,text,"time: " << double(t2-t1)/CLOCKS_PER_SEC << " Sekunden");
00069 
00070   //SEND_DEBUG_IMAGE(imageProcessorGeneral);
00071   //SEND_DEBUG_IMAGE(imageProcessorBall);
00072   //SEND_DEBUG_IMAGE(imageProcessor_flagsAndGoals);
00073   //SEND_DEBUG_IMAGE(imageProcessor_obstacles);
00074   DEBUG_DRAWING_FINISHED(imageProcessor_general);
00075   DEBUG_DRAWING_FINISHED(imageProcessor_ball1);
00076   DEBUG_DRAWING_FINISHED(imageProcessor_ball2);
00077   DEBUG_DRAWING_FINISHED(imageProcessor_ball3);
00078   DEBUG_DRAWING_FINISHED(imageProcessor_obstacles);
00079   DEBUG_DRAWING_FINISHED(imageProcessor_ground);
00080   DEBUG_DRAWING_FINISHED(imageProcessor_flagsAndGoals);
00081 };
00082 
00083 bool RasterImageProcessor::handleMessage(InMessage &message)
00084 {
00085   //InMessage *pMess = &message;  
00086   
00087   return false;
00088 };
00089 
00090 RasterSpecialist *RasterImageProcessor::getSpecialist(int type)
00091 {
00092   return specials[type];
00093 }
00094 
00095 void RasterImageProcessor::setSpecialist(RasterSpecialist *specialist)
00096 {
00097   int type = specialist->getType();
00098   if (specials[type]!=0) delete specials[type];
00099   specials[type] = specialist;
00100 
00101 }
00102 
00103 void RasterImageProcessor::removeSpecialist(int type)
00104 {
00105   delete specials[type];
00106   specials[type] = NULL;
00107 }
00108 
00109 
00110 void RasterImageProcessor::changeStrategy(RasterStrategy &newStrategy)
00111 {
00112   waitingStrategy = &newStrategy;
00113 
00114 }
00115 
00116 void RasterImageProcessor::init()
00117 { 
00118   if (waitingStrategy != NULL) {
00119     delete strategy;
00120     strategy = waitingStrategy;
00121     waitingStrategy = NULL;
00122   }
00123   
00124   strategy->init();
00125 
00126 //  INIT_DEBUG_IMAGE(imageProcessorPlayers, image); 
00127 
00128   GENERATE_DEBUG_IMAGE(segmentedImage1,
00129   colorTable.generateColorClassImage(image, segmentedImage1ColorClassImage));
00130 
00131   SEND_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1);
00132   //OUTPUT(idText,text,"frame: " << image.frameNumber);       
00133   // reset everything
00134   landmarksPercept.reset(image.frameNumber);
00135   linesPercept.reset(image.frameNumber);
00136   ballPercept.reset(image.frameNumber);
00137   playersPercept.reset(image.frameNumber);
00138   obstaclesPercept.reset(image.frameNumber);
00139 
00140   landmarksPercept.cameraOffset = cameraMatrix.translation;
00141 
00142   horizon = Geometry::calculateHorizon(cameraMatrix, image.cameraInfo);
00143   
00144   LINE(imageProcessor_general,
00145     (int)(horizon.base.x - 120 * horizon.direction.x ), (int)(horizon.base.y - 120 * horizon.direction.y), 
00146     (int)(horizon.base.x + 120 * horizon.direction.x), (int)(horizon.base.y + 120 * horizon.direction.y), 
00147     1, Drawings::ps_solid, Drawings::white );
00148 //  flagSpecialist.init(image);
00149 
00150 }
00151 
00152 void RasterImageProcessor::addFlag(Vector2<double>& left,Vector2<double>& right,
00153   Vector2<double>& top, Vector2<double>& bottom,Flag::FlagType type){
00154   DOT(imageProcessor_flagsAndGoals, right.x, right.y,
00155     Drawings::red, Drawings::black);
00156   DOT(imageProcessor_flagsAndGoals, left.x, left.y,
00157     Drawings::green, Drawings::black);
00158 
00159   bool topOnBorder = !isValidPoint(top);
00160   bool bottomOnBorder = !isValidPoint(bottom);
00161   bool leftOnBorder = !isValidPoint(left);
00162   bool rightOnBorder = !isValidPoint(right);
00163 
00164   double factor = image.cameraInfo.resolutionWidth / 2 / tan(image.cameraInfo.openingAngleWidth / 2);
00165   int flip = getPlayer().getTeamColor() == Player::blue ? -1 : 1;
00166   
00167   Vector3<double> vectorToLeft(factor,
00168     image.cameraInfo.resolutionWidth / 2 - left.x,
00169     image.cameraInfo.resolutionHeight / 2 - left.y);
00170     Vector3<double> vectorToRight(factor,
00171     image.cameraInfo.resolutionWidth / 2 - right.x,
00172     image.cameraInfo.resolutionHeight / 2 - right.y);
00173   Vector3<double> vectorToTop(factor,
00174     image.cameraInfo.resolutionWidth / 2 - top.x,
00175     image.cameraInfo.resolutionHeight / 2 - top.y);
00176     Vector3<double> vectorToBottom(factor,
00177     image.cameraInfo.resolutionWidth / 2 - bottom.x,
00178     image.cameraInfo.resolutionHeight / 2 - bottom.y);
00179 
00180     Vector3<double>
00181     vectorToLeftWorld = cameraMatrix.rotation * vectorToLeft,
00182     vectorToRightWorld = cameraMatrix.rotation * vectorToRight,
00183     vectorToTopWorld = cameraMatrix.rotation * vectorToTop,
00184     vectorToBottomWorld = cameraMatrix.rotation * vectorToBottom;
00185        
00186     double 
00187       leftAngle = atan2(vectorToLeftWorld.y,vectorToLeftWorld.x),
00188       rightAngle = atan2(vectorToRightWorld.y,vectorToRightWorld.x),
00189       topAngle = atan2(vectorToTopWorld.z,sqrt((double)sqr(vectorToTopWorld.x) + sqr(vectorToTopWorld.y)) ),
00190       bottomAngle = atan2(vectorToBottomWorld.z,sqrt((double)sqr(vectorToBottomWorld.x) + sqr(vectorToBottomWorld.y)) );
00191 
00192 
00193     Vector2<double>flagPosition;
00194     
00195     switch (type)
00196     {
00197     case Flag::pinkAboveYellow:
00198       flagPosition.x = xPosBackFlags * flip;
00199       flagPosition.y = yPosRightFlags * flip;
00200       break;
00201     case Flag::pinkAboveSkyblue:
00202       flagPosition.x = xPosFrontFlags * flip;
00203       flagPosition.y = yPosRightFlags * flip;
00204       break;
00205     case Flag::yellowAbovePink:
00206       flagPosition.x = xPosBackFlags * flip;
00207       flagPosition.y = yPosLeftFlags * flip;
00208       break;
00209     case Flag::skyblueAbovePink:
00210       flagPosition.x = xPosFrontFlags * flip;
00211       flagPosition.y = yPosLeftFlags * flip;
00212       break;
00213     }
00214 
00215   Vector2<double> centerAngle;
00216     ConditionalBoundary boundary;
00217 
00218     boundary.addX(leftAngle,leftOnBorder);
00219     boundary.addX(rightAngle,rightOnBorder);
00220     boundary.addY(topAngle,topOnBorder);
00221     boundary.addY(bottomAngle,bottomOnBorder);
00222     landmarksPercept.addFlag(type, flagPosition, boundary);
00223 } 
00224 
00225 
00226 /*
00227 * Change log :
00228 * 
00229 * $Log: RasterImageProcessor.cpp,v $
00230 * Revision 1.4  2004/09/06 12:02:26  schmidtb
00231 * commented almost all members, removed warnings in documentation
00232 
00233 * did further code clean up
00234 *
00235 * Revision 1.3  2004/09/02 07:59:29  schmidtb
00236 * Added RasterImageProcessor to repository, because we used it for the OpenChallenge.
00237 *
00238 * Revision 1.29  2004/06/09 13:05:57  schmidtb
00239 * removed memory leaks
00240 *
00241 * Revision 1.28  2004/06/02 14:51:31  koh
00242 * RDefaultStrategy2 wax not included, so temporarely commented out
00243 *
00244 * Revision 1.27  2004/06/02 11:25:33  deom
00245 * now uses RDefaultStrategy2
00246 *
00247 * Revision 1.26  2004/04/08 17:14:26  wachter
00248 * GT04 checkin of Microsoft-Hellounds
00249 *
00250 * Revision 1.26  2004/03/25 15:21:19  pg_besc
00251 * made some changes
00252 *
00253 * Revision 1.25  2004/03/17 22:13:15  schmidtb
00254 * *** empty log message ***
00255 *
00256 * Revision 1.24  2004/03/11 20:53:52  schmidtb
00257 * removed errors
00258 *
00259 * Revision 1.23  2004/03/11 20:32:36  schmidtb
00260 * new version of rip
00261 *
00262 * Revision 1.22  2004/03/08 01:39:02  roefer
00263 * Interfaces should be const
00264 *
00265 * Revision 1.21  2004/03/03 12:53:21  schmidtb
00266 * color correction integrated
00267 *
00268 * Revision 1.20  2004/03/02 12:00:09  koh
00269 * included RFlexibleStrategy-File
00270 *
00271 * Revision 1.19  2004/03/01 15:49:31  dueffert
00272 * temporary removed for compilability
00273 *
00274 * Revision 1.18  2004/03/01 14:17:25  koh
00275 * added new strategy "RFlexibleStrategy" + new specialist "EnemyOnlySpecialist";
00276 * changed references to "RDefaultStrategy" to references to "RasterStrategy" in RFieldSpecialist
00277 * added Geometry::Line horizon to "RasterStrategy"
00278 *
00279 * Revision 1.17  2004/02/25 15:43:56  schmidtb
00280 * enabled resets
00281 *
00282 * Revision 1.16  2004/02/25 11:56:29  neubach
00283 * - landmarksPercept.reset disabled in order to get combo to work
00284 *
00285 * Revision 1.15  2004/02/18 14:56:19  neubach
00286 * new Segmentation established, code not cleared at all
00287 *
00288 * Revision 1.14  2004/02/04 13:12:23  nistico
00289 * Removed unneeded references in RasterImageProcessor to ManualCalibration, which were binding it
00290 * to ColorTable64
00291 *
00292 * Revision 1.13  2004/02/02 13:42:12  schmidtb
00293 * merged sources of RIP. added som functions.
00294 *
00295 * Revision 1.12  2004/01/31 11:45:02  hyung
00296 * modified enemyValidity-calculation;
00297 * established basical enviroment for TrikotErkennung, based on Arrays and Lists, changes will take affect only #ifdef TrikotErkennung!
00298 *
00299 * Revision 1.11  2004/01/21 11:04:30  loetzsch
00300 * removed some OUTPUTs
00301 *
00302 * Revision 1.10  2003/12/31 23:50:38  roefer
00303 * Removed inclusion of RobotDimensions.h because it is not used
00304 *
00305 * Revision 1.9  2003/12/15 13:55:32  schmidtb
00306 * Merged and patched new version of RasterImageProcessor.
00307 *
00308 * Revision 1.8  2003/12/15 11:49:08  juengel
00309 * Introduced CameraInfo
00310 *
00311 * Revision 1.7  2003/12/08 15:02:55  schmidtb
00312 * new version of RIP
00313 *
00314 * Revision 1.6  2003/12/04 09:51:23  schmidtb
00315 * better BallSpecialist
00316 *
00317 * Revision 1.5  2003/12/02 21:59:02  schmidtb
00318 * New version of RasterImageProcessor
00319 *
00320 * Revision 1.4  2003/11/28 14:50:01  dueffert
00321 * bugs and warnings fixed
00322 *
00323 * Revision 1.3  2003/11/20 10:26:56  schmidtb
00324 * Ball Detection added
00325 *
00326 * Revision 1.2  2003/11/13 10:41:29  schmidtb
00327 * renewed RBallSpeciaslist and Strategy
00328 *
00329 * Revision 1.1  2003/11/12 13:13:20  schmidtb
00330 * new RasterImageProcessor added
00331 *
00332 *
00333 */

Generated on Thu Sep 23 19:57:30 2004 for GT2004 by doxygen 1.3.6