]> Creatis software - clitk.git/blob - common/clitkCommonGenericFilter.h
added the new headers
[clitk.git] / common / clitkCommonGenericFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef CLITKCOMMONGENERICFILTER_H
19 #define CLITKCOMMONGENERICFILTER_H
20 #include "clitkCommon.h"
21
22 /*--------------------------------------------------------------------
23   DISCLAIMER : I obviously know how to make this mess much clearer and
24   shorter, but I fear its being too long to put in this margin ...
25   D.S.
26   -------------------------------------------------------------------- */
27
28 namespace clitk {
29   
30   //--------------------------------------------------------------------
31   template<class FilterType>
32   class GenericFilterFunctorBase {
33   public:
34     GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
35     virtual void Execute()= 0;
36     FilterType * mFilter;
37   };
38  
39   //--------------------------------------------------------------------
40   template<class FilterType, class InputImageType>
41   class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
42   public:
43     GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
44     virtual void Execute() {       
45       GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
46     }
47   };
48
49   //--------------------------------------------------------------------
50   template<class FilterType>
51   class ImageTypesManager  {
52   public:
53     typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
54     typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
55     typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
56     MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
57
58     ImageTypesManager(FilterType * f) { mFilter = f;  }
59     virtual void DoIt(int dim, int ncomp, std::string pixelname) {
60       // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
61       if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
62         mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
63     }
64     template<unsigned int Dim, unsigned int NComp, class PixelType>
65     void AddNewDimensionAndPixelType() {
66         typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
67         mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] = 
68             new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
69     }
70     /// Specialization for NComp == 1
71     template<unsigned int Dim, class PixelType>
72     void AddNewDimensionAndPixelType() {
73         typedef itk::Image<PixelType,Dim> InputImageType;
74         mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] = 
75             new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
76     }
77     FilterType * mFilter;
78   };
79   //--------------------------------------------------------------------
80
81 } // end namespace
82
83 #endif // end CLITKCOMMONGENERICFILTER_H