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