[Insight-users] ITK-VTK pipeline connection

Michael Kuhn michakuhn at gmx . ch
Mon, 21 Jul 2003 10:50:57 -0600


This is a multi-part message in MIME format.
--------------000102090503050207000202
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I have a problem concerning the size/extent when I try to connect the 
pipeline between itk and vtk. I tried to connect the pipelines using the 
itk::ImageToVTKImageFilter (found in applications/auxilary/vtk) (method 
1, refer to the comments in the attached code) as well as by explicitly 
instantiating a itk::VTKImageExport and a vtkImageImport (method 2).

With both methods, the extent of the vtk data is -1, -1, -1 (using int 
*extent = vtkImporter->GetOutput()->GetWholeExtent(); (I've tried 
GetExtent() as well)) (method 1) and the attempt to afterwards visualize 
the data in vtk fails.

However, when I explicitely set the extent  to the size of the itk data 
(method 2), the visualization works fine. Is it necessary that I 
explicitely set this extent, or is there a way to have it updated 
automatically?

Thanks,

Michael

--------------000102090503050207000202
Content-Type: text/plain;
 name="DebugProject.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DebugProject.cxx"

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMetaImageIO.h"

#include "vtkAIMReader.h"

#include "vtkPNGReader.h"
#include "vtkPointData.h"

#include "itkVTKImageToImageFilter.h"
#include "itkImageToVTKImageFilter.h"

#include "vtkPipelineConnectorITK2VTK.h"
#include "vtkImageConstantPad.h"
#include "vtkMarchingCubes.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"


#include <iostream>

int main(int argc, char** argv) {
	typedef  itk::MetaImageIO MetaReaderType;
	MetaReaderType ::Pointer  metaReader  = MetaReaderType::New();

	typedef unsigned short PixelType;
	typedef itk::Image<PixelType, 3> ImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::ImageFileWriter<ImageType> WriterType;

	ReaderType::Pointer reader = ReaderType::New();
	reader->SetImageIO( metaReader );
	reader->SetFileName("d:\\regProjectData\\MHAs\\brainweb1.mha");
	try {
		reader->Update();
	} catch (itk::ExceptionObject e) {
		cerr << e << endl;
	}
	
	
	// ##### method 1 to connect the pipelines #####
	typedef itk::VTKImageExport<ImageType> ImageExportType;
	ImageExportType::Pointer itkExporter = ImageExportType::New();
	itkExporter->SetInput(reader->GetOutput());
	vtkImageImport* vtkImporter = vtkImageImport::New();  
	vtkPipelineConnectorITK2VTK<ImageExportType, vtkImageImport*>::
		ConnectPipelines(itkExporter, vtkImporter);
	

	/*
	// ##### method 2 to connect the pipelines #####
	typedef itk::ImageToVTKImageFilter<ImageType> ITK2VTKType;
	ITK2VTKType::Pointer vtkImporter = ITK2VTKType::New();
	vtkImporter->SetInput(reader->GetOutput());
	*/


	vtkImageConstantPad *pad = vtkImageConstantPad::New();
	pad->SetInput(vtkImporter->GetOutput());
	

	/*

	// ##### method 1 to get the extent #####
	int *extent = vtkImporter->GetOutput()->GetWholeExtent();

	*/
	

	// ##### method 2 to get the extent #####
	ImageType::SizeType size = 
		reader->GetOutput()->GetBufferedRegion().GetSize();
	int *extent = new int[6];
	extent[0] = 0;
	extent[1] = size[0];
	extent[2] = 0;
	extent[3] = size[1];
	extent[4] = 0;
	extent[5] = size[2];
	

	
	pad->SetOutputWholeExtent(extent[0]-1, extent[1] + 1 , extent[2]-1, 
		extent[3]+1, extent[4]-1, extent[5] +1 );
	pad->SetConstant(0);


	vtkMarchingCubes *mc = vtkMarchingCubes::New();
	mc->SetInput(pad->GetOutput());
	mc->SetValue(0,128);

	vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
	mapper->SetInput(mc->GetOutput());
	mapper->ScalarVisibilityOff();

	vtkActor *actor= vtkActor::New();
	actor->SetMapper(mapper);
	actor->GetProperty()->SetColor(0,1,0);

	vtkRenderer *aRenderer = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
	renWin->AddRenderer(aRenderer);
	renWin->SetSize(200,200);
	renWin->SetWindowName("MyWindow"); 
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);
	aRenderer->SetBackground(0.0, 0.0, 1);
	aRenderer->AddActor(actor);
	aRenderer->ResetCamera();
	renWin->Render();
	iren->Start();


	return 0;
}

--------------000102090503050207000202--