]> Creatis software - clitk.git/blob - vv/vvImageWriter.txx
upport
[clitk.git] / vv / vvImageWriter.txx
1 /*=========================================================================
2
3  Program:   vv
4  Module:    $RCSfile: vvImageWriter.txx,v $
5  Language:  C++
6  Date:      $Date: 2010/01/06 13:31:57 $
7  Version:   $Revision: 1.1 $
8  Author :   Pierre Seroul (pierre.seroul@gmail.com)
9
10 Copyright (C) 2008
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 =========================================================================*/
27 #ifndef vvImageWriter_TXX
28 #define vvImageWriter_TXX
29
30 #include <itkImageFileWriter.h>
31 #include "vvToITK.h"
32
33 //====================================================================
34 template<unsigned int VImageDimension>
35 void vvImageWriter::UpdateWithDim(std::string OutputPixelType)
36 {
37     if (OutputPixelType == "short")
38     {
39         UpdateWithDimAndOutputPixelType<short,VImageDimension>();
40     }
41     else if (OutputPixelType == "unsigned_short")
42     {
43         UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
44     }
45     else if (OutputPixelType == "char")
46     {
47         UpdateWithDimAndOutputPixelType<char,VImageDimension>();
48     }
49     else if (OutputPixelType == "unsigned_char")
50     {
51         UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
52     }
53     else if (OutputPixelType == "int")
54     {
55         UpdateWithDimAndOutputPixelType<int,VImageDimension>();
56     }
57     else if (OutputPixelType == "double")
58     {
59         UpdateWithDimAndOutputPixelType<double,VImageDimension>();
60     }
61     else if (OutputPixelType == "float")
62     {
63         UpdateWithDimAndOutputPixelType<float,VImageDimension>();
64     }
65     else
66     {
67         std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
68     }
69 }
70 //====================================================================
71
72 //====================================================================
73 template<class OutputPixelType, unsigned int VImageDimension>
74 void vvImageWriter::UpdateWithDimAndOutputPixelType()
75 {
76     //Create the writer
77     typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
78     typedef itk::ImageFileWriter<OutputImageType> WriterType;
79     typename WriterType::Pointer writer = WriterType::New();
80     writer->SetFileName(mOutputFilename);
81     writer->SetInput(vvImageToITK<OutputImageType>(mImage));
82     if (mUseAnObserver) {
83         writer->AddObserver(itk::ProgressEvent(), mObserver);
84     }
85     try {
86         writer->Update();
87     }
88     catch ( itk::ExceptionObject & err ) {
89         std::cerr << "Error while reading " << mOutputFilename.c_str()
90                   << " " << err << std::endl;
91         std::stringstream error;
92         error << err;
93         mLastError = error.str();
94         return;
95     }
96 }
97 //====================================================================
98
99 #endif /* end #define vvImageWriter_TXX */
100