]> Creatis software - clitk.git/blob - vv/vvImageWriter.txx
Fixed compilation with VC++ 9
[clitk.git] / vv / vvImageWriter.txx
1 /*=========================================================================
2
3  Program:   vv
4  Language:  C++
5  Author :   Pierre Seroul (pierre.seroul@gmail.com)
6
7 Copyright (C) 2008
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
10
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.
14
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.
19
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/>.
22
23 =========================================================================*/
24 #ifndef vvImageWriter_TXX
25 #define vvImageWriter_TXX
26
27 #include <itkImageFileWriter.h>
28 #include "vvToITK.h"
29
30 //====================================================================
31 template<unsigned int VImageDimension>
32 void vvImageWriter::UpdateWithDim(std::string OutputPixelType)
33 {
34     if (OutputPixelType == "short")
35     {
36         UpdateWithDimAndOutputPixelType<short,VImageDimension>();
37     }
38     else if (OutputPixelType == "unsigned short")
39     {
40         UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
41     }
42     else if (OutputPixelType == "unsigned_short")
43     {
44         UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
45     }
46     else if (OutputPixelType == "char")
47     {
48         UpdateWithDimAndOutputPixelType<char,VImageDimension>();
49     }
50     else if (OutputPixelType == "unsigned_char")
51     {
52         UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
53     }
54     else if (OutputPixelType == "int")
55     {
56         UpdateWithDimAndOutputPixelType<int,VImageDimension>();
57     }
58     else if (OutputPixelType == "double")
59     {
60         UpdateWithDimAndOutputPixelType<double,VImageDimension>();
61     }
62     else if (OutputPixelType == "float")
63     {
64         UpdateWithDimAndOutputPixelType<float,VImageDimension>();
65     }
66     else
67     {
68         std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
69     }
70 }
71 //====================================================================
72
73 //====================================================================
74 template<class OutputPixelType, unsigned int VImageDimension>
75 void vvImageWriter::UpdateWithDimAndOutputPixelType()
76 {
77     //Create the writer
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));
83     if (mUseAnObserver) {
84         writer->AddObserver(itk::ProgressEvent(), mObserver);
85     }
86     try {
87         writer->Update();
88     }
89     catch ( itk::ExceptionObject & err ) {
90         std::cerr << "Error while reading " << mOutputFilename.c_str()
91                   << " " << err << std::endl;
92         std::stringstream error;
93         error << err;
94         mLastError = error.str();
95         return;
96     }
97 }
98 //====================================================================
99
100 #endif /* end #define vvImageWriter_TXX */
101