LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiHistogramViewer.h

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  * project ....: LTI Digital Image/Signal Processing Library
00025  * file .......: ltiHistogramViewer.h
00026  * authors ....: Pablo Alvarado
00027  * organization: LTI, RWTH Aachen
00028  * creation ...: 21.6.2002
00029  * revisions ..: $Id: ltiHistogramViewer.h,v 1.8 2006/02/08 12:57:01 ltilib Exp $
00030  */
00031 
00032 #ifndef _LTI_HISTOGRAM_VIEWER_H_
00033 #define _LTI_HISTOGRAM_VIEWER_H_
00034 
00035 #include "ltiConfig.h"
00036 
00037 #ifdef HAVE_GTK
00038 
00039 #include "ltiViewerBase3D.h"
00040 #include "ltiHistogram.h"
00041 
00042 namespace lti {
00043 
00044   /**
00045    * This class display the histograms of images or channels.  Histograms
00046    * can also be given directly (1D, 2D or 3D).
00047    */
00048   class histogramViewer : public viewerBase3D {
00049   public:
00050     /**
00051      * the parameters for the class viewerBase3D
00052      */
00053     class parameters : public viewerBase3D::parameters {
00054     public:
00055       /**
00056        * default constructor
00057        */
00058       parameters();
00059 
00060       /**
00061        * copy constructor
00062        * @param other the parameters object to be copied
00063        */
00064       parameters(const parameters& other);
00065 
00066       /**
00067        * destructor
00068        */
00069       ~parameters();
00070 
00071       /**
00072        * returns name of this type
00073        */
00074       const char* getTypeName() const;
00075 
00076       /**
00077        * copy the contents of a parameters object
00078        * @param other the parameters object to be copied
00079        * @return a reference to this parameters object
00080        */
00081       virtual parameters& copy(const parameters& other);
00082 
00083       /**
00084        * returns a pointer to a clone of the parameters
00085        */
00086       virtual functor::parameters* clone() const;
00087 
00088       /**
00089        * write the parameters in the given ioHandler
00090        * @param handler the ioHandler to be used
00091        * @param complete if true (the default) the enclosing begin/end will
00092        *        be also written, otherwise only the data block will be written.
00093        * @return true if write was successful
00094        */
00095       virtual bool write(ioHandler& handler,const bool complete=true) const;
00096 
00097       /**
00098        * read the parameters from the given ioHandler
00099        * @param handler the ioHandler to be used
00100        * @param complete if true (the default) the enclosing begin/end will
00101        *        be also written, otherwise only the data block will be written.
00102        * @return true if write was successful
00103        */
00104       virtual bool read(ioHandler& handler,const bool complete=true);
00105 
00106 #     ifdef _LTI_MSC_6
00107       /**
00108        * this function is required by MSVC only, as a workaround for a
00109        * very awful bug, which exists since MSVC V.4.0, and still by
00110        * V.6.0 with all bugfixes (so called "service packs") remains
00111        * there...  This method is also public due to another bug, so please
00112        * NEVER EVER call this method directly: use read() instead
00113        */
00114       bool readMS(ioHandler& handler,const bool complete=true);
00115 
00116       /**
00117        * this function is required by MSVC only, as a workaround for a
00118        * very awful bug, which exists since MSVC V.4.0, and still by
00119        * V.6.0 with all bugfixes (so called "service packs") remains
00120        * there...  This method is also public due to another bug, so please
00121        * NEVER EVER call this method directly: use write() instead
00122        */
00123       bool writeMS(ioHandler& handler,const bool complete=true) const;
00124 #     endif
00125 
00126       // ------------------------------------------------
00127       // the parameters
00128       // ------------------------------------------------
00129 
00130       /**
00131        * Number of cells (or bins) per dimension for the histograms created.
00132        * For the one dimensional case, only the \a x attribute will be
00133        * considered.  In the two dimesional case \a x and \a y are
00134        * important, and in the three dimensional case all attributes
00135        * are relevant.
00136        *
00137        * Note that this parameter is ignored for the show method that
00138        * directly receives a histogram, where it intrinsically defines the
00139        * number of bins per dimension.
00140        *
00141        * Default: tpoint3D<int>(32,32,32)
00142        */
00143       tpoint3D<int> cells;
00144 
00145       /**
00146        * Used to specify if the cells should be represented with boxes
00147        * or with points.
00148        *
00149        * If false, points will represent each cell:
00150        * \code
00151        *  |
00152        *  |           .
00153        *  |           |
00154        *  |        .  |           .
00155        *  |        |  |     .     |
00156        *  |  .     |  |  .  |     |
00157        *  |  |  .  |  |  |  |  .  |
00158        *  .  |  |  |  |  |  |  |  |
00159        *  |__|__|__|__|__|__|__|__|____
00160        * \endcode
00161        *
00162        * If true, boxes will be used:
00163        * \code
00164        *  |
00165        *  |           .__
00166        *  |           |  |
00167        *  |        .__|  |        .__
00168        *  |        |  |  |  .__   |  |
00169        *  |  .__   |  |  .__|  |  |  |
00170        *  |  |  .__|  |  |  |  .__|  |
00171        *  .__|  |  |  |  |  |  |  |  |
00172        *  |__|__|__|__|__|__|__|__|__|_
00173        * \endcode
00174        *
00175        * Default value: true (i.e. boxes will be displayed)
00176        */
00177       bool useBoxes;
00178 
00179 
00180       /**
00181        * Flag to specify if the "color" of the point/box should represent
00182        * the entry value in the corresponding histogram cell.
00183        *
00184        * If true, a grey value will be used to represent the value.  White will
00185        * be the highest value in the histogram and Black will represent the
00186        * cells with zero entries.  (see also binThreshold)
00187        *
00188        * If false, the color for the cell will be determined with the
00189        * indices of each cell, assuming that the first element of the index
00190        * correponds with red, the second with green and the third with blue.
00191        * This is used to display the "color clouds" of images.
00192        *
00193        * Default value: false
00194        */
00195       bool greyEntries;
00196 
00197       /**
00198        * show the lines in case of 2D and 1D histograms to denote the
00199        * boundaries of the cells:
00200        *
00201        * If true, (and with boxes=false) the result will be like the one
00202        * on the left side.
00203        *
00204        * \code
00205        *  |                               |
00206        *  |           .                   |           .
00207        *  |           |                   |
00208        *  |        .  |           .       |        .              .
00209        *  |        |  |     .     |       |                 .
00210        *  |  .     |  |  .  |     |       |  .           .
00211        *  |  |  .  |  |  |  |  .  |       |     .              .
00212        *  .  |  |  |  |  |  |  |  |       .
00213        *  |__|__|__|__|__|__|__|__|____   |____________________________
00214        * \endcode
00215        *
00216        * Default value: false;
00217        */
00218       bool useLines;
00219 
00220       /**
00221        * an entry in the histogram must have a value greater than this
00222        * threshold multiplied with the maximum entry value in order to
00223        * be displayed.  Valid values are between 0 and 1.
00224        *
00225        * Default: 0.0
00226        */
00227       double binThreshold;
00228 
00229       /**
00230        * \name Info fields
00231        * The following attributes are not viewer parameters, but
00232        * are required to give some information to the configuration
00233        * dialog.
00234        * This can change in the feature (enclosed in a new class, for example).
00235        * The values you write here will be ignored.
00236        */
00237       //@{
00238 
00239       /**
00240        * maximal entry value of histogram being displayed
00241        */
00242       double infoMaxEntry;
00243 
00244       /**
00245        * number of entries in the histogram
00246        */
00247       double infoNumEntries;
00248 
00249       /**
00250        * dimensions and bins of the histogram
00251        */
00252       ivector infoCells;
00253 
00254       //@}
00255     };
00256 
00257     /**
00258      * default constructor
00259      */
00260     histogramViewer(bool createDefaultParameters = true);
00261 
00262     /**
00263      * copy constructor
00264      * @param other the object to be copied
00265      */
00266     histogramViewer(const histogramViewer& other);
00267 
00268     /**
00269      * constructor with windows title
00270      */
00271     histogramViewer(const std::string& title);
00272 
00273     /**
00274      * constructor with windows title
00275      */
00276     histogramViewer(const char* title);
00277 
00278     /**
00279      * destructor
00280      */
00281     virtual ~histogramViewer();
00282 
00283     /**
00284      * returns the name of this type ("histogramViewer")
00285      */
00286     virtual const char* getTypeName() const;
00287 
00288     /**
00289      * copy data of "other" functor.
00290      * @param other the functor to be copied
00291      * @return a reference to this functor object
00292      */
00293     histogramViewer& copy(const histogramViewer& other);
00294 
00295     /**
00296      * alias for copy member
00297      * @param other the functor to be copied
00298      * @return a reference to this functor object
00299      */
00300     histogramViewer& operator=(const histogramViewer& other);
00301 
00302     /**
00303      * returns a pointer to a clone of this functor.
00304      */
00305     virtual viewerBase* clone() const;
00306 
00307     /**
00308      * returns used parameters
00309      */
00310     const parameters& getParameters() const;
00311 
00312     /**
00313      * compute a 3D histogram for the image, where the numbers of 
00314      * bins per dimension are taken from the parameters' attribute \a cells.
00315      *
00316      * Each dimension will cover the entire R,G, or B color component from
00317      * 0 to 255 divided by the corresponding number of cells. (x for red, y
00318      * for green and z for blue).
00319      *
00320      * The value in the cell will be displayed as a gray level, with
00321      * white assigned to the highest value in the histogram and black
00322      * to the lowest, or, in a color cloud where each cell-box will have
00323      * the corresponding color of the color space, and will be display if
00324      * its value is greater that a threshold given through the parameter 
00325      * \c binThreshold
00326      *
00327      * @param data image, which histogram will be displayed.
00328      * @return true if successful, false otherwise.
00329      */
00330     virtual bool show(const image& data);
00331 
00332     /**
00333      * compute a 1D histogram for the channel8, where the number of 
00334      * bins is taken from the parameters' attribute \a cells.
00335      *
00336      * The value-axis covers the entire ubyte value range from 0 to 255
00337      * divided by the corresponding number of cells. (x component).
00338      *
00339      * @param data channel8, which histogram will be displayed.
00340      * @return true if successful, false otherwise.
00341      */
00342     virtual bool show(const channel8& data);
00343 
00344     /**
00345      * compute a 1D histogram for the channel, where the number of 
00346      * bins per dimension is taken from the parameters' attribute \a cells.
00347      *
00348      * The value-axis covers the entire value range found in the channel
00349      * divided by the corresponding number of cells. (x component).
00350      *
00351      * @param data channel, which histogram will be displayed.
00352      * @return true if successful, false otherwise.
00353      */
00354     virtual bool show(const channel& data);
00355 
00356     /**
00357      * compute a 1D histogram for the matrix, where the number of 
00358      * bins per dimension is taken from the parameters' attribute \a cells.
00359      *
00360      * The value-axis covers the entire value range found in the matrix
00361      * divided by the corresponding number of cells. (x component).
00362      *
00363      * @param data matrix, which histogram will be displayed.
00364      * @param data the object to be shown.
00365      * @return true if successful, false otherwise.
00366      */
00367     virtual bool show(const matrix<float>& data);
00368 
00369     /**
00370      * compute a 1D histogram for the matrix, where the number of 
00371      * bins per dimension is taken from the parameters' attribute \a cells.
00372      *
00373      * The value-axis covers the entire value range found in the matrix
00374      * divided by the corresponding number of cells. (x component).
00375      *
00376      * @param data matrix, which histogram will be displayed.
00377      * @return true if successful, false otherwise.
00378      */
00379     virtual bool show(const matrix<double>& data);
00380 
00381     /**
00382      * compute a 1D histogram for the matrix, where the number of 
00383      * bins per dimension is taken from the parameters' attribute \a cells.
00384      *
00385      * The value-axis covers the entire value range found in the matrix
00386      * divided by the corresponding number of cells. (x component).
00387      *
00388      * @param data matrix, which histogram will be displayed.
00389      * @return true if successful, false otherwise.
00390      */
00391     virtual bool show(const matrix<int>& data);
00392 
00393     /**
00394      * compute a 1D histogram for the values in the vector, where the
00395      * number of bins per dimension is taken from the parameters'
00396      * attribute \a cells.
00397      *
00398      * The value-axis covers the entire value range found in the channel
00399      * divided by the corresponding number of cells. (x component).
00400      *
00401      * Please note that the lti::viewer is faster displaying vectors.
00402      *
00403      * shows a vector of double
00404      * @param data the object to be shown.
00405      * @return true if successful, false otherwise.
00406      */
00407     virtual bool show(const vector<double>& data);
00408 
00409     /**
00410      * compute a 1D histogram for the values in the vector, where the
00411      * number of bins per dimension is taken from the parameters'
00412      * attribute \a cells.
00413      *
00414      * The value-axis covers the entire value range found in the channel
00415      * divided by the corresponding number of cells. (x component).
00416      *
00417      * Please note that the lti::viewer is faster displaying vectors.
00418      *
00419      * shows a vector of double
00420      * @param data the object to be shown.
00421      * @return true if successful, false otherwise.
00422      */
00423     virtual bool show(const vector<float>& data);
00424 
00425     /**
00426      * compute a 1D histogram for the values in the vector, where the
00427      * number of bins per dimension is taken from the parameters'
00428      * attribute \a cells.
00429      *
00430      * The value-axis covers the entire value range found in the channel
00431      * divided by the corresponding number of cells. (x component).
00432      *
00433      * Please note that the lti::viewer is faster displaying vectors.
00434      *
00435      * shows a vector of double
00436      * @param data the object to be shown.
00437      * @return true if successful, false otherwise.
00438      */
00439     virtual bool show(const vector<int>& data);
00440 
00441     /**
00442      * shows the given histogram.
00443      *
00444      * Please note that the lti::viewer is faster displaying one-dimensional
00445      * histograms.
00446      *
00447      * @param data the object to be shown.
00448      * @return true if successful, false otherwise.
00449      */
00450     virtual bool show(const thistogram<double>& data);
00451 
00452   protected:
00453     /**
00454      * the histogram being displayed
00455      */
00456     thistogram<double> theHistogram;
00457 
00458     /**
00459      * return a new instance of the mainWindow class.
00460      *
00461      * This class must be reimplemented in order to get the
00462      * proper class instance.
00463      */
00464     virtual viewerBase3D::mainWindow* getNewMainWindow() const;
00465 
00466 # ifdef _LTI_MSC_6
00467   public:
00468 # endif
00469     /**
00470      * GTK Widget for the configuration dialog of the histogram viewer
00471      */
00472     class configDialog : public viewerBase3D::configDialog {
00473     public:
00474       /**
00475        * create dialog and tell it in which parameter block
00476        * the user data should be stored
00477        */
00478       configDialog();
00479 
00480       /**
00481        * destroy the dialog
00482        */
00483       virtual ~configDialog();
00484 
00485     protected:
00486       /**
00487        * Inserts all Pages in the main settings dialog
00488        */
00489       virtual void insertPages();
00490 
00491       /**
00492        * Build a page in the main settings dialog
00493        */
00494       pageWidget buildHistoPage();
00495 
00496       /**
00497        * copy the contents of the dialog in the parameters object
00498        */
00499       virtual bool getDialogData();
00500 
00501       /**
00502        * copy the contents of the parameters object into the dialog entries
00503        */
00504       virtual bool setDialogData();
00505 
00506 #   ifdef _LTI_MSC_6
00507       /**
00508        * this function is required by MSVC only, as a workaround for a
00509        * very awful bug, which exists since MSVC V.4.0, and still by
00510        * V.6.0 with all bugfixes (so called "service packs") remains
00511        * there...  This method is also public due to another bug, so please
00512        * NEVER EVER call this method directly: use mouseMovedHandler instead
00513        */
00514       bool getDialogDataMS();
00515 
00516       /**
00517        * this function is required by MSVC only, as a workaround for a
00518        * very awful bug, which exists since MSVC V.4.0, and still by
00519        * V.6.0 with all bugfixes (so called "service packs") remains
00520        * there...  This method is also public due to another bug, so please
00521        * NEVER EVER call this method directly: use mouseMovedHandler instead
00522        */
00523       bool setDialogDataMS();
00524 #   endif
00525 
00526       /**
00527        * @name GTK+ Callbacks
00528        * Callback functions created by Glade
00529        */
00530       //@{
00531       static void on_greycell_toggled(GtkToggleButton *togglebutton,
00532                                       gpointer user_data);
00533 
00534       static void on_rgbCell_toggled(GtkToggleButton *togglebutton,
00535                                      gpointer user_data);
00536 
00537       static void on_points_toggled(GtkToggleButton *togglebutton,
00538                                     gpointer user_data);
00539 
00540       static void on_boxes_toggled(GtkToggleButton *togglebutton,
00541                                    gpointer user_data);
00542 
00543       static void on_celllines_toggled(GtkToggleButton *togglebutton,
00544                                        gpointer user_data);
00545 
00546       static void on_threshold_changed(GtkEditable *editable,
00547                                        gpointer user_data);
00548 
00549       static void on_binr_changed(GtkEditable *editable,
00550                                   gpointer user_data);
00551 
00552       static void on_bing_changed(GtkEditable *editable,
00553                                   gpointer user_data);
00554 
00555       static void on_binb_changed(GtkEditable *editable,
00556                                   gpointer user_data);
00557       //@}
00558 
00559       /**
00560        * @name GTK+ Widgets
00561        * Callback functions created by Glade
00562        */
00563       //@{
00564       // gtkWidget, which needs to be controled
00565       GtkWidget* cellcolor;
00566       GtkWidget* cellcolorGrey;
00567       GtkWidget* cellcolorRGB;
00568 
00569       GtkWidget* cellformPoint;
00570       GtkWidget* cellformBox;
00571       GtkWidget* cellformLines;
00572 
00573       GtkWidget* cellThreshold;
00574 
00575       GtkWidget* binr;
00576       GtkWidget* bing;
00577       GtkWidget* binb;
00578 
00579       GtkWidget* maxcellvalue;
00580       GtkWidget* numofentry;
00581       GtkWidget* bins;
00582       //@}
00583     };
00584 
00585     /**
00586      * GTK Widget for the main class of the histogram viewer
00587      */
00588     class mainWindow : public viewerBase3D::mainWindow {
00589     public:
00590       /**
00591        * default constructor
00592        */
00593       mainWindow();
00594 
00595       /**
00596        * copy constructor
00597        */
00598       mainWindow(const mainWindow& other);
00599 
00600       /**
00601        * destructor
00602        */
00603       ~mainWindow();
00604 
00605       /**
00606        * indicate which data should be used when drawing.
00607        */
00608       void putData(const thistogram<double>& hist);
00609 
00610       /**
00611        * returns used parameters
00612        */
00613       const parameters& getParameters() const;
00614 
00615     protected:
00616       /**
00617        * indicate if there are valid data to show
00618        */
00619       virtual bool validData(void);
00620 
00621       /**
00622        * set the data pointer to NULL to indicate
00623        * that the window is hidden
00624        */
00625       virtual void indicateDataHide(void);
00626 
00627       /**
00628        * pointer to external histogram with the data to be
00629        * converted
00630        */
00631       const thistogram<double>* theHistogram;
00632 
00633       /**
00634        * maximum of theHistogram
00635        */
00636       double histMaximum;
00637 
00638       /**
00639        * convert the histogram into a color image
00640        */
00641       virtual void dataToImage();
00642 
00643       /**
00644        * convert the histogram into a color image
00645        */
00646       void his3DToImage();
00647 
00648       /**
00649        * convert the histogram into a color image
00650        */
00651       void his2DToImage();
00652 
00653       /**
00654        * convert the histogram into a color image
00655        */
00656       void his1DToImage();
00657 
00658       /**
00659        * prepares the parameters before the settings dialog is started
00660        */
00661       virtual void prepareParameters(void);
00662 
00663       /**
00664        * this function is called when the right button is pressed and moved.
00665        * @param button which button is pressed (0 means none,
00666        *               1 left button, 3 right button)
00667        * @param pos actual position of mouse pointer
00668        * @param shift true if the shift-key has been pressed while moving the
00669        *              mouse.
00670        * @param ctrl true if the control-key has been pressed while moving the
00671        *              mouse.
00672        */
00673       virtual void mouseMovedHandler(const int& button,
00674                                      const point& pos,
00675                                      const bool shift,
00676                                      const bool ctrl);
00677 
00678 #     ifdef _LTI_MSC_6
00679       /**
00680        * this function is required by MSVC only, as a workaround for a
00681        * very awful bug, which exists since MSVC V.4.0, and still by
00682        * V.6.0 with all bugfixes (so called "service packs") remains
00683        * there...  This method is also public due to another bug, so please
00684        * NEVER EVER call this method directly: use mouseMovedHandler instead
00685        */
00686       void mouseMovedHandlerMS(const int& button,
00687                                const point& pos,
00688                                const bool shift,
00689                                const bool ctrl);
00690 #     endif
00691     };
00692   };
00693 
00694 }
00695 
00696 #endif
00697 #endif

Generated on Sat Apr 10 15:25:38 2010 for LTI-Lib by Doxygen 1.6.1