[Insight-users] [ITK Community] newbie C++ question

Luis Ibanez luis.ibanez at kitware.com
Sat Jan 11 11:56:36 EST 2014


Massinissa,


What is wrong with the code in your example,
is that, in the expression


   typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
   const ScalarPixelType pixelTypeSource = imageIOsource->
GetComponentType();


The IOComponentType is actually an "enum".

A type for which we have not consider it to be used as a valid image type.


Note that what GetComponentType() is returning is not a "pixel type",
but a "number" that refers to a "pixel type".  That is, it is just a label
that enumerates the potential expected pixel types.


The DefaultConvertPixelTraits, compilation error, in

   itk::DefaultConvertPixelTraits<PixelType>::ComponentType

happens because we have a set of traits defined for the expected
pixel types, common types such as : char, int, float....etc.

                    Not so for the IOComponentType enum.

That is, the compiler is complaining about the use of

           itk::DefaultConvertPixelTraits< IOComponentType >

because it was expecting something like:

           itk::DefaultConvertPixelTraits< char >
           itk::DefaultConvertPixelTraits< short >
           itk::DefaultConvertPixelTraits< float >
           ...
           etc

For a full list of the expected types, please see:

ITK/Modules/Core/Common/include/itkDefaultConvertPixelTraits.h


https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkDefaultConvertPixelTraits.h#L67
 67 #define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type)
...

and

https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkDefaultConvertPixelTraits.h#L95

 95 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(float)
 96 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(double)
 97 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(int)
 98 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(char)
 99 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(short)
100 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned int)
101 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(signed char)
102 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned char)
103 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned short)
104 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(long)
105 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned long)
106 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(long long)
107 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned long long)
108 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(bool)



The way that the IOComponentTyep enum is expected to be used, is not by
taking it directly as the pixel template type argument of an itk::Image<>,
but as the driving variable of a Switch() statement.


Something like:


     switch(   imageIOSource->GetComponentType() )
     {
     case UCHAR:
          {
          typedef itk::Image< unsigned char, 3 > ImageType;
          ... etc...
         break;
         }
     case CHAR:
          {
          typedef itk::Image< char, 3 > ImageType;
          ... etc...
         break;
         }
     case UINT:
          {
          typedef itk::Image< unsigned int, 3 > ImageType;
          ... etc...
         break;
         }
     ...etc...
     }




Regards,


    Luis




On Fri, Jan 10, 2014 at 1:34 AM, Massinissa Bandou <
Massinissa.Bandou at usherbrooke.ca> wrote:

> Hi Dženan Zukić,
>
> I just want to know what's wrong with the code below because I have 5
> errors:
>
>
> Error   2       error C2146: syntax error : missing ';' before identifier
> 'ComponentType' c:\program
> files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1
> TomoRegistration
> Error   4       error C2602:
> 'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' is not a member
> of a base class of 'itk::DefaultConvertPixelTraits<PixelType>'  c:\program
> files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1
> TomoRegistration
> Error   1       error C2838: 'ComponentType' : illegal qualified name in
> member
> declaration     c:\program
> files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1
> TomoRegistration
> Error   5       error C2868:
> 'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' : illegal syntax
> for using-declaration; expected qualified-name  c:\program
> files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1
> TomoRegistration
> Error   3       error C4430: missing type specifier - int assumed. Note:
> C++ does
> not support default-int c:\program
> files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1
> TomoRegistration
>
>
>
>
>         typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
>         itk::ImageIOBase::Pointer imageIOsource =
>
> itk::ImageIOFactory::CreateImageIO("writesource.mhd",itk::ImageIOFactory::ReadMode);
>         imageIOsource->SetFileName("writesource.mhd");
>         imageIOsource->ReadImageInformation();
>         const ScalarPixelType pixelTypeSource =
> imageIOsource->GetComponentType();
>
>         itk::ImageIOBase::Pointer imageIOtarget =
>
> itk::ImageIOFactory::CreateImageIO("writetarget.mhd",itk::ImageIOFactory::ReadMode);
>         imageIOtarget->SetFileName("writetarget.mhd");
>         imageIOtarget->ReadImageInformation();
>         const ScalarPixelType pixelTypeTarget =
> imageIOtarget->GetComponentType();
>
>        myClass* a= new myClass;
>        a->VolumeRegistration(pixelTypeSource,pixelTypeTarget);
>
> class myClass
> {
>         ....
>         template<typename pixelType1, typename pixelType2>
>         void VolumeRegistration(pixelType1,pixelType2)
>         {
>                 typedef itk::Image< pixelType1, 3 >  FixedImageType;
>                 typedef itk::Image< pixelType2, 3 >  MovingImageType;
>         }
> };
>
>
>
>
> --
> View this message in context:
> http://itk-users.7.n7.nabble.com/newbie-C-question-tp33081p33162.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
> _____________________________________
> 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.php
>
> 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
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20140111/472f0794/attachment.html>


More information about the Insight-users mailing list