[vtkusers] how to connect ITK to VTK?

paulus joo paulusjoo at hotmail.com
Thu Jul 8 12:51:29 EDT 2004


Hi Serhat

You can use these code as an example. I build in windows, but I am sure will
work also in other OS.
I use Cmake to generate the  project file and open the project file with
MSVC.
Make sure that you have brain.png file or you can change the code for other
file.

Good luck

//-------------------------CMakelist.txt
# This project is designed to be built outside the Insight source tree.
PROJECT(image)

# Find ITK.
FIND_PACKAGE(ITK)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
  MESSAGE(FATAL_ERROR "Cannot build without ITK.  Please set ITK_DIR.")
ENDIF(ITK_FOUND)

# Find VTK.
FIND_PACKAGE(VTK)
IF(VTK_FOUND)
  INCLUDE(${VTK_USE_FILE})
ELSE(VTK_FOUND)
  MESSAGE(FATAL_ERROR "Cannot build without VTK.  Please set VTK_DIR.")
ENDIF(VTK_FOUND)

ADD_EXECUTABLE(image image.cxx)

TARGET_LINK_LIBRARIES(image ITKBasicFilters ITKCommon ITKIO vtkCommon
vtkRendering vtkGraphics vtkHybrid vtkImaging vtkIO vtkFiltering)




//-------image.cxx -------
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "itkImageToVTKImageFilter.h"


//int main( int argc, char ** argv )
int main()
{
  typedef unsigned short      PixelType;
  const   unsigned int        Dimension = 2;

  typedef itk::Image< PixelType, Dimension >   ImageType;
  typedef itk::ImageFileReader< ImageType >    ReaderType;
  typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType;

  ReaderType::Pointer reader = ReaderType::New();
  ConnectorType::Pointer connector = ConnectorType::New();
  //reader->SetFileName( argv[1] );
  reader->SetFileName("Brain.png");
  //reader->Update();

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

  vtkImageViewer *viewer=vtkImageViewer::New();
  vtkRenderWindowInteractor
*renderWindowInteractor=vtkRenderWindowInteractor ::New();
  viewer->SetupInteractor(renderWindowInteractor);
  viewer->SetInput(connector->GetOutput());
  viewer->Render();
  viewer->SetColorWindow(255);
  viewer->SetColorLevel(128);
  renderWindowInteractor->Start();

  return 0;
}



----- Original Message ----- 
From: "Serhat Guneyli" <serhatguneyli at yahoo.com>
To: <vtkusers at vtk.org>
Sent: Thursday, July 08, 2004 9:40 AM
Subject: [vtkusers] how to connect ITK to VTK?


> Hi vtk users,
>
> I joined the itk & vtk family about a few weeks ago.
> Up to now, i didn't write any meesages, but I tried to
> find the answers to my questions by checking the
> discussions you had in the past on this email list.. I
> think, now i need some help.. It would be very nice,
> if anyone can answer my question.
>
> So, i am trying to connect ITK and VTK. I want to
> visualize the output of an ITK filter via VTK. I am
> using itkImageToVTKImageFilter.h class for it, and my
> sample is an .png image. I added almost all of the
> libs but still couldn't solve the problem.
> Here down is my code and the error messages I get.
>
> Thanks in advance,
>
> Serhat Guneyli
>
>
> // Define input image
> #ifdef WIN32
> #include "..\\..\\data\\Data.h"
> #else
> #include "../../data/Data.h"
> #endif
>
> // ITK
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkGradientMagnitudeImageFilter.h"
>
> // ITK to VTK
> #include "itkImageToVTKImageFilter.h"
>
> // VTK
> #include "vtkImageViewer.h"
> #include "vtkRenderWindowInteractor.h"
>
> // Standard libs
> #include <iostream>
>
> int main()
> {
> // Define image
> const unsigned int Dimension = 2;
> typedef unsigned short PixelType;
> typedef itk::Image< PixelType, Dimension > ImageType;
>
> // Read Image from file
> typedef itk::ImageFileReader< ImageType >
> FileReaderType;
> FileReaderType::Pointer pReader =
> FileReaderType::New();
> pReader->SetFileName( INPUT_IMAGE_FILE );
>
> /*
> * Create ITK image (gradient magnitude, page 126)
> */
>
> typedef itk::GradientMagnitudeImageFilter< ImageType,
> ImageType > GradMagFilterType;
> GradMagFilterType::Pointer pFilter =
> GradMagFilterType::New();
>
> pFilter->SetInput( pReader->GetOutput() );
>
> /*
> * ITK -> VTK
> */
>
> typedef itk::ImageToVTKImageFilter< ImageType >
> ConnectorType;
>
> ConnectorType::Pointer pConnector;
> pConnector->SetInput( pFilter->GetOutput() );
>
> vtkRenderWindowInteractor *pInteractor =
> vtkRenderWindowInteractor::New();
> vtkImageViewer *pViewer     = vtkImageViewer::New();
>
> pViewer->SetInput( pConnector->GetOutput() );
>
> pViewer->SetupInteractor( pInteractor );
> pViewer->SetColorWindow( 255 );
> pViewer->SetColorLevel( 128 );
> pViewer->Render();
> pInteractor->Start();
> return 0;
> }
>
>
> and the errors:
>
> Gradients2.obj : error LNK2001: unresolved external
> symbol "public: class vtkImageData * __thiscall
> itk::ImageToVTKImageFilter<class itk::Image<unsigned
> short,2> >::GetOutput(void)const "
> (?GetOutput@?$ImageToVTKImageFilter at V?$Image at G$01 at itk@@@itk@@
> QBEPAVvtkImageData@@XZ)
>
> Gradients2.obj : error LNK2001: unresolved external
> symbol "public: void __thiscall
> itk::ImageToVTKImageFilter<class itk::Image<unsigned
> short,2> >::SetInput(class itk::Image<unsigned
> short,2> const *)"
> (?SetInput@?$ImageToVTKImageFilter at V?$Image at G$
> 01 at itk@@@itk@@QAEXPBV?$Image at G$01 at 2@@Z)
>
> Debug/Gradients2.exe : fatal error LNK1120: 2
> unresolved externals
>
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.
> http://promotions.yahoo.com/new_mail
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list