NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkReadImage.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 __itkReadImage_h
16 #define __itkReadImage_h
17 
18 #include <itkImageFileReader.h>
19 
20 #include <niftkFileHelper.h>
21 
22 
23 namespace itk
24 {
25 
26 
27 
28 // --------------------------------------------------------------------------
30 // --------------------------------------------------------------------------
31 
32 template < typename TInputImage >
33 bool
34 ReadImageFromFile( const char *fileInput, const char *description,
35  typename TInputImage::Pointer &image )
36 {
37  std::string strFileInput( fileInput );
38 
39  if ( description )
40  {
41  std::string strDescription( description );
42  return ReadImageFromFile( strFileInput, image, strDescription );
43  }
44  else
45  {
46  return ReadImageFromFile( strFileInput, image );
47  }
48 }
49 
50 
51 // --------------------------------------------------------------------------
53 // --------------------------------------------------------------------------
54 
55 template < typename TInputImage >
56 bool
57 ReadImageFromFile( const char *fileInput, const char *description,
58  typename TInputImage::ConstPointer &image )
59 {
60  std::string strFileInput( fileInput );
61 
62  if ( description )
63  {
64  std::string strDescription( description );
65  return ReadImageFromFile( strFileInput, image, strDescription );
66  }
67  else
68  {
69  return ReadImageFromFile( strFileInput, image );
70  }
71 }
72 
73 
74 // --------------------------------------------------------------------------
76 // --------------------------------------------------------------------------
77 
78 template < typename TInputImage >
79 bool
80 ReadImageFromFile( std::string fileInput, typename TInputImage::Pointer &image,
81  std::string *description=0 )
82 {
83  if ( ( fileInput.length() > 0 ) && niftk::FileExists( fileInput ) )
84  {
85 
86  typedef itk::ImageFileReader< TInputImage > FileReaderType;
87 
88  typename FileReaderType::Pointer reader = FileReaderType::New();
89 
90  reader->SetFileName( fileInput );
91 
92  if ( description )
93  {
94  std::cout << "Reading " << description << " from file: "
95  << fileInput << std::endl;
96  }
97 
98  reader->Update();
99  image = reader->GetOutput();
100 
101  return true;
102  }
103 
104  return false;
105 }
106 
107 // --------------------------------------------------------------------------
109 // --------------------------------------------------------------------------
110 
111 template < typename TInputImage >
112 bool
113 ReadImageFromFile( std::string fileInput, typename TInputImage::ConstPointer &image,
114  std::string *description=0 )
115 {
116  if ( ( fileInput.length() > 0 ) && niftk::FileExists( fileInput ) )
117  {
118 
119  typedef itk::ImageFileReader< TInputImage > FileReaderType;
120 
121  typename FileReaderType::Pointer reader = FileReaderType::New();
122 
123  reader->SetFileName( fileInput );
124 
125  if ( description )
126  {
127  std::cout << "Reading " << description << " from file: "
128  << fileInput << std::endl;
129  }
130 
131  reader->Update();
132  image = reader->GetOutput();
133 
134  return true;
135  }
136 
137  return false;
138 }
139 
140 
141 
142 
143 } // end namespace itk
144 
145 #endif /* __itkReadImage_h */
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
Definition: niftkITKAffineResampleImage.cxx:74
bool ReadImageFromFile(const char *fileInput, const char *description, typename TInputImage::Pointer &image)
Read an ITK image to a file and print a message.
Definition: itkReadImage.h:34
bool FileExists(const std::string &fileName)
Definition: niftkFileHelper.cxx:233
GLsizei const GLcharARB ** string
Definition: glew.h:5194