]> Creatis software - clitk.git/blob - vv/vvImageWriter.txx
remove MACRO for vvTool and others minors stuffs
[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 == "char")
43     {
44         UpdateWithDimAndOutputPixelType<char,VImageDimension>();
45     }
46     else if (OutputPixelType == "unsigned_char")
47     {
48         UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
49     }
50     else if (OutputPixelType == "int")
51     {
52         UpdateWithDimAndOutputPixelType<int,VImageDimension>();
53     }
54     else if (OutputPixelType == "double")
55     {
56         UpdateWithDimAndOutputPixelType<double,VImageDimension>();
57     }
58     else if (OutputPixelType == "float")
59     {
60         UpdateWithDimAndOutputPixelType<float,VImageDimension>();
61     }
62     else
63     {
64         std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
65     }
66 }
67 //====================================================================
68
69 //====================================================================
70 template<class OutputPixelType, unsigned int VImageDimension>
71 void vvImageWriter::UpdateWithDimAndOutputPixelType()
72 {
73     //Create the writer
74     typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
75     typedef itk::ImageFileWriter<OutputImageType> WriterType;
76     typename WriterType::Pointer writer = WriterType::New();
77     writer->SetFileName(mOutputFilename);
78     writer->SetInput(vvImageToITK<OutputImageType>(mImage));
79     if (mUseAnObserver) {
80         writer->AddObserver(itk::ProgressEvent(), mObserver);
81     }
82     try {
83         writer->Update();
84     }
85     catch ( itk::ExceptionObject & err ) {
86         std::cerr << "Error while reading " << mOutputFilename.c_str()
87                   << " " << err << std::endl;
88         std::stringstream error;
89         error << err;
90         mLastError = error.str();
91         return;
92     }
93 }
94 //====================================================================
95
96 #endif /* end #define vvImageWriter_TXX */
97