[Insight-users] viewing slices

W. Storteboom W.Storteboom at student.rug.nl
Fri May 13 08:49:02 EDT 2005


I am only using FLTK, VTK and ITK for only a few weeks but 
I want to view orthogonal slices. After searching through 
the Insight applications (cellularsegmentation, 
deformablemodelsimplexmesh) and the mailing list, the 
imagesliceviewer class was recommended. Looking through 
the code of the deformablemodelsimplexmesh, I thought I 
knew how it should work and tried to add it in my own 
application. But no image is shown and when issuing a 
render a second render window appears with no image in it. 
The relevant code is listed below.

FLTK::Run is used for running the application. Building it 
is done with Visual Studio 6 on Windows XP.

*** ImageApp.h ***

#ifndef ImageApp_h
#define ImageApp_h

#include "ImageUI.h"
#include "ImageSliceViewer.h"

class ImageApp : public ImageUI {
private:
	ImageSliceViewer m_ImageSliceViewer;

public:
   virtual void Quit();
   virtual void Initialize();
   virtual void Redraw();
};
#endif

*** ImageApp.cxx ***

#include "ImageApp.h"

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkConeSource.h>
#include <vtkSuperquadricSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include "FL/Fl_File_Chooser.H"

#include <vtkBMPReader.h>
#include <vtkImageActor.h>

void ImageApp::Quit() {
	exit(0);
}

void ImageApp::Initialize() {
	m_ImageSliceViewer.SetOrientation(ImageSliceViewer::Axial);

	main_window->show();
	axialview->show();

	m_ImageSliceViewer.SetInteractor(axialview);

	axialview->Initialize();

	vtkBMPReader *reader=vtkBMPReader::New();
	reader->SetFileName("grey00001.bmp");

	m_ImageSliceViewer.SetInput(reader->GetOutput());

	//m_ImageSliceViewer.Render();
	m_ImageSliceViewer.Render();

	reader->Delete();
}

void ImageApp::Redraw() {
	m_ImageSliceViewer.SelectSlice( 0 );
	axialview->redraw();
	Fl::check();
}

*** CMakeLists.txt ***

# CMakeLists.txt for the vtkFlRWI Cone3 example
# copyright 2004 by Charl P. Botha http://cpbotha.net/
# $Id: CMakeLists.txt,v 1.2 2004/06/08 12:48:33 cpbotha 
Exp $

# Use cmake on any platform supported by VTK to create a 
build environment
# for this example.  Alternatively, but not recommended, 
modify and make use
# of the Makefile.vtk3 or Makefile.vtk4 example makefiles 
for GNU C++

PROJECT(Image)

# first we have to find VTK
FIND_PACKAGE(VTK)
IF(VTK_FOUND)
   INCLUDE(${VTK_USE_FILE})
ENDIF(VTK_FOUND)

# then FLTK
FIND_PACKAGE(FLTK)
IF(FLTK_FOUND)
   INCLUDE_DIRECTORIES(${FLTK_INCLUDE_DIR})
ENDIF(FLTK_FOUND)

# and last ITK
FIND_PACKAGE(ITK)
IF(ITK_FOUND)
   INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)

# then vtkFlRenderWindowInteractor.h and .cxx
FIND_PATH(VTK_FL_RWI_H_PATH vtkFlRenderWindowInteractor.h)
FIND_PATH(VTK_FL_RWI_CXX_PATH 
vtkFLRenderWindowInteractor.cxx)

IF(NOT VTK_FL_RWI_H_PATH)
    MESSAGE(FATAL_ERROR "Please enter the path of 
vtkFlRenderWindowInteractor.h")
ENDIF(NOT VTK_FL_RWI_H_PATH)

IF(NOT VTK_FL_RWI_CXX_PATH)
    MESSAGE(FATAL_ERROR "Please enter the path of 
vtkFlRenderWindowInteractor.cxx")
ENDIF(NOT VTK_FL_RWI_CXX_PATH)

# add the vtkFlRenderWindowInteractor.h path to the 
include directories
INCLUDE_DIRECTORIES(${VTK_FL_RWI_H_PATH})

# remember to actually build and link with 
vtkFlRenderWindowInteractor.cxx
ADD_EXECUTABLE(Image Image.cxx ImageUI.cxx ImageApp.cxx 
ImageSliceViewer.cxx InteractorObserver.cxx
${VTK_FL_RWI_CXX_PATH}/vtkFlRenderWindowInteractor.cxx)

TARGET_LINK_LIBRARIES(Image vtkRendering ITKAlgorithms
   ${FLTK_LIBRARIES})


More information about the Insight-users mailing list