1 /*=========================================================================
5 Author : Pierre Seroul (pierre.seroul@gmail.com)
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 =========================================================================*/
24 #ifndef vvImageWriter_TXX
25 #define vvImageWriter_TXX
27 #include <itkImageFileWriter.h>
30 //====================================================================
31 template<unsigned int VImageDimension>
32 void vvImageWriter::UpdateWithDim(std::string OutputPixelType)
34 if (OutputPixelType == "short")
36 UpdateWithDimAndOutputPixelType<short,VImageDimension>();
38 else if (OutputPixelType == "unsigned short")
40 UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
42 else if (OutputPixelType == "unsigned_short")
44 UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
46 else if (OutputPixelType == "char")
48 UpdateWithDimAndOutputPixelType<char,VImageDimension>();
50 else if (OutputPixelType == "unsigned_char")
52 UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
54 else if (OutputPixelType == "int")
56 UpdateWithDimAndOutputPixelType<int,VImageDimension>();
58 else if (OutputPixelType == "double")
60 UpdateWithDimAndOutputPixelType<double,VImageDimension>();
62 else if (OutputPixelType == "float")
64 UpdateWithDimAndOutputPixelType<float,VImageDimension>();
68 std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
71 //====================================================================
73 //====================================================================
74 template<class OutputPixelType, unsigned int VImageDimension>
75 void vvImageWriter::UpdateWithDimAndOutputPixelType()
78 typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
79 typedef itk::ImageFileWriter<OutputImageType> WriterType;
80 typename WriterType::Pointer writer = WriterType::New();
81 writer->SetFileName(mOutputFilename);
82 writer->SetInput(vvImageToITK<OutputImageType>(mImage));
84 writer->AddObserver(itk::ProgressEvent(), mObserver);
89 catch ( itk::ExceptionObject & err ) {
90 std::cerr << "Error while reading " << mOutputFilename.c_str()
91 << " " << err << std::endl;
92 std::stringstream error;
94 mLastError = error.str();
98 //====================================================================
100 #endif /* end #define vvImageWriter_TXX */