[vtkusers] Crash in vtkImageViewer2 when Input is changed

itkvtk123 at gmx.net itkvtk123 at gmx.net
Thu Jan 7 06:21:17 EST 2010


Hey guys,

I broke down the problem and found out, that vtkImageViewer2 crashes when one of its Input's pipeline elements loses its scope.
(it occurs when itkImageToVTKImageFilter loses its scope)


It does work if I use vtk components only, e.g. the pipeline

vtkPNGReader -> vtkImageViewer2

This pipeline does not crash, even if vtkPNGReader loses its scope.




But if I do my desired way of using itk components as well, it crashes, e.g. the pipeline

itkImageFileReader -> itkImageToVTKImageFilter -> vtkImageViewer2

This pipeline crashes when itkImageToVTKImageFilter loses its scope.



I found out, that the GetOutput() Method of itkImageToVTKImageFilter returns a raw pointer instead of a vtkSmartPointer.
But replacing the raw pointer with a vtkSmartPointer did not do the trick.

Why does itkImageToVTKImageFilter return a raw pointer?
And why does my pipeline still crash?




=============
Minimal Code:
=============


#include "vtkImageViewer2.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkPNGReader.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"

typedef unsigned short PixelType;
typedef itk::Image<PixelType, 2> Image2DType;
typedef itk::ImageFileReader<Image2DType> ImageReaderType;
typedef itk::ImageToVTKImageFilter<Image2DType> Converter2DType;

int main()
{
	vtkSmartPointer<vtkImageViewer2> viewer = vtkSmartPointer<vtkImageViewer2>::New();
	vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	viewer->SetupInteractor(iren);

	// First way to do it - works not
	// -> does only work when converter is declared outside
	// the curly braces (-> as long as converter does not lose its scope)
	{
		ImageReaderType::Pointer reader = ImageReaderType::New();
		reader->SetFileName("C:/image.png");
		reader->Update();

		Image2DType::Pointer image = reader->GetOutput();
		Converter2DType::Pointer converter = Converter2DType::New();
		converter->SetInput(image);
		converter->Update();
		viewer->SetInput(converter->GetOutput());
	}

	//// Second way to do it - works
	//{
	//	vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
	//	reader->SetFileName("C:/image.png");
	//	reader->Update();
	//	viewer->SetInput(reader->GetOutput());
	//}

	viewer->Render();
	iren->Start();
}
-- 
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02



More information about the vtkusers mailing list