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

lti::viewer Class Reference

Use objects of this class to display your data in a window. More...

#include <ltiViewer.h>

Inheritance diagram for lti::viewer:
Inheritance graph
[legend]
Collaboration diagram for lti::viewer:
Collaboration graph
[legend]

List of all members.

Classes

class  configChannelFixed
 Configuration Dialog for viewer of images of fixed point scalar values, like channel8 or matrix<int>. More...
class  configChannelFloat
 Configuration Dialog for viewer of images of floating point scalar values, like channel or matrix<double>. More...
class  configDialog
 Parent class for all types of configuration dialogs for the normal viewer. More...
class  configImage
 Configuration Dialog for viewer of images of rgbPixel elements. More...
class  configVector
 Configuration Dialog for viewer of vectors. More...
class  mainWindow
 Abstract class for all main windows for the different data types. More...
class  mainWndChannelFixed
 Main Window for channels of fixed point values. More...
class  mainWndChannelFloat
 Main Window for channels of floating point values. More...
class  mainWndImage
 Main Window for color images. More...
class  mainWndVector
 Main Window for vectors. More...
class  parameters
 The parameters for the class viewer. More...

Public Member Functions

 viewer (const std::string &title="lti::viewer", const float contrast=1.0f, const float brightness=0.0f, const int zoom=0, const bool labelMap=false)
 viewer (const parameters &par)
 viewer (const viewer &other)
virtual ~viewer ()
virtual const char * getTypeName () const
virtual bool show (const image &data)
virtual bool show (const matrix< float > &data)
virtual bool show (const matrix< double > &data)
virtual bool show (const matrix< int > &data)
virtual bool show (const matrix< ubyte > &data)
virtual bool show (const histogram1D &data)
virtual bool show (const histogram2D &data)
virtual bool show (const vector< double > &data)
virtual bool show (const vector< float > &data)
virtual bool show (const vector< int > &data)
virtual bool show (const vector< ubyte > &data)
bool hide ()
viewercopy (const viewer &other)
virtual viewerBaseclone () const
bool lastClickedPosition (point &pos) const
point waitButtonPressed (const bool reportOnlyValidPos=false) const
int lastKey () const
int waitKey () const
point waitKeyOrButton (bool &key, bool &button) const
Parameters



const parametersgetParameters () const
virtual bool setParameters (const viewerBase::parameters &param)
void setPosition (const point &p)
point getPosition () const
void setSize (const point &p)
point getSize () const

Protected Member Functions

void ensureWindow (const int newWnd)
parametersgetParameters ()

Protected Attributes

int wnd
mainWindowwnds [4]
viewerFunctormaster

Static Protected Attributes

static const int winTypes

Detailed Description

Use objects of this class to display your data in a window.

The GTK-GUI Toolkit is required to compile this object.

The use of the lti::viewer is very simple. Each viewer administrates one window, and this window will exist as long as the viewer object exists. This means, if you destroy the viewer-object, the window will be automatically destroyed.

To use the viewer see following example:

  #include "ltiImage.h"
  #include "ltiSplitImage.h"
  #include "ltiViewer.h"
  #include "ltiBMPFunctor.h"

  ...

  lti::image img;                // an image
  lti::channel chnl;             // a channel
  lti::splitImageTorgI splitter; // a functor to get the intensity channel

  lti::loadBMP loader;

  loader.load("yourImage.bmp",img); // load the image in the given file
  splitter.getIntensity(img,chnl);  // get the intensity channel of the img

  lti::viewer view1,view2;

  view1.show(img);                  // open a window and show the image
  view2.show(chnl);                 // open a new window and show the
                                    // intensity channel.
  ...

  // until the end of the execution block the images will be displayed.
  // When view1 and view2 are destroyed, their windows will disappear!

If you press the left-button of the mouse on a pixel, the value of this pixel will be displayed on the status bar.

You can configure some display-options by using the viewer::parameters.

If you press the right-mouse button an options-dialog will be displayed. You can control directly some display parameters (brightness, contrast, zoom, etc.) You can also save exactly the image you are viewing pressing the button "Save" on the options dialog. See lti::viewer::parameters for more information

The statistic values computed will correspond always to intensity values, even for color images. Remember that intensity is defined as (R+G+B)/3.

The method waitButtonPressed() allows you to block the execution of your program until the user clicks somewhere on the viewer window. The position of the pixel clicked will be returned.

Known Bugs

The multithreaded nature of the viewer functor has shown a few bugs. Until a proper fix is provided, the following workaround have to be done:

1. A crash at the very end of the application can be expected since the destruction of window handlers is done by two threads simultaneously. The secondary GTK+ thread is the only one that should do this, but the main thread destroys everything open at the end of the application, which also include stuff that secondary thread should do. To avoid this conflict you can force termination of the secondary "GTK-Server" thread explicitely:

   #include "ltiGtkServer.h"
   #include "ltiTimer.h"

   int main() {

     // ... your code here
     // ... try to hide all viewers that aren't used any more
     //

     lti::passiveWait(50000);     // wait 50ms that all viewers end its 
                                  // event handling
     lti::gtkServer::shutdown();  // stop the server (secondary thread)
     lti::passiveWait(50000);     // wait 50ms that all viewers end its 
                                  // event handling
     return 1;
   }

Please note that the shutdown() method is called at the very end of the main method. This must be done this way, because after removing the GTK Server, there is no way to start it again in order to create or display the data on viewers. The last passiveWait forces to wait until everything that has to do with viewers is removed.

2. The second bug has to do with a race condition when two viewers try to display data at almost the same time. Even if the LTI-Lib calls the locking mechanisms of GTK, they don't seem to work and the application ends in a dead-lock. The workaround is to avoid calling show() methods successively, separating them by small pauses. This has to be done only once, before the windows are created:

    lti::viewer v1,v2; // two viewers
    v1.show(img1);     // show an image
    lti::passiveWait(50000) // wait 50ms (WORKAROUND FOR BUG)
    v2.show(img2);     // show another image

    for (int i=0;i<10;i++) {
      v1.show(imgs[i]); // show images, since the viewer was already
                        // displayed, the problem does not occur anymore.
    }

3. There is also a "bug" in X.Org's composite extension and some pixbuf stuff of GTK. If you get the following error message when starting your application (or something similar):

      Gdk-ERROR **: BadMatch (invalid parameter attributes)
        serial 252 error_code 8 request_code 148 minor_code 3

then you can wether desactivate the composite extension in the xorg.conf file (in /etc/X11/) or you can define the variable

      export XLIB_SKIP_ARGB_VISUALS=1

before starting your application.

A new viewer generation is being developed to fix this awful bugs.


Constructor & Destructor Documentation

lti::viewer::viewer ( const std::string &  title = "lti::viewer",
const float  contrast = 1.0f,
const float  brightness = 0.0f,
const int  zoom = 0,
const bool  labelMap = false 
)

construct a viewer with the given title, contrast and brightness

Parameters:
title Window title. Default value "lti::viewer"
contrast contrast for the image. Default value 1.0f (see viewer::parameters::contrast)
brightness brightness for the image. Default value 0.0f (see viewer::parameters::brightness)
zoom zoom factor. Default value 0. (see viewer::parameters::zoomFactor)
labelMap if true, the label adjacency map modus will be turned on
lti::viewer::viewer ( const parameters par  ) 

constructor with given parameters

lti::viewer::viewer ( const viewer other  ) 

copy constructor

Parameters:
other the object to be copied
virtual lti::viewer::~viewer (  )  [virtual]

destructor


Member Function Documentation

virtual viewerBase* lti::viewer::clone (  )  const [virtual]

returns a pointer to a clone of the functor.

Implements lti::viewerBase.

viewer& lti::viewer::copy ( const viewer other  ) 

copy data of "other" functor.

Reimplemented from lti::viewerBase.

void lti::viewer::ensureWindow ( const int  newWnd  )  [protected]

Ensure that the wnds array contains a valid window with the actual parameters at each given position.

parameters& lti::viewer::getParameters (  )  [protected]

returns used parameters as a read/write reference

Reimplemented from lti::viewerBase.

const parameters& lti::viewer::getParameters (  )  const

returns used parameters

Reimplemented from lti::viewerBase.

point lti::viewer::getPosition (  )  const

get position of the window

point lti::viewer::getSize (  )  const

get size of the window

virtual const char* lti::viewer::getTypeName (  )  const [virtual]

returns the name of this type ("viewer")

Reimplemented from lti::viewerBase.

bool lti::viewer::hide (  )  [virtual]

hides the display window

Implements lti::viewerBase.

bool lti::viewer::lastClickedPosition ( point pos  )  const

Get the last clicked position and write the result at the given parameter.

If this position lies within the displayed image, the returned value is true, otherwise false.

This method does not block the program execution. It just returns the last clicked position (which can be seen in the status bar)

Note that the clicked position can be out of range.

See also:
waitButtonPressed()
Parameters:
pos the last clicked position will be written here
Returns:
true, if the position lies within the displayed image, false otherwise.
int lti::viewer::lastKey (  )  const

return the last pressed key

This method does not block the program execution. It just returns the value of the last key pressed.

See also:
waitKey()
virtual bool lti::viewer::setParameters ( const viewerBase::parameters param  )  [virtual]

set the parameters to be used

Reimplemented from lti::viewerBase.

void lti::viewer::setPosition ( const point p  ) 

set position of the window

void lti::viewer::setSize ( const point p  ) 

set size of the window

virtual bool lti::viewer::show ( const vector< ubyte > &  data  )  [virtual]

shows a vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.
virtual bool lti::viewer::show ( const vector< int > &  data  )  [virtual]

shows a vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const vector< float > &  data  )  [virtual]

shows a vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const vector< double > &  data  )  [virtual]

shows a vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const histogram2D data  )  [virtual]

shows histogram as vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.
virtual bool lti::viewer::show ( const histogram1D data  )  [virtual]

shows histogram as vector of double

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.
virtual bool lti::viewer::show ( const matrix< ubyte > &  data  )  [virtual]

shows a channel

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.
virtual bool lti::viewer::show ( const matrix< int > &  data  )  [virtual]

shows a channel

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const matrix< double > &  data  )  [virtual]

shows a matrix of doubles as a channel

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const matrix< float > &  data  )  [virtual]

shows a channel

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Reimplemented from lti::viewerBase.

virtual bool lti::viewer::show ( const image data  )  [virtual]

shows a color image.

Parameters:
data the object to be shown.
Returns:
true if successful, false otherwise.

Implements lti::viewerBase.

point lti::viewer::waitButtonPressed ( const bool  reportOnlyValidPos = false  )  const

Wait until the user clicks somewhere on the image/vector and returns the clicked position.

Note that the clicked position can be out of range, unless you specify with the parameter, that you expect only in-image points.

See also:
lastClickedPosition()
int lti::viewer::waitKey (  )  const

Wait until the user press some key while the viewer window is active and return the code of the key pressed.

Returns:
the last key pressed or a negative number if the window was destroyed.
See also:
lastKey()
point lti::viewer::waitKeyOrButton ( bool &  key,
bool &  button 
) const

Wait until the user presses a key or a mouse button.

Parameters:
key will be set to true if the user presses a key, otherwise will be set to false.
button will be set to true if the user presses a mouse button, otherwise will be set to false.
Returns:
the key code at the x attribute of the point if the user presses a key or the clicked position if the user pressed a mouse button.

Member Data Documentation

This is the master who paints everything nice.

const int lti::viewer::winTypes [static, protected]

Number of different window types.

int lti::viewer::wnd [protected]

The current used window (the index in the wnds vector.

mainWindow* lti::viewer::wnds[4] [protected]

Window instance for channels of fixed point arithmetic.


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:29:03 2010 for LTI-Lib by Doxygen 1.6.1