41
ITK and Graphical User Interface Luis Ibáñez William Schroeder Insight Software Consortium

ITK and GUI

  • Upload
    srib925

  • View
    92

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ITK and GUI

ITK and Graphical User Interface

Luis IbáñezWilliam SchroederInsight Software Consortium

Page 2: ITK and GUI

Insight

ITK is not Visualization

ITK is not Graphic Interface

ITK is image Segmentation andRegistration

Page 3: ITK and GUI

ITK + Graphic Interface

GUI LayerFLTK http://www.fltk.orgQt http://www.trolltech.com

ITK Layer

Page 4: ITK and GUI

ITK + FLTK

Page 5: ITK and GUI

Starting your own project

Download and Install FLTK

(Select the same compilation mode as ITK: Debug, Release)

Create a clean new directory

Write a CMakeLists.txt file

Write a simple .cxx file

Create a GUI with fluid

Configure with CMake

Build

Page 6: ITK and GUI

Step 1. Writing CMakeLists.txtPROJECT( myProject )

FIND_PACKAGE ( ITK )IF ( ITK_FOUND )

INCLUDE( ${USE_ITK_FILE} )ENDIF( ITK_FOUND )

FIND_PACKAGE ( FLTK )IF ( FLTK_FOUND )

INCLUDE_DIRECTORIES( ${FLTK_INCLUDE_DIR} )ENDIF( FLTK_FOUND )

(continue...)

Page 7: ITK and GUI

Step 1. Writing CMakeLists.txt(continue...)

ADD_EXECUTABLE( myProject myProject.cxx )

IF ( FLTK_FOUND )FLTK_WRAP_UI( myProject myProjectGUI.fl )

ENDIF ( FLTK_FOUND )

TARGET_LINK_LIBRARIES( myProjectITKIO ITKBasicFilters ITKNumerics ITKCommon${FLTK_LIBRARIES})

Page 8: ITK and GUI

Step 2. Writing myProject.cxx#include "myProjectGUI.h"

#include "itkImageFileReader.h"#include "itkImage.h"#include "itkCurvatureFlowImageFilter.h"

int main( int argc, char ** argv ){typedef itk::Image< float, 2 > ImageType;typedef itk::ImageFileReader< ImageType > ReaderType;typedef itk::CurvatureFlowImageFilter<

ImageType, ImageType

> SmootherFilterType;

ReaderType::Pointer reader = ReaderType::New();

Page 9: ITK and GUI

Step 2. Writing myProject.cxxSmootherFilterType::Pointer smoother =

SmootherFilterType::New();

reader->SetFileName( argv[1] );

smoother->SetInput( reader->GetOutput() );

smoother->SetNumberOfIterations( 7 );

smoother->SetTimeStep( 0.5 );

myProjectGUI gui;

gui.Show();

Fl::run();

return 0;

}

Page 10: ITK and GUI

Step 3. Running Fluid

Page 11: ITK and GUI

Step 4. Running CMake

Page 12: ITK and GUI

Step 4. Running CMake

Provide ITK_DIR

Provide FLTK_INCLUDE_DIR

Provide FLTK_FLUID_EXECUTABLE

Click on Configure button

Page 13: ITK and GUI

Step 4. Running CMake

Page 14: ITK and GUI

Step 4. Running CMake

Page 15: ITK and GUI

Step 4. Running CMake

Click on Configure button

Click on OK button

Page 16: ITK and GUI

Step 5. Building the Project

Open myProject.dsw generated by CMake

Select ALL_BUILD

Build the project

Page 17: ITK and GUI

Step 6. Connecting FLTK to ITK

Fl_Slider

mySliderMemberCommand<mySlider>

itk::ProcessObject

itk::FilterX

AddObserver( ProgressEvent, . )

Page 18: ITK and GUI

Step 6. Connecting FLTK to ITK#include "itkCommand.h"

#include <FL/Fl_Slider.H>

namespace fltk {

class ProgressBar : public Fl_Slider {

public:

typedef itk::MemberCommand< ProgressBar > RedrawCommandType;

ProgressBar(int x, int y, int w, int h, char * label=0);

void ProcessEvent( itk::Object * , const itk::EventObject & );

void Observe( itk::Object *caller );

private:

RedrawCommandType::Pointer m_RedrawCommand;

};

} // end namespace fltk

Page 19: ITK and GUI

Step 6. Connecting FLTK to ITK#include "fltkProgressBar.h"

#include "itkProcessObject.h"

#include <FL/Fl.H>

namespace fltk {

ProgressBar::ProgressBar(int x, int y, int w, int h,char * label):

Fl_Slider( x, y, w, h, label )

{

m_RedrawCommand = RedrawCommandType::New();

m_RedrawCommand->SetCallbackFunction( this,& ProgressBar::ProcessEvent

);

}

Page 20: ITK and GUI

Step 6. Connecting FLTK to ITK

void

ProgressBar::ProcessEvent( itk::Object * caller,

const itk::EventObject & event )

{

if( typeid( itk::ProgressEvent ) == typeid( event ) )

{

::itk::ProcessObject::Pointer process =

dynamic_cast< ::itk::ProcessObject *>( caller );

this->value( process->GetProgress() );

this->redraw();

Fl::check();

}

}

Page 21: ITK and GUI

Step 6. Connecting FLTK to ITK

void

ProgressBar::Observe( itk::Object * caller )

{

caller->AddObserver( itk::ProgressEvent(),m_RedrawCommand.GetPointer() );

}

Page 22: ITK and GUI

Step 6. Connecting FLTK to ITK[ myProject.cxx ]:

SmootherFilterType::Pointer smoother =SmootherFilterType::New();

smoother->SetInput( reader->GetOutput() );

myProjectGUI gui;gui.Show();

gui.progressBar->Observe( smoother );

gui.SetFilter( smoother );

Fl::run();

Page 23: ITK and GUI

Step 7. Extend GUI with Fluid

Page 24: ITK and GUI

ITK + Qt

Page 25: ITK and GUI

Starting your own project

Download and Install Qt

Create a clean new directory

Write a CMakeLists.txt file

Write a simple .cxx file

Configure with CMake

Build

Run

Page 26: ITK and GUI

Step 1. Writing CmakeLists.txt

PROJECT( myProject )

FIND_PACKAGE ( ITK )IF ( ITK_FOUND )

INCLUDE( ${USE_ITK_FILE} )ENDIF( ITK_FOUND )

FIND_PACKAGE ( QT )IF ( QT_FOUND )

INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )ENDIF( QT_FOUND )

LINK_LIBRARIES ( ITKIO ${QT_LIBRARIES} )

(continue...)

Page 27: ITK and GUI

Step 1. Writing CMakeLists.txt

(continue...)

SET( QtITK_SRCS itkQtProgressBar.cxx qtITK.cxx )

SET( QtITK_MOC_SRCS itkQtAdaptor.h itkQtLightIndicator.h )

IF( QT_WRAP_CPP )QT_WRAP_CPP( QtITK ${QtITK_SRCS} ${QtITK_MOC_SRCS } )

ENDIF( QT_WRAP_CPP )

ADD_EXECUTABLE( QtITK QtITK_SRCS )

Page 28: ITK and GUI

Step 1. Running CMake

Page 29: ITK and GUI

Step 1. Running CMake

Page 30: ITK and GUI

Step 1. Running CMake

Provide ITK_DIR

Provide QT_INCLUDE_DIR

Provide QT_MOC_EXECUTABLE

Provide QT_UIC_EXECUTABLE

Provide QT_QTMAIN_LIBRARY

Provide QT_QT_LIBRARY

Page 31: ITK and GUI

Qt Communications

QobjectMethodX()

MethodY()

MethodZ()

MethodW()

MethodK()

Signals

Slots

MethodA()

MethodB()

MethodC()

MethodD()

MethodE()

Signals

Slots

Qobject

Page 32: ITK and GUI

Qt - ITK Communications

ITK

InvokeEvent

Observers

QT

Signals

Slots

Page 33: ITK and GUI

Qt – ITK Communications

QobjectMethodA()

MethodB()

MethodC()

MethodD()

MethodE()

Signals

Slots

itk::Object

MethodX()

MethodY()

MethodZ()

MethodW()

MethodK()

QtITK

Adaptor

Page 34: ITK and GUI

Qt – ITK Communications

QtITK

Adaptor

itk::Object

MethodX()

MethodY()

MethodZ()

Slots

MethodA()

MethodB()

MethodC()

Slot Adaptor

Page 35: ITK and GUI

Qt – ITK Communications

QtITK

Adaptor

Command

Signal Adaptor

Signals

MethodA()

MethodB()

MethodC()EventP()

EventQ()

EventR()

itk::Object

Page 36: ITK and GUI

Qt – ITK Communications

Qobject

QtTranslator

QtSlotAdaptor< T > QtSignalAdaptor

Page 37: ITK and GUI

Step 2. Writing myProject.cxx#include <qapplication.h>

#include <qpushbutton.h>

#include "itkImage.h"

#include "itkAddImageFilter.h"

#include "itkQtAdaptor.h"

int main(int argc, char **argv) {

typedef itk::Image< float, 2 > ImageType;

typedef itk::AddImageFilter<ImageType,ImageType,ImageType> FilterType;

QApplication app( argc, argv );

QWidget mainwidget;

mainwidget.resize(620,100);

Page 38: ITK and GUI

Step 2. Writing myProject.cxx

QPushButton bb( "Start", &mainwidget );

bb.setGeometry( horizontalPosition, 20, buttonWidth, buttonHeight );

typedef itk::QtSlotAdaptor< FilterType > SlotAdaptorType;

SlotAdaptorType slotAdaptor;

slotAdaptor.SetCallbackFunction( filter, & FilterType::Update );

QObject::connect( &bb, SIGNAL(clicked()), &slotAdaptor, SLOT(Slot()));

app.setMainWidget( &mainwidget );

mainwidget.show();

return app.exec();

}

Page 39: ITK and GUI

Step 3. Creating Qt-ITK widgets

itk::QtProgressBar

itk::ProcessObject

itk::FilterX

AddObserver( ProgressEvent, . )

MemberCommand<QtProgressBar>

QProgressBar

Page 40: ITK and GUI

Step 3. Creating Qt-ITK widgets

itk::ProcessObject

itk::FilterX

AddObserver( ModifiedEvent, . )AddObserver( StartEvent, . )AddObserver( EndEvent, . )

QButton

itk::QtLightIndicator

Modified()Start()End()

QtITK

Adaptor

Slots

Page 41: ITK and GUI

Enjoy ITK !