[vtkusers] VTK to ITK image export/import

Rick Frank rickfrank at me.com
Wed Nov 2 17:43:06 EDT 2011


Hi,

I'm trying to pass a vtkImage to ITK.

I have the following code:



template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
  importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
  importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
  importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
  importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

void ExportToITK(vtkImageData* image)
{


   vtkImageExport* vtkExporter = vtkImageExport::New();
   vtkExporter->SetInput((vtkDataObject*) image);
  
 typedef itk::Image<float, 3> ImageType;
  typedef itk::VTKImageImport<ImageType> ImageImportType;
  ImageImportType::Pointer itkImporter = ImageImportType::New();
  ConnectPipelines(vtkExporter, itkImporter);

	
  itkImporter->Update();
	

}

In the UpdateCall()  I get an exception because it says the Spacing is 0. 
Tracing the code seems to show that the userData of the SetSpacingCallback is not correct, it returns the default spacing
which is zero, and then an exception is thrown.

Can someone point out where I'm missing something?

Thanks


Rick Frank



More information about the vtkusers mailing list