1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #ifndef CLITKCOMMONGENERICFILTER_H
20 #define CLITKCOMMONGENERICFILTER_H
22 #include "clitkCommon.h"
23 #include "clitkFilterBase.h"
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 ...
29 -------------------------------------------------------------------- */
33 //--------------------------------------------------------------------
34 template<class FilterType>
35 class GenericFilterFunctorBase {
37 GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
38 virtual ~GenericFilterFunctorBase() { delete mFilter; }
39 virtual void Execute()= 0;
43 //--------------------------------------------------------------------
44 template<class FilterType, class InputImageType>
45 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
47 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
48 virtual void Execute() {
49 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
53 //--------------------------------------------------------------------
54 template<class FilterType>
55 class ImageTypesManager {
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;
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();
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);
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);
83 //--------------------------------------------------------------------
87 #endif // end CLITKCOMMONGENERICFILTER_H