[Insight-users] connecting vtk to itk

Diego R. Medaglia diegomedaglia at terra.com.br
Wed Apr 12 09:52:47 EDT 2006


Hi!
    I'm working on a simple example to read a RAW 2D image with VTK, then exporting it to ITK and writing it as a PNG file. I couldn't find the class itkImageToVTKImageFilter that everyone is talking about, so I used the function defined at itk\applications\\connectVTKToITK. The program compiles, links, but when I call the Print() method on the ITK importer it says its got "No Inputs". It must be really a simple thing, but I can´t figure it out....
    I'm using VTK v4.2 and ITK v 2.4.1
    Here's the code:

#include "vtkVolume16Reader.h"
#include "vtkImageExport.h"
#include <itkVTKImageImport.h>
#include <itkVTKImageExport.h>
#include "itkPNGImageIO.h"
#include "itkImageFileWriter.h"

typedef itk::Image<unsigned short,2> imageType;
typedef itk::VTKImageImport<imageType> importerType;
typedef itk::ImageFileWriter<imageType> writerType;


void ConnectVTKToITK(vtkImageExport* in, importerType* out)
{
out->SetUpdateInformationCallback(in->GetUpdateInformationCallback());
out->SetPipelineModifiedCallback(in->GetPipelineModifiedCallback());
out->SetWholeExtentCallback(in->GetWholeExtentCallback());
out->SetSpacingCallback(in->GetSpacingCallback());
out->SetOriginCallback(in->GetOriginCallback());
out->SetScalarTypeCallback(in->GetScalarTypeCallback());
out->SetNumberOfComponentsCallback(in->GetNumberOfComponentsCallback());
out->SetPropagateUpdateExtentCallback(in->GetPropagateUpdateExtentCallback());
out->SetUpdateDataCallback(in->GetUpdateDataCallback());
out->SetDataExtentCallback(in->GetDataExtentCallback());
out->SetBufferPointerCallback(in->GetBufferPointerCallback());
out->SetCallbackUserData(in->GetCallbackUserData());
}


int main(){

vtkVolume16Reader* reader = vtkVolume16Reader::New();
reader->SetFilePrefix("d:\\quarter");
reader->SetImageRange(50,50);
reader->SetDataDimensions(64,64);
reader->SetDataSpacing(3.2,3.2,1);

vtkImageExport* exporter = vtkImageExport::New();
exporter->SetInput(reader->GetOutput());

importerType::Pointer importer = importerType::New();
ConnectVTKToITK(exporter,importer);

typedef itk::PNGImageIO ioType;
ioType::Pointer PNGio = ioType::New();

writerType::Pointer writer = writerType::New();
writer->SetImageIO(PNGio);
writer->SetInput(importer->GetOutput());
writer->SetFileName("d:\\quarterteste.png");

importer->Print(std::cout);
exporter->Print(std::cout);

system("pause");

try{
writer->Update();
}

catch( itk::ExceptionObject & err ){
std::cerr<<"Excecao capturada!";
std::cout << err << std::endl;
system("pause");
}
}

    Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060412/6cf59729/attachment.htm


More information about the Insight-users mailing list