]> Creatis software - clitk.git/blob - vv/vvImageWriter.txx
added the new headers
[clitk.git] / vv / vvImageWriter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef vvImageWriter_TXX
19 #define vvImageWriter_TXX
20 #include <itkImageFileWriter.h>
21 #include "vvToITK.h"
22
23 //====================================================================
24 template<unsigned int VImageDimension>
25 void vvImageWriter::UpdateWithDim(std::string OutputPixelType)
26 {
27     if (OutputPixelType == "short")
28     {
29         UpdateWithDimAndOutputPixelType<short,VImageDimension>();
30     }
31     else if (OutputPixelType == "unsigned short")
32     {
33         UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
34     }
35     else if (OutputPixelType == "unsigned_short")
36     {
37         UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
38     }
39     else if (OutputPixelType == "char")
40     {
41         UpdateWithDimAndOutputPixelType<char,VImageDimension>();
42     }
43     else if (OutputPixelType == "unsigned_char")
44     {
45         UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
46     }
47     else if (OutputPixelType == "int")
48     {
49         UpdateWithDimAndOutputPixelType<int,VImageDimension>();
50     }
51     else if (OutputPixelType == "double")
52     {
53         UpdateWithDimAndOutputPixelType<double,VImageDimension>();
54     }
55     else if (OutputPixelType == "float")
56     {
57         UpdateWithDimAndOutputPixelType<float,VImageDimension>();
58     }
59     else
60     {
61         std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
62     }
63 }
64 //====================================================================
65
66 //====================================================================
67 template<class OutputPixelType, unsigned int VImageDimension>
68 void vvImageWriter::UpdateWithDimAndOutputPixelType()
69 {
70     //Create the writer
71     typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
72     typedef itk::ImageFileWriter<OutputImageType> WriterType;
73     typename WriterType::Pointer writer = WriterType::New();
74     writer->SetFileName(mOutputFilename);
75     writer->SetInput(vvImageToITK<OutputImageType>(mImage));
76     if (mUseAnObserver) {
77         writer->AddObserver(itk::ProgressEvent(), mObserver);
78     }
79     try {
80         writer->Update();
81     }
82     catch ( itk::ExceptionObject & err ) {
83         std::cerr << "Error while reading " << mOutputFilename.c_str()
84                   << " " << err << std::endl;
85         std::stringstream error;
86         error << err;
87         mLastError = error.str();
88         return;
89     }
90 }
91 //====================================================================
92
93 #endif /* end #define vvImageWriter_TXX */
94