[Insight-users] Re: Problem of transforming itk data to vtk.

Luis Ibanez luis . ibanez at kitware . com
Wed, 01 Oct 2003 11:56:36 -0400


Hi Jiang,

You shouldn't add .h nor .txx files to the list
of sources in your CMakeLists.txt file.

.h and .txx files are not compiled directly,
they are compiled only when their type is instantiated
in included in a .cxx. your list of sources should
only have .cxx files.

VC++ will not know what to do with a .txx file
since the templated class is not a fully defined
type.

In order to use the ITK to VTK adaptor, just
include the header file in your code and
instantiate one adaptor for the ITK image type
that you are using.



Something like:

#include "itkImageToVTKImageFilter.h"

typedef unsigned char  VisualizationPixelType;

typedef itk::Image<
               VisualizationPixelType, 3
                        >VisualizationVolumeType;

typedef itk::ImageToVTKImageFilter<
                    VisualizationVolumeType
                           > ITK2VTKAdaptorFilterType;


// Note the use of the SmartPointer !!
ITK2VTKAdaptorFilterType::Pointer
         adaptor = ITK2VTKAdaptorFilterType::New();


// Connect the reader

    adaptor->SetInput( reader->GetOutput() );

// Then you can get the output vtkImageData by doing

    vtkImageData  * image = adaptor->GetOutput();





   Regards,


     Luis


------------------------
jiang wrote:
> Hi, Luis,
> In order to verify that the data converted from itk to vtk correctly, I
> write out the converted data by vtkImageWriter. The code is:
> 	vtkImageWriter* writer = vtkImageWriter::New();
> 	writer->SetFileName("Importer");
> 	writer->SetInput(importer->GetOutput());//importer is vtkImageImport that
> import data from itk to vtk.
> 	writer->SetFileDimensionality(3);
> 	writer->Write();
> 
> Then I read the "Importer" by VolView. The result rendered by VolView is not
> correct. So I consider my pipeline from itk to vtk was wrong. However this
> pipeline is exactly same as the Auxiliary\vtk\itkImageToVTKImageFilter, the
> import part. I don't know how to modify it.
> As your suggestion, I try to use itkImageToVTKImageFilter in my program
> dirrectly. So I add itkImageToVTKImageFilter.h and
> itkImageToVTKImageFilter.txx to my CMakeLists as below:
> 
> SET(MyProject_SRCS
> ... ...
> itkImageToVTKImageFilter.txx
> )
> 
> SET(MyProject_MOC_SRCS
> ... ...
> itkImageToVTKImageFilter.h
> )
> 
> Then I use itkImageToVTKImageFilter in my program:
> 	ImageToVTKImageFilter* connector=ImageToVTKImageFilter::New();
> 	connector->SetInput(reader->GetOutput());//reader is typedef
> itk::ImageSeriesReader<ImageNDType>   ReaderType;
> 	ImageDataSet=vtkImageData::New();
> 	ImageDataSet=connector->GetOutput();
> 
> But some errors occor:
> error C2065: 'ImageToVTKImageFilter' : undeclared identifier
>  error C2065: 'connector' : undeclared identifier
>  error C2653: 'ImageToVTKImageFilter' : is not a class or namespace name
>  error C2065: 'New' : undeclared identifier
>  error C2106: '=' : left operand must be l-value
>  error C2227: left of '->SetInput' must point to class/struct/union
>  error C2227: left of '->GetOutput' must point to class/struct/union
> 
> And the itkImageToVTKImageFilter.txx can not be compiled by VC++
> 
> How can I use itkImageToVTKImageFilter in my program and convert the itk
> data to vtk correctly?
> 
> Thank you very much!
> 
> Chunyan Jiang
> 
>