ITK  5.2.0
Insight Toolkit
itkImageFileReader.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 itkImageFileReader_h
19 #define itkImageFileReader_h
21 
22 #include "ITKIOImageBaseExport.h"
23 
24 #include "itkImageIOBase.h"
25 #include "itkImageSource.h"
26 #include "itkMacro.h"
27 #include "itkImageRegion.h"
30 
31 namespace itk
32 {
33 
73 template <typename TOutputImage,
74  typename ConvertPixelTraits = DefaultConvertPixelTraits<typename TOutputImage::IOPixelType>>
75 class ITK_TEMPLATE_EXPORT ImageFileReader : public ImageSource<TOutputImage>
76 {
77 public:
78  ITK_DISALLOW_COPY_AND_MOVE(ImageFileReader);
79 
84 
86  itkNewMacro(Self);
87 
89  itkTypeMacro(ImageFileReader, ImageSource);
90 
92  using SizeType = typename TOutputImage::SizeType;
93 
96 
99 
101  using OutputImagePixelType = typename TOutputImage::InternalPixelType;
102 
104  itkSetGetDecoratedInputMacro(FileName, std::string);
105 
112  void
113  SetImageIO(ImageIOBase * imageIO);
114  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
116 
118  itkSetMacro(UseStreaming, bool);
119  itkGetConstReferenceMacro(UseStreaming, bool);
120  itkBooleanMacro(UseStreaming);
122 
123 protected:
124  ImageFileReader();
125  ~ImageFileReader() override = default;
126  void
127  PrintSelf(std::ostream & os, Indent indent) const override;
128 
130  void
131  DoConvertBuffer(void * inputData, size_t numberOfPixels);
132 
138  void
139  TestFileExistanceAndReadability();
140 
143  void
144  GenerateOutputInformation() override;
145 
151  void
152  EnlargeOutputRequestedRegion(DataObject * output) override;
153 
155  void
156  GenerateData() override;
157 
159 
160  bool m_UserSpecifiedImageIO; // keep track whether the
161  // ImageIO is user specified
162 
164 
165 private:
166  std::string m_ExceptionMessage;
167 
168  // The region that the ImageIO class will return when we ask to
169  // produce the requested region.
171 };
172 
173 
183 template <typename TOutputImage,
185 typename TOutputImage::Pointer
186 ReadImage(const std::string & filename)
187 {
189  reader->SetFileName(filename);
190  reader->Update();
191  return reader->GetOutput();
192 }
194 
195 
196 } // namespace itk
197 
198 #ifndef ITK_MANUAL_INSTANTIATION
199 # include "itkImageFileReader.hxx"
200 #endif
201 
202 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
203 # include "itkImageIOFactoryRegisterManager.h"
204 #endif
205 
206 #endif // itkImageFileReader_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:77
itk::ImageFileReader::New
static Pointer New()
itkImageSource.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageIORegion
An ImageIORegion represents a structured region of data.
Definition: itkImageIORegion.h:52
itkImageFileReaderException.h
itk::ImageFileReader::SizeType
typename TOutputImage::SizeType SizeType
Definition: itkImageFileReader.h:92
itkImageRegion.h
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itkDefaultConvertPixelTraits.h
itk::ImageFileReader::m_ExceptionMessage
std::string m_ExceptionMessage
Definition: itkImageFileReader.h:166
itk::ImageFileReader::IndexType
typename TOutputImage::IndexType IndexType
Definition: itkImageFileReader.h:95
itkMacro.h
itk::ImageFileReader::m_ActualIORegion
ImageIORegion m_ActualIORegion
Definition: itkImageFileReader.h:170
itk::DefaultConvertPixelTraits
Traits class used to by ConvertPixels to convert blocks of pixels.
Definition: itkDefaultConvertPixelTraits.h:41
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ReadImage
TOutputImage::Pointer ReadImage(const std::string &filename)
Definition: itkImageFileReader.h:186
itkImageIOBase.h
itk::ImageFileReader::m_UserSpecifiedImageIO
bool m_UserSpecifiedImageIO
Definition: itkImageFileReader.h:160
itk::ImageFileReader::ImageRegionType
typename TOutputImage::RegionType ImageRegionType
Definition: itkImageFileReader.h:98
itk::ImageFileReader::m_UseStreaming
bool m_UseStreaming
Definition: itkImageFileReader.h:163
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ImageSource::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itkSimpleDataObjectDecorator.h
itk::ImageFileReader::m_ImageIO
ImageIOBase::Pointer m_ImageIO
Definition: itkImageFileReader.h:158
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293