1 /*=========================================================================
4 Module: $RCSfile: clitkCommonGenericFilter.h,v $
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>
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 DoIt()= 0;
52 //--------------------------------------------------------------------
53 template<class FilterType, unsigned int Dim, class PixelType>
54 class GenericFilterFunctorWithDimAndPixelType: public GenericFilterFunctorBase<FilterType> {
56 GenericFilterFunctorWithDimAndPixelType(FilterType * f): GenericFilterFunctorBase<FilterType>(f) {}
58 //GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithDimAndPixelType<Dim,PixelType>();
59 typedef itk::Image<PixelType,Dim> InputImageType;
60 GenericFilterFunctorBase<FilterType>::mFilter->template UpdateWithInputImageType<InputImageType>();
64 //--------------------------------------------------------------------
65 template<class FilterType>
66 class ImageTypesManager {
68 typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
69 std::map<int, MapOfPixelTypeToFunctionType> mMapOfImageTypeToFunction;
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();
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);
86 //--------------------------------------------------------------------
90 #endif // end CLITKCOMMONGENERICFILTER_H