SimpleITK  2.0.0
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  class MetaDataDictionary;
30 
31  namespace simple {
32 
61  : public ImageReaderBase
62  {
63  public:
65 
66  ~ImageFileReader() override;
67 
69 
71  std::string ToString() const override;
72 
74  std::string GetName() const override { return std::string("ImageFileReader"); }
75 
76  SITK_RETURN_SELF_TYPE_HEADER SetFileName ( const std::string &fn );
77  std::string GetFileName() const;
78 
79  Image Execute() override;
80 
81  // Interface methods to access image file's meta-data and image
82  // information after calling Execute or after calling
83  // MetaDataRead, which does not load the bulk pixel data.
84 
93  void ReadImageInformation();
94 
109  PixelIDValueEnum GetPixelID( ) const;
110  PixelIDValueType GetPixelIDValue( ) const;
111  unsigned int GetDimension( ) const;
112  unsigned int GetNumberOfComponents( ) const;
113  const std::vector<double> &GetOrigin( ) const;
114  const std::vector<double> &GetSpacing( ) const;
115  const std::vector<double> &GetDirection() const;
116  const std::vector<uint64_t> &GetSize( ) const;
117  /* @} */
118 
128  std::vector<std::string> GetMetaDataKeys( ) const;
129 
132  bool HasMetaDataKey( const std::string &key ) const;
133 
142  std::string GetMetaData( const std::string &key ) const;
143 
144 
171  SITK_RETURN_SELF_TYPE_HEADER SetExtractSize( const std::vector<unsigned int> &size);
172  const std::vector<unsigned int> &GetExtractSize( ) const;
173 
174 
181  SITK_RETURN_SELF_TYPE_HEADER SetExtractIndex( const std::vector<int> &index );
182  const std::vector<int> &GetExtractIndex( ) const;
183 
184  protected:
185 
186  template <class TImageType> Image ExecuteInternal ( itk::ImageIOBase * );
187 
191  void UpdateImageInformationFromImageIO( const itk::ImageIOBase* iobase );
192 
193  private:
194 
195  // Internal method used implement extracting a region from the reader
196  template <class TImageType, class TInternalImageType>
197  Image ExecuteExtract( TInternalImageType * itkImage );
198 
199  // function pointer type
200  typedef Image (Self::*MemberFunctionType)( itk::ImageIOBase * );
201 
202  // friend to get access to executeInternal member
203  friend struct detail::MemberFunctionAddressor<MemberFunctionType>;
204  std::unique_ptr<detail::MemberFunctionFactory<MemberFunctionType> > m_MemberFactory;
205 
206 
207  std::function<std::vector<std::string>()> m_pfGetMetaDataKeys;
208  std::function<bool(const std::string &)> m_pfHasMetaDataKey;
209  std::function<std::string(const std::string &)> m_pfGetMetaData;
210 
211  std::string m_FileName;
212 
213  std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary;
214 
216  unsigned int m_Dimension;
217  unsigned int m_NumberOfComponents;
218  std::vector<double> m_Direction;
219  std::vector<double> m_Origin;
220  std::vector<double> m_Spacing;
221 
222  std::vector<uint64_t> m_Size;
223 
224  std::vector<unsigned int> m_ExtractSize;
225  std::vector<int> m_ExtractIndex;
226  };
227 
239  SITKIO_EXPORT Image ReadImage ( const std::string &filename,
240  PixelIDValueEnum outputPixelType = sitkUnknown,
241  const std::string &imageIO = "");
242  }
243 }
244 
245 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:75
itk::ImageIOBase
itk::simple::ImageFileReader::m_Size
std::vector< uint64_t > m_Size
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:222
itk::simple::ImageFileReader::m_Dimension
unsigned int m_Dimension
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:216
itk::simple::ImageFileReader::m_ExtractSize
std::vector< unsigned int > m_ExtractSize
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:224
itk::simple::detail::MemberFunctionAddressor
Definition: sitkDetail.h:32
SITKIO_EXPORT
#define SITKIO_EXPORT
Definition: sitkIO.h:33
itk::simple::ImageFileReader::m_ExtractIndex
std::vector< int > m_ExtractIndex
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:225
sitkImage.h
itk::simple::ImageFileReader
Read an image file and return a SimpleITK Image.
Definition: sitkImageFileReader.h:60
itk::simple::ImageFileReader::m_MetaDataDictionary
std::unique_ptr< MetaDataDictionary > m_MetaDataDictionary
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:213
itk::simple::PixelIDValueEnum
PixelIDValueEnum
Enumerated values of pixelIDs.
Definition: sitkPixelIDValues.h:90
sitkMemberFunctionFactory.h
itk::simple::ImageFileReader::m_Origin
std::vector< double > m_Origin
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:219
itk::simple::ImageFileReader::m_FileName
std::string m_FileName
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:211
itk::simple::ImageFileReader::m_pfHasMetaDataKey
std::function< bool(const std::string &)> m_pfHasMetaDataKey
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:208
sitkMacro.h
itk::simple::ImageFileReader::GetName
std::string GetName() const override
Definition: sitkImageFileReader.h:74
itk::simple::ImageFileReader::m_NumberOfComponents
unsigned int m_NumberOfComponents
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:217
sitkImageReaderBase.h
itk::simple::ImageFileReader::m_Direction
std::vector< double > m_Direction
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:218
itk::simple::ReadImage
SITKIO_EXPORT Image ReadImage(const std::string &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::ImageFileReader::m_Spacing
std::vector< double > m_Spacing
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:220
itk::simple::ImageFileReader::m_MemberFactory
std::unique_ptr< detail::MemberFunctionFactory< MemberFunctionType > > m_MemberFactory
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:204
itk::simple::ImageReaderBase
An abract base class for image readers.
Definition: sitkImageReaderBase.h:39
itk
itk::simple::ImageFileReader::m_PixelType
PixelIDValueEnum m_PixelType
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:215
itk::simple::ProcessObject
Base class for SimpleITK classes based on ProcessObject.
Definition: sitkProcessObject.h:51
itk::simple::ImageFileReader::m_pfGetMetaDataKeys
std::function< std::vector< std::string >)> m_pfGetMetaDataKeys
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:207
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:91
itk::simple::PixelIDValueType
int PixelIDValueType
Definition: sitkPixelIDValues.h:32
itk::simple::ImageFileReader::m_pfGetMetaData
std::function< std::string(const std::string &)> m_pfGetMetaData
Image information methods updated via ReadImageInformation.
Definition: sitkImageFileReader.h:209