[Insight-developers] Use one algorithm or another in a filter,
depending of the pixel type
Miller, James V (GE, Research)
millerjv at crd.ge.com
Mon Mar 13 09:17:14 EST 2006
Gaetan,
This can be done. There is a certain pattern to follow that makes this tractable.
We call this a "dispatch" pattern. Basically, you create a set of overloaded functions.
For instance, in itkMinMaxCurvatureFlowFunction, the dispatch pattern is used to
call either a 2D specific implementation, a 3D specific implementation, or a general
ND implementation. The same can be done for pixel types. The pattern creates
a heirarchy of dispatch types so that the general case ends up calling an
function overloaded on the root dispatch type. Subclasses of the dispatch
type are used to provided overloaded functions for specific types.
Here is the design from MinMaxCurvatureFlowFunction
struct DispatchBase {};
template<signed int VDimension>
struct Dispatch : DispatchBase {};
/** This method computes the threshold by averaging the intensity
* in direction perpendicular to the image gradient. */
virtual PixelType ComputeThreshold( const Dispatch<2> &,
const NeighborhoodType & neighborhood ) const;
virtual PixelType ComputeThreshold( const Dispatch<3> &,
const NeighborhoodType & neighborhood ) const;
virtual PixelType ComputeThreshold( const DispatchBase &,
const NeighborhoodType & neighborhood ) const;
The appropriate function is called by the main entry point
threshold = this->ComputeThreshold( Dispatch<ImageDimension>(), it);
This pattern will force only one of the overloaded functions to be instantiated. The
same pattern can be used for pixel types (a DispatchBase class and a Dispatch<short>, etc.).
Jim
-----Original Message-----
From: insight-developers-bounces+millerjv=crd.ge.com at itk.org
[mailto:insight-developers-bounces+millerjv=crd.ge.com at itk.org]On Behalf
Of Gaetan Lehmann
Sent: Sunday, March 12, 2006 10:21 AM
To: insight-developers at itk.org
Subject: [Insight-developers] Use one algorithm or another in a
filter,depending of the pixel type
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 ?
Regards,
Gaetan
More information about the Insight-developers
mailing list