[Insight-users] itk to vtk connection problems

Sven Prevrhal sven . prevrhal at oarg . ucsf . edu
Thu, 29 May 2003 09:23:56 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C325C4.076A4A90
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

I religiously followed the examples and still get an error =E2=98=BA! =
The relevant code is

=20

#include <itkVTKImageImport.h>

#include <itkVTKImageExport.h>

=20

/**

 * This function will connect the given itk::VTKImageExport filter to

 * the given vtkImageImport filter.

 */

template <typename ITK_Exporter, typename VTK_Importer>

void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)

{

  =
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCall=
back());

  =
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallba=
ck());

  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());

  importer->SetSpacingCallback(exporter->GetSpacingCallback());

  importer->SetOriginCallback(exporter->GetOriginCallback());

  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());

  =
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCa=
llback());

  =
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateEx=
tentCallback());

  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());

  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());

  =
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());=


  importer->SetCallbackUserData(exporter->GetCallbackUserData());

}

=20

vtkImageData *Foo() {

      typedef itk::Image<unsigned short , 3> OutputImageType;

=20

      typedef itk::ImageFileReader< OutputImageType > ReaderType;

      ReaderType::Pointer reader =3D ReaderType::New();

=20

      reader->SetFileName("C:\\data\\headsq\\quarter.mhd"); //Thanks =
Luis!

      reader->Update();

=20

      OutputImageType::Pointer data =3D reader->GetOutput();

=20

=20

      typedef =
itk::BinaryThresholdImageFilter<OutputImageType,OutputImageType> =
ThresholdingFilterType;

      ThresholdingFilterType::Pointer thresholder =3D =
ThresholdingFilterType::New();

//    thresholder->SetInput(data);

      thresholder->SetInput(reader->GetOutput());

      thresholder->SetLowerThreshold(1000);

      thresholder->SetUpperThreshold(3000);

      thresholder->SetOutsideValue(0);

      thresholder->SetInsideValue(3000);

      thresholder->Update();

      //

      //pipe itk data back into vtk

      //

      typedef itk::VTKImageExport<OutputImageType> ImageExportType;

    ImageExportType::Pointer itkExporter =3D ImageExportType::New();

      itkExporter->SetInput(thresholder->GetOutput());

      itkExporter->Update();

      vtkImageImport *vtkImporter =3D vtkImageImport::New();

      ConnectPipelines(itkExporter, vtkImporter);

      vtkImporter->Update();

      return vtkImporter->GetOutput();

=20

I threw Update()s in to check where the error occurs. It does not occur =
here but when I connect the vtkImporter output to the VTK imaging =
pipeline, and the camera->ResetCamera() triggers an UpdateInformation(). =
Everything seems to be connected correctly, because execution makes it =
down to itkVTKImageExportBase.cxx

=20

void VTKImageExportBase::UpdateInformationCallbackFunction(void* =
userData)

{

  static_cast<VTKImageExportBase*>(userData)->

    UpdateInformationCallback();

}

=20

and at calling UpdateInformationCallback() it fails with a unhandled =
exception! Seems to me the cast goes wrong because some information on =
the image type is missing. But what?

=20

:-) sven

--

=20


------=_NextPart_000_0005_01C325C4.076A4A90
Content-Type: text/html;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html>

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dutf-8">


<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">

<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.EmailStyle17
	{font-family:Arial;
	color:windowtext;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 77.95pt 1.0in 77.95pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>I religiously followed the examples and still get an error =
=E2=98=BA! The
relevant code is</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>#include =
&lt;itkVTKImageImport.h&gt;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>#include =
&lt;itkVTKImageExport.h&gt;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>/**</span></font></p>

<p class=3DMsoPlainText style=3D'margin-right:-74.9pt'><font size=3D2
face=3D"Courier New"><span lang=3DDE-AT =
style=3D'font-size:10.0pt'>=C2=A0* This function
will connect the given itk::VTKImageExport filter to</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0* the given vtkImageImport =
filter.</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0*/</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>template &lt;typename ITK_Exporter, typename
VTK_Importer&gt;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>void ConnectPipelines(ITK_Exporter exporter,
VTK_Importer* importer)</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>{</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetUpdateInformationCallback(exporter-&gt;GetUpdateInformati=
onCallback());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetPipelineModifiedCallback(exporter-&gt;GetPipelineModified=
Callback());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetWholeExtentCallback(exporter-&gt;GetWholeExtentCallback()=
);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0 =
importer-&gt;SetSpacingCallback(exporter-&gt;GetSpacingCallback());</span=
></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetOriginCallback(exporter-&gt;GetOriginCallback());</span><=
/font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetScalarTypeCallback(exporter-&gt;GetScalarTypeCallback());=
</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetNumberOfComponentsCallback(exporter-&gt;GetNumberOfCompon=
entsCallback());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetPropagateUpdateExtentCallback(exporter-&gt;GetPropagateUp=
dateExtentCallback());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetUpdateDataCallback(exporter-&gt;GetUpdateDataCallback());=
</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetDataExtentCallback(exporter-&gt;GetDataExtentCallback());=
</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0 =
importer-&gt;SetBufferPointerCallback(exporter-&gt;GetBufferPointerCallba=
ck());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0
importer-&gt;SetCallbackUserData(exporter-&gt;GetCallbackUserData());</sp=
an></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>}</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>vtkImageData *Foo() {</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 typedef =
itk::Image&lt;unsigned short , 3&gt;
OutputImageType;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0 =C2=A0=C2=A0 typedef =
itk::ImageFileReader&lt; OutputImageType
&gt; ReaderType;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
ReaderType::Pointer reader =3D ReaderType::New();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
reader-&gt;SetFileName(&quot;C:\\data\\headsq\\quarter.mhd&quot;);
//Thanks Luis!</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
reader-&gt;Update();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
OutputImageType::Pointer data =3D
reader-&gt;GetOutput();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 typedef =
itk::BinaryThresholdImageFilter&lt;OutputImageType,OutputImageType&gt;
ThresholdingFilterType;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
ThresholdingFilterType::Pointer thresholder =3D
ThresholdingFilterType::New();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>//=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetInput(data);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetInput(reader-&gt;GetOutput());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetLowerThreshold(1000);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetUpperThreshold(3000);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetOutsideValue(0);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;SetInsideValue(3000);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
thresholder-&gt;Update();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
//</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 //pipe itk =
data back into vtk</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
//</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 typedef
itk::VTKImageExport&lt;OutputImageType&gt; =
ImageExportType;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0 ImageExportType::Pointer =
itkExporter =3D
ImageExportType::New();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
itkExporter-&gt;SetInput(thresholder-&gt;GetOutput());</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
itkExporter-&gt;Update();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vtkImageImport =
*vtkImporter =3D
vtkImageImport::New();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
ConnectPipelines(itkExporter, vtkImporter);</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
vtkImporter-&gt;Update();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
lang=3DDE-AT
style=3D'font-size:10.0pt'>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return =
vtkImporter-&gt;GetOutput();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>I threw Update()s in to check where the error occurs. It does =
not occur
here but when I connect the vtkImporter output to the VTK imaging =
pipeline, and
the camera-&gt;ResetCamera() triggers an UpdateInformation(). Everything =
seems
to be connected correctly, because execution makes it down to =
itkVTKImageExportBase.cxx</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>void VTKImageExportBase::UpdateInformationCallbackFunction(void* =
userData)</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>{</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>=C2=A0 =
static_cast&lt;VTKImageExportBase*&gt;(userData)-&gt;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>=C2=A0=C2=A0=C2=A0 =
UpdateInformationCallback();</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>}</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>and at calling UpdateInformationCallback() it fails with a =
unhandled
exception! Seems to me the cast goes wrong because some information on =
the
image type is missing. But what?</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>&nbsp;</span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>:-) sven</span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>--</span></font></p>

<p class=3DMsoPlainText><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>&nbsp;</span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0005_01C325C4.076A4A90--