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
27namespace itk
28{
29
31
32namespace simple
33{
34
75{
76public:
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 void
95 SetFileName(const PathType & fn);
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
116
132 GetPixelID() const;
135 unsigned int
137 unsigned int
139 const std::vector<double> &
140 GetOrigin() const;
141 const std::vector<double> &
142 GetSpacing() const;
143 const std::vector<double> &
145 const std::vector<uint64_t> &
146 GetSize() const;
147
159 bool
162
172 std::vector<std::string>
174
177 bool
178 HasMetaDataKey(const std::string & key) const;
179
188 std::string
189 GetMetaData(const std::string & key) const;
190
191
218 void
219 SetExtractSize(const std::vector<unsigned int> & size);
220 const std::vector<unsigned int> &
222
223
230 void
231 SetExtractIndex(const std::vector<int> & index);
232 const std::vector<int> &
234
235protected:
236 template <class TImageType>
237 Image
239
243 void
245
246private:
247 // Internal method used implements extracting a region from the reader
248 template <class TImageType, class TInternalImageType>
249 Image
250 ExecuteExtract(TInternalImageType * itkImage);
251
252 // function pointer type
254
255 // friend to get access to executeInternal member
259
260
261 std::function<std::vector<std::string>()> m_pfGetMetaDataKeys;
262 std::function<bool(const std::string &)> m_pfHasMetaDataKey;
263 std::function<std::string(const std::string &)> m_pfGetMetaData;
264
266
267 std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary;
268
270 unsigned int m_Dimension{ 0 };
271 unsigned int m_NumberOfComponents{ 0 };
272 std::vector<double> m_Direction;
273 std::vector<double> m_Origin;
274 std::vector<double> m_Spacing;
275
276 std::vector<uint64_t> m_Size;
277 bool m_CanStreamRead{ false };
278
279 std::vector<unsigned int> m_ExtractSize;
280 std::vector<int> m_ExtractIndex;
281};
282
295ReadImage(const PathType & filename, PixelIDValueEnum outputPixelType = sitkUnknown, const std::string & imageIO = "");
296} // namespace simple
297} // namespace itk
298
299#endif
std::function< std::vector< std::string >()> m_pfGetMetaDataKeys
unsigned int GetDimension() const
Image information methods updated via ReadImageInformation.
std::function< bool(const std::string &)> m_pfHasMetaDataKey
void UpdateImageInformationFromImageIO(itk::ImageIOBase *iobase)
static const detail::MemberFunctionFactory< MemberFunctionType > & GetMemberFunctionFactory()
Image(Self::* MemberFunctionType)(itk::ImageIOBase *)
PathType GetFileName() const
const std::vector< double > & GetOrigin() const
Image information methods updated via ReadImageInformation.
std::vector< unsigned int > m_ExtractSize
Image ExecuteExtract(TInternalImageType *itkImage)
bool CanStreamRead() const
Query if the a sub-region of the file can be read without decoding the whole image.
const std::vector< double > & GetSpacing() const
Image information methods updated via ReadImageInformation.
const std::vector< double > & GetDirection() const
Image information methods updated via ReadImageInformation.
void ReadImageInformation()
Read only the meta-data and image information in the file.
unsigned int GetNumberOfComponents() const
Image information methods updated via ReadImageInformation.
std::vector< double > m_Direction
std::vector< uint64_t > m_Size
void SetExtractSize(const std::vector< unsigned int > &size)
size of image to extract from file.
const std::vector< uint64_t > & GetSize() const
Image information methods updated via ReadImageInformation.
std::vector< std::string > GetMetaDataKeys() const
Get the meta-data dictionary keys.
void SetExtractIndex(const std::vector< int > &index)
starting index from the image on disk to extract.
std::string ToString() const override
const std::vector< int > & GetExtractIndex() const
std::string GetMetaData(const std::string &key) const
Get the value of a meta-data dictionary entry as a string.
const std::vector< unsigned int > & GetExtractSize() const
PixelIDValueEnum GetPixelID() const
Image information methods updated via ReadImageInformation.
std::string GetName() const override
std::function< std::string(const std::string &)> m_pfGetMetaData
Image ExecuteInternal(itk::ImageIOBase *)
bool HasMetaDataKey(const std::string &key) const
Query a meta-data dictionary for the existence of a key.
void SetFileName(const PathType &fn)
std::unique_ptr< MetaDataDictionary > m_MetaDataDictionary
PixelIDValueType GetPixelIDValue() const
Image information methods updated via ReadImageInformation.
The Image class for SimpleITK.
Definition sitkImage.h:77
A class used to instantiate and generate function object to templated member functions.
std::string PathType
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...
PixelIDValueEnum
Enumerated values of pixelIDs.
#define SITKIO_EXPORT
Definition sitkIO.h:33