[Insight-users] Using ImageToVTKImageFilter with SetRequestedRegion

Mathieu Malaterre mathieu.malaterre at gmail.com
Fri Oct 5 06:13:54 EDT 2007


Hi there,

  I must be missing something trivial here. I am using the
ImageToVTKImageFilter to convert my ITK data to VTK data (*). Even if
I explicitely set a specific update/requested extent, the filter seems
to discard it and decide to recompute everything on the
whole/largestpossible extent instead.

Any suggestion ?

Thanks,

-- 
Mathieu

itk2vtk.cxx:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkCastImageFilter.h"
#include "itkImageToVTKImageFilter.h"

int main(int argc, char *argv[])
{
  if( argc < 2 ) return 1;
  typedef   unsigned char    InputPixelType;
  typedef   float            OutputPixelType;
  typedef itk::Image< InputPixelType,  3 >   InputImageType;
  typedef itk::Image< OutputPixelType, 3 >   OutputImageType;

  typedef itk::ImageFileReader< InputImageType >  ReaderType;

  typedef itk::CastImageFilter<
               InputImageType, OutputImageType >  CastFilterType;

  typedef itk::ImageToVTKImageFilter<OutputImageType> ITK2VTKFilter;


  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );

  CastFilterType::Pointer       castFilter       = CastFilterType::New();
  castFilter->SetInput(       reader->GetOutput() );

  CastFilterType::OutputImageRegionType request;
  request.SetIndex(0,0);
  request.SetIndex(1,0);
  request.SetIndex(2,0);
  request.SetSize(0,10);
  request.SetSize(1,10);
  request.SetSize(2,10);
  //castFilter->DebugOn();
  castFilter->GetOutput()->SetRequestedRegion( request );
  castFilter->Update(); // Keep me

  std::cout << "After Cast Update" << std::endl;
  //castFilter->GetOutput()->Print( std::cout );
  castFilter->GetOutput()->GetRequestedRegion().Print( std::cout );

  // Now pass the Output to the itk2vtk filter:
  ITK2VTKFilter::Pointer itk2vtk = ITK2VTKFilter::New();
  itk2vtk->SetInput( castFilter->GetOutput() );
  itk2vtk->Update(); // Keep me

  std::cout << std::endl << std::endl;
  std::cout << "After itk2vtk Update" << std::endl;
  castFilter->GetOutput()->GetRequestedRegion().Print( std::cout );

  return 0;
}


CMakeLists.txt:
FIND_PACKAGE(VTK REQUIRED)
FIND_PACKAGE(ITK REQUIRED)

INCLUDE(${VTK_USE_FILE})
INCLUDE(${ITK_USE_FILE})

INCLUDE_DIRECTORIES(
  # Unfortunately ITK does not export it's source path anymore:
  /home/mathieu/Projects/Insight/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/
)

ADD_EXECUTABLE(itk2vtk itk2vtk.cxx)
TARGET_LINK_LIBRARIES(itk2vtk
  ITKCommon
  ITKIO
  ITKBasicFilters
  vtkIO
  vtkImaging
)


More information about the Insight-users mailing list