1 /*=========================================================================
4 Module: $RCSfile: clitkImageToImageGenericFilter.txx,v $
6 Date: $Date: 2010/02/18 14:47:20 $
7 Version: $Revision: 1.6 $
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 //--------------------------------------------------------------------
30 template<class ImageType>
31 void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output) {
32 if (mOutputFilenames.size())
34 clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
35 mOutputFilenames.pop_front();
37 if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
38 mOutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
40 //--------------------------------------------------------------------
43 //--------------------------------------------------------------------
44 template<class ImageType>
45 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n) {
46 if (mInputFilenames.size() > n) {
47 return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
49 else if (mInputVVImages.size() > n)
50 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
53 assert(false); //No input, this shouldn't happen
54 return typename ImageType::Pointer(NULL);
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61 template<class FilterType>
62 clitk::ImageToImageGenericFilter<FilterType>::ImageToImageGenericFilter(std::string filterName) :
63 ImageToImageGenericFilterBase(filterName),
64 mImageTypesManager(static_cast<FilterType*>(this))
67 //--------------------------------------------------------------------
70 //--------------------------------------------------------------------
71 template<class FilterType>
72 bool clitk::ImageToImageGenericFilter<FilterType>::Update() {
73 GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);
76 if (!CheckImageType()) {
77 if (mFailOnImageTypeError) ImageTypeError();
78 else SetImageTypeError();
82 // Go ! Call the right templatized function
83 mImageTypesManager.DoIt(mDim, mNbOfComponents, mPixelTypeName);
86 //--------------------------------------------------------------------
87 template<class FilterType>
88 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype)
90 return static_cast<bool>(mImageTypesManager.mMapOfImageTypeToFunction[dim][ncomp][pixeltype]);
93 template<class FilterType>
94 bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
96 return static_cast<bool>(mImageTypesManager.mMapOfImageTypeToFunction[mDim][mNbOfComponents][mPixelTypeName]);
99 template<class FilterType>
100 std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes() {
101 std::ostringstream oss;
102 oss << "The filter <" << mFilterName << "> manages:" << std::endl;
104 typedef typename ImageTypesManager<FilterType>::MapOfImageComponentsToFunctionType::const_iterator MCompItType;
105 typedef typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType::const_iterator MDimItType;
106 typedef typename ImageTypesManager<FilterType>::MapOfPixelTypeToFunctionType::const_iterator MPixelItType;
107 for (MDimItType i=mImageTypesManager.mMapOfImageTypeToFunction.begin();
108 i!=mImageTypesManager.mMapOfImageTypeToFunction.end();
110 for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) {
111 for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) {
112 oss << "Dim: " << (*i).first
113 << ", Components: " << (*j).first
114 << ", Type: " << (*k).first << std::endl;
120 //--------------------------------------------------------------------