SimpleITK  
sitkImageFileReader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef sitkImageFileReader_h
19 #define sitkImageFileReader_h
20 
21 #include "sitkMacro.h"
22 #include "sitkImage.h"
23 #include "sitkImageReaderBase.h"
25 
26 
27 namespace itk
28 {
29 
30 class MetaDataDictionary;
31 
32 namespace simple
33 {
34 
75 {
76 public:
78 
79  ~ImageFileReader() override;
80 
82 
84  std::string
85  ToString() const override;
86 
88  std::string
89  GetName() const override
90  {
91  return std::string("ImageFileReader");
92  }
93 
94  SITK_RETURN_SELF_TYPE_HEADER
95  SetFileName(const PathType & fn);
96  PathType
97  GetFileName() const;
98 
99  Image
100  Execute() override;
101 
102  // Interface methods to access image file's meta-data and image
103  // information after calling Execute or after calling
104  // MetaDataRead, which does not load the bulk pixel data.
105 
114  void
115  ReadImageInformation();
116 
132  GetPixelID() const;
134  GetPixelIDValue() const;
135  unsigned int
136  GetDimension() const;
137  unsigned int
138  GetNumberOfComponents() const;
139  const std::vector<double> &
140  GetOrigin() const;
141  const std::vector<double> &
142  GetSpacing() const;
143  const std::vector<double> &
144  GetDirection() const;
145  const std::vector<uint64_t> &
146  GetSize() const;
158  std::vector<std::string>
159  GetMetaDataKeys() const;
160 
163  bool
164  HasMetaDataKey(const std::string & key) const;
165 
174  std::string
175  GetMetaData(const std::string & key) const;
176 
177 
204  SITK_RETURN_SELF_TYPE_HEADER
205  SetExtractSize(const std::vector<unsigned int> & size);
206  const std::vector<unsigned int> &
207  GetExtractSize() const;
208 
209 
216  SITK_RETURN_SELF_TYPE_HEADER
217  SetExtractIndex(const std::vector<int> & index);
218  const std::vector<int> &
219  GetExtractIndex() const;
220 
221 protected:
222  template <class TImageType>
223  Image
224  ExecuteInternal(itk::ImageIOBase *);
225 
229  void
230  UpdateImageInformationFromImageIO(const itk::ImageIOBase * iobase);
231 
232 private:
233  // Internal method used implement extracting a region from the reader
234  template <class TImageType, class TInternalImageType>
235  Image
236  ExecuteExtract(TInternalImageType * itkImage);
237 
238  // function pointer type
239  typedef Image (Self::*MemberFunctionType)(itk::ImageIOBase *);
240 
241  // friend to get access to executeInternal member
242  friend struct detail::MemberFunctionAddressor<MemberFunctionType>;
243  std::unique_ptr<detail::MemberFunctionFactory<MemberFunctionType>> m_MemberFactory;
244 
245 
246  std::function<std::vector<std::string>()> m_pfGetMetaDataKeys;
247  std::function<bool(const std::string &)> m_pfHasMetaDataKey;
248  std::function<std::string(const std::string &)> m_pfGetMetaData;
249 
251 
252  std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary;
253 
255  unsigned int m_Dimension;
256  unsigned int m_NumberOfComponents;
257  std::vector<double> m_Direction;
258  std::vector<double> m_Origin;
259  std::vector<double> m_Spacing;
260 
261  std::vector<uint64_t> m_Size;
262 
263  std::vector<unsigned int> m_ExtractSize;
264  std::vector<int> m_ExtractIndex;
265 };
266 
279 ReadImage(const PathType & filename, PixelIDValueEnum outputPixelType = sitkUnknown, const std::string & imageIO = "");
280 } // namespace simple
281 } // namespace itk
282 
283 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::ImageIOBase
itk::simple::ImageFileReader::m_Size
std::vector< uint64_t > m_Size
Definition: sitkImageFileReader.h:261
itk::simple::ImageFileReader::m_Dimension
unsigned int m_Dimension
Definition: sitkImageFileReader.h:255
itk::simple::ImageFileReader::m_ExtractSize
std::vector< unsigned int > m_ExtractSize
Definition: sitkImageFileReader.h:263
itk::simple::detail::MemberFunctionAddressor
Definition: sitkDetail.h:29
SITKIO_EXPORT
#define SITKIO_EXPORT
Definition: sitkIO.h:33
itk::simple::ImageFileReader::m_ExtractIndex
std::vector< int > m_ExtractIndex
Definition: sitkImageFileReader.h:264
sitkImage.h
itk::simple::ImageFileReader
Read an image file and return a SimpleITK Image.
Definition: sitkImageFileReader.h:74
itk::simple::ImageFileReader::m_MetaDataDictionary
std::unique_ptr< MetaDataDictionary > m_MetaDataDictionary
Definition: sitkImageFileReader.h:252
itk::simple::ReadImage
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
itk::simple::PixelIDValueEnum
PixelIDValueEnum
Enumerated values of pixelIDs.
Definition: sitkPixelIDValues.h:100
itk::simple::ImageFileReader::m_FileName
PathType m_FileName
Definition: sitkImageFileReader.h:250
sitkMemberFunctionFactory.h
itk::simple::ImageFileReader::m_Origin
std::vector< double > m_Origin
Definition: sitkImageFileReader.h:258
itk::simple::ImageFileReader::m_pfHasMetaDataKey
std::function< bool(const std::string &)> m_pfHasMetaDataKey
Definition: sitkImageFileReader.h:247
sitkMacro.h
itk::simple::ImageFileReader::GetName
std::string GetName() const override
Definition: sitkImageFileReader.h:89
itk::simple::ImageFileReader::m_NumberOfComponents
unsigned int m_NumberOfComponents
Definition: sitkImageFileReader.h:256
sitkImageReaderBase.h
itk::simple::ImageFileReader::m_Direction
std::vector< double > m_Direction
Definition: sitkImageFileReader.h:257
itk::simple::ImageFileReader::m_Spacing
std::vector< double > m_Spacing
Definition: sitkImageFileReader.h:259
itk::simple::ImageFileReader::m_MemberFactory
std::unique_ptr< detail::MemberFunctionFactory< MemberFunctionType > > m_MemberFactory
Definition: sitkImageFileReader.h:243
itk::simple::ImageReaderBase
An abstract base class for image readers.
Definition: sitkImageReaderBase.h:42
itk
itk::simple::ImageFileReader::m_PixelType
PixelIDValueEnum m_PixelType
Definition: sitkImageFileReader.h:254
itk::simple::ProcessObject
Base class for SimpleITK classes based on ProcessObject.
Definition: sitkProcessObject.h:54
itk::simple::ImageFileReader::m_pfGetMetaDataKeys
std::function< std::vector< std::string >)> m_pfGetMetaDataKeys
Definition: sitkImageFileReader.h:246
itk::simple::PathType
std::string PathType
Definition: sitkPathType.h:25
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:102
itk::simple::PixelIDValueType
int PixelIDValueType
Definition: sitkPixelIDValues.h:30
itk::simple::ImageFileReader::m_pfGetMetaData
std::function< std::string(const std::string &)> m_pfGetMetaData
Definition: sitkImageFileReader.h:248