]> Creatis software - clitk.git/blob - common/clitkCommonGenericFilter.h
Debug RTStruct conversion with empty struc
[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://www.centreleonberard.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
19 #ifndef CLITKCOMMONGENERICFILTER_H
20 #define CLITKCOMMONGENERICFILTER_H
21
22 #include "clitkCommon.h"
23 #include "clitkFilterBase.h"
24
25 /*--------------------------------------------------------------------
26   DISCLAIMER : I obviously know how to make this mess much clearer and
27   shorter, but I fear its being too long to put in this margin ...
28   D.S.
29   -------------------------------------------------------------------- */
30
31 namespace clitk {
32   
33   //--------------------------------------------------------------------
34   template<class FilterType>
35   class GenericFilterFunctorBase {
36   public:
37     GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
38     virtual ~GenericFilterFunctorBase() { delete mFilter; }
39     virtual void Execute()= 0;
40     FilterType * mFilter;
41   };
42  
43   //--------------------------------------------------------------------
44   template<class FilterType, class InputImageType>
45   class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
46   public:
47     GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
48     virtual void Execute() {       
49       GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
50     }
51   };
52
53   //--------------------------------------------------------------------
54   template<class FilterType>
55   class ImageTypesManager  {
56   public:
57     typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
58     typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
59     typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
60     MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
61
62     ImageTypesManager(FilterType * f) { mFilter = f;  }
63     virtual void DoIt(int dim, int ncomp, std::string pixelname) {
64       //std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
65       if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
66         mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
67     }
68     template<unsigned int Dim, unsigned int NComp, class PixelType>
69       void AddNewDimensionAndPixelType() {
70         typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
71         mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] = 
72             new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
73     }
74     /// Specialization for NComp == 1
75     template<unsigned int Dim, class PixelType>
76       void AddNewDimensionAndPixelType() {
77         typedef itk::Image<PixelType,Dim> InputImageType;
78         mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] = 
79             new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
80     }
81     FilterType * mFilter;
82   };
83   //--------------------------------------------------------------------
84
85 } // end namespace
86
87 #endif // end CLITKCOMMONGENERICFILTER_H