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 ======================================================================-====*/
18 #ifndef CLITKCOMMONGENERICFILTER_H
19 #define CLITKCOMMONGENERICFILTER_H
20 #include "clitkCommon.h"
22 /*--------------------------------------------------------------------
23 DISCLAIMER : I obviously know how to make this mess much clearer and
24 shorter, but I fear its being too long to put in this margin ...
26 -------------------------------------------------------------------- */
30 //--------------------------------------------------------------------
31 template<class FilterType>
32 class GenericFilterFunctorBase {
34 GenericFilterFunctorBase(FilterType * f) { mFilter = f; }
35 virtual void Execute()= 0;
39 //--------------------------------------------------------------------
40 template<class FilterType, class InputImageType>
41 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
43 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
44 virtual void Execute() {
45 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
49 //--------------------------------------------------------------------
50 template<class FilterType>
51 class ImageTypesManager {
53 typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
54 typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
55 typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
56 MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
58 ImageTypesManager(FilterType * f) { mFilter = f; }
59 virtual void DoIt(int dim, int ncomp, std::string pixelname) {
60 // std::cout << "ImageTypesManager DoIt " << dim << " " << pixelname << std::endl;
61 if (mMapOfImageTypeToFunction[dim][ncomp][pixelname])
62 mMapOfImageTypeToFunction[dim][ncomp][pixelname]->Execute();
64 template<unsigned int Dim, unsigned int NComp, class PixelType>
65 void AddNewDimensionAndPixelType() {
66 typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
67 mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] =
68 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
70 /// Specialization for NComp == 1
71 template<unsigned int Dim, class PixelType>
72 void AddNewDimensionAndPixelType() {
73 typedef itk::Image<PixelType,Dim> InputImageType;
74 mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] =
75 new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
79 //--------------------------------------------------------------------
83 #endif // end CLITKCOMMONGENERICFILTER_H