1 /*=========================================================================
4 Module: $RCSfile: clitkCommonGenericFilter.h,v $
6 Date: $Date: 2010/02/09 14:19:28 $
7 Version: $Revision: 1.3 $
8 Author : Joel Schaerer <joel.schaerer@creatis.insa-lyon.fr>
9 David Sarrut <david.sarrut@creatis.insa-lyon.fr>
12 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
13 CREATIS-LRMN http://www.creatis.insa-lyon.fr
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.
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.
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/>.
27 =========================================================================*/
29 #ifndef CLITKCOMMONGENERICFILTER_H
30 #define CLITKCOMMONGENERICFILTER_H
33 #include "clitkCommon.h"
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 ...
39 -------------------------------------------------------------------- */
43 //--------------------------------------------------------------------
44 template<class FilterType>
45 class GenericFilterFunctorBase {
47 GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
48 virtual void Execute()= 0;
52 //--------------------------------------------------------------------
53 template<class FilterType, class InputImageType>
54 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
56 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
57 virtual void Execute() {
58 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
62 //--------------------------------------------------------------------
63 template<class FilterType>
64 class ImageTypesManager {
66 typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
67 typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
68 typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
69 MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
71 ImageTypesManager(FilterType * f) { mFilter = f; }
72 virtual void DoIt(int dim, int ncomp, std::string pixelname) {
73 // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
74 if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
75 mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
77 template<unsigned int Dim, unsigned int NComp, class PixelType>
78 void AddNewDimensionAndPixelType() {
79 typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
80 mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] =
81 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
83 /// Specialization for NComp == 1
84 template<unsigned int Dim, class PixelType>
85 void AddNewDimensionAndPixelType() {
86 typedef itk::Image<PixelType,Dim> InputImageType;
87 mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] =
88 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
92 //--------------------------------------------------------------------
96 #endif // end CLITKCOMMONGENERICFILTER_H