[Insight-users] adding GUI to ITK and VTK

Gavin Baker gavinb+xtk at cs.mu.OZ.AU
Tue, 2 Mar 2004 13:02:08 +1100


Hello,

On Sat, Feb 28, 2004 at 02:22:38AM +0800, #YEO SI YONG# wrote:

> i've to build a windows application that includes some ITK and VTK
> features, and i'm new to c++ and especially GUI programming. i've already
> build some ITK applications such as reading and writing volume files,
> segmenting them, and viewing them in VTK, however these applications have
> no user interaction at all (The application created uptill now have all
> the file names and functions predefined). The objective is to create a
> windows application (prefably with MFC) such that the user can choose the
> directory, choose the images, choose the segmentation tools, interact with
> the volume model, etc..  Can anyone give me some advices on this issue,
> especially on the following:

As Josh suggested, looking at InsightApplications is the best place to
start.  But if you are new to C++, there is a pretty enormous amount of
stuff to come to grips with in order to get the most benefit from ITK/VTK.
A good C++ book (there are many) would be well worth the investment too.

Start with the simple examples (such as ImageViewer) and then look at
slightly more involved examples like GaussianFilter, Curves2DExtractor,
DistanceMapFilter and so on.  Then have a look at the Auxiliary directory to
see how the various toolkits are integrated.  Then check out
SegmentationEditorFltkGUI.  Finally, obtain a caffeine source and have a
look at SNAP, a complete example of a sophisticated applcation integrating
all the libraries.

This "tour" should give you a good idea of how to structure your
application.

> -- Should i create the applications (such as reading/writing the files,
> creating volumes, segmentation tools, meshing, viewing with VTK)
> separately and test them first, or join all the codes together as i file.

I suggest you design the application as an engine, with a GUI layer on top.
The engine provides all the core functionality, with an interface that
reflects the types of operations or functions it is supposed to carry out.
You can add hooks for things like progress bars and so on, but the engine
should know nothing about how it is 'driven'.  Then you can add the GUI
layer on top, which gets the engine to do all the work, and the only code in
the GUI layer is some glue to interface with the engine.

This will give you maximum flexibility, allow you to test more easily,
extend features, add scripting, and so on.  A number of the
InsightApplication examples follow this pattern.

> --Should i create these applications first (without any GUI) and add the
> GUI after i created all the required applications, or build these
> applications together with GUI.

With some design effort up front, you can easily build an engine (without
GUI) that has a well-defined interface, onto which you can add the GUI
later.  You want loose coupling between the layers and high cohesion within.

> --What are the microsoft foundation classes that i should take note of for
> the: selection of directories, selecting files, scroll bar for varying
> image intensites, and for the other functions which are typical of a 3D
> modeling/visualisation application etc.

The problem with using MFC (apart from it's rather unfortunate design and
proprietary nature) is that it will limit you to only running on Windows.
Both ITK and VTK are cross-platform and there are numerous portable GUI
toolkits that you can use to build for Windows, and also target Linux, Mac,
Solaris, and so on.  Why limit yourself?

There are some excellent alternatives from which you can choose a GUI
toolkit:

  * Qt - http://www.trolltech.com/

    A very powerful, well-designed API, with lots of widgets as well as
    application-framework libraries.  Used in many commercial products.  May
    cost for Windows apps.

  * wxWidgets - http://www.wxwidgets.org/

    The API is similar to MFC, but runs on multiple platforms.  A
    comprehensive library, well documented, stable.

  * Gtk+ - http://www.gtk.org/

    This is the GUI toolkit that Gnome uses, which is now highly functional
    on Win32 as well (eg. see Gimp).  Nice clean consistent API, also has
    the Glade interface designer.

  * FLTK (The Fast Light Toolkit) - http://www.fltk.org/

    Very popular with ITK/VTK developers, and true to its name in that it is
    very fast and light.  Has a great widget set, and a really nice WYSIWYG
    editor for doing GUI layout (called Fluid).  Integrates well with
    OpenGL/VTK.

All the above are known to work with ITK/VTK, and widgets are available to
embed VTK into the GUI.  Of course other toolkits can be made to work also.

You should definitely have a look at FLTK - I highly recommend it.  It has a
great GUI designer tool called Fluid, which means you don't have to write
GUI code - just the glue to call your engine.  There are lots of good
examples in the InsightApplications directory too, as well as slice viewer
widgets and other really useful things (see Auxiliary).

Good luck!

  :: Gavin

-- 
Gavin Baker                                      Complex Systems Group
http://www.cs.mu.oz.au/~gavinb             The University of Melbourne