[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-&gt;GetOutput()), =
always got=20
an error&nbsp;"segmentation error"&nbsp;. Below is the =
Pseudo-code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1.code don't work:</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>vtkImageDate*&nbsp;Test::Update(void)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize =
vtkImageReader=20
reader;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize=20
itk::VTKImageToImageFilter vtkToItk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
vtkToItk-&gt;SetInput(reader-&gt;GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
vtkToItk-&gt;GetImporter()-&gt;Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; //do nothing inside=20
itk</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize=20
itk::ImageToVTKImageFilter itkToVtk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
itkToVtk-&gt;SetInput(vtkToItk-&gt;GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
itkToVtk-&gt;GetImporter()-&gt;Update();&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return=20
itkToVtk-&gt;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>&nbsp;&nbsp;&nbsp; Initialize Test =
t;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;image=3Dt-&gt;Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
image-&gt;Update();&nbsp;=20
//failed here or later when rendering pipeline force it to update, =
segmentation=20
fault</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; //rendering pipeline =

below</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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&nbsp;Test::Update(void)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize =
vtkImageReader=20
reader;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize=20
itk::VTKImageToImageFilter vtkToItk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
vtkToItk-&gt;SetInput(reader-&gt;GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
vtkToItk-&gt;GetImporter()-&gt;Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; //do nothing inside=20
itk</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Initialize=20
itk::ImageToVTKImageFilter itkToVtk;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
itkToVtk-&gt;SetInput(vtkToItk-&gt;GetOutput());</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
itkToVtk-&gt;GetImporter()-&gt;Update();&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV>&nbsp;&nbsp;&nbsp; //image rendering pipeline below, without return =

value</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </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>&nbsp;&nbsp;&nbsp; Initialize Test =
t;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;t-&gt;Update();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV>&nbsp;</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&nbsp;give me&nbsp;a suggestion about the =
error?&nbsp;</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>&nbsp;</DIV>
<DIV>Many thanks in advance&nbsp;&nbsp;</DIV>
<DIV>&nbsp;</DIV></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Nick Hu, M.E.Sc.<BR>Medical Imaging =
Software=20
Developer<BR>Imaging Research, Sunnybrook &amp; 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--