[Insight-developers] Use one algorithm or another in a filter, depending of the pixel type

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Mon Mar 13 05:24:06 EST 2006


On Mon, 13 Mar 2006 03:42:51 +0100, Peter Cech <pcech at vision.ee.ethz.ch>  
wrote:

> On Sun, Mar 12, 2006 at 16:21:26 +0100, Gaetan Lehmann wrote:
>>
>> Hi,
>>
>> Lots of algorithm can be implemented a lots more efficiently with some  
>> pixels
>> types - most of the time with char and short (signed or not).
>> Is it possible automatically choose the algorithm used in a filter,  
>> depending
>> of the pixel type ?
>> If yes, can it be done at build time ?
>
> Yes, it can be done using template specialization. You don't have to
> create template specialization of your whole filter class, instead you
> can extend existing pixel type traits classes or create new specialized
> ones and then write:
>
>   if (Traits<PixelType>::is_short) {
>     // ... your specialized faster algorithm ...
>   } else {
>     // ... generic algorithm ...
>   }
>
> As the value of the condition is known at compile time, compiler will
> optimize out the block that will not be taken.
>

Ok, I'll try, but with "typeid(PixelType) == typeid(short)" instead of  
modifying NumericTraits: it's surely lots of work.

Thanks,

Gaetan

-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr


More information about the Insight-developers mailing list