[Insight-users] Problem using ITK + VTK + QT (QVTKWidget)
Dirk Boye
body at nabla.org
Wed Mar 18 08:27:54 EDT 2009
Hello guys,
I got a problem using ITKtoVTK Image Filter together with QVTKWidget in QT.
Here's my code:
---------------------------------
typedef itk::Image<unsigned short,2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
ReaderType::Pointer reader = ReaderType::New();
ConnectorType::Pointer connector = ConnectorType::New();
std::string filename = ui.lineEdit_file->text().toStdString();
vtkDICOMImageReader *reader2=vtkDICOMImageReader::New();
reader->SetFileName( filename.c_str() );
connector->SetInput( reader->GetOutput() );
reader2->SetFileName( filename.c_str() );
vtkImageData* vtkimage = vtkImageData::New();
vtkimage=reader2->GetOutput(); // Uses VTK Classes to read
DICOM file
//Problem vtkimage=connector->GetOutput(); // Uses ITK -> VTK Filter
vtkImageViewer* viewer = vtkImageViewer::New();
viewer->SetInput( vtkimage );
ui.qvtkWidget->SetRenderWindow(viewer->GetRenderWindow());
viewer->SetupInteractor(ui.qvtkWidget->GetRenderWindow()->GetInteractor());
viewer->Render();
viewer->SetColorWindow( 254 );
viewer->SetColorLevel( 128 );
--------------------------------------
In this example I use "vtkimage=reader2->GetOutput()".
"reader2" is using vtkDICOMImageReader. That works just fine. I can
adjust contrast etc. by using my mouse in the QVTKWidget.
When i change that "vtkimage=..." to "vtkmage=connector->GetOutput()"
I get an Segmentation Fault as soon as i click on my button to load
the DICOM file.
Any suggestions? I really don't understand why I get that segmentation
fault. Both "connector->GetOutput()" and "reader2->GetOutput()" give a
vtkImageData.
Somebody had a similar problem here:
http://marc.info/?l=vtkusers&m=121225544421713&w=2
But overriding all mouse event handlers didn't work for me.
Thanks for your help!
Greetings from sunny Villigen (Switzerland)
Dirk Boye
More information about the Insight-users
mailing list