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 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() {
30 GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);
33 if (!CheckImageType()) {
34 if (mFailOnImageTypeError) ImageTypeError();
35 else SetImageTypeError();
39 // Go ! Call the right templatized function
40 mImageTypesManager.DoIt(mDim, mNbOfComponents, mPixelTypeName);
43 //--------------------------------------------------------------------
45 //--------------------------------------------------------------------
46 template<class FilterType>
47 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim, unsigned int ncomp, std::string pixeltype)
48 { //SR: commented line creates an element in mMapOfImageTypeToFunction which, even if 0, is confusing, e.g. for GetAvailableImageTypes
49 //return static_cast<bool>(mImageTypesManager.mMapOfImageTypeToFunction[dim][ncomp][pixeltype]);
50 typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType &m = mImageTypesManager.mMapOfImageTypeToFunction;
51 return (m .find(dim) != m.end() &&
52 m[dim] .find(ncomp) != m[dim].end() &&
53 m[dim][ncomp].find(pixeltype) != m[dim][ncomp].end());
55 //--------------------------------------------------------------------
58 //--------------------------------------------------------------------
59 template<class FilterType>
60 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
62 return CheckImageType(mDim, mNbOfComponents, mPixelTypeName);
64 //--------------------------------------------------------------------
67 //--------------------------------------------------------------------
68 template<class FilterType>
69 std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes() {
70 std::ostringstream oss;
71 oss << "The filter <" << mFilterName << "> manages:" << std::endl;
73 typedef typename ImageTypesManager<FilterType>::MapOfImageComponentsToFunctionType::const_iterator MCompItType;
74 typedef typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType::const_iterator MDimItType;
75 typedef typename ImageTypesManager<FilterType>::MapOfPixelTypeToFunctionType::const_iterator MPixelItType;
76 for (MDimItType i=mImageTypesManager.mMapOfImageTypeToFunction.begin();
77 i!=mImageTypesManager.mMapOfImageTypeToFunction.end();
79 for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) {
80 for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) {
81 oss << "Dim: " << (*i).first;
82 if ((*j).first != 1) oss << ", Components: " << (*j).first;
83 oss << ", Type: " << (*k).first << std::endl;
89 //--------------------------------------------------------------------