1 /*=========================================================================
4 Module: $RCSfile: vvImageWriter.txx,v $
6 Date: $Date: 2010/01/06 13:31:57 $
7 Version: $Revision: 1.1 $
8 Author : Pierre Seroul (pierre.seroul@gmail.com)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
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.
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.
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/>.
26 =========================================================================*/
27 #ifndef vvImageWriter_TXX
28 #define vvImageWriter_TXX
30 #include <itkImageFileWriter.h>
33 //====================================================================
34 template<unsigned int VImageDimension>
35 void vvImageWriter::UpdateWithDim(std::string OutputPixelType)
37 if (OutputPixelType == "short")
39 UpdateWithDimAndOutputPixelType<short,VImageDimension>();
41 else if (OutputPixelType == "unsigned_short")
43 UpdateWithDimAndOutputPixelType<unsigned short,VImageDimension>();
45 else if (OutputPixelType == "char")
47 UpdateWithDimAndOutputPixelType<char,VImageDimension>();
49 else if (OutputPixelType == "unsigned_char")
51 UpdateWithDimAndOutputPixelType<unsigned char,VImageDimension>();
53 else if (OutputPixelType == "int")
55 UpdateWithDimAndOutputPixelType<int,VImageDimension>();
57 else if (OutputPixelType == "double")
59 UpdateWithDimAndOutputPixelType<double,VImageDimension>();
61 else if (OutputPixelType == "float")
63 UpdateWithDimAndOutputPixelType<float,VImageDimension>();
67 std::cerr << "Error, output pixel type : \"" << OutputPixelType << "\" unknown !" << std::endl;
70 //====================================================================
72 //====================================================================
73 template<class OutputPixelType, unsigned int VImageDimension>
74 void vvImageWriter::UpdateWithDimAndOutputPixelType()
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));
83 writer->AddObserver(itk::ProgressEvent(), mObserver);
88 catch ( itk::ExceptionObject & err ) {
89 std::cerr << "Error while reading " << mOutputFilename.c_str()
90 << " " << err << std::endl;
91 std::stringstream error;
93 mLastError = error.str();
97 //====================================================================
99 #endif /* end #define vvImageWriter_TXX */