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

Tools/Debugging/DebugImages.h

Go to the documentation of this file.
00001 /**
00002 * @file Tools/Debugging/DebugImages.h
00003 *
00004 * Macros to manipulate and send debug images
00005 * 
00006 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Jüngel</a>
00007 */ 
00008 #ifndef __DebugImages_h_
00009 #define __DebugImages_h_
00010 
00011 #include "Tools/Debugging/Debugging.h"
00012 
00013 #ifdef NDEBUG
00014 #define NODEBUGDRAWINGS
00015 #endif
00016 #ifdef NO_DEBUG_DRAWING
00017 #define NODEBUGDRAWINGS
00018 #endif
00019 
00020 #ifdef NODEBUGDRAWINGS
00021 #define DECLARE_DEBUG_COLOR_CLASS_IMAGE(id) /**/
00022 #define SEND_DEBUG_COLOR_CLASS_IMAGE(id) /**/
00023 #else //NODEBUGDRAWINGS
00024 /**
00025 * Declares a debug image
00026 * @param id An image id (Images::ImageID)
00027 */
00028 #define DECLARE_DEBUG_COLOR_CLASS_IMAGE(id) ColorClassImage id##ColorClassImage
00029 
00030 /**Sends the debug image with the specified id (Images::ImageID) */
00031 #define SEND_DEBUG_COLOR_CLASS_IMAGE(id) INFO(send_##id##_image, idDebugColorClassImage, bin, Images::id << id##ColorClassImage)
00032 
00033 #endif //NODEBUGDRAWINGS
00034 
00035 
00036 #if defined(_WIN32)
00037 
00038 /**
00039 * Declares a debug image
00040 * @param id An image id (Images::ImageID)
00041 */
00042 #define DECLARE_DEBUG_IMAGE(id) Image id##Image
00043 
00044 /**
00045 * Initializes a debug image with an image
00046 * @param id An image id (Images::ImageID)
00047 * @param image The Image.
00048 */
00049 #define INIT_DEBUG_IMAGE(id, image) id##Image = image
00050 
00051 /** 
00052 * If an debug image is not created with macros the source code for
00053 * image generation should be encapsuled by this macro.
00054 */
00055 #define GENERATE_DEBUG_IMAGE(id,expression) \
00056   if (getDebugKeyTable().isActive(DebugKeyTable::send_##id##_image)) {\
00057   expression;\
00058   }
00059 
00060 /**Sends the debug image with the specified id (Images::ImageID) */
00061 #define SEND_DEBUG_IMAGE(id) INFO(send_##id##_image, idDebugImage, bin, Images::id << id##Image)
00062 
00063 /**Changes the y channel of the specified pixel in the specified debug image */
00064 #define DEBUG_IMAGE_SET_PIXEL_Y(id, xx, yy, y) \
00065   { \
00066     if(xx >= 0 && xx < id##Image.cameraInfo.resolutionWidth && \
00067       yy >= 0 && yy < id##Image.cameraInfo.resolutionHeight) \
00068     id##Image.image[yy][0][xx] = y; \
00069   }
00070 
00071 /**Sets the y, u and v values of the specified pixel in the specified debug image */
00072 #define DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, y, u, v) \
00073   { \
00074     if(xx >= 0 && xx < id##Image.cameraInfo.resolutionWidth && \
00075       yy >= 0 && yy < id##Image.cameraInfo.resolutionHeight) \
00076     { \
00077       id##Image.image[yy][0][xx] = y; \
00078       id##Image.image[yy][1][xx] = u; \
00079       id##Image.image[yy][2][xx] = v; \
00080     } \
00081   }
00082 
00083 #define DEBUG_IMAGE_GET_PIXEL_Y(id, xx, yy) id##Image.image[yy][0][xx]
00084 #define DEBUG_IMAGE_GET_PIXEL_U(id, xx, yy) id##Image.image[yy][1][xx]
00085 #define DEBUG_IMAGE_GET_PIXEL_V(id, xx, yy) id##Image.image[yy][2][xx]
00086 
00087 
00088 #define DEBUG_IMAGE_SET_PIXEL_BLACK(id, xx, yy)\
00089   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 0, 127, 127)
00090 
00091 #define DEBUG_IMAGE_SET_PIXEL_WHITE(id, xx, yy)\
00092   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 255, 127, 127)
00093 
00094 #define DEBUG_IMAGE_SET_PIXEL_GREEN(id, xx, yy)\
00095   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 180, 0, 0)
00096 
00097 #define DEBUG_IMAGE_SET_PIXEL_LIGHT_GRAY(id, xx, yy)\
00098   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 192, 127, 127)
00099 
00100 #define DEBUG_IMAGE_SET_PIXEL_GRAY(id, xx, yy)\
00101   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 127, 127, 127)
00102 
00103 #define DEBUG_IMAGE_SET_PIXEL_DARK_GRAY(id, xx, yy)\
00104   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 64, 127, 127)
00105 
00106 #define DEBUG_IMAGE_SET_PIXEL_DARK_GREEN(id, xx, yy)\
00107   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 0, 0, 0)
00108 
00109 #define DEBUG_IMAGE_SET_PIXEL_ORANGE(id, xx, yy)\
00110   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 100, 255, 0)
00111 
00112 #define DEBUG_IMAGE_SET_PIXEL_YELLOW(id, xx, yy)\
00113   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 180, 255, 0)
00114 
00115 #define DEBUG_IMAGE_SET_PIXEL_RED(id, xx, yy)\
00116   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 0, 255, 0)
00117 
00118 #define DEBUG_IMAGE_SET_PIXEL_MAUVE(id, xx, yy)\
00119   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 0, 180, 255)
00120 
00121 #define DEBUG_IMAGE_SET_PIXEL_BLUE(id, xx, yy)\
00122   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 180, 0, 255)
00123 
00124 #define DEBUG_IMAGE_SET_PIXEL_PINK(id, xx, yy)\
00125   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 255, 255, 255)
00126 
00127 #define DEBUG_IMAGE_SET_PIXEL_DARK_BLUE(id, xx, yy)\
00128   DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, 100, 0, 255)
00129 
00130 #else //_WIN32
00131 
00132 #ifdef __GNUC__
00133 #define DECLARE_DEBUG_IMAGE(id) /**/
00134 #else
00135 #define DECLARE_DEBUG_IMAGE(id) static bool id##Dummy
00136 #endif
00137 #define INIT_DEBUG_IMAGE(id, image) /**/
00138 #define GENERATE_DEBUG_IMAGE(id,expression) /**/
00139 #define SEND_DEBUG_IMAGE(id) /**/
00140 #define DEBUG_IMAGE_SET_PIXEL_Y(id, xx, yy, y) /**/
00141 #define DEBUG_IMAGE_SET_PIXEL_YUV(id, xx, yy, y, u, v) /**/
00142 #define DEBUG_IMAGE_SET_PIXEL_BLACK(id, xx, yy) /**/
00143 #define DEBUG_IMAGE_SET_PIXEL_WHITE(id, xx, yy) /**/
00144 #define DEBUG_IMAGE_SET_PIXEL_GREEN(id, xx, yy) /**/
00145 #define DEBUG_IMAGE_SET_PIXEL_GRAY(id, xx, yy) /**/
00146 #define DEBUG_IMAGE_SET_PIXEL_LIGHT_GRAY(id, xx, yy) /**/
00147 #define DEBUG_IMAGE_SET_PIXEL_DARK_GRAY(id, xx, yy) /**/
00148 #define DEBUG_IMAGE_SET_PIXEL_DARK_GREEN(id, xx, yy) /**/
00149 #define DEBUG_IMAGE_SET_PIXEL_ORANGE(id, xx, yy) /**/
00150 #define DEBUG_IMAGE_SET_PIXEL_YELLOW(id, xx, yy) /**/
00151 #define DEBUG_IMAGE_SET_PIXEL_RED(id, xx, yy) /**/
00152 #define DEBUG_IMAGE_SET_PIXEL_MAUVE(id, xx, yy) /**/
00153 #define DEBUG_IMAGE_SET_PIXEL_BLUE(id, xx, yy) /**/
00154 #define DEBUG_IMAGE_SET_PIXEL_PINK(id, xx, yy) /**/
00155 #define DEBUG_IMAGE_SET_PIXEL_DARK_BLUE(id, xx, yy) /**/
00156 #define DEBUG_IMAGE_GET_PIXEL_Y(id, xx, yy) 0
00157 #define DEBUG_IMAGE_GET_PIXEL_U(id, xx, yy) 0
00158 #define DEBUG_IMAGE_GET_PIXEL_V(id, xx, yy) 0
00159 
00160 #endif //_WIN32
00161 
00162 /**
00163 * Contains IDs for different (debug) image types
00164 * as well as a method to output their names.
00165 */
00166 class Images
00167 {
00168 public:
00169 /**
00170 * IDs for images.
00171 * enter new image IDs here and add the corresponding string in getImageIDName.
00172   */
00173   enum ImageID
00174   {
00175     noImage,
00176     rawImage,
00177     segmentedImage1,
00178     segmentedImage2,
00179     segmentedImage3,
00180     classificationY,
00181     classificationU,
00182     classificationV,
00183     colorFrequency,
00184     imageProcessorGeneral,
00185     imageProcessorScanLines,
00186     imageProcessorBall,
00187     imageProcessorGoals,
00188     imageProcessorFlags,
00189     imageProcessorPlayers,
00190     imageProcessorGradients,
00191     imageMotionRecognition, 
00192     numberOfImageIDs,
00193     image = numberOfImageIDs, // dummy entry, never use it when constructing a DebugDrawing
00194     segmentedImage, // dummy entry, never use it when constructing a DebugDrawing
00195     correctedImage, // dummy entry, never use it when constructing a DebugDrawing
00196     correctedSegmentedImage // dummy entry, never use it when constructing a DebugDrawing
00197   };
00198 
00199   /**
00200   * Returns a description for an indexed image id.
00201   * Add descriptions for new image ids here.
00202   */
00203   static char* getImageIDName(ImageID imageID)
00204   {
00205     switch (imageID) 
00206     {
00207     case noImage: return "no image";
00208     case rawImage: return "raw image";
00209     case segmentedImage1: return "segmented image 1";
00210     case segmentedImage2: return "segmented image 2";
00211     case segmentedImage3: return "segmented image 3";
00212     case classificationY: return "classificationY";
00213     case classificationU: return "classificationU";
00214     case classificationV: return "classificationV";
00215     case colorFrequency: return "colorFrequency";
00216     case imageProcessorGeneral: return "imageProcessorGeneral";
00217     case imageProcessorScanLines: return "imageProcessorScanLines";
00218     case imageProcessorBall: return "imageProcessorBall";
00219     case imageProcessorFlags: return "imageProcessorFlags";
00220     case imageProcessorGoals: return "imageProcessorGoals";
00221     case imageProcessorPlayers: return "imageProcessorPlayers";
00222     case imageProcessorGradients: return "imageProcessorGradients";
00223     case imageMotionRecognition: return "imageMotionRecognition"; 
00224     default: return "check available drawings";
00225     }
00226   }
00227 
00228   static bool getDebugKeyID(enum ImageID imageID, DebugKeyTable::debugKeyID& debugKeyID)
00229   {
00230     switch (imageID) 
00231     {
00232     case segmentedImage1: debugKeyID = DebugKeyTable::send_segmentedImage1_image; return true;
00233     case segmentedImage2: debugKeyID = DebugKeyTable::send_segmentedImage2_image; return true;
00234     case segmentedImage3: debugKeyID = DebugKeyTable::send_segmentedImage3_image; return true;
00235     case classificationY: debugKeyID = DebugKeyTable::send_classificationY_image; return true;
00236     case classificationU: debugKeyID = DebugKeyTable::send_classificationU_image; return true;
00237     case classificationV: debugKeyID = DebugKeyTable::send_classificationV_image; return true;
00238     case colorFrequency: debugKeyID = DebugKeyTable::send_colorFrequency_image; return true;
00239     case imageProcessorGeneral: debugKeyID = DebugKeyTable::send_imageProcessorGeneral_image; return true;
00240     case imageProcessorScanLines: debugKeyID = DebugKeyTable::send_imageProcessorScanLines_image; return true;
00241     case imageProcessorBall: debugKeyID = DebugKeyTable::send_imageProcessorBall_image; return true;
00242     case imageProcessorFlags: debugKeyID = DebugKeyTable::send_imageProcessorFlags_image; return true;
00243     case imageProcessorGoals: debugKeyID = DebugKeyTable::send_imageProcessorGoals_image; return true;
00244     case imageProcessorPlayers: debugKeyID = DebugKeyTable::send_imageProcessorPlayers_image; return true;
00245     case imageProcessorGradients: debugKeyID = DebugKeyTable::send_imageProcessorGradients_image; return true;
00246     case imageMotionRecognition: debugKeyID = DebugKeyTable::send_imageMotionRecognition_image; return true;
00247     
00248     default: return false;
00249     }
00250   }
00251 };
00252 
00253 #endif //__DebugImages_h_
00254 
00255 /*
00256  * Change log :
00257  * 
00258  * $Log: DebugImages.h,v $
00259  * Revision 1.2  2004/05/26 09:34:30  roefer
00260  * Only set pixels if they are inside the image
00261  *
00262  * Revision 1.1.1.1  2004/05/22 17:36:03  cvsadm
00263  * created new repository GT2004_WM
00264  *
00265  * Revision 1.8  2004/05/01 17:10:51  roefer
00266  * Debug images are only defined if also drawing functions are available
00267  *
00268  * Revision 1.7  2004/04/27 19:39:37  roefer
00269  * Support for debug images added to simulator
00270  *
00271  * Revision 1.6  2004/04/07 13:00:46  risler
00272  * ddd checkin after go04 - second part
00273  *
00274  * Revision 1.3  2004/04/06 13:19:37  risler
00275  * cleaned up and improved high resolution image support
00276  *
00277  * Revision 1.2  2004/03/29 15:19:02  Marc
00278  * Intruduced the Black and White Image
00279  * Normal Images (not Jpeg) images were now send as Color Image with BW
00280  *
00281  * Revision 1.5  2004/01/03 23:07:49  ordyniak
00282  * new debugimage imageMotionRecognition
00283  *
00284  * Revision 1.4  2003/11/03 20:16:09  juengel
00285  * color class images can be sent from robot now
00286  *
00287  * Revision 1.3  2003/10/29 13:32:57  juengel
00288  * Added colorFrequencyImage
00289  *
00290  * Revision 1.2  2003/10/12 20:29:11  juengel
00291  * DebugImages are only sent if requested.
00292  *
00293  * Revision 1.1  2003/10/07 10:13:22  cvsadm
00294  * Created GT2004 (M.J.)
00295  *
00296  * Revision 1.3  2003/09/01 10:23:14  juengel
00297  * DebugDrawings clean-up 2
00298  * DebugImages clean-up
00299  * MessageIDs clean-up
00300  * Stopwatch clean-up
00301  *
00302  * Revision 1.2  2003/08/25 17:23:19  juengel
00303  * Added some debug images.
00304  *
00305  * Revision 1.1.1.1  2003/07/02 09:40:28  cvsadm
00306  * created new repository for the competitions in Padova from the 
00307  * tamara CVS (Tuesday 2:00 pm)
00308  *
00309  * removed unused solutions
00310  *
00311  * Revision 1.15  2003/06/18 09:01:40  wachter
00312  * Added macros to get pixel data from debug images
00313  *
00314  * Revision 1.14  2003/06/05 12:53:24  dueffert
00315  * useless Greenhills warnings removed
00316  *
00317  * Revision 1.13  2003/05/04 17:34:33  roefer
00318  * Support for debug images only in RobotControl
00319  *
00320  * Revision 1.12  2003/03/31 03:37:36  osterhues
00321  * added DEBUG_IMAGE_SET_PIXEL_DARK_BLUE(id, xx, yy)
00322  *
00323  * Revision 1.11  2003/02/25 13:59:40  juengel
00324  * added
00325  * DEBUG_IMAGE_SET_PIXEL_GRAY(id, xx, yy) ,
00326  * DEBUG_IMAGE_SET_PIXEL_LIGHT_GRAY(id, xx, yy), and
00327  * DEBUG_IMAGE_SET_PIXEL_DARK_GRAY(id, xx, yy)
00328  *
00329  * Revision 1.10  2003/02/19 15:58:04  dueffert
00330  * some checkerboard detection work
00331  *
00332  * Revision 1.9  2002/11/26 12:19:26  dueffert
00333  * doxygen docu added
00334  *
00335  * Revision 1.8  2002/11/25 14:50:24  jhoffman
00336  * added motion detector
00337  *
00338  * Revision 1.7  2002/11/19 17:13:05  juengel
00339  * Some "SET_PIXEL_..." macros added.
00340  *
00341  * Revision 1.6  2002/11/18 10:33:01  juengel
00342  * Comments added.
00343  *
00344  * Revision 1.5  2002/11/12 23:00:47  dueffert
00345  * started restore greenhills compatibility
00346  *
00347  * Revision 1.4  2002/10/10 13:30:14  jhoffman
00348  * added ISL related stuff
00349  *
00350  * Revision 1.3  2002/09/21 23:17:05  juengel
00351  * Removed different debug image types.
00352  *
00353  * Revision 1.2  2002/09/20 23:28:34  juengel
00354  * Moved instance of DebugDrawingManager to RobotControlMainFrame.
00355  *
00356  * Revision 1.1  2002/09/19 23:49:08  juengel
00357  * Changed debug image mechanisms.
00358  *
00359  */

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