[Insight-users] Changing InputPixelType in an easy way?
Julien Michel
julien.michel at c-s.cnes.fr
Thu May 24 10:07:04 EDT 2007
Hi Frédéric,
I remember trying to do the same some time ago. Unfortunately, it won't
work. One alternative you can use is to write the code of which you want
to change the pixel type at runtime in a generic method templated by
this pixel type. Then you can do something like :
int main(int argc, char * argv[])
{
swith(...)
case MYCASE1:
myGenericFunction<short>();
break;
case MYCASE2:
myGenericFunction<unsigned char>();
...
}
and :
template <class TMyType> GenericFunction()
{
typedef TMyType InputPixelType;
...
}
Just remember that generic code is resolved at compilation time :
your compiler need to know which type he has to compile with, otherwise
it can not achieve compilation. With your code, you ask it to decide at
compilation time what is the type of InputPixelType based on a value you
won't know until runtime.
In the code above, there is no such conditional decision : you compile
each instantiation of your code and it is up to you to choose which one
you want to run based on some runtime value.
Hope that helps,
Best regards,
Julien
Frédéric Stevens a écrit :
> Hi,
>
> I was wondering if you could change the InputPixelType easily ?
> I have tried something like :
>
> int test = 1; // just to be sure it enters the first if for
> InputPixeltype to be defined
> if( test == 1)
> {
> typedef unsigned char InputPixelType;
> typedef unsigned char OutputPixelType;
> }
> else
> {
> typedef short InputPixelType;
> typedef short OutputPixelType;
> }
>
> typedef itk::Image< InputPixelType, 2 > InputImageType;
> typedef itk::Image< OutputPixelType, 2> OutputImageType;
>
> But It doesn't work: gives that error " Error 4 error C2065:
> 'InputPixelType' : undeclared identifier
> e:\tmp\Imageimport\binarytest.cxx 62 "
> If i put directly one type it works, but if i put an "if", even though I
> am sure in goes in, the InputPixelType isn't known. Could you explain me
> why it doesn't recognize it ?
>
> Thank you in advance,
> Regards,
>
> Frédéric
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: julien.michel.vcf
Type: text/x-vcard
Size: 255 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20070524/4aa00c16/julien.michel.vcf
More information about the Insight-users
mailing list