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

Peter Cech pcech at vision.ee.ethz.ch
Sun Mar 12 21:42:51 EST 2006


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.

Regards,
Peter


More information about the Insight-developers mailing list