[Insight-developers] Questions on Program Style/Design Functors/Function Parameters

Luis Ibanez luis . ibanez at kitware . com
Sat, 31 May 2003 00:24:36 -0400


Hi Kent,

I would suggest to use something similar to
the pattern of PixelAccessor that is used
in the itk::Image for supporting ImageAdaptors.
PixelAccessors do not incurr in the overhead
of calling virtual functions, which is unbearable
when it comes to pixel by pixel access.

The pixel accessor mechanism is quite similar
to the Functors. In the sense that the color
conversion could be implemented as a class
(Functor) and the octree will  be templated
of the this Functor (the default being a kind
of identiy Functor).

Between PixelAccessors and Functors, it is likely
that Functors are better suited for what you seem
to need in this class.

You may want to take a closer look to the
UnaryFunctorImageFilter. The power of such
implementation is highlighted by the number of
pixel-wise filters that are implemented just
by defining the Functor in a new header file.
There are currently 40 filters in the tookit
taking advantage of the Functor mechanism.
This makes a huge difference when it comes
to maintain the code.

An interesting case is the AdaptImageFilter
which uses a PixelAcessor for defining a
Functor and with it creating a pixel-wise
filter based on the UnaryFunctorFilter.



    Luis


-------------------------

Kent Williams wrote:
> So I've got a working version of my Octree template class working. 
> Functionality includes:
> 
> 1. templated over Pixel type, and size of the Color Table.
> 2. requires user-defined Pixel mapping function.
> 3. Tree can be generated from itk::Image.
> 4. itk::Image can be generated from the Octree.
> 
> I'm converting some code from Brains2 that will generate an 
> itk::PolygonGroupSpatialObject from an Octree.  When that is done, you'll be 
> able to go from an itk::Image to an itk::PolygonGroupSpatialObject -- simply 
> specify a colormapping function that converts to two color mode via 
> threshold, create the Octree from an image, then the 
> PolygonGroupSpatialObject from the Octree.
> 
> First question -- my Color Mapping function currently is a function pointer, 
> set after the tree is instantiated.  The function pointer type is defined as
> 
> typedef unsigned (*OctreeColorMappingFunction) (void *PixelPtr);
> 
> This function pointer is NOT templated; at this point anyone defining such a 
> function will have to do something like this:
> 
> unsigned MappingFunction(const void *PixelPtr)
> {
> 	const TPixel *Pixel = static_cast<TPixel *>(PixelPtr);
> 	// For some pixel type TPixel, evaluate *TPixel and convert to
> 	// a unsigned int.
> }
> 
> I'd like to use something like a itk::FunctionBase but it seems like a way to 
> introduce even more overhead to the process of generating a tree.
> If anyone can point me at existing ITK code that would be applicable as a 
> pattern to follow, I'd be much obliged.
> 
> }
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at public . kitware . com
> http://public . kitware . com/mailman/listinfo/insight-developers
>