Michael :<br><br>Upon return from your functiion, the smart pointer goes out of scope and will cleanup its resources, which includes the generated output, since noone is holding a reference to it. You could rephrase that method as below, with a shallow copy. The shallow copy will cause the "output" to hold a reference to the output of the converter and prevent it from vanishing upon return.
<br><br>void itk2vtk(ReaderType3D::OutputImageType::Pointer image, vtkImageData *output) <br>{<br> // --- Same stuff as you have below until converter->Update() ---- <br> ....<br> converter->Update();<br> output->ShallowCopy(converter->GetOutput());
<br>}<br><br><br>-- <br>Karthik Krishnan<br>R&D Engineer,<br>Kitware Inc.<br><div><span class="gmail_quote">On 8/22/07, <b class="gmail_sendername">Michael Schildt</b> <<a href="mailto:michael.schildt@ifn-magdeburg.de">
michael.schildt@ifn-magdeburg.de</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello!<br><br>I Want to display data from ITK in VTK but I have trouble to return a
<br>VTK object from a function to the main function. I call the function<br>with a valid 3d ITK image. The y-axis is flipped to account for the<br>different coordinate systems of ITK and VTK. Then converted via<br>ImageToVTKImageFilter. It works fine. I want to return the generated VTK
<br>image. It is valid up to the return statement. After that it seems to be<br>deleted. How can I tell the program not to delete this object? Do i have<br>to return the object instead of its pointer?<br><br>Function in question is (vtkImage is valid until return, in main the
<br>return value is invalid):<br><br> vtkImageData* itk2vtk(ReaderType3D::OutputImageType::Pointer image) {<br><br>itk::FlipImageFilter<ReaderType3D::OutputImageType>::FlipAxesArrayType<br>SourceAxes;<br> SourceAxes[0] = false;
<br> SourceAxes[1] = true;<br> SourceAxes[2] = false;<br><br> itk::FlipImageFilter<ReaderType3D::OutputImageType>::Pointer flip<br> = itk::FlipImageFilter<ReaderType3D::OutputImageType>::New();<br>
flip->SetFlipAxes(SourceAxes);<br> flip->SetInput(image);<br> flip->Update();<br><br> itk::ImageToVTKImageFilter<ReaderType3D::OutputImageType>::Pointer<br>converter<br> = itk::ImageToVTKImageFilter<ReaderType3D::OutputImageType>::New();
<br> converter->SetInput(flip->GetOutput());<br> converter->Update();<br> vtkImageData *vtkImage = converter->GetOutput();<br> return vtkImage;<br> }<br><br>Greetings,<br> Michael Schildt<br><br>
<br>_______________________________________________<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ
</a><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div>