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

Tools/Debugging/DebugDrawings2.h

Go to the documentation of this file.
00001 /**
00002 * @file Tools/Debugging/DebugDrawings.h
00003 *
00004 * Macros for drawing
00005 * 
00006 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Jüngel</a>
00007 */ 
00008 #ifndef __DebugDrawings2_h_
00009 #define __DebugDrawings2_h_
00010 
00011 #include "Tools/Debugging/Debugging.h"
00012 #include "Tools/Debugging/DebugKeyTable.h"
00013 
00014 #ifndef NEWDEBUGGING
00015 
00016 /////// to be ignored
00017 #define NDECLARE_DEBUGDRAWING( id, type, description) /**/
00018 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor) /**/
00019 #define NDOT(id, x, y, penColor, fillColor) /**/
00020 #define NLARGE_DOT(id, x, y, penColor, fillColor) /**/
00021 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor) /**/
00022 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor) /**/
00023 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB) /**/
00024 #define NPOSE_2D_SAMPLE(id, p, color) /**/
00025 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill) /**/
00026 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor) /**/
00027 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor) /**/
00028 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor) /**/
00029 #define NCOMPLEX_DRAWING(id,expression) /**/
00030 #define NDEBUG_DRAWING_FINISHED(id) /**/
00031 ////////
00032 #else
00033 #ifdef WIN32
00034   #pragma warning(disable:4786) 
00035   #include <typeinfo.h>
00036   #if _MSC_VER > 1200
00037     #include <hash_map>
00038     using stdext::hash_map;
00039   #else
00040     #include <map>
00041     #define hash_map map
00042     using std::map;
00043   #endif
00044 #else
00045   #include <typeinfo>
00046   #include <ext/hash_map>
00047   using __gnu_cxx::hash_map;
00048 #endif
00049 
00050 class DrawingManager;
00051 
00052 In& operator>>(In& stream, DrawingManager&);
00053 Out& operator<<(Out& stream, const DrawingManager&);
00054 
00055 class DrawingManager
00056 {
00057   typedef hash_map< const char*, char> DrawingNameTypeTable;
00058   DrawingNameTypeTable drawingNameTypeTable;
00059   int idCounter, typeCounter;
00060   bool freeStrings;
00061 
00062   void reset();
00063 
00064 public:
00065   class DrawingNameIdTableEntry
00066   {
00067   public:
00068     char id;
00069     char type;
00070     const char* description;
00071   };
00072   
00073 
00074   typedef hash_map< const char*, DrawingNameIdTableEntry> DrawingNameIdTable;
00075   DrawingNameIdTable drawingNameIdTable;
00076 
00077   DrawingManager():idCounter(0), typeCounter(2), freeStrings(false)
00078   {
00079     drawingNameTypeTable["drawingOnField"] = 0;
00080     drawingNameTypeTable["drawingOnImage"] = 1;
00081   }
00082 
00083   ~DrawingManager() {reset();}
00084 
00085   void addDrawingId(const char* name, const char* typeName, const char* description);
00086 
00087   char getDrawingId(const char* name) const
00088   { 
00089     DrawingNameIdTable::const_iterator i = drawingNameIdTable.find(name);
00090     if(i != drawingNameIdTable.end())
00091       return i->second.id;
00092     OUTPUT(idText, text, "Warning! Debug drawing " << name << " not declared");
00093     return -1;
00094   }
00095 
00096   const char* getDrawingType(const char* name) const
00097   { 
00098     DrawingNameIdTable::const_iterator i = drawingNameIdTable.find(name);
00099     if(i != drawingNameIdTable.end())
00100     {
00101       for(DrawingNameTypeTable::const_iterator j = drawingNameTypeTable.begin(); 
00102           j != drawingNameTypeTable.end(); ++j)
00103         if(j->second == i->second.type)
00104           return j->first;
00105       OUTPUT(idText, text, "Warning! Debug drawing " << name << " has unknown type " << int(i->second.type));
00106       return "unknown";
00107     }
00108     OUTPUT(idText, text, "Warning! Debug drawing " << name << " not declared");
00109     return "unknown";
00110   }
00111 
00112   const char* getDrawingName(char id) const
00113   {
00114     for(DrawingNameIdTable::const_iterator i = drawingNameIdTable.begin(); 
00115         i != drawingNameIdTable.end(); ++i)
00116       if(i->second.id == id)
00117         return i->first;
00118     OUTPUT(idText, text, "Warning! Unknown debug drawing id " << int(id));
00119     return "unknown";
00120   }
00121 
00122   friend In& operator>>(In& stream, DrawingManager&);
00123   friend Out& operator<<(Out& stream, const DrawingManager&);
00124 };
00125 
00126 #ifdef NDEBUG
00127 #define NODEBUGDRAWINGS
00128 #endif
00129 #ifdef NO_DEBUG_DRAWING
00130 #define NODEBUGDRAWINGS
00131 #endif
00132 
00133 #ifdef NODEBUGDRAWINGS
00134 
00135 #define NDECLARE_DEBUGDRAWING( id, type, description) /**/
00136 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor) /**/
00137 #define NDOT(id, x, y, penColor, fillColor) /**/
00138 #define NLARGE_DOT(id, x, y, penColor, fillColor) /**/
00139 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor) /**/
00140 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor) /**/
00141 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB) /**/
00142 #define NPOSE_2D_SAMPLE(id, p, color) /**/
00143 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill) /**/
00144 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor) /**/
00145 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor) /**/
00146 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor) /**/
00147 #define NCOMPLEX_DRAWING(id,expression) /**/
00148 #define NDEBUG_DRAWING_FINISHED(id) /**/
00149 
00150 #else //NODEBUGDRAWINGS
00151 // global DrawingManager stuff
00152 // global DrawingManager Object
00153 void initDrawingManager(DrawingManager* streamHandlerPtr);
00154 DrawingManager& getDrawingManager();
00155 
00156 
00157 ///////////////////////////////// new macros
00158 
00159 /** 
00160 * A macro that declares
00161 * @param id A drawing id
00162 * @param type A drawing type
00163 * @param description A description for this debug drawing
00164 */
00165 #define NDECLARE_DEBUGDRAWING( id, type, description) \
00166   getDrawingManager().addDrawingId( id, type, description);\
00167   DEBUG_RESPONSE("debug drawing:" id , );
00168 
00169 
00170 /** 
00171 * A macro that sends a circle
00172 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00173 * @param center_x The x coordinate of the center of the circle
00174 * @param center_y The y coordinate of the center of the circle
00175 * @param radius The radius of the circle
00176 * @param penWidth The width of the arc of the circle
00177 * @param penStyle The pen style of the arc of the circle (Drawings::PenStyle)
00178 * @param penColor The color of the arc of the circle (Drawings::Color)
00179 */
00180 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor) \
00181   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00182     OUTPUT( idDebugDrawing2, bin, \
00183       (char)Drawings::circle << \
00184       (char)getDrawingManager().getDrawingId( id ) << \
00185       (int)(center_x) << (int)(center_y) << (int)(radius) << (char)(penWidth) << \
00186       (char)(penStyle) << (char)(penColor) \
00187      ); \
00188   );
00189 
00190 
00191 /** 
00192 * A macro that sends a dot (a quadratic box with a border)
00193 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00194 * @param x The x coordinate of the center of the box
00195 * @param y The y coordinate of the center of the box
00196 * @param penColor The color of the border of the dot (Drawings::Color)
00197 * @param fillColor The color of the dot (Drawings::Color)
00198 */
00199 #define NDOT(id, x, y, penColor, fillColor) \
00200   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00201     OUTPUT( idDebugDrawing2, bin, \
00202       (char)Drawings::dot << \
00203       (char)getDrawingManager().getDrawingId( id ) << \
00204       (int)(x) << (int)(y) << (char)(penColor) << (char)(fillColor) \
00205     ); \
00206   );
00207 
00208 
00209 /** 
00210 * A macro that sends a dot (a quadratic box with a border)
00211 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00212 * @param x The x coordinate of the center of the box
00213 * @param y The y coordinate of the center of the box
00214 * @param penColor The color of the border of the dot (Drawings::Color)
00215 * @param fillColor The color of the dot (Drawings::Color)
00216 */  
00217 #define NLARGE_DOT(id, x, y, penColor, fillColor) \
00218   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00219     OUTPUT( idDebugDrawing2, bin, \
00220       (char)Drawings::largeDot << \
00221       (char)getDrawingManager().getDrawingId( id ) << \
00222       (int)(x) << (int)(y) << (char)(penColor) << (char)(fillColor) \
00223      ); \
00224   );
00225 
00226 /**
00227 * A macro that sends a line
00228 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00229 * @param x1 The x coordinate of the starting point.
00230 * @param y1 The y coordinate of the starting point.
00231 * @param x2 The x coordinate of the end point.
00232 * @param y2 The y coordinate of the end point.
00233 * @param penWidth The width of the line
00234 * @param penStyle The pen style of the line (Drawings::PenStyle)
00235 * @param penColor The color of the line (Drawings::Color)
00236 */
00237 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor) \
00238   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00239      OUTPUT( idDebugDrawing2, bin, \
00240       (char)Drawings::line << \
00241       (char)getDrawingManager().getDrawingId( id ) << \
00242       (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColor) \
00243       ); \
00244   );
00245 
00246 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB) \
00247   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00248     OUTPUT( idDebugDrawing2, bin, \
00249       (char)Drawings::coloredLine << \
00250       (char)getDrawingManager().getDrawingId( id ) << \
00251       (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColorR) << (char)(penColorG) << (char)(penColorB)\
00252       ); \
00253   );
00254 
00255 
00256 /**
00257 * A macro that sends an arrow
00258 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00259 * @param x1 The x coordinate of the starting point.
00260 * @param y1 The y coordinate of the starting point.
00261 * @param x2 The x coordinate of the end point.
00262 * @param y2 The y coordinate of the end point.
00263 * @param penWidth The width of the line
00264 * @param penStyle The pen style of the line (Drawings::PenStyle)
00265 * @param penColor The color of the line (Drawings::Color)
00266 */
00267 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor) \
00268   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00269    OUTPUT( idDebugDrawing2, bin, \
00270     (char)Drawings::arrow << \
00271     (char)getDrawingManager().getDrawingId( id ) << \
00272     (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColor) \
00273     ); \
00274   );
00275 
00276 
00277 /**
00278 * A macro that sends an arrow for a pose
00279 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00280 * @param p A Pose2D describing the arrow
00281 * @param color The color of the line arrow (Drawings::Color)
00282 */
00283 #define NPOSE_2D_SAMPLE(id, p, color) \
00284   Pose2D current = p; current += Pose2D(-100,0); \
00285   NLINE(id, int(current.translation.x),int(current.translation.y), int(p.translation.x), int(p.translation.y), \
00286   1, Drawings::ps_solid, color); \
00287   current = p; current += Pose2D(-40,-40); \
00288   NLINE(id, int(current.translation.x), int(current.translation.y), int(p.translation.x), int(p.translation.y), \
00289   1, Drawings::ps_solid, color); \
00290   current = p; current += Pose2D(-40,40); \
00291   NLINE(id, int(current.translation.x),int(current.translation.y),int(p.translation.x), int(p.translation.y), \
00292   1, Drawings::ps_solid, color); \
00293 
00294 /** 
00295 * A macro that sends an octangle
00296 * @param id A drawing id (Drawings::FieldDrawing or Drawings::drawingOnField)
00297 * @param x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8 The coordinates of the 8 octagon vertices
00298 * @param color The color of the octangle
00299 * @param fill A boolean indicating if the octangle is filled
00300 */
00301 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill) \
00302   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" #id , \
00303      OUTPUT( idDebugDrawing2, bin, \
00304       (char)Drawings::octangle << \
00305       (char)getDrawingManager().getDrawingId( #id ) << \
00306       (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (int)(x3) << (int)(y3) << (int)(x4) << (int)(y4) << \
00307       (int)(x5) << (int)(y5) << (int)(x6) << (int)(y6) << (int)(x7) << (int)(y7) << (int)(x8) << (int)(y8) << \
00308       (char)ColorClasses::colorClassToDrawingsColor(color) << (char)fill \
00309   );
00310 
00311 /** 
00312 * A macro that sends an quadrangle
00313 * @param x1,y1,x2,y2,x3,y3,x4,y4 The coordinates of the 4 quadrangle vertices
00314 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00315 * @param penWidth The line width of the quadrangle
00316 * @param penStyle The line style, e.g. dotted
00317 * @param penColor The color of the quadrangle
00318 */
00319 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor) \
00320   NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor); \
00321   NLINE(id, x2, y2, x3, y3, penWidth, penStyle, penColor); \
00322   NLINE(id, x3, y3, x4, y4, penWidth, penStyle, penColor); \
00323   NLINE(id, x4, y4, x1, y1, penWidth, penStyle, penColor); 
00324 
00325 /** 
00326 * A macro that sends an rectangle
00327 * @param x1,y1,x2,y2 The coordinates of 2 opposite corners
00328 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00329 * @param penWidth The line width of the rectangle
00330 * @param penStyle The line style, e.g. dotted
00331 * @param penColor The color of the quadrangle
00332 */
00333 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor) \
00334   NLINE(id, x1, y1, x1, y2, penWidth, penStyle, penColor); \
00335   NLINE(id, x1, y2, x2, y2, penWidth, penStyle, penColor); \
00336   NLINE(id, x2, y2, x2, y1, penWidth, penStyle, penColor); \
00337   NLINE(id, x2, y1, x1, y1, penWidth, penStyle, penColor); 
00338 
00339 /** 
00340 * A macro that sends a cross
00341 * @param x,y The center of the cross
00342 * @param half of the height of the rectangle enclosing the cross
00343 * @param id A drawing id (Drawings::FieldDrawing or Drawings::ImageDrawing)
00344 * @param penWidth The line width of the rectangle
00345 * @param penStyle The line style, e.g. dotted
00346 * @param penColor The color of the quadrangle
00347 */
00348 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor)\
00349   NLINE(id, x+size, y+size, x-size, y-size, penWidth, penStyle, penColor);\
00350   NLINE(id, x+size, y-size, x-size, y+size, penWidth, penStyle, penColor);
00351 
00352 
00353 /** 
00354 * Complex drawings should be encapsuled by this macro.
00355 */
00356 #define NCOMPLEX_DRAWING(id,expression) \
00357   NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00358     expression;\
00359   );
00360   
00361 #endif //NODEBUGDRAWINGS
00362 
00363 #endif //__DebugDrawings_h_
00364 
00365 #endif

Generated on Mon Mar 20 22:00:04 2006 for GT2005 by doxygen 1.3.6