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://oncora1.lyon.fnclcc.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"
24 /*--------------------------------------------------------------------
25 DISCLAIMER : I obviously know how to make this mess much clearer and
26 shorter, but I fear its being too long to put in this margin ...
28 -------------------------------------------------------------------- */
32 //--------------------------------------------------------------------
33 template<class FilterType>
34 class GenericFilterFunctorBase {
36 GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
37 virtual ~GenericFilterFunctorBase() { delete mFilter; }
38 virtual void Execute()= 0;
42 //--------------------------------------------------------------------
43 template<class FilterType, class InputImageType>
44 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
46 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
47 virtual void Execute() {
48 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
52 //--------------------------------------------------------------------
53 template<class FilterType>
54 class ImageTypesManager {
56 typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
57 typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
58 typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
59 MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
61 ImageTypesManager(FilterType * f) { mFilter = f; }
62 virtual void DoIt(int dim, int ncomp, std::string pixelname) {
63 // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
64 if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
65 mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
67 template<unsigned int Dim, unsigned int NComp, class PixelType>
68 void AddNewDimensionAndPixelType() {
69 typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
70 mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] =
71 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
73 /// Specialization for NComp == 1
74 template<unsigned int Dim, class PixelType>
75 void AddNewDimensionAndPixelType() {
76 typedef itk::Image<PixelType,Dim> InputImageType;
77 mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] =
78 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
82 //--------------------------------------------------------------------
86 #endif // end CLITKCOMMONGENERICFILTER_H