[Insight-users] ITK-VTK pipeline connection
Luis Ibanez
luis . ibanez at kitware . com
Mon, 21 Jul 2003 16:23:08 -0400
Hi Stephan,
The output of an ITK or VTK filter is only valid
after the Update() method has been invoked on it.
It is normal for the output of vtkImporter to have
an invalid extent, since no Update() call has been
invoked in this filter so far.
The extent on the output of the reader, on the other
hand, is valid because an Update() call has been done
there.
You should be ok by calling
vtkImporter->GetImporter()->Update();
instead of
vtkImporter->GetOutput()->Update();
Note also the the classes
itkImageToVTKImage
itkVTKImageToImage
are not really filters in themselves. They are simply
holders of an ITK and VTK importer and exporter.
An artificial Update() call has been added now
to these classes in order to make them look more
like a filter. The Update() call simply delegates
to the internal importer.
Thanks for pointing this out.
Regards,
Luis
-----------------------
itk at stmoser . ch wrote:
> 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
>
>------------------------------------------------------------------------
>
>#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;
>}
>
>