field_drawer.h

00001 /***************************************************************************
00002  *  field_drawer.h - Encapsulates a soccer field
00003  *
00004  *  Created:  23.09.2008
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 "field.h"
00026
00027 #include <utils/math/types.h>
00028 #include <fvutils/color/yuv.h>
00029
00030
00031 class SharedMemoryImageBuffer;
00032
00033 class FieldDrawer
00034 {
00035 public:
00036   FieldDrawer(const FieldLines &lines);
00037   virtual ~FieldDrawer();
00038
00039   void set_head_yaw(float head_yaw);
00040   void set_own_pos(fawkes::field_pos_t own_position);
00041   void set_own_pos_est(fawkes::field_pos_t own_position_estimate);
00042
00043   void set_line_points(const fld_line_points_t *points);
00044   void set_line_points_est(const fld_line_points_t *points_est);
00045
00046   void set_color_background(YUV_t color);
00047   void set_color_field(YUV_t color);
00048   void set_color_lines(YUV_t color);
00049   void set_color_line_points(YUV_t color);
00050   void set_color_line_points_est(YUV_t color);
00051   void set_color_own_pos(YUV_t color);
00052   void set_color_own_pos_est(YUV_t color);
00053
00054   virtual void draw_field(unsigned char *yuv422_planar, unsigned int img_width, unsigned int img_height,
00055                           bool draw_background = true, bool draw_landscape = true);
00056
00057 protected:
00058   inline void clear_own_pos();
00059   inline float get_scale(unsigned int img_width, unsigned int img_height, bool draw_landscape = true) const;
00060   virtual void draw_line_points(bool draw_landscape = true, float scale = 0) const;
00061   virtual void draw_lines(YUV_t color, bool draw_landscape = true, float scale = 0) const;
00062
00063   unsigned char *_img_buffer;
00064   unsigned int   _img_width;
00065   unsigned int   _img_height;
00066
00067 private: //Members
00068   const FieldLines     &__lines;
00069   fawkes::field_pos_t   __own_position, __own_pos_est;
00070   float                 __head_yaw;
00071
00072   const fld_line_points_t     *__points;
00073   const fld_line_points_t     *__points_est;
00074
00075   YUV_t __c_background;
00076   YUV_t __c_field;
00077   YUV_t __c_lines;
00078   YUV_t __c_line_points;
00079   YUV_t __c_line_points_est;
00080   YUV_t __c_own_pos;
00081   YUV_t __c_own_pos_est;
00082 };
00083
00084 #endif /* __FVUTILS_DRAWER_FIELD_DRAWER_H__ */