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

Luis Ibanez luis . ibanez at kitware . com
Wed, 01 Oct 2003 13:25:14 -0400


Hi Jiang,

If your application is crashing, there is no
much confidence we could have in the data that
it is writing.

Please try the code in the "ApplicationModel"
from Georgetown University. Instructions for
downloading it from CVS were posted to the
users list.

http://www . itk . org/pipermail/insight-users/2003-September/005090 . html

This code is doing exactly what you want and
it will save you a lot of time. Once you get
this code to work for you, it will be easy
modify it for the purpose of your application.


BTW: did you try reading the original DICOM
slices with MRIConvert or with VolView ?
Did the data look ok when loaded in any of
these two applications ?

--

Please let us know if you find any problem
using the ApplicationModel code.


Thanks


   Luis


------------------
jiang wrote:
> Hi Luis,
> I modify the code as you said. The compiling is no problem. When I run it,
> the application crashes. Then I debug it try to find out the problem. I find
> that the transfer part can pass debug. It stops at the end of the function.
> And it enters itkVTKImageExportBase.cxx, and stops at UpdateDataCallback();
> or somewhere.
> But the vtk writing has be executed. I render it by VolView. The result is
> still wrong. Then I use my itk to vtk pipeline. Then render the vtk writing
> file by VolView. The result is same as above.
> So I consider that either the both convert methods are correct, or both are
> incorrect. Since the results are same. And other possibilities are vtk write
> procesure was wrong, or VolView render procesure was wrong.
> The vtk write part is:
> 	vtkImageWriter* writer = vtkImageWriter::New();
> 	writer->SetFileName("Importer");
> 	writer->SetInput(importer->GetOutput());
> 	writer->SetFileDimensionality(3);
> 	writer->Write();
> 
> I open "Importer" by VolView as raw data, other steps are all performed as
> Open Wizard with default parameter.
> 
> Could you please help me to judge what's wrong with my program? Thank you
> very much for your kind help!
> 
> Best regards,
> Chunyan Jiang
> 
> -----Ursprungliche Nachricht-----
> Von: Luis Ibanez [mailto:luis . ibanez at kitware . com]
> Gesendet: Mittwoch, 1. Oktober 2003 17:57
> An: jiang
> Cc: ITK
> Betreff: Re: Problem of transforming itk data to vtk.
> 
> 
> 
> 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
>>
>>
> 
> 
> 
> 
> 
>