[vtkusers] Re: how to connect ITK and VTK?

Laurent Mundeleer lmundele at ulb.ac.be
Mon Feb 23 03:20:37 EST 2004


Hi Nicolas,
here's an example how to connect vtk with itk :

/// connexion de ITK a VTK
template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
  
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
  
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
  
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
  
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

//-----------------------------------------------------------------

/// connexion de VTK a ITK
template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
  
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
  
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
  
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
  
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

//-----------------------------------------------------------------

///contructeur initialisant le pipeline ITK
regionGrowingITK::regionGrowingITK(vtkImageImport* vtkImporter, 
vtkImageExport *vtkExporter)
{       
    itkImporter = ImageImportType::New();
    itkExporter = ImageExportType::New();

    itkExporter->SetInput(itkImporter->GetOutput());
   
    ConnectPipelines(vtkExporter, itkImporter);
    ConnectPipelines(itkExporter, vtkImporter);   
}

//-----------------------------------------------------------------

/// execution du region growing
void regionGrowingITK::RegionGrowingExec(QProgressDialog* progress, 
float *seedPos, float ratio, int *x)
{
  ...
    connectedThreshold->Update();
    //region growing à partir d'un point initial
   
    itkExporter->SetInput(connectedThreshold->GetOutput());
}

hope it'll help...

Laurent


>Message: 5
>From: "Nicolas DUMONT" <s991848 at student.ulg.ac.be>
>To: <insight-users at itk.org>, <vtkusers at vtk.org>
>Date: Fri, 20 Feb 2004 17:29:57 +0100
>Subject: [vtkusers] how to connect ITK and VTK?
>
>This is a multi-part message in MIME format.
>
>------=_NextPart_000_029C_01C3F7D7.29565960
>Content-Type: text/plain;
>	charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>Hello users !=20
>
>I'm a student, novice with itk/vtk. I'm trying to connect Itk to Vtk =
>along the lines of 'getting started with vtk+itk , Luis Ibanez - William =
>Schroeder'.
>The problem is I cannot find the filter 'ItkImageToVTKImagefilter.h'.=20
>
>I saw that It is also possible to do it using 'itkVtkImageExport' at the =
>end of the itk pipeline and 'vtkImageImport' at the beginning of the vtk =
>pipeline.=20
>But i cant manage to use 'vtkImageImport': I read the doxygen =
>documentation about it but I cant figure out which method to use....
>
>Help ! Does someone have a C++ example ?
>
>Thanks in advance,=20
>Nicolas Dumont.
>
>I tried to adapt the code found in 'getting started with vtk+itk', here =
>is it:=20
>
>*****************************************************************
>#include "itkImage.h"
>#include "itkImageFileReader.h"
>#include "itkVTKImageExport.h"
>
>#include "vtkImageImport.h"
>#include "vtkRenderWindowInteractor.h"
>#include "vtkImageViewer.h"
>
>int main (int argc, char **argv) {
> typedef itk::Image<unsigned short,2> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::VTKImageExport<ImageType> ConnectorType;
>
> ReaderType::Pointer reader =3D ReaderType::New();
> ConnectorType::Pointer connector =3D ConnectorType::New();
>
> reader->SetFileName(argv[1]);
> connector->SetInput(reader->GetOutput());
>
>vtkImageImport ?????????????????????;
>
> vtkImageViewer * viewer =3D vtkImageViewer::New();
>
> vtkRenderWindowInteractor * renderWindowInteractor =3D =
>vtkRenderWindowInteractor::New();
>
> viewer->SetupInteractor(renderWindowInteractor);
> viewer->SetInput( ???????? );
>
> viewer->Render();
> viewer->SetColorWindow(255);
> viewer->SetColorLevel(128);
> renderWindowInteractor->Start();
>
> return 0;
>}
>*************************************************************************=
>*
>
>------=_NextPart_000_029C_01C3F7D7.29565960
>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.2600.0" name=3DGENERATOR>
><STYLE></STYLE>
></HEAD>
><BODY bgColor=3D#ffffff>
><DIV><FONT face=3DArial size=3D2>Hello users ! </FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT face=3DArial size=3D2>I'm a student, novice with itk/vtk. I'm =
>trying to=20
>connect Itk to Vtk along the lines of 'getting started with vtk+itk , =
>Luis=20
>Ibanez - William Schroeder'.</FONT></DIV>
><DIV><FONT face=3DArial size=3D2>The problem is I cannot find the filter =
>
>'ItkImageToVTKImagefilter.h'. </FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT face=3DArial size=3D2>I saw that It is also possible to do =
>it&nbsp;using=20
>'itkVtkImageExport' at the end of the itk pipeline and 'vtkImageImport' =
>at the=20
>beginning of the vtk pipeline. </FONT></DIV>
><DIV><FONT face=3DArial size=3D2>But i cant manage to use =
>'vtkImageImport': I read=20
>the doxygen documentation about it but I cant figure out which method to =
>
>use....</FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT face=3DArial size=3D2>Help ! Does someone have a C++ example=20
>?</FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT face=3DArial size=3D2>Thanks in advance, </FONT></DIV>
><DIV><FONT face=3DArial size=3D2>Nicolas Dumont.</FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT face=3DArial size=3D2>I tried to adapt the code found in =
>'getting started=20
>with vtk+itk', here is it: </FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
>size=3D2>
><DIV>*****************************************************************<BR=
>  
>
>>#include=20
>>    
>>
>"itkImage.h"<BR>#include "itkImageFileReader.h"<BR>#include=20
>"itkVTKImageExport.h"</DIV>
><DIV>&nbsp;</DIV>
><DIV>#include "vtkImageImport.h"<BR>#include=20
>"vtkRenderWindowInteractor.h"<BR>#include "vtkImageViewer.h"</DIV>
><DIV>&nbsp;</DIV>
><DIV>int main (int argc, char **argv) {<BR>&nbsp;typedef =
>itk::Image&lt;unsigned=20
>short,2&gt;&nbsp;ImageType;<BR>&nbsp;typedef=20
>itk::ImageFileReader&lt;ImageType&gt;&nbsp;ReaderType;<BR>&nbsp;typedef=20
>itk::VTKImageExport&lt;ImageType&gt;&nbsp;ConnectorType;</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;ReaderType::Pointer reader =3D=20
>ReaderType::New();<BR>&nbsp;ConnectorType::Pointer connector =3D=20
>ConnectorType::New();</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;reader-&gt;SetFileName(argv[1]);<BR>&nbsp;connector-&gt;SetInp=
>ut(reader-&gt;GetOutput());</DIV>
><DIV>&nbsp;</DIV>
><DIV>vtkImageImport ?????????????????????;</DIV>
><DIV><BR>&nbsp;vtkImageViewer * viewer =3D vtkImageViewer::New();</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;vtkRenderWindowInteractor * renderWindowInteractor =3D=20
>vtkRenderWindowInteractor::New();</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;viewer-&gt;SetupInteractor(renderWindowInteractor);<BR>&nbsp;v=
>iewer-&gt;SetInput(=20
>???????? );</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;viewer-&gt;Render();<BR>&nbsp;viewer-&gt;SetColorWindow(255);<=
>BR>&nbsp;viewer-&gt;SetColorLevel(128);<BR>&nbsp;renderWindowInteractor-&=
>gt;Start();</DIV>
><DIV>&nbsp;</DIV>
><DIV>&nbsp;return 0;<BR>}</FONT></DIV>
><DIV><FONT face=3DArial=20
>size=3D2>****************************************************************=
>**********</FONT></DIV></BODY></HTML>
>
>  
>
>  
>

-- 
********************************************
Laurent Mundeleer
Université Libre de Bruxelles (ULB)
Service des Systèmes Logiques et Numériques (SLN) CP165/57
50, Av. F.Roosevelt
1050 Bruxelles
Belgium
tel : ++32.2.650.22.97
fax : ++32.2.650.22.98
e-mail : lmundele at ulb.ac.be
********************************************




More information about the vtkusers mailing list