[Insight-users] about changing itk image to vtk image

Luis Ibanez luis.ibanez at kitware.com
Sat Apr 29 14:50:26 EDT 2006


Hi Yixun,

A call to the Register() method should have solved the problem,
if you put this call at the end of the fun1() function. That is,
you must increase the reference count of the vtkImageData before
the end of that function.


  Regards,



     Luis



------------------
Yixun Liu wrote:
> Hi Luis,
> 
> I am sorry for my incaution.:-) fun1 returns vtkImagedata* .
> 
> To invoke Register() method of vtkImageData may not be useful.
> 
> If I set the connector as a local variable, when I debug into Update() method of vtkRendererWindow(), the exception occurs at the UpdateImformation() method, which is invoked by Update().
> 
> So, I guess the reason may be that when fun1 return, connector destroyed but the vtkImageData will exist. Because it is referenced by vtkVolumeMapper. However, when the data is requested by the render, the Update() method will propagate up the pipeline. When the Update() method travel to vtkImageData, it will invoke the Update() method of its source, which is the connector.But the connector has been destroyed, so the exception occur.If taking the connector as a member variable, the Update() method can reach it. Although the pipeline befor the connector has been destroyed, I guess ,the connector can stop the propagation of the Update() method. I do not know what I guess is corrrct or not.
> 
> Regards,
> 
> Yixun Liu
> 
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "Yixun Liu" <yxliu at fudan.edu.cn>
> To: "Y.X.Liu" <yxliu at fudan.edu.cn>
> Sent: Friday, April 28, 2006 10:12 PM
> Subject: Fw: [Insight-users] about changing itk image to vtk image
> 
> 
> 
>>----- Original Message ----- 
>>From: "Luis Ibanez" <luis.ibanez at kitware.com>
>>To: "Yixun Liu" <yxliu at fudan.edu.cn>
>>Cc: "ITK" <insight-users at itk.org>
>>Sent: Friday, April 28, 2006 9:24 PM
>>Subject: Re: [Insight-users] about changing itk image to vtk image
>>
>>
>>
>>>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
>>>>...
>>>>  file://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