latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiHsvHistogramViewer.h 00027 * authors ....: Joerg Zieren 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 19.7.2002 00030 * revisions ..: $Id: ltiHsvHistogramViewer.h,v 1.9 2006/02/08 12:57:18 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_HSV_HISTOGRAM_VIEWER_H_ 00034 #define _LTI_HSV_HISTOGRAM_VIEWER_H_ 00035 00036 #include "ltiConfig.h" 00037 00038 #ifdef HAVE_GTK 00039 00040 #include "ltiViewer.h" 00041 #include "ltiHistogram.h" 00042 #include "ltiMergeHSVToImage.h" 00043 #include "ltiFunctor.h" 00044 00045 namespace lti { 00046 /** 00047 * A simple HSV histogram viewer. It displays an HSV histogram as a 2D 00048 * image. Hue (H) corresponds to the y coordinate (ordinate), and saturation 00049 * (S) to the x coordinate (abscissa). Value (V) is ignored in the histogram 00050 * in one of the following two ways: 1) A histogram2D is given to the apply 00051 * method, containing H and S pairs (in this order). 2) A 3D histogram 00052 * containing H, S, V triples (in this order) is given, but is projected 00053 * into 2D (H,S)-space by summing up over all values (V). 00054 00055 * In the display, V is always set to maximum, and the background is black. 00056 * Every histogram cell corresponds to a square with a fixed side length 00057 * defineable in the parameters. This square is filled with the corresponding 00058 * color depending on the cell's value (completely for maximum, empty for 0). 00059 */ 00060 class hsvHistogramViewer : public functor { 00061 protected: 00062 /** A helper class for drawing. */ 00063 class ray { 00064 public: 00065 ray( 00066 const point& start, 00067 const point& direction, 00068 const point& nextStartOffset, 00069 const int& steps); 00070 void getNextPoint(point& p); 00071 protected: 00072 point m_start; 00073 point m_cursor; 00074 point m_direction; 00075 point m_nextStartOffset; 00076 int m_steps; 00077 int m_stepsLeft; 00078 }; 00079 public: 00080 /** 00081 * the parameters for the class hsvHistogramViewer 00082 */ 00083 class parameters : public functor::parameters { 00084 public: 00085 /** 00086 * default constructor 00087 */ 00088 parameters(); 00089 00090 /** 00091 * copy constructor 00092 * @param other the parameters object to be copied 00093 */ 00094 parameters(const parameters& other); 00095 00096 /** 00097 * destructor 00098 */ 00099 ~parameters(); 00100 00101 /** 00102 * returns name of this type 00103 */ 00104 const char* getTypeName() const; 00105 00106 /** 00107 * copy the contents of a parameters object 00108 * @param other the parameters object to be copied 00109 * @return a reference to this parameters object 00110 */ 00111 parameters& copy(const parameters& other); 00112 00113 /** 00114 * copy the contents of a parameters object 00115 * @param other the parameters object to be copied 00116 * @return a reference to this parameters object 00117 */ 00118 parameters& operator=(const parameters& other); 00119 00120 00121 /** 00122 * returns a pointer to a clone of the parameters 00123 */ 00124 virtual functor::parameters* clone() const; 00125 00126 /** 00127 * write the parameters in the given ioHandler 00128 * @param handler the ioHandler to be used 00129 * @param complete if true (the default) the enclosing begin/end will 00130 * be also written, otherwise only the data block will be written. 00131 * @return true if write was successful 00132 */ 00133 virtual bool write(ioHandler& handler,const bool complete=true) const; 00134 00135 /** 00136 * read the parameters from the given ioHandler 00137 * @param handler the ioHandler to be used 00138 * @param complete if true (the default) the enclosing begin/end will 00139 * be also written, otherwise only the data block will be written. 00140 * @return true if write was successful 00141 */ 00142 virtual bool read(ioHandler& handler,const bool complete=true); 00143 00144 # ifdef _LTI_MSC_6 00145 /** 00146 * this function is required by MSVC only, as a workaround for a 00147 * very awful bug, which exists since MSVC V.4.0, and still by 00148 * V.6.0 with all bugfixes (so called "service packs") remains 00149 * there... This method is also public due to another bug, so please 00150 * NEVER EVER call this method directly: use read() instead 00151 */ 00152 bool readMS(ioHandler& handler,const bool complete=true); 00153 00154 /** 00155 * this function is required by MSVC only, as a workaround for a 00156 * very awful bug, which exists since MSVC V.4.0, and still by 00157 * V.6.0 with all bugfixes (so called "service packs") remains 00158 * there... This method is also public due to another bug, so please 00159 * NEVER EVER call this method directly: use write() instead 00160 */ 00161 bool writeMS(ioHandler& handler,const bool complete=true) const; 00162 # endif 00163 00164 // ------------------------------------------------ 00165 // the parameters 00166 // ------------------------------------------------ 00167 00168 /** 00169 * Scale factor: Side length (in pixels) of the square that 00170 * corresponds to one histogram cell. (Default: 10) 00171 */ 00172 int scale; 00173 00174 }; 00175 00176 /** 00177 * default constructor 00178 */ 00179 hsvHistogramViewer(); 00180 00181 /** 00182 * Uses the given window title. 00183 */ 00184 hsvHistogramViewer(const std::string& windowTitle); 00185 00186 /** 00187 * copy constructor 00188 * @param other the object to be copied 00189 */ 00190 hsvHistogramViewer(const hsvHistogramViewer& other); 00191 00192 /** 00193 * destructor 00194 */ 00195 virtual ~hsvHistogramViewer(); 00196 00197 /** 00198 * returns the name of this type ("hsvHistogramViewer") 00199 */ 00200 virtual const char* getTypeName() const; 00201 00202 /** 00203 * Show the given HSV histogram. The histogram must be 3D 00204 * (H, S, V - in this order). It is projected into (H,S)-space. 00205 * @param hist thistogram<double> with the source data. 00206 * @return true if apply successful or false otherwise. 00207 */ 00208 bool apply(thistogram<double>& hist) const; 00209 00210 /** 00211 * Show the given HSV histogram. The histogram is 2D 00212 * (H, S - in this order). 00213 * @param hist histogram2D with the source data. 00214 * @return true if apply successful or false otherwise. 00215 */ 00216 bool apply(histogram2D& hist) const; 00217 00218 /** 00219 * copy data of "other" functor. 00220 * @param other the functor to be copied 00221 * @return a reference to this functor object 00222 */ 00223 hsvHistogramViewer& copy(const hsvHistogramViewer& other); 00224 00225 /** 00226 * alias for copy member 00227 * @param other the functor to be copied 00228 * @return a reference to this functor object 00229 */ 00230 hsvHistogramViewer& operator=(const hsvHistogramViewer& other); 00231 00232 /** 00233 * returns a pointer to a clone of this functor. 00234 */ 00235 virtual functor* clone() const; 00236 00237 /** 00238 * returns used parameters 00239 */ 00240 const parameters& getParameters() const; 00241 00242 protected: 00243 /** For converting HSV to RGB (for display) */ 00244 mergeHSVToImage m_hsvToRgb; 00245 00246 /** For actually showing the histogram. */ 00247 mutable viewer m_viewer; 00248 00249 /** Fill a square area in the given image with the given color. 00250 * The square has the the given side length, and its upper left 00251 * corder is at fromRow/fromCol. The cell is filled to the 00252 * given percentage. I hope it looks nice :-) 00253 */ 00254 void fillCell( 00255 image& img, 00256 const rgbPixel& color, 00257 const int& fromRow, 00258 const int& fromCol, 00259 const int& sideLength, 00260 float percent) const; 00261 00262 /** Convert an (H,S) pair to RGB. V=max is assumed. */ 00263 rgbPixel getColor( 00264 const int&h, const int& hValues, 00265 const int&s, const int& sValues) const; 00266 }; 00267 } 00268 00269 #endif 00270 #endif