NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkWriteImage.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef __itkWriteImage_h
16 #define __itkWriteImage_h
17 
18 #include <itkImageFileWriter.h>
19 
20 
21 namespace itk
22 {
23 
24 
25 
26 // --------------------------------------------------------------------------
28 // --------------------------------------------------------------------------
29 
30 template < typename TOutputImage >
31 void
32 WriteImageToFile( const char *fileOutput, const char *description,
33  typename TOutputImage::Pointer image )
34 {
35  if ( fileOutput ) {
36 
37  typedef itk::ImageFileWriter< TOutputImage > FileWriterType;
38 
39  typename FileWriterType::Pointer writer = FileWriterType::New();
40 
41  writer->SetFileName( fileOutput );
42  writer->SetInput( image );
43 
44  std::cout << "Writing " << description << " to file: "
45  << fileOutput << std::endl;
46 
47  writer->Update();
48  }
49 }
50 
51 // --------------------------------------------------------------------------
53 // --------------------------------------------------------------------------
54 
55 template < typename TOutputImage >
56 void
57 WriteImageToFile( const char *fileOutput, const char *description,
58  typename TOutputImage::ConstPointer image )
59 {
60  if ( fileOutput ) {
61 
62  typedef itk::ImageFileWriter< TOutputImage > FileWriterType;
63 
64  typename FileWriterType::Pointer writer = FileWriterType::New();
65 
66  writer->SetFileName( fileOutput );
67  writer->SetInput( image );
68 
69  std::cout << "Writing " << description << " to file: "
70  << fileOutput << std::endl;
71 
72  writer->Update();
73  }
74 }
75 
76 
77 // --------------------------------------------------------------------------
79 // --------------------------------------------------------------------------
80 
81 template < typename TOutputImage >
82 void
83 WriteImageToFile( std::string fileOutput, typename TOutputImage::Pointer image,
84  std::string *description=0 )
85 {
86  if ( fileOutput.length() > 0 ) {
87 
88  typedef itk::ImageFileWriter< TOutputImage > FileWriterType;
89 
90  typename FileWriterType::Pointer writer = FileWriterType::New();
91 
92  writer->SetFileName( fileOutput );
93  writer->SetInput( image );
94 
95  if ( description )
96  {
97  std::cout << "Writing " << description << " to file: "
98  << fileOutput << std::endl;
99  }
100 
101  writer->Update();
102  }
103 }
104 
105 // --------------------------------------------------------------------------
107 // --------------------------------------------------------------------------
108 
109 template < typename TOutputImage >
110 void
111 WriteImageToFile( std::string fileOutput, typename TOutputImage::ConstPointer image,
112  std::string *description=0 )
113 {
114  if ( fileOutput.length() > 0 ) {
115 
116  typedef itk::ImageFileWriter< TOutputImage > FileWriterType;
117 
118  typename FileWriterType::Pointer writer = FileWriterType::New();
119 
120  writer->SetFileName( fileOutput );
121  writer->SetInput( image );
122 
123  if ( description )
124  {
125  std::cout << "Writing " << description << " to file: "
126  << fileOutput << std::endl;
127  }
128 
129  writer->Update();
130  }
131 }
132 
133 
134 
135 
136 } // end namespace itk
137 
138 #endif /* __itkWriteImage_h */
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
void WriteImageToFile(const char *fileOutput, const char *description, typename TOutputImage::Pointer image)
Write an ITK image to a file and print a message.
Definition: itkWriteImage.h:32
Definition: niftkITKAffineResampleImage.cxx:74
GLsizei const GLcharARB ** string
Definition: glew.h:5194