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

Luis Ibanez luis . ibanez at kitware . com
Tue, 03 Jun 2003 14:58:16 -0400


Hi Kent,

Looking at the Watershed example, it seems that Josh alreay
implemented a class with similar functionality to what you
seem to be looking for.


This is in

    Insight/Examples/Segmentation/WatershedSegmentation1.cxx

The class in question is the:

            "ScalarToRGBPixelFunctor"

which is used like:

    #include "itkScalarToRGBPixelFunctor.h"

    typedef itk::Functor::ScalarToRGBPixelFunctor<
                                           unsigned long>
                                             ColorMapFunctorType;


Josh uses it for coloring the labeled image resulting from
the watershed filter. The functor holds a color look up table.
This functor is used directly on the UnaryFunctorImageFilter:


typedef itk::UnaryFunctorImageFilter<
                            LabeledImageType,
                            RGBImageType,
                            ColorMapFunctorType
                                         > ColorMapFilterType;

ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();



Details about the example are treated in the SoftwareGuide
on section 8.2.2, pdf-page 264


Maybe this functor can be adapted to your needs.



   Regards,


       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
>