[Insight-users] vtk-itk-vtk problem
Nick Hu
nhu@sten.sunnybrook.utoronto.ca
Wed, 23 Apr 2003 15:37:32 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01C309AE.41A3A8F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
I tried to write a new class which contains a simple test of vtk image =
to itk image and then back to vtk image. I used the two filters, =
itkImageToVTKImage and itkVTKImageToImageFilter, to convert the image =
between itk and vtk. When I build the image rendering pipeline inside =
the class, everything works fine. But then when I get the vtkimage as =
output to other program outside (just like regular =
vtkImageFilter->GetOutput()), always got an error "segmentation error" . =
Below is the Pseudo-code:
1.code don't work:
vtkImageDate* Test::Update(void)
{
Initialize vtkImageReader reader;
Initialize itk::VTKImageToImageFilter vtkToItk;
vtkToItk->SetInput(reader->GetOutput());
vtkToItk->GetImporter()->Update();
//do nothing inside itk
Initialize itk::ImageToVTKImageFilter itkToVtk;
itkToVtk->SetInput(vtkToItk->GetOutput());
itkToVtk->GetImporter()->Update(); =20
=20
return itkToVtk->GetOutput();
}
main()
{
Initialize Test t;
image=3Dt->Update();
image->Update(); //failed here or later when rendering pipeline =
force it to update, segmentation fault
=20
//rendering pipeline below
}
2. If I build pipe line inside the class:
void Test::Update(void)
{
Initialize vtkImageReader reader;
Initialize itk::VTKImageToImageFilter vtkToItk;
vtkToItk->SetInput(reader->GetOutput());
vtkToItk->GetImporter()->Update();
//do nothing inside itk
Initialize itk::ImageToVTKImageFilter itkToVtk;
itkToVtk->SetInput(vtkToItk->GetOutput());
itkToVtk->GetImporter()->Update(); =20
=20
//image rendering pipeline below, without return value
=20
}
main()
{
Initialize Test t;
t->Update();
}
Then everything works correct. I even print the vtkImageData before =
return it in the first code and it looks right. Both codes can be =
compiled and linked correctly.=20
Can anyone give me a suggestion about the error?=20
By the way, the reason I want to wrap itk in vtk class is I have some =
existing project written in Python and I need to call itk from python =
application :(
Many thanks in advance =20
Nick Hu, M.E.Sc.
Medical Imaging Software Developer
Imaging Research, Sunnybrook & Women's
Suite 6020, 3080 Young Street / PO Box 89, Toronto
ON M4N 3N1
Tel: 416-4823856 Fax: 416-4823807
------=_NextPart_000_0012_01C309AE.41A3A8F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I tried to write a new class which =
contains a=20
simple test of vtk image to itk image and then back to vtk image. I used =
the two=20
filters, itkImageToVTKImage and itkVTKImageToImageFilter, to convert the =
image=20
between itk and vtk. When I build the image rendering pipeline inside =
the class,=20
everything works fine. But then when I get the vtkimage as output to =
other=20
program outside (just like regular vtkImageFilter->GetOutput()), =
always got=20
an error "segmentation error" . Below is the =
Pseudo-code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>1.code don't work:</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>vtkImageDate* Test::Update(void)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize =
vtkImageReader=20
reader;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize=20
itk::VTKImageToImageFilter vtkToItk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
vtkToItk->SetInput(reader->GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
vtkToItk->GetImporter()->Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //do nothing inside=20
itk</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Initialize=20
itk::ImageToVTKImageFilter itkToVtk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
itkToVtk->SetInput(vtkToItk->GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
itkToVtk->GetImporter()->Update(); </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> return=20
itkToVtk->GetOutput();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>main()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize Test =
t;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> image=3Dt->Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
image->Update(); =20
//failed here or later when rendering pipeline force it to update, =
segmentation=20
fault</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> //rendering pipeline =
below</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>2. If I build pipe line inside the=20
class:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial =
size=3D2>void Test::Update(void)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize =
vtkImageReader=20
reader;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize=20
itk::VTKImageToImageFilter vtkToItk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
vtkToItk->SetInput(reader->GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
vtkToItk->GetImporter()->Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //do nothing inside=20
itk</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Initialize=20
itk::ImageToVTKImageFilter itkToVtk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
itkToVtk->SetInput(vtkToItk->GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
itkToVtk->GetImporter()->Update(); </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV>
<DIV> //image rendering pipeline below, without return =
value</DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>main()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Initialize Test =
t;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> t->Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV> </DIV>
<DIV>Then everything works correct. I even print the vtkImageData before =
return=20
it in the first code and it looks right. Both codes can be compiled and =
linked=20
correctly. </DIV>
<DIV>Can anyone give me a suggestion about the =
error? </DIV>
<DIV>By the way, the reason I want to wrap itk in vtk class is I have =
some=20
existing project written in Python and I need to call itk from python=20
application :(</DIV>
<DIV> </DIV>
<DIV>Many thanks in advance </DIV>
<DIV> </DIV></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Nick Hu, M.E.Sc.<BR>Medical Imaging =
Software=20
Developer<BR>Imaging Research, Sunnybrook & Women's<BR>Suite 6020, =
3080=20
Young Street / PO Box 89, Toronto<BR>ON M4N 3N1<BR>Tel: 416-4823856 Fax: =
416-4823807</FONT></DIV></BODY></HTML>
------=_NextPart_000_0012_01C309AE.41A3A8F0--