[Insight-users] connecting vtk to itk

Andinet Enquobahrie andinet.enqu at kitware.com
Wed Apr 12 11:37:32 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, 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".

But, it is ok you are getting "No Inputs" . It means the number of 
required inputs for VTKImageImport is zero. If you trace the class hierarchy

VTKImageImport->ImageSource->ProcessObject

ImageSource is a base class for all process objects that output image 
data (doesn't require input) and VTKImageImport doesn't explicitly 
define SetInput()...

-Andinet


> 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