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
26namespace firevision {
27
28/** @class ColorObjectMap <fvutils/color/color_object_map.h>
29 * Color mapping class.
30 * This class defines a mapping between regions of interest and @see color_t
31 * values. It also provides corresponding @see YUVColor values for a color_t.
32 *
33 * @author Christof Rath
34 */
35
36/** @var static ColorObjectMap* ColorObjectMap::singleton_
37 * A singelton instance of ColorObjectMap
38 */
39/** @var std::map<hint_t, color_t> ColorObjectMap::color_for_hint_
40 * A list of color_t with hint_t (ROI's) as index
41 */
42/** @var std::map<color_t, hint_t> ColorObjectMap::hint_for_color_
43 * A list of hint_t (ROI's) with color_t as index
44 */
45/** @var color_t ColorObjectMap::c_other_
46 * The default color
47 */
48/** @var hint_t ColorObjectMap::h_unknown_
49 * The default hint
50 */
51
52/** @fn static const ColorObjectMap& ColorObjectMap::get_instance()
53 * ColorObjectMap getter.
54 * @return the one and only instance of ColorObjectMap
55 */
56
57/** @fn const color_t& ColorObjectMap::get(hint_t hint) const
58 * Inline color_t reference getter.
59 * @param hint the ROI of interest
60 * @return the matching color_t value
61 */
62
63/** @fn const hint_t ColorObjectMap::get(color_t color) const
64 * Inline hint_t(ROI) reference getter
65 * @param color value of interest
66 * @return corresponding ROI
67 */
68
69/** Static initialzer */
70ColorObjectMap *ColorObjectMap::singleton_ = new ColorObjectMap();
71
72/** Default Contructor.
73 * The constructor is private to implement a singelton pattern
74 */
75ColorObjectMap::ColorObjectMap()
76{
77 c_other_ = C_OTHER;
78 h_unknown_ = H_UNKNOWN;
79
80 //Standard mapping:
81 set_mapping(H_BALL, C_ORANGE);
82 set_mapping(H_ROBOT, C_BLACK);
83 set_mapping(H_ROBOT_OPP, C_RED);
84 set_mapping(H_FIELD, C_GREEN);
85 set_mapping(H_GOAL_YELLOW, C_YELLOW);
86 set_mapping(H_GOAL_BLUE, C_CYAN);
87 set_mapping(H_LINE, C_WHITE);
88 set_mapping(H_BACKGROUND, C_BACKGROUND);
89}
90
91/** Destructor */
93{
94}
95
96/** YUV_t getter.
97 * @param color a color_t value (@see color_t enumeration)
98 * @return a corresponding YUV color
99 */
100YUV_t
102{
103 switch (color) {
104 case C_ORANGE: return YUV_t::orange();
105
106 case C_MAGENTA: return YUV_t::magenta();
107
108 case C_CYAN: return YUV_t::cyan();
109
110 case C_BLUE: return YUV_t::blue();
111
112 case C_YELLOW: return YUV_t::yellow();
113
114 case C_GREEN: return YUV_t::green();
115
116 case C_WHITE: return YUV_t::white();
117
118 case C_RED: return YUV_t::red();
119
120 case C_BLACK: return YUV_t::black();
121
122 default: //also C_BACKGROUND
123 return YUV_t::gray();
124 }
125}
126
127/** Mapping setter.
128 * Sets the mapping between ROI and color_t values
129 * @param roi region of interest (@see hint_t enumeration)
130 * @param color matching color_t value (@see color_t enumeration)
131 */
132void
133ColorObjectMap::set_mapping(hint_t roi, color_t color)
134{
135 hint_t cur_roi = get(color);
136 if (cur_roi != H_UNKNOWN) //There is a previous mapping -> unlink it
137 {
138 color_t cur_col = get(roi);
139 color_for_hint_[cur_roi] = C_OTHER;
140 hint_for_color_[cur_col] = H_UNKNOWN;
141 }
142
143 color_for_hint_[roi] = color;
144 hint_for_color_[color] = roi;
145}
146
147} // end namespace firevision
static YUV_t get_color(color_t color)
YUV_t getter.
color_t get(hint_t hint) const
Inline color_t reference getter.
YUV pixel.
Definition: yuv.h:58
static YUV_t_struct gray()
Definition: yuv.h:101
static YUV_t_struct cyan()
Definition: yuv.h:91
static YUV_t_struct green()
Definition: yuv.h:86
static YUV_t_struct orange()
Definition: yuv.h:106
static YUV_t_struct blue()
Definition: yuv.h:116
static YUV_t_struct magenta()
Definition: yuv.h:96
static YUV_t_struct white()
Definition: yuv.h:76
static YUV_t_struct yellow()
Definition: yuv.h:111
static YUV_t_struct black()
Definition: yuv.h:81
static YUV_t_struct red()
Definition: yuv.h:121