]> Creatis software - clitk.git/blob - common/clitkImageToImageGenericFilter.txx
Merge branch 'master' of https://github.com/open-vv/vv
[clitk.git] / common / clitkImageToImageGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 template<class FilterType>
19 clitk::ImageToImageGenericFilter<FilterType>::ImageToImageGenericFilter(std::string filterName) :
20   ImageToImageGenericFilterBase(filterName),
21   mImageTypesManager(static_cast<FilterType*>(this))
22 {
23 }
24 //--------------------------------------------------------------------
25
26
27 //--------------------------------------------------------------------
28 template<class FilterType>
29 bool clitk::ImageToImageGenericFilter<FilterType>::Update()
30 {
31   GetInputImageDimensionAndPixelType(m_Dim,m_PixelTypeName,m_NbOfComponents);
32
33   // Check ImageType
34   if (!CheckImageType()) {
35     if (m_FailOnImageTypeError) ImageTypeError();
36     else SetImageTypeError();
37     return false;
38   }
39
40   // Go ! Call the right templatized function
41   mImageTypesManager.DoIt(m_Dim, m_NbOfComponents, m_PixelTypeName);
42   return true;
43 }
44 //--------------------------------------------------------------------
45
46 //--------------------------------------------------------------------
47 template<class FilterType>
48 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim, unsigned int ncomp, std::string pixeltype)
49 {
50   //SR: commented line creates an element in mMapOfImageTypeToFunction which, even if 0, is confusing, e.g. for GetAvailableImageTypes
51   //return static_cast<bool>(mImageTypesManager.mMapOfImageTypeToFunction[dim][ncomp][pixeltype]);
52   typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType &m = mImageTypesManager.mMapOfImageTypeToFunction;
53   return (m            .find(dim)       != m.end()      &&
54           m[dim]       .find(ncomp)     != m[dim].end() &&
55           m[dim][ncomp].find(pixeltype) != m[dim][ncomp].end());
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 template<class FilterType>
62 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
63 {
64   return CheckImageType(m_Dim, m_NbOfComponents, m_PixelTypeName);
65 }
66 //--------------------------------------------------------------------
67
68
69 //--------------------------------------------------------------------
70 template<class FilterType>
71 std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes()
72 {
73   std::ostringstream oss;
74   oss << "The filter <" << m_FilterName << "> manages:" << std::endl;
75
76   typedef typename ImageTypesManager<FilterType>::MapOfImageComponentsToFunctionType::const_iterator MCompItType;
77   typedef typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType::const_iterator MDimItType;
78   typedef typename ImageTypesManager<FilterType>::MapOfPixelTypeToFunctionType::const_iterator MPixelItType;
79   for (MDimItType i=mImageTypesManager.mMapOfImageTypeToFunction.begin();
80        i!=mImageTypesManager.mMapOfImageTypeToFunction.end();
81        i++) {
82     for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) {
83       for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) {
84         oss << "Dim: " << (*i).first;
85         if ((*j).first != 1) oss << ", Components: " << (*j).first;
86         oss << ", Type: " << (*k).first << std::endl;
87       }
88     }
89   }
90   return oss.str();
91 }
92 //--------------------------------------------------------------------
93