CVR-Lib last update 20 Sep 2009

cvrViewer2DGtk.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 
00042 /**
00043  * \file    cvrViewer2DGtk.h
00044  *          This is a "private" file.  It contains GTK specific stuff for
00045  *          implementing the viewer2D class.  Unless you are implementing
00046  *          GTK derived classes, you don't need to include this file.  See
00047  *          cvrViewer2D.h instead.
00048  * \authors Pablo Alvarado
00049  * \date    05.07.2005
00050  *
00051  * $Id: cvrViewer2DGtk.h,v 1.3 2006/09/19 09:58:12 doerfler Exp $
00052  */
00053 
00054 #ifndef _CVR_VIEWER_2D_GTK_H_
00055 #define _CVR_VIEWER_2D_GTK_H_
00056 
00057 #include "cvrViewer2D.h"
00058 #include "cvrViewerBaseGtk.h"
00059 #include "cvrViewer2DPainter.h"
00060 #include "cvrTimer.h"
00061 
00062 #ifdef HAVE_GTK
00063 
00064 #include <gtk/gtk.h>
00065 
00066 namespace cvr {
00067 
00068   /**
00069    * Dialog for curve selection
00070    */
00071   class gtkCurveSelection {
00072   public:
00073     /**
00074      * Create the dialog
00075      */
00076     gtkCurveSelection();
00077 
00078     /**
00079      * Destructor
00080      */
00081     virtual ~gtkCurveSelection();
00082 
00083     /**
00084      * Show the dialog
00085      */
00086     void show();
00087 
00088     /**
00089      * Hide the dialog
00090      */
00091     void hide();
00092 
00093     /**
00094      * Destroy the dialog
00095      */
00096     void destroy();
00097 
00098     /**
00099      * Specify the vector of the curve to be used.
00100      *
00101      * At the end, this vector will be unmodified if the selector is not used or
00102      * "cancel" is pressed or it will be filled with the corresponding data.
00103      *
00104      * The lenght is not modified.
00105      */
00106     void use(vector<ubyte>& data);
00107 
00108   protected:
00109 
00110     /**
00111      * Construct the GTK widgets
00112      */
00113     void build();
00114 
00115     GtkWidget *curveSelector_;
00116     GtkWidget *dialogVBox_;
00117     GtkWidget *gammaCurve_;
00118     GtkWidget *dialogActionArea_;
00119     GtkWidget *cancelButton_;
00120     GtkWidget *okButton_;
00121 
00122     vector<ubyte>* holder_;
00123 
00124     /**
00125      * Callback function called when the user selects the "close window"
00126      * button of the window.  This method overrides the delete structure with
00127      * a hide().
00128      */
00129     static gint cbCloseWindow(GtkWidget *widget,
00130                               GdkEvent  *event,
00131                               gpointer   data);
00132 
00133     /**
00134      * Callback function called when the user has pressed the cancel button
00135      */
00136     static void cbOnCancelButtonClicked(GtkButton* button,
00137                                         gpointer data);
00138 
00139     /**
00140      * Callback function called when the user has pressed the cancel button
00141      */
00142     static void cbOnOkButtonClicked(GtkButton* button,
00143                                     gpointer data);
00144 
00145     /**
00146      * Transfer information from the curve to the holder vector
00147      */
00148     void transferFromCurve(GtkCurve* curve);
00149 
00150     /**
00151      * Transfer information from the holder vector to the curve
00152      */
00153     void transferFromVector(GtkCurve* curve);
00154   };
00155 
00156 
00157   /**
00158    * Private class of the configuration dialogs which deals with
00159    * all internal issues of the GTK toolkit.
00160    */
00161   class viewer2D::configDialog::tk : public viewerBase::configDialog::tk {
00162   public:
00163     /**
00164      * Constructor.
00165      *
00166      * This constructor does not call build(), since at creation time GTK
00167      * may not be initialized yet.
00168      */
00169     tk(viewer2D::configDialog& parent);
00170 
00171     /**
00172      * Destructor
00173      */
00174     virtual ~tk();
00175 
00176     /**
00177      * Create window
00178      */
00179     virtual bool build();
00180 
00181     /**
00182      * Show the window
00183      */
00184     virtual bool show();
00185 
00186     /**
00187      * Hide this window
00188      */
00189     virtual bool hide();
00190 
00191     /**
00192      * Destroy window
00193      */
00194     virtual bool destroy();
00195 
00196     /**
00197      * Copy another mainWindow toolkit configuration
00198      */
00199     tk& copy(const tk& other);
00200 
00201     /**
00202      * Update parameters
00203      */
00204     virtual bool updateParameters();
00205 
00206     /**
00207      * Update information
00208      */
00209     virtual bool updateInformation(const viewer2D::information& info);
00210 
00211 
00212     /**
00213      * Cast the internal parameters object to the proper type
00214      */
00215     parameters& getParameters();
00216 
00217   protected:
00218     /**
00219      * Timer used to avoid a too frequent update
00220      */
00221     timer updateTime;
00222 
00223     /**
00224      * @name All GTK widgets initialized in the build() method
00225      */
00226     //@{
00227     GtkWidget *vboxTop_;
00228     GtkWidget *displayCtrlFrame_;
00229     GtkWidget *displayCtrlAlignment_;
00230     GtkWidget *disCtrlVBox_;
00231     GtkWidget *zoomHBox_;
00232     GtkWidget *zoomLabel_;
00233     GtkWidget *zoomEntry_;
00234     GtkWidget *zoomHScale_;
00235     GtkAdjustment* zoomHAdjustment_;
00236     GtkWidget *linearButton_;
00237     GSList *linearButton__group;
00238     GtkWidget *offsetSlopeHBox_;
00239     GtkWidget *offsetButton_;
00240     GtkWidget *offsetEntry_;
00241     GtkWidget *offsetHScale_;
00242     GtkAdjustment* offsetHAdjustment_;
00243     GtkWidget *slopeLabel_;
00244     GtkWidget *slopeEntry_;
00245     GtkWidget *slopeHScale_;
00246     GtkAdjustment* slopeHAdjustment_;
00247     GtkWidget *mappingsTable_;
00248     GtkWidget *minButton_;
00249     GtkWidget *maxButton_;
00250     GtkWidget *optLinButton_;
00251     GtkWidget *histEqButton_;
00252     GtkWidget *logButton_;
00253     GtkWidget *optLogButton_;
00254     GtkWidget *userCurveHBox_;
00255     GtkWidget *userDefButton_;
00256     GtkWidget *editCurveButton_;
00257     GtkWidget *hexColorVBox_;
00258     GtkWidget *hexButton_;
00259     GtkWidget *underflowColorButton_;
00260     GtkWidget *overflowColorButton_;
00261     GtkWidget *displayLabel_;
00262     GtkWidget *paletteCtrlFrame_;
00263     GtkWidget *paletteCtrlAlignment_;
00264     GtkWidget *paletteCtrlVBox_;
00265     GtkWidget *paletteColorHBox_;
00266     GtkWidget *grayPaletteButton_;
00267     GSList *grayPaletteButton__group;
00268     GtkWidget *redPaletteButton_;
00269     GtkWidget *greenPaletteButton_;
00270     GtkWidget *bluePaletteButton_;
00271     GtkWidget *huePaletteButton_;
00272     GtkWidget *userPaletteButton_;
00273     GtkWidget *labelAdjacencyAnalysisButton_;
00274     GtkWidget *labelAdjacencyRadioBox_;
00275     GtkWidget *fourNeighborhoodButton_;
00276     GSList *fourNeighborhoodButton__group;
00277     GtkWidget *eightNeighborhoodButton_;
00278     GtkWidget *minColorsButton_;
00279     GtkWidget *paletteCtrlLabel_;
00280     GtkWidget *informationFrame_;
00281     GtkWidget *infoHBox_;
00282     GtkWidget *generalStatsTable_;
00283     GtkWidget *generalStatsRightTable_;
00284     GtkWidget *imgSizeLabel_;
00285     GtkWidget *minValLabel_;
00286     GtkWidget *maxValLabel_;
00287     GtkWidget *avrgValLabel_;
00288     GtkWidget *stdDevLabel_;
00289     GtkWidget *imgSizeEntry_;
00290     GtkWidget *minValEntry_;
00291     GtkWidget *maxValEntry_;
00292     GtkWidget *avrgValEntry_;
00293     GtkWidget *stdDevEntry_;
00294     GtkWidget *covLabel_;
00295     GtkWidget *covarTable_;
00296     GtkWidget *rgEntry_;
00297     GtkWidget *rbEntry_;
00298     GtkWidget *ggEntry_;
00299     GtkWidget *bgEntry_;
00300     GtkWidget *grEntry_;
00301     GtkWidget *brEntry_;
00302     GtkWidget *gbEntry_;
00303     GtkWidget *bbEntry_;
00304     GtkWidget *rrEntry_;
00305     GtkWidget *infoLabel_;
00306     GtkWidget *ioFrame_;
00307     GtkWidget *saveImgAlignment_;
00308     GtkWidget *saveHBox_;
00309     GtkWidget *filenameEntry_;
00310     GtkWidget *browseButton_;
00311     GtkWidget *saveButton_;
00312     GtkWidget *saveImageLabel_;
00313     GtkTooltips *tooltips_;
00314 
00315     gtkCurveSelection* curveSelector_;
00316     //@}
00317 
00318     /**
00319      * @name Static functions used by GTK.
00320      *
00321      * Static functions used by GTK as callbacks and their corresponding local
00322      * versions.
00323      *
00324      * Even if the CVR-Lib forbids the use of prefixes, here an exception
00325      * has been done with "cb", meaning "callback", which is used to keep
00326      * a direct correspondence between the GTK required static function and
00327      * a local instance-bounded virtual method.
00328      */
00329     //@{
00330     /**
00331      * If the browse button is clicked
00332      */
00333     static void cbOnBrowseButtonClicked(GtkButton *button,
00334                                         gpointer   userData);
00335 
00336     static void cbOnSaveButtonClicked(GtkButton *button,
00337                                       gpointer   userData);
00338 
00339     /**
00340      * Callback for zoom text entry
00341      */
00342     static void cbOnZoomEntryActivate(GtkCellEditable *celleditable,
00343                                       gpointer         userData);
00344 
00345     /**
00346      * Callback for zoom horizontal scale bar
00347      */
00348     static void cbOnZoomHAdjustmentValueChanged(GtkAdjustment* scale,
00349                                                 gpointer       userData);
00350 
00351     /**
00352      * Callback if the user typed something in the offset entry
00353      */
00354     static void cbOnOffsetEntryActivate(GtkCellEditable *celleditable,
00355                                         gpointer         userData);
00356 
00357     /**
00358      * Callback if the user moved the offset slider
00359      */
00360     static void cbOnOffsetHAdjustmentValueChanged(GtkAdjustment* scale,
00361                                                   gpointer       userData);
00362 
00363     /**
00364      * Callback if the user typed something in the slope entry
00365      */
00366     static void cbOnSlopeEntryActivate(GtkCellEditable *celleditable,
00367                                        gpointer         userData);
00368 
00369     /**
00370      * Callback if the user moved the slope slider
00371      */
00372     static void cbOnSlopeHAdjustmentValueChanged(GtkAdjustment* scale,
00373                                                  gpointer       userData);
00374 
00375     /**
00376      * Callback for radio buttons to select a mapping type
00377      */
00378     static void cbOnMappingRadioToggled(GtkToggleButton* toggleButton,
00379                                         gpointer userData);
00380 
00381     /**
00382      * Callback when the curve edit button is clicked
00383      */
00384     static void cbOnCurveButtonClicked(GtkButton *button,
00385                                        gpointer   userData);
00386 
00387     /**
00388      * Callback when hex display button is clicked
00389      */
00390     static void cbOnHexButtonToggled(GtkToggleButton* toggleButton,
00391                                      gpointer userData);
00392 
00393     /**
00394      * Callback when underflow color selection button is clicked
00395      */
00396     static void cbOnUnderflowColorButtonSet(GtkColorButton  *colorbutton,
00397                                             gpointer         userData);
00398 
00399     /**
00400      * Callback when overflow color selection button is clicked
00401      */
00402     static void cbOnOverflowColorButtonSet(GtkColorButton  *colorbutton,
00403                                            gpointer         userData);
00404 
00405 
00406     /**
00407      * Callback for radio buttons to select the palette type
00408      */
00409     static void cbOnPaletteRadioToggled(GtkToggleButton* toggleButton,
00410                                         gpointer userData);
00411 
00412     /**
00413      * Callback when hex display button is clicked
00414      */
00415     static void cbOnLabelAdjacencyButtonToggled(GtkToggleButton* toggleButton,
00416                                                 gpointer userData);
00417 
00418     /**
00419      * Callback for radio buttons to select the palette type
00420      */
00421     static void cbOnNeighborhoodRadioToggled(GtkToggleButton* toggleButton,
00422                                              gpointer userData);
00423 
00424     /**
00425      * Callback for min number of colors
00426      */
00427     static void cbOnMinColorsButtonToggled(GtkToggleButton* toggleButton,
00428                                            gpointer userData);
00429 
00430     /**
00431      * Callback when the filename has been changed
00432      */
00433     static void cbOnFilenameEntryActivate(GtkCellEditable *celleditable,
00434                                           gpointer         userData);
00435 
00436 
00437     //@}
00438 
00439     /**
00440      * @name Convert the given values to a string
00441      */
00442     //@{
00443     static std::string toString(const double val,const int decimals=5);
00444     static std::string toString(const int val);
00445     static double fromString(const char* val);
00446     static std::string toString(const ipoint& val);
00447     static std::string toString(const rgbaPixel& val);
00448     static std::string toString(const frgbPixel& val,const int decimals=2);
00449 
00450     //@}
00451 
00452     /**
00453      * Set the GUI elements to the proper zoom value
00454      */
00455     void setZoom(const float zoom);
00456 
00457     /**
00458      * Get the proper zoom value from the GUI elements
00459      */
00460     float getZoom() const;
00461 
00462     /**
00463      * Set the GUI elements to the proper mapping style
00464      */
00465     void setMapping(const viewer2DPainter::eMappingType mapping);
00466 
00467     /**
00468      * Get the proper mapping style from the GUI elements
00469      */
00470     viewer2DPainter::eMappingType getMapping();
00471 
00472 
00473     /**
00474      * Set the GUI elements to the proper palette type
00475      */
00476     void setPaletteType(const viewer2DPainter::ePaletteType pal);
00477 
00478     /**
00479      * Get the proper mapping style from the GUI elements
00480      */
00481     viewer2DPainter::ePaletteType getPaletteType();
00482 
00483     /**
00484      * Set the GUI elements to the proper neighborhood
00485      */
00486     void setNeighborhood(const viewer2DPainter::eNeighborhoodType n);
00487 
00488     /**
00489      * Get the proper neighborhood from the GUI elements
00490      */
00491     viewer2DPainter::eNeighborhoodType getNeighborhood();
00492 
00493     /**
00494      * Set the adjacency flag and activate/deactivate all necessary GUI
00495      * elements
00496      */
00497     void setAdjacency(const bool adjOn,
00498                       const eDataType type);
00499 
00500     /**
00501      * Data type being displayed
00502      */
00503     eDataType dataType_;
00504   };
00505 
00506 
00507   class viewer2D::mainWindow::tk : public viewerBase::mainWindow::tk {
00508   public:
00509     /**
00510      * Constructor.
00511      *
00512      * This constructor does not call build(), since at creation time GTK
00513      * may not be initialized yet.
00514      */
00515     tk(viewer2D::mainWindow& parent);
00516 
00517     /**
00518      * Destructor
00519      */
00520     virtual ~tk();
00521 
00522     /**
00523      * suggestWindowSize()
00524      */
00525     virtual ipoint suggestWindowSize() const;
00526 
00527     /**
00528      * Called when some part of the window has been exposed and need to be
00529      * redrawn.
00530      */
00531     virtual bool drawingAreaExposed(const irectangle& area);
00532 
00533     /**
00534      * Called when the user pressed the save button
00535      */
00536     virtual bool saveButtonPressed(const std::string& filename);
00537   };
00538 
00539 
00540 }
00541 
00542 #endif
00543 #endif

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8