Fawkes API  Fawkes Development Version
color_object_map.cpp
1 
2 /***************************************************************************
3  * color_object_map.cpp - Mapping between color and roi
4  *
5  * Created: Mon May 16 00:00:00 2008
6  * Copyright 2008 Christof Rath <c.rath@student.tugraz.at>
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvutils/color/color_object_map.h>
25 
26 namespace firevision {
27 #if 0 /* just to make Emacs auto-indent happy */
28 }
29 #endif
30 
31 /** @class ColorObjectMap <fvutils/color/color_object_map.h>
32  * Color mapping class.
33  * This class defines a mapping between regions of interest and @see color_t
34  * values. It also provides corresponding @see YUVColor values for a color_t.
35  *
36  * @author Christof Rath
37  */
38 
39 /** @var static ColorObjectMap* ColorObjectMap::__singleton
40  * A singelton instance of ColorObjectMap
41  */
42 /** @var std::map<hint_t, color_t> ColorObjectMap::__color_for_hint
43  * A list of color_t with hint_t (ROI's) as index
44  */
45 /** @var std::map<color_t, hint_t> ColorObjectMap::__hint_for_color
46  * A list of hint_t (ROI's) with color_t as index
47  */
48 /** @var color_t ColorObjectMap::__c_other
49  * The default color
50  */
51 /** @var hint_t ColorObjectMap::__h_unknown
52  * The default hint
53  */
54 
55 /** @fn static const ColorObjectMap& ColorObjectMap::get_instance()
56  * ColorObjectMap getter.
57  * @return the one and only instance of ColorObjectMap
58  */
59 
60 /** @fn const color_t& ColorObjectMap::get(hint_t hint) const
61  * Inline color_t reference getter.
62  * @param hint the ROI of interest
63  * @return the matching color_t value
64  */
65 
66 /** @fn const hint_t ColorObjectMap::get(color_t color) const
67  * Inline hint_t(ROI) reference getter
68  * @param color value of interest
69  * @return corresponding ROI
70  */
71 
72 /** Static initialzer */
73 ColorObjectMap* ColorObjectMap::__singleton = new ColorObjectMap();
74 
75 /** Default Contructor.
76  * The constructor is private to implement a singelton pattern
77  */
78 ColorObjectMap::ColorObjectMap()
79 {
80  __c_other = C_OTHER;
81  __h_unknown = H_UNKNOWN;
82 
83  //Standard mapping:
84  set_mapping(H_BALL, C_ORANGE);
85  set_mapping(H_ROBOT, C_BLACK);
86  set_mapping(H_ROBOT_OPP, C_RED);
87  set_mapping(H_FIELD, C_GREEN);
88  set_mapping(H_GOAL_YELLOW, C_YELLOW);
89  set_mapping(H_GOAL_BLUE, C_CYAN);
90  set_mapping(H_LINE, C_WHITE);
91  set_mapping(H_BACKGROUND, C_BACKGROUND);
92 }
93 
94 /** Destructor */
96 {
97 }
98 
99 /** YUV_t getter.
100  * @param color a color_t value (@see color_t enumeration)
101  * @return a corresponding YUV color
102  */
104 {
105  switch (color) {
106  case C_ORANGE:
107  return YUV_t::orange();
108 
109  case C_MAGENTA:
110  return YUV_t::magenta();
111 
112  case C_CYAN:
113  return YUV_t::cyan();
114 
115  case C_BLUE:
116  return YUV_t::blue();
117 
118  case C_YELLOW:
119  return YUV_t::yellow();
120 
121  case C_GREEN:
122  return YUV_t::green();
123 
124  case C_WHITE:
125  return YUV_t::white();
126 
127  case C_RED:
128  return YUV_t::red();
129 
130  case C_BLACK:
131  return YUV_t::black();
132 
133  default: //also C_BACKGROUND
134  return YUV_t::gray();
135  }
136 }
137 
138 /** Mapping setter.
139  * Sets the mapping between ROI and color_t values
140  * @param roi region of interest (@see hint_t enumeration)
141  * @param color matching color_t value (@see color_t enumeration)
142  */
143 void ColorObjectMap::set_mapping(hint_t roi, color_t color)
144 {
145  hint_t cur_roi = get(color);
146  if (cur_roi != H_UNKNOWN) //There is a previous mapping -> unlink it
147  {
148  color_t cur_col = get(roi);
149  __color_for_hint[cur_roi] = C_OTHER;
150  __hint_for_color[cur_col] = H_UNKNOWN;
151  }
152 
153  __color_for_hint[roi] = color;
154  __hint_for_color[color] = roi;
155 }
156 
157 } // end namespace firevision
static YUV_t_struct yellow()
Definition: yuv.h:83
static YUV_t_struct magenta()
Definition: yuv.h:80
static YUV_t_struct red()
Definition: yuv.h:85
static YUV_t_struct cyan()
Definition: yuv.h:79
static YUV_t_struct black()
Definition: yuv.h:77
static YUV_t_struct gray()
Definition: yuv.h:81
static YUV_t_struct orange()
Definition: yuv.h:82
static YUV_t_struct green()
Definition: yuv.h:78
YUV pixel.
Definition: yuv.h:59
static YUV_t_struct blue()
Definition: yuv.h:84
static YUV_t get_color(color_t color)
YUV_t getter.
static YUV_t_struct white()
Definition: yuv.h:76