field_drawer.h

00001 /***************************************************************************
00002  *  field_drawer.h - Encapsulates a soccer field
00003  *
00004  *  Created:  Tue Sep 23 00:00:00 2009
00005  *  Copyright 2008 Christof Rath <christof.rath@gmail.com>
00006  *
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU Library General Public License for more details.
00018  *
00019  *  Read the full text in the LICENSE.GPL file in the doc directory.
00020  */
00021 
00022 #ifndef __FVUTILS_DRAWER_FIELD_DRAWER_H__
00023 #define __FVUTILS_DRAWER_FIELD_DRAWER_H__
00024 
00025 #include <fvutils/draw/field.h>
00026 
00027 #include <utils/math/types.h>
00028 #include <fvutils/color/yuv.h>
00029 
00030 namespace firevision {
00031 #if 0 /* just to make Emacs auto-indent happy */
00032 }
00033 #endif
00034 
00035 
00036 class SharedMemoryImageBuffer;
00037 
00038 class FieldDrawer
00039 {
00040 public:
00041   FieldDrawer(const FieldLines &lines);
00042   virtual ~FieldDrawer();
00043 
00044   void set_head_yaw(float head_yaw);
00045   void set_own_pos(fawkes::field_pos_t own_position);
00046   void set_own_pos_est(fawkes::field_pos_t own_position_estimate);
00047 
00048   void set_line_points(const fld_line_points_t *points);
00049   void set_line_points_est(const fld_line_points_t *points_est);
00050 
00051   void set_color_background(YUV_t color);
00052   void set_color_field(YUV_t color);
00053   void set_color_lines(YUV_t color);
00054   void set_color_line_points(YUV_t color);
00055   void set_color_line_points_est(YUV_t color);
00056   void set_color_own_pos(YUV_t color);
00057   void set_color_own_pos_est(YUV_t color);
00058 
00059   virtual void draw_field(unsigned char *yuv422_planar, unsigned int img_width, unsigned int img_height,
00060                           bool draw_background = true, bool draw_landscape = true);
00061 
00062 protected:
00063   inline void clear_own_pos();
00064   inline float get_scale(unsigned int img_width, unsigned int img_height, bool draw_landscape = true) const;
00065   virtual void draw_line_points(bool draw_landscape = true, float scale = 0) const;
00066   virtual void draw_lines(YUV_t color, bool draw_landscape = true, float scale = 0) const;
00067 
00068   unsigned char *_img_buffer;
00069   unsigned int   _img_width;
00070   unsigned int   _img_height;
00071 
00072 private: //Members
00073   const FieldLines     &__lines;
00074   fawkes::field_pos_t   __own_position, __own_pos_est;
00075   float                 __head_yaw;
00076 
00077   const fld_line_points_t     *__points;
00078   const fld_line_points_t     *__points_est;
00079 
00080   YUV_t __c_background;
00081   YUV_t __c_field;
00082   YUV_t __c_lines;
00083   YUV_t __c_line_points;
00084   YUV_t __c_line_points_est;
00085   YUV_t __c_own_pos;
00086   YUV_t __c_own_pos_est;
00087 };
00088 
00089 } // end namespace firevision
00090 
00091 #endif