Dear all:
I am trying to build modified examples inspired by Luis Ibáñez's tutorial "ITK and Graphical User Interface" found here:
I changed the first example to read a color image and converted it to a grayscale image (the original was about smoothing). This part works fine. I like to know how I can display the output image in the displayed window when pressing the Run button. I tried different things but nothing worked.
In the second example, I am not sure where to put the code in the pages 18-21 in the above pdf file. Currently, I put it in two separate files fltkProgressBar.h fltkProgressBar.cxx ( I am not cpp expert) . I also don't know where to put the itk #include statements in the fl file. With the code that I listed bellow in example 2, I got this error:
-----------------------------------------------------------------------------------------------------------
[ 14%] Generating myGUI.h
Scanning dependencies of target myGUI
[ 28%] Building CXX object CMakeFiles/myGUI.dir/itkGUI.cxx.o
In file included from /home/ibr/ZmyProjects/itk/itkGUI/example2/src/itkGUI.cxx:2:0:
./myGUI.h:20:3: error: ‘fltk’ does not name a type
fltk::ProgressBar *progressBar;
^
/home/ibr/ZmyProjects/itk/itkGUI/example2/src/itkGUI.cxx: In function ‘int main()’:
/home/ibr/ZmyProjects/itk/itkGUI/example2/src/itkGUI.cxx:36:9: error: ‘class myGUI’ has no member named ‘progressBar’
gui.progressBar->Observe( smoother );
^
make[2]: *** [CMakeFiles/myGUI.dir/itkGUI.cxx.o] Error 1
make[1]: *** [CMakeFiles/myGUI.dir/all] Error 2
make: *** [all] Error 2
-----------------------------------------------------------------------------------------------------------
Your suggestion is appreciated. Here are the file contents. I also attached the complete examples with this post.
####################################################################
# First example #
####################################################################
-------------------------------------------------------------------
itkGUI.cxx
-------------------------------------------------------------------
// =========== FLTK ===================
#include "myGUI.h"
// =========== ITK ===================
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkCastImageFilter.h"
#include "itkRGBToLuminanceImageFilter.h"
int main( ){
//**************************** ITK ********************************
// read 2D RGB PNG image and convert it to gray scale.
// Initialization
const unsigned int Dimension = 2;
typedef unsigned char ComponentType;
typedef itk::RGBPixel< ComponentType > InputPixelType;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
// Reading
typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( "../img.png" );
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
// Convert to gray scale
typedef itk::RGBToLuminanceImageFilter< InputImageType, OutputImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput( reader->GetOutput() );
// Writing
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( "../out.png" );
writer->SetInput( filter->GetOutput() );
writer->Update();
//**************************** FLTK ********************************
myGUI gui;
gui.Show();
Fl::run();
return 0;
}
-------------------------------------------------------------------
myGUI.fl
-------------------------------------------------------------------
code_name {.cxx}
class myGUI {open
} {
Function {myGUI()} {open
} {
Fl_Window myWin {open
xywh {4028 486 590 440} type Single hide
code0 {\#include "itkProcessObject.h"}
} {
Fl_Button {} {
label Quit
callback {Quit();}
xywh {345 315 120 40}
}
Fl_Box {} {
label {FLTK and ITK} selected
xywh {135 185 305 100} labelfont 9 labelsize 20
}
Fl_Button {} {
label Run
xywh {140 315 105 40}
}
}
}
Function {~myGUI()} {} {
code {} {}
}
Function {Quit()} {} {
code {myWin->hide();} {}
}
Function {Show()} {} {
code {myWin->show();} {}
}
Function {Run()} {open
} {
code {} {}
}
}
-------------------------------------------------------------------
CMakeLists.txt
-------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.1)
PROJECT(itkGUI)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
FIND_PACKAGE(FLTK REQUIRED NO_MODULE)
include_directories(${FLTK_INCLUDE_DIRS})
link_directories(${FLTK_LIBRARY_DIRS})
add_definitions(${FLTK_DEFINITIONS})
FLTK_WRAP_UI( myGUI myGUI.fl ) # create variable myGUI_FLTK_UI_SRCS, myGUI.cxx, and myGUI.h files
ADD_LIBRARY(myGUI itkGUI.cxx ${myGUI_FLTK_UI_SRCS})
ADD_EXECUTABLE( itkGUI itkGUI.cxx )
TARGET_LINK_LIBRARIES( itkGUI fltk myGUI ${ITK_LIBRARIES} )
####################################################################
# second example #
####################################################################
-------------------------------------------------------------------
itkGUI.cxx
-------------------------------------------------------------------
// =========== FLTK ===================
#include "myGUI.h"
#include <FL/Fl.H>
#include <FL/Fl_Slider.H>
#include "fltkProgressBar.h"
// =========== ITK ===================
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkCurvatureFlowImageFilter.h"
int main( ){
//**************************** ITK ********************************
// Initialization
typedef itk::Image< float, 2 > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::CurvatureFlowImageFilter<ImageType,ImageType> SmootherFilterType;
// Reading
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( "../img.png" );
// filtering
SmootherFilterType::Pointer smoother = SmootherFilterType::New();
smoother->SetInput( reader->GetOutput() );
//smoother->SetNumberOfIterations( 7 );
//smoother->SetTimeStep( 0.5 );
//**************************** FLTK ********************************
myGUI gui;
gui.Show();
gui.progressBar->Observe( smoother );
gui.SetFilter( smoother );
//Fl::run();
return 0;
}
-------------------------------------------------------------------
fltkProgressBar.h
-------------------------------------------------------------------
#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
-------------------------------------------------------------------
fltkProgressBar.cxx
-------------------------------------------------------------------
#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);
}
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();
}
}
void ProgressBar::Observe( itk::Object * caller ) {
caller->AddObserver(
itk::ProgressEvent(),
m_RedrawCommand.GetPointer() );
}
} // end namespace fltk
-------------------------------------------------------------------
myGUI.fl
-------------------------------------------------------------------
# data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cxx}
class myGUI {open
} {
decl {itk::ProcessObject * m_Filter;} {private local
}
Function {myGUI()} {open
} {
Fl_Window myWin {open
xywh {3882 145 590 440} type Single hide
code0 {\#include "itkProcessObject.h"}
} {
Fl_Button {} {
label Quit
callback {Quit();}
xywh {345 315 120 40}
}
Fl_Box {} {
label {FLTK and ITK}
xywh {135 185 305 100} labelfont 9 labelsize 20
}
Fl_Button {} {
label Run
xywh {140 315 105 40}
}
Fl_Progress progressBar {
label progressBar selected
xywh {180 265 245 35}
code0 {\#include "itkProcessObject.h"}
class {fltk::ProgressBar}
}
}
}
Function {~myGUI()} {open
} {
code {} {}
}
Function {Quit()} {open
} {
code {myWin->hide();} {}
}
Function {Hide()} {open
} {
code {myWin->hide();} {}
}
Function {Show()} {open
} {
code {myWin->show();} {}
}
Function {SetFilter(itk::ProcessObject * po)} {open
} {
code {myWin->show();} {}
code {m_Filter=po;} {}
}
Function {Run()} {open
} {
code {this->Hide();} {}
code {m_Filter->Update();} {}
}
}
-------------------------------------------------------------------
CMakeLists.txt
-------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.1)
PROJECT(itkGUI)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
FIND_PACKAGE(FLTK REQUIRED NO_MODULE)
include_directories(${FLTK_INCLUDE_DIRS})
link_directories(${FLTK_LIBRARY_DIRS})
add_definitions(${FLTK_DEFINITIONS})
FLTK_WRAP_UI( myGUI myGUI.fl ) # create variable myGUI_FLTK_UI_SRCS, myGUI.cxx, and myGUI.h files
ADD_LIBRARY(myGUI itkGUI.cxx ${myGUI_FLTK_UI_SRCS})
ADD_EXECUTABLE( itkGUI itkGUI.cxx )
TARGET_LINK_LIBRARIES( itkGUI fltk myGUI ${ITK_LIBRARIES} )
TARGET_LINK_LIBRARIES( itkGUI fltk myGUI ${ITK_LIBRARIES} )