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
74{
75public:
77
78 ~ImageFileReader() override;
79
81
83 std::string
84 ToString() const override;
85
87 std::string
88 GetName() const override
89 {
90 return std::string("ImageFileReader");
91 }
92
93 void
94 SetFileName(const PathType & fn);
96 GetFileName() const;
97
98 Image
99 Execute() override;
100
101 // Interface methods to access image file's meta-data and image
102 // information after calling Execute or after calling
103 // MetaDataRead, which does not load the bulk pixel data.
104
113 void
115
131 GetPixelID() const;
134 unsigned int
136 unsigned int
138 const std::vector<double> &
139 GetOrigin() const;
140 const std::vector<double> &
141 GetSpacing() const;
142 const std::vector<double> &
144 const std::vector<uint64_t> &
145 GetSize() const;
146
158 bool
161
171 std::vector<std::string>
173
176 bool
177 HasMetaDataKey(const std::string & key) const;
178
187 std::string
188 GetMetaData(const std::string & key) const;
189
190
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
235 typedef enum
236 {
240 } DirectionCollapseStrategyType;
241
262 void
266
267protected:
268 template <class TImageType>
269 Image
271
275 void
277
278private:
279 // Internal method used implements extracting a region from the reader
280 template <class TImageType, class TInternalImageType>
281 Image
282 ExecuteExtract(TInternalImageType * itkImage);
283
284 // function pointer type
286
287 // friend to get access to executeInternal member
291
292
293 std::function<std::vector<std::string>()> m_pfGetMetaDataKeys;
294 std::function<bool(const std::string &)> m_pfHasMetaDataKey;
295 std::function<std::string(const std::string &)> m_pfGetMetaData;
296
298
299 std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary;
300
302 unsigned int m_Dimension{ 0 };
303 unsigned int m_NumberOfComponents{ 0 };
304 std::vector<double> m_Direction;
305 std::vector<double> m_Origin;
306 std::vector<double> m_Spacing;
307
308 std::vector<uint64_t> m_Size;
309 bool m_CanStreamRead{ false };
310
311 std::vector<unsigned int> m_ExtractSize;
312 std::vector<int> m_ExtractIndex;
313
315};
316
329ReadImage(const PathType & filename, PixelIDValueEnum outputPixelType = sitkUnknown, const std::string & imageIO = "");
330} // namespace simple
331} // namespace itk
332
333#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)
void SetDirectionCollapseToStrategy(DirectionCollapseStrategyType strategy)
Set the strategy used to collapse the direction cosine matrix when the extraction reduces the image d...
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.
DirectionCollapseStrategyType m_DirectionCollapseToStrategy
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 *)
DirectionCollapseStrategyType GetDirectionCollapseToStrategy() const
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