]> Creatis software - clitk.git/blob - vv/vvImageWriter.txx
Reformatted using new coding style
[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     UpdateWithDimAndOutputPixelType<short,VImageDimension>();
29   } else if (OutputPixelType == "unsigned short") {
30     UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
31   } else if (OutputPixelType == "unsigned_short") {
32     UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
33   } else if (OutputPixelType == "char") {
34     UpdateWithDimAndOutputPixelType<char,VImageDimension>();
35   } else if (OutputPixelType == "unsigned_char") {
36     UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
37   } else if (OutputPixelType == "int") {
38     UpdateWithDimAndOutputPixelType<int,VImageDimension>();
39   } else if (OutputPixelType == "double") {
40     UpdateWithDimAndOutputPixelType<double,VImageDimension>();
41   } else if (OutputPixelType == "float") {
42     UpdateWithDimAndOutputPixelType<float,VImageDimension>();
43   } else {
44     std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
45   }
46 }
47 //====================================================================
48
49 //====================================================================
50 template<class OutputPixelType, unsigned int VImageDimension>
51 void vvImageWriter::UpdateWithDimAndOutputPixelType()
52 {
53   //Create the writer
54   typedef itk::Image< OutputPixelType, VImageDimension > OutputImageType;
55   typedef itk::ImageFileWriter<OutputImageType> WriterType;
56   typename WriterType::Pointer writer = WriterType::New();
57   writer->SetFileName(mOutputFilename);
58   writer->SetInput(vvImageToITK<OutputImageType>(mImage));
59   if (mUseAnObserver) {
60     writer->AddObserver(itk::ProgressEvent(), mObserver);
61   }
62   try {
63     writer->Update();
64   } catch ( itk::ExceptionObject & err ) {
65     std::cerr << "Error while reading " << mOutputFilename.c_str()
66               << " " << err << std::endl;
67     std::stringstream error;
68     error << err;
69     mLastError = error.str();
70     return;
71   }
72 }
73 //====================================================================
74
75 #endif /* end #define vvImageWriter_TXX */
76