[Insight-users] ITK-VTK pipeline connection

Stephan Moser stepmose at ee . ethz . ch
Mon, 21 Jul 2003 21:40:40 +0200 (MEST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime at docserver . cac . washington . edu for more info.

--------------000102090503050207000202
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; FORMAT=flowed

Hi

I have done some debugging on the code that Michael posted this morning.
I found out that the extent of the vtkImageData is not correct at the
time when it is accessed. If an update() is done on the image data
itself in:

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

then the extent is updated and correct.

Is this a legitimate workaround? I thought that Update() methods should
only be invoked on filters rather than on the image data itself.

The reason to access the extent data is that in order to run a marching
cube on the data in VTK, the image is extended by one pixel in every
dimension using a vtkConstantPad filter, which requires the extent to
explicitely be set, so interference with the dataflow is inevitable.

Stephan
--------------000102090503050207000202
Content-Type: TEXT/PLAIN; NAME="DebugProject.cxx"
Content-Description: 
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--