[Insight-users] VTKImageImport - Input Components Mayhem

Christian Werner christian.werner at rwth-aachen.de
Fri Feb 19 05:35:10 EST 2010


Hi Luis!

Here is my code. In principal, it does what I want. There is an 
ApplyFilter Function which works directly on ITK Image Data. Now I can 
implement what ever ITK Filters I want by just overwriting this 
Function. The bad thing is: I mean OVERWRITE, because I can't override 
it. It is a  template function, so I cannot make it virtual and override 
it in child classes. But the actual idea was to implement all different 
filters in child classes...

I know this is a standard "template-newbie" issue, template functions 
can't be virtual. Well, I AM a template-newbie and just don't have any 
clue how to work around this. My dream of a "Just override this 
ApplyFilter with your ITK filtering" becomes a "Take that code and 
overwrite the part in ApplyFilter..." That's especially bad because this 
way every single filter will be about 9MB huuuuuge. Every filter will 
have that big vtk2itk2vtk stuff plus the vtkImageToImageFilter stuff in 
its backback... Not to mention that I have duplicate code all around my 
filter directory.

If you or anybody happens to be a "I can override templated 
functionality"-expert, please take a look at my code, I really would 
appreciate any directions. I was already trying to do something like a 
helper class that is templated, but that did not lead to anything...


Best regards,
Christian


Luis Ibanez wrote:
> Hi Christian,
>
> Thanks for sharing your findings.
>
> We clearly have some documentation bugs here.
>
> We probably should put a full example of conversions
> between vtkImageData and itk::Image in the directory:
>
>            InsightApplications/Auxiliary/vtk
>
> and then use it as a Nightly test for validating its behavior.
>
> Then once we have verified that the conversions work
> properly we should update the documentation of the
> itkVTKImageImporter.
>
>
> Could you please send me the code that you end up
> using ?
>
>
>    Thanks
>
>
>          Luis
>
>
>
> ---------------------------------------------------------------------------
> On Wed, Feb 17, 2010 at 2:22 PM, Christian Werner
> <christian.werner at rwth-aachen.de> wrote:
>   
>> Gee, that's embarassing. All the headache just because I did not know how to
>> properly set up RGB PixelTypes in ITK. But one thing was really irritating
>> and working against me:
>>
>> The ITK Reference on the itkVTKImageImporter states:
>> "Note that the VTK images are assumed to be of 1, 2, or 3 dimensions. Scalar
>> value types can be one of: float, ... The images must have pixel types with
>> one component."
>>
>> Do I misunderstand something here?? "The Images must have pixel types with
>> one component", what does that mean? I nearly spammed the VTK Mailing List
>> on how to convert vtkImageData to Data which have one scalar component per
>> pixel...
>> The other irritating thing was that I found one post where somebody told the
>> poster to use SetNumberOfScalarComponents(1) before importing to ITK. That
>> is not a good choice, because you corrupt your data that way...
>>
>> Anyway I am glad everything works fine. In case somebody wants to know:
>>
>>  typedef itk::RGBPixel< unsigned char >        PixelType;
>>  typedef itk::Image<PixelType, DIM>    InputType;
>>
>> that does the trick and any itkVTKImageImporter instantiated that way is
>> happy with RGB images from VTK!
>>
>> Are there still more PixelTypes I have to account for?
>>
>>
>> Best regards,
>> Christian
>>
>>
>>
>> Christian Werner wrote:
>>     
>>> Hi Luis!
>>>
>>> I am instatiating according to what I get from
>>>
>>> vtkInput->GetDataDimension();
>>> vtkInput->GetScalarTypeAsString();
>>>
>>> and (DIM is a template parameter)
>>>
>>>   if (strcmp("unsigned char", scalarTypeString) == 0) {
>>>   typedef itk::Image<unsigned char, DIM>    InputType;
>>>   return applyConversion<InputType>(vtkOutImage);   //return vtkImageData*
>>>   ...
>>>
>>> and then I call my templated conversion functions, which instantias the
>>> Importer:
>>>
>>> template <typename InputType>
>>> applyConversion(vtkImageData* vtkSourceImage)
>>> {
>>>   //vtkErrorMacro(<<"Applying Conversion...");
>>>
>>>   typedef itk::VTKImageImport<InputType>     ImageImportType;
>>>   typename ImageImportType::Pointer itkImporter;
>>>   itkImporter = ImageImportType::New();
>>>     vtkImageExport* vtkExporter = vtkImageExport::New();
>>>   vtkExporter->SetInput( vtkSourceImage) );
>>>  ...ConnectPipelines...
>>> }
>>>
>>> =>corrupted ITK image or
>>>
>>> (ERROR: VTKImageImport(0x22900f0): Input number of components is 3 but
>>> should be 1)
>>>
>>> if I do not set the number of scalar components to 1.
>>>  So I don't really have any influence here. Is there some information that
>>> I am missing? Aren't the number of components passed by the
>>> SetNumberOfComponentsCallback(...) in the ConnectPipelines?
>>>
>>> Best regards,
>>> Christian
>>>
>>>
>>>
>>> Luis Ibanez wrote:
>>>       
>>>> Hi Christian,
>>>>
>>>> Does your image actually has 3 components ?
>>>>
>>>> Are you instantiating the ITK image with a pixel
>>>> type that has 3 components ?
>>>>
>>>> The typedef for the ITK image was not included
>>>> in your email.
>>>>
>>>>
>>>>    Please let us know,
>>>>
>>>>
>>>>           Thanks
>>>>
>>>>
>>>>               Luis
>>>>
>>>>
>>>> ----------------------------------------------------
>>>> On Mon, Feb 15, 2010 at 4:04 PM, Christian Werner
>>>> <christian.werner at rwth-aachen.de> wrote:
>>>>
>>>>         
>>>>> Hello!
>>>>>
>>>>> At first I want to thank Arunachalam and Wagner for their responses on
>>>>> my
>>>>> last thread, thanks! :-) I finally managed to implement my vtk2itk2vtk
>>>>> templated super-class. It works with one little flaw:
>>>>>
>>>>> I have to SetNumberOfScalarComponents my vtkImageData to 1 before going
>>>>> through the whole conversion loop...
>>>>> (ERROR: VTKImageImport(0x22900f0): Input number of components is 3 but
>>>>> should be 1)
>>>>>
>>>>> This is bad, because the image content is clearly corrupted that way. It
>>>>> goes well through my vtk2itk2vtk and I can save a result vtk image, but
>>>>> this
>>>>> is distorted, as I fiddled around with these scalar components. Also the
>>>>> ITK
>>>>> filters I want to use on my import complain about
>>>>>
>>>>> ERROR: In /opt/ParaView3/VTK/Filtering/vtkImageData.cxx, line 1473
>>>>> vtkImageData (0x228afd0): GetScalarPointer: Pixel (0, 0, 0) not in
>>>>> memory.
>>>>> Current extent= (0, -1, 0, -1, 0, 0)
>>>>>
>>>>>
>>>>> This is how my pipelines connect:
>>>>>
>>>>> 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());
>>>>> }
>>>>>
>>>>> I hope this can easily be fixed as I am so happy that after working the
>>>>> whole day on that vtk2itk2vtk stuff I finally got a vtk image that goes
>>>>> through this conversion jungle. How can it be equipped to survive this
>>>>> adventure undistorted?
>>>>>
>>>>>
>>>>> Best regards,
>>>>> Christian
>>>>> _____________________________________
>>>>> Powered by www.kitware.com
>>>>>
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>
>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>> http://www.kitware.com/products/protraining.html
>>>>>
>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>
>>>>>
>>>>>           
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>       
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>     

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkSimpleImageToImageITKFilter.cxx
Type: text/x-c++src
Size: 8807 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100219/0e143fab/attachment-0001.cxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkSimpleImageToImageITKFilter.h
Type: text/x-chdr
Size: 1331 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100219/0e143fab/attachment-0001.h>


More information about the Insight-users mailing list