1 #ifndef CLITKCOMMONGENERICFILTER_H
2 #define CLITKCOMMONGENERICFILTER_H
3 #include "clitkCommon.h"
5 /*--------------------------------------------------------------------
6 DISCLAIMER : I obviously know how to make this mess much clearer and
7 shorter, but I fear its being too long to put in this margin ...
9 -------------------------------------------------------------------- */
13 //--------------------------------------------------------------------
14 template<class FilterType>
15 class GenericFilterFunctorBase {
17 GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
18 virtual void Execute()= 0;
22 //--------------------------------------------------------------------
23 template<class FilterType, class InputImageType>
24 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
26 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
27 virtual void Execute() {
28 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
32 //--------------------------------------------------------------------
33 template<class FilterType>
34 class ImageTypesManager {
36 typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
37 typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
38 typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
39 MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
41 ImageTypesManager(FilterType * f) { mFilter = f; }
42 virtual void DoIt(int dim, int ncomp, std::string pixelname) {
43 // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
44 if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
45 mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
47 template<unsigned int Dim, unsigned int NComp, class PixelType>
48 void AddNewDimensionAndPixelType() {
49 typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
50 mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] =
51 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
53 /// Specialization for NComp == 1
54 template<unsigned int Dim, class PixelType>
55 void AddNewDimensionAndPixelType() {
56 typedef itk::Image<PixelType,Dim> InputImageType;
57 mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] =
58 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
62 //--------------------------------------------------------------------
66 #endif // end CLITKCOMMONGENERICFILTER_H