[vtkusers] How to retrun a vtkImageData object pointer from function call

Michael Schildt michael.schildt at ifn-magdeburg.de
Wed Aug 22 10:29:53 EDT 2007


Hello!

I Want to display data from ITK in VTK but I have trouble to return a 
VTK object from a function to the main function. I call the function 
with a valid 3d ITK image. The y-axis is flipped to account for the 
different coordinate systems of ITK and VTK. Then converted via 
ImageToVTKImageFilter. It works fine. I want to return the generated VTK 
image. It is valid up to the return statement. After that it seems to be 
deleted. How can I tell the program not to delete this object? Do i have 
to return the object instead of its pointer?

Function in question is (vtkImage is valid until return, in main the 
return value is invalid):

  vtkImageData* itk2vtk(ReaderType3D::OutputImageType::Pointer image) {
    
itk::FlipImageFilter<ReaderType3D::OutputImageType>::FlipAxesArrayType 
SourceAxes;
    SourceAxes[0] = false;
    SourceAxes[1] = true;
    SourceAxes[2] = false;
   
    itk::FlipImageFilter<ReaderType3D::OutputImageType>::Pointer flip
      = itk::FlipImageFilter<ReaderType3D::OutputImageType>::New();
    flip->SetFlipAxes(SourceAxes);
    flip->SetInput(image);
    flip->Update();

    itk::ImageToVTKImageFilter<ReaderType3D::OutputImageType>::Pointer 
converter
      = itk::ImageToVTKImageFilter<ReaderType3D::OutputImageType>::New();
    converter->SetInput(flip->GetOutput());   
    converter->Update();
    vtkImageData *vtkImage = converter->GetOutput();
    return vtkImage;
  }

Greetings,
    Michael Schildt
   




More information about the vtkusers mailing list