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 ===========================================================================**/
18 template<class FilterType>
19 clitk::ImageToImageGenericFilter<FilterType>::ImageToImageGenericFilter(std::string filterName) :
20 ImageToImageGenericFilterBase(filterName),
21 mImageTypesManager(static_cast<FilterType*>(this))
24 //--------------------------------------------------------------------
27 //--------------------------------------------------------------------
28 template<class FilterType>
29 bool clitk::ImageToImageGenericFilter<FilterType>::Update()
31 GetInputImageDimensionAndPixelType(m_Dim,m_PixelTypeName,m_NbOfComponents);
34 if (!CheckImageType()) {
35 if (m_FailOnImageTypeError) ImageTypeError();
36 else SetImageTypeError();
40 // Go ! Call the right templatized function
41 mImageTypesManager.DoIt(m_Dim, m_NbOfComponents, m_PixelTypeName);
44 //--------------------------------------------------------------------
46 //--------------------------------------------------------------------
47 template<class FilterType>
48 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim, unsigned int ncomp, std::string pixeltype)
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());
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61 template<class FilterType>
62 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
64 return CheckImageType(m_Dim, m_NbOfComponents, m_PixelTypeName);
66 //--------------------------------------------------------------------
69 //--------------------------------------------------------------------
70 template<class FilterType>
71 std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes()
73 std::ostringstream oss;
74 oss << "The filter <" << m_FilterName << "> manages:" << std::endl;
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();
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;
92 //--------------------------------------------------------------------