[vtkusers] vtkImageViewer and vtkDICOMImageReader success (almost)
jonas
mail at jonaswestberg.net
Wed Dec 14 06:10:00 EST 2005
When doing an simple example the DICOM reader works just fine:
DicomSimple.cxx
---------------------------------------
#include "vtkDICOMImageReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
int main( int argc, char *argv[] )
{
vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
reader->SetFileName("test.dcm");
vtkImageViewer *viewer = vtkImageViewer::New();
viewer->SetInput(reader->GetOutput());
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
viewer->SetupInteractor(iren);
viewer->Render();
iren->Initialize();
iren->Start();
reader->Delete();
viewer->Delete();
iren->Delete();
return 0;
}
---------------------------------------
But I would like to have more control of the code, because vtkDICOMImageReader
just work as a wrapper for a few classes. When doing the following (and i am
using the same image again) i get a segmentation fault:
DicomSimple.cxx
---------------------------------------
#include "vtkDICOMImageReader.h"
#include "vtkBMPReader.h"
#include "vtkImageMapper.h"
#include "vtkActor2D.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
int main( int argc, char *argv[] )
{
vtkRenderWindow *RenderWindow = vtkRenderWindow::New();
vtkRenderer *Renderer = vtkRenderer::New();
vtkImageMapper *ImageMapper = vtkImageMapper::New();
vtkActor2D *Actor2D = vtkActor2D::New();
// Using a bmp reader works fine
//vtkBMPReader *reader = vtkBMPReader::New();
//reader->SetFileName("test.bmp");
// But the dicom image from last example results in a seg. faults
vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
reader->SetFileName("test.dcm");
ImageMapper->SetInput(reader->GetOutput());
Actor2D->SetMapper(ImageMapper);
Renderer->AddActor2D(Actor2D);
RenderWindow->AddRenderer(Renderer);
vtkRenderWindowInteractor *RenderWindowInteractor =
vtkRenderWindowInteractor::New();
RenderWindowInteractor->SetRenderWindow(RenderWindow);
RenderWindow->Render();
RenderWindowInteractor->Initialize();
RenderWindowInteractor->Start();
return 0;
}
---------------------------------------
CMakeLists.txt
---------------------------------------
PROJECT (Step1)
INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
IF (USE_VTK_FILE)
INCLUDE(${USE_VTK_FILE})
ENDIF (USE_VTK_FILE)
LINK_LIBRARIES(vtkRendering vtkIO vtkDICOMParser)
ADD_EXECUTABLE(DicomSimple DicomSimple.cxx)
TARGET_LINK_LIBRARIES(DicomSimple vtkDICOMParser)
---------------------------------------
I am using VTK 4.4.2 using CMake 2.2 in Windows XP with CygWin and gcc 3.4.4.
Do you get the same error when running these two programs (I assume you use a
DICOM image named test.dcm for testing)?
More information about the vtkusers
mailing list