color_object_map.cpp

00001 
00002 /***************************************************************************
00003  *  color_object_map.cpp - Mapping between color and roi
00004  *
00005  *  Created: Mon May 16 00:00:00 2008
00006  *  Copyright  2008 Christof Rath <c.rath@student.tugraz.at>
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <fvutils/color/color_object_map.h>
00025 
00026 namespace firevision {
00027 #if 0 /* just to make Emacs auto-indent happy */
00028 }
00029 #endif
00030 
00031 /** @class ColorObjectMap <fvutils/color/color_object_map.h>
00032  * Color mapping class.
00033  * This class defines a mapping between regions of interest and @see color_t
00034  * values. It also provides corresponding @see YUVColor values for a color_t.
00035  *
00036  * @author Christof Rath
00037  */
00038 
00039 /** @var static ColorObjectMap* ColorObjectMap::__singleton
00040  * A singelton instance of ColorObjectMap
00041  */
00042 /** @var std::map<hint_t, color_t> ColorObjectMap::__color_for_hint
00043  * A list of color_t with hint_t (ROI's) as index
00044  */
00045 /** @var std::map<color_t, hint_t> ColorObjectMap::__hint_for_color
00046  * A list of hint_t (ROI's) with color_t as index
00047  */
00048 /** @var color_t ColorObjectMap::__c_other
00049  * The default color
00050  */
00051 /** @var hint_t ColorObjectMap::__h_unknown
00052  * The default hint
00053  */
00054 
00055 /** @fn static const ColorObjectMap& ColorObjectMap::get_instance()
00056  * ColorObjectMap getter.
00057  * @return the one and only instance of ColorObjectMap
00058  */
00059 
00060 /** @fn const color_t& ColorObjectMap::get(hint_t hint) const
00061  * Inline color_t reference getter.
00062  * @param hint the ROI of interest
00063  * @return the matching color_t value
00064  */
00065 
00066 /** @fn const hint_t ColorObjectMap::get(color_t color) const
00067  * Inline hint_t(ROI) reference getter
00068  * @param color value of interest
00069  * @return corresponding ROI
00070  */
00071 
00072 /** Static initialzer */
00073 ColorObjectMap* ColorObjectMap::__singleton = new ColorObjectMap();
00074 
00075 /** Default Contructor.
00076  * The constructor is private to implement a singelton pattern
00077  */
00078 ColorObjectMap::ColorObjectMap()
00079 {
00080   __c_other   = C_OTHER;
00081   __h_unknown = H_UNKNOWN;
00082 
00083   //Standard mapping:
00084   set_mapping(H_BALL, C_ORANGE);
00085   set_mapping(H_ROBOT, C_BLACK);
00086   set_mapping(H_ROBOT_OPP, C_RED);
00087   set_mapping(H_FIELD, C_GREEN);
00088   set_mapping(H_GOAL_YELLOW, C_YELLOW);
00089   set_mapping(H_GOAL_BLUE, C_CYAN);
00090   set_mapping(H_LINE, C_WHITE);
00091   set_mapping(H_BACKGROUND, C_BACKGROUND);
00092 }
00093 
00094 /** Destructor */
00095 ColorObjectMap::~ColorObjectMap()
00096 {
00097 }
00098 
00099 /** YUV_t getter.
00100  * @param color a color_t value (@see color_t enumeration)
00101  * @return a corresponding YUV color
00102  */
00103 YUV_t ColorObjectMap::get_color(color_t color)
00104 {
00105   switch (color) {
00106     case C_ORANGE:
00107       return YUV_t::orange();
00108 
00109     case C_MAGENTA:
00110       return YUV_t::magenta();
00111 
00112     case C_CYAN:
00113       return YUV_t::cyan();
00114 
00115     case C_BLUE:
00116       return YUV_t::blue();
00117 
00118     case C_YELLOW:
00119       return YUV_t::yellow();
00120 
00121     case C_GREEN:
00122       return YUV_t::green();
00123 
00124     case C_WHITE:
00125       return YUV_t::white();
00126 
00127     case C_RED:
00128       return YUV_t::red();
00129 
00130     case C_BLACK:
00131       return YUV_t::black();
00132 
00133     default: //also C_BACKGROUND
00134       return YUV_t::gray();
00135   }
00136 }
00137 
00138 /** Mapping setter.
00139  * Sets the mapping between ROI and color_t values
00140  * @param roi region of interest (@see hint_t enumeration)
00141  * @param color matching color_t value (@see color_t enumeration)
00142  */
00143 void ColorObjectMap::set_mapping(hint_t roi, color_t color)
00144 {
00145   hint_t cur_roi = get(color);
00146   if (cur_roi != H_UNKNOWN) //There is a previous mapping -> unlink it
00147   {
00148     color_t cur_col = get(roi);
00149     __color_for_hint[cur_roi] = C_OTHER;
00150     __hint_for_color[cur_col] = H_UNKNOWN;
00151   }
00152 
00153   __color_for_hint[roi] = color;
00154   __hint_for_color[color] = roi;
00155 }
00156 
00157 } // end namespace firevision

Generated on Tue Feb 22 13:32:15 2011 for Fawkes API by  doxygen 1.4.7