]> Creatis software - clitk.git/blob - common/clitkCommonGenericFilter.h
- new GF system
[clitk.git] / common / clitkCommonGenericFilter.h
1 /*=========================================================================
2
3   Program:   clitk
4   Module:    $RCSfile: clitkCommonGenericFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2010/01/29 08:48:42 $
7   Version:   $Revision: 1.1 $
8   Author :   Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
9              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
10
11   Copyright (C) 2008
12   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
13   CREATIS-LRMN http://www.creatis.insa-lyon.fr
14
15   This program is free software: you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation, version 3 of the License.
18
19   This program is distributed in the hope that it will be useful,
20   but WITHOUT ANY WARRANTY; without even the implied warranty of
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   GNU General Public License for more details.
23
24   You should have received a copy of the GNU General Public License
25   along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27   =========================================================================*/
28
29 #ifndef CLITKCOMMONGENERICFILTER_H
30 #define CLITKCOMMONGENERICFILTER_H
31
32 // clitk include
33 #include "clitkCommon.h"
34
35 /*--------------------------------------------------------------------
36   DISCLAIMER : I obviously know how to make this mess much clearer and
37   shorter, but I fear its being too long to put in this margin ...
38   D.S.
39   -------------------------------------------------------------------- */
40
41 namespace clitk {
42   
43   //--------------------------------------------------------------------
44   template<class FilterType>
45   class GenericFilterFunctorBase {
46   public:
47     GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
48     virtual void DoIt()= 0;
49     FilterType * mFilter;
50   };
51  
52   //--------------------------------------------------------------------
53   template<class FilterType, unsigned int Dim, class PixelType>
54   class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
55   public:
56     GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
57     virtual void DoIt() {       
58       //GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithDimAndPixelType<Dim,PixelType>();
59       typedef itk::Image<PixelType,Dim> InputImageType;
60       GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
61     }
62   };
63
64   //--------------------------------------------------------------------
65   template<class FilterType>
66   class ImageTypesManager  {
67   public:
68     typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
69     std::map<int, MapOfPixelTypeToFunctionType> mMapOfImageTypeToFunction;
70
71     ImageTypesManager(FilterType * f) { mFilter = f;  }
72     virtual void DoIt(int dim, std::string pixelname) {
73       // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
74       if (mMapOfImageTypeToFunction[dim][pixelname])
75         mMapOfImageTypeToFunction[dim][pixelname]->DoIt();
76     }
77     template<unsigned int Dim, class Pixeltype>
78     void AddNewDimensionAndPixelType() {
79       // std::cout << "Adding Dim=" << Dim << " and PT = " << GetTypeAsString<Pixeltype>() << std::endl;
80       mFilter->AddImageType(Dim, GetTypeAsString<Pixeltype>());
81       mMapOfImageTypeToFunction[Dim][ GetTypeAsString<Pixeltype>() ] = 
82         new GenericFilterFunctorWithDimAndPixelType<FilterType, Dim, Pixeltype>(mFilter);
83     }
84     FilterType * mFilter;
85   };
86   //--------------------------------------------------------------------
87
88 } // end namespace
89
90 #endif // end CLITKCOMMONGENERICFILTER_H