SimpleITK  1.3.0.dev466
sitkImageFileReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
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  virtual ~ImageFileReader();
67 
69 
71  virtual std::string ToString() const;
72 
74  virtual std::string GetName() const { 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();
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(void);
94 
109  PixelIDValueEnum GetPixelID( void ) const;
110  PixelIDValueType GetPixelIDValue( void ) const;
111  unsigned int GetDimension( void ) const;
112  unsigned int GetNumberOfComponents( void ) const;
113  const std::vector<double> &GetOrigin( void ) const;
114  const std::vector<double> &GetSpacing( void ) const;
115  const std::vector<double> &GetDirection() const;
116  const std::vector<uint64_t> &GetSize( void ) const;
117  /* @} */
118 
128  std::vector<std::string> GetMetaDataKeys( void ) 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  nsstd::auto_ptr<detail::MemberFunctionFactory<MemberFunctionType> > m_MemberFactory;
205 
206 
207  nsstd::function<std::vector<std::string>()> m_pfGetMetaDataKeys;
208  nsstd::function<bool(const std::string &)> m_pfHasMetaDataKey;
209  nsstd::function<std::string(const std::string &)> m_pfGetMetaData;
210 
211  std::string m_FileName;
212 
213  nsstd::auto_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
An abract base class for image readers.
std::vector< double > m_Spacing
std::vector< double > m_Origin
PixelIDValueEnum
Enumerated values of pixelIDs.
nsstd::function< bool(const std::string &)> m_pfHasMetaDataKey
Read an image file and return a SimpleITK Image.
nsstd::auto_ptr< detail::MemberFunctionFactory< MemberFunctionType > > m_MemberFactory
nsstd::function< std::string(const std::string &)> m_pfGetMetaData
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...
std::vector< double > m_Direction
#define SITKIO_EXPORT
Definition: sitkIO.h:33
The Image class for SimpleITK.
Definition: sitkImage.h:78
nsstd::auto_ptr< MetaDataDictionary > m_MetaDataDictionary
std::vector< uint64_t > m_Size
virtual std::string GetName() const
std::vector< unsigned int > m_ExtractSize