[Insight-users] connecting vtk to itk

Karthik Krishnan Karthik.Krishnan at kitware.com
Wed Apr 12 10:36:56 EDT 2006



Diego R. Medaglia wrote:

> 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,

http://www.itk.org/cgi-bin/viewcvs.cgi/Auxiliary/vtk/itkVTKImageToImageFilter.h?rev=1.5&root=InsightApplications&view=log
http://www.itk.org/cgi-bin/viewcvs.cgi/Auxiliary/vtk/itkImageToVTKImageFilter.h?rev=1.6&root=InsightApplications&view=log

Your code should be a lot shorter using this filter

> 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!
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>  
>


More information about the Insight-users mailing list