[Insight-users] about changing itk image to vtk image
Luis Ibanez
luis.ibanez at kitware.com
Fri Apr 28 09:24:46 EDT 2006
Hi Yixun,
Your code does not seem to be correct:
ImageType::Pointer* fun1()
are you returning a pointer to an ITK SmartPointer ?
If you are using the ITK to VTK image filter, the
output of connectMRI should be a vtkImageData *.
--
Note that, as you correctly guessed, variables declared
inside the function will be destroyed when the function
return. So, if you are creating the connector filter
inside the function, then the connector filter will be
destroyed by the time you pass the pointer to to fun2().
--
Note also that VTK *DOES NOT* use smart pointers,
therefore if you want to keep the image alive after
the destruction of the connector filter, then you
will have to invoke the Register() method in that
vtkImageData.
--
In any case, if you are writing a C++ class with this,
the simplest solution is to make that connector filter
to be a member variable of your class.
Regards,
Luis
===================
Yixun Liu wrote:
> Hi,
>
> I read dicom using itk and change it to vtk to visualize it. I read
> dicom and change it to vtk in fun1();
>
> ImageType::Pointer* fun1()
> {
> ...
> dicomReader = ReaderType_Short::New();//itk
> ...
> //convert itk image to vtk image
> connectorMRI = ConnectorType::New();
> connectorMRI->SetInput(dicomReader->GetOutput());
> try
> {
> connectorMRI->Update();
> }
> catch( itk::ExceptionObject & excp )
> {
> std::cerr << "Error reading the series " << std::endl;
> std::cerr << excp << std::endl;
> }
>
> return connectorMRI->GetOutput();
>
> }
>
>
> In fun2(), I generate a volume and render it.
> fun2()
> {
> vtkVolume *volume = GenerateVolume(fun1());
>
> vtkWin->Render();
>
> }
>
>
> However, exception occurs. If I change the connectoMRI to class variable
> instead of local variable. I can render it correctly. I do not konw the
> reason. I guess that if connectorMIR is a local variable it release
> memory when the fun1 return.
>
> Regards,
>
> Yixun Liu
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list