SimpleITK  
sitkImageSeriesReader.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 sitkImageSeriesReader_h
19 #define sitkImageSeriesReader_h
20 
21 #include "sitkMacro.h"
22 #include "sitkImage.h"
23 #include "sitkImageReaderBase.h"
25 
26 namespace itk::simple
27 {
28 
69 {
70 public:
72 
73  ~ImageSeriesReader() override;
74 
76 
78  std::string
79  ToString() const override;
80 
82  std::string
83  GetName() const override
84  {
85  return std::string("ImageSeriesReader");
86  }
87 
88 
94  SITK_RETURN_SELF_TYPE_HEADER
95  SetMetaDataDictionaryArrayUpdate(bool metaDataDictionaryArrayUpdate)
96  {
97  this->m_MetaDataDictionaryArrayUpdate = metaDataDictionaryArrayUpdate;
98  return *this;
99  }
100  bool
102  {
103  return this->m_MetaDataDictionaryArrayUpdate;
104  }
105 
106 
108  SITK_RETURN_SELF_TYPE_HEADER
110  {
111  return this->SetMetaDataDictionaryArrayUpdate(true);
112  }
113  SITK_RETURN_SELF_TYPE_HEADER
115  {
116  return this->SetMetaDataDictionaryArrayUpdate(false);
117  }
118 
119 
147  static std::vector<PathType>
148  GetGDCMSeriesFileNames(const PathType & directory,
149  const std::string & seriesID = "",
150  bool useSeriesDetails = false,
151  bool recursive = false,
152  bool loadSequences = false);
153 
164  static std::vector<std::string>
165  GetGDCMSeriesIDs(const PathType & directory, bool useSeriesDetails = false);
166 
167  SITK_RETURN_SELF_TYPE_HEADER
168  SetFileNames(const std::vector<PathType> & fileNames);
169  const std::vector<PathType> &
170  GetFileNames() const;
171 
173  SITK_RETURN_SELF_TYPE_HEADER
174  SetSpacingWarningRelThreshold(double spacingWarningRelThreshold);
175  double
176  GetSpacingWarningRelThreshold() const;
177 
178  Image
179  Execute() override;
180 
195  std::vector<std::string>
196  GetMetaDataKeys(unsigned int slice) const
197  {
198  return this->m_pfGetMetaDataKeys(slice);
199  }
200 
203  bool
204  HasMetaDataKey(unsigned int slice, const std::string & key) const
205  {
206  return this->m_pfHasMetaDataKey(slice, key);
207  }
208 
217  std::string
218  GetMetaData(unsigned int slice, const std::string & key) const
219  {
220  return this->m_pfGetMetaData(slice, key);
221  }
222 
223 
224 protected:
225  template <class TImageType>
226  Image
227  ExecuteInternal(itk::ImageIOBase *);
228 
229 private:
230  // function pointer type
231  typedef Image (Self::*MemberFunctionType)(itk::ImageIOBase *);
232 
233  // friend to get access to executeInternal member
234  friend struct detail::MemberFunctionAddressor<MemberFunctionType>;
235  std::unique_ptr<detail::MemberFunctionFactory<MemberFunctionType>> m_MemberFactory;
236 
237 
238  std::function<std::vector<std::string>(int)> m_pfGetMetaDataKeys;
239  std::function<bool(int, const std::string &)> m_pfHasMetaDataKey;
240  std::function<std::string(int, const std::string &)> m_pfGetMetaData;
241 
242  // Holder of process object for active measurements
243  itk::ProcessObject * m_Filter{nullptr};
244 
245 
246  std::vector<PathType> m_FileNames;
247 
248  double m_SpacingWarningRelThreshold{1e-4};
249 
250  bool m_MetaDataDictionaryArrayUpdate{false};
251 };
252 
278 ReadImage(const std::vector<PathType> & fileNames,
279  PixelIDValueEnum outputPixelType = sitkUnknown,
280  const std::string & imageIO = "");
281 } // namespace itk::simple
282 
283 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::ImageIOBase
itk::simple::ImageSeriesReader::m_pfHasMetaDataKey
std::function< bool(int, const std::string &)> m_pfHasMetaDataKey
Definition: sitkImageSeriesReader.h:239
itk::simple::ImageSeriesReader::GetMetaDataDictionaryArrayUpdate
bool GetMetaDataDictionaryArrayUpdate()
Definition: sitkImageSeriesReader.h:101
itk::simple::ImageSeriesReader::m_pfGetMetaData
std::function< std::string(int, const std::string &)> m_pfGetMetaData
Definition: sitkImageSeriesReader.h:240
itk::simple::detail::MemberFunctionAddressor
Definition: sitkDetail.h:29
itk::simple::ImageSeriesReader::GetMetaDataKeys
std::vector< std::string > GetMetaDataKeys(unsigned int slice) const
Get the meta-data dictionary keys for a slice.
Definition: sitkImageSeriesReader.h:196
itk::simple::ImageSeriesReader::GetMetaData
std::string GetMetaData(unsigned int slice, const std::string &key) const
Get the value of a meta-data dictionary entry as a string.
Definition: sitkImageSeriesReader.h:218
itk::simple::ImageSeriesReader::HasMetaDataKey
bool HasMetaDataKey(unsigned int slice, const std::string &key) const
Query a meta-data dictionary for the existence of a key.
Definition: sitkImageSeriesReader.h:204
SITKIO_EXPORT
#define SITKIO_EXPORT
Definition: sitkIO.h:33
sitkImage.h
itk::simple::ImageSeriesReader::m_FileNames
std::vector< PathType > m_FileNames
Definition: sitkImageSeriesReader.h:246
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
sitkMemberFunctionFactory.h
itk::simple::ImageSeriesReader::m_pfGetMetaDataKeys
std::function< std::vector< std::string >int)> m_pfGetMetaDataKeys
Definition: sitkImageSeriesReader.h:238
sitkMacro.h
sitkImageReaderBase.h
itk::simple::ImageSeriesReader
Read series of image files into a SimpleITK image.
Definition: sitkImageSeriesReader.h:68
itk::simple::ImageSeriesReader::MetaDataDictionaryArrayUpdateOff
Self & MetaDataDictionaryArrayUpdateOff()
Definition: sitkImageSeriesReader.h:114
itk::simple::ImageSeriesReader::SetMetaDataDictionaryArrayUpdate
Self & SetMetaDataDictionaryArrayUpdate(bool metaDataDictionaryArrayUpdate)
Definition: sitkImageSeriesReader.h:95
itk::simple::ImageReaderBase
An abstract base class for image readers.
Definition: sitkImageReaderBase.h:42
itk::simple::ImageSeriesReader::m_MemberFactory
std::unique_ptr< detail::MemberFunctionFactory< MemberFunctionType > > m_MemberFactory
Definition: sitkImageSeriesReader.h:235
itk::simple::ImageSeriesReader::MetaDataDictionaryArrayUpdateOn
Self & MetaDataDictionaryArrayUpdateOn()
Definition: sitkImageSeriesReader.h:109
itk::ProcessObject
itk::simple::ProcessObject
Base class for SimpleITK classes based on ProcessObject.
Definition: sitkProcessObject.h:54
itk::simple::ImageSeriesReader::GetName
std::string GetName() const override
Definition: sitkImageSeriesReader.h:83
itk::Image
Definition: sitkPixelIDTypes.h:28
itk::simple
Definition: sitkAdditionalProcedures.h:28
itk::simple::PathType
std::string PathType
Definition: sitkPathType.h:25
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:102