ITK  5.4.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 * https://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
31namespace itk
32{
33
73template <typename TOutputImage,
74 typename ConvertPixelTraits = DefaultConvertPixelTraits<typename TOutputImage::IOPixelType>>
75class ITK_TEMPLATE_EXPORT ImageFileReader : public ImageSource<TOutputImage>
76{
77public:
78 ITK_DISALLOW_COPY_AND_MOVE(ImageFileReader);
79
84
86 itkNewMacro(Self);
87
89 itkOverrideGetNameOfClassMacro(ImageFileReader);
90
93
96
99
101 using OutputImagePixelType = typename TOutputImage::InternalPixelType;
102
104 itkSetGetDecoratedInputMacro(FileName, std::string);
105
112 void
114 itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
118 itkSetMacro(UseStreaming, bool);
119 itkGetConstReferenceMacro(UseStreaming, bool);
120 itkBooleanMacro(UseStreaming);
123protected:
125 ~ImageFileReader() override = default;
126 void
127 PrintSelf(std::ostream & os, Indent indent) const override;
128
130 void
131 DoConvertBuffer(const void * inputData, size_t numberOfPixels);
132
138 void
140
143 void
145
151 void
153
155 void
156 GenerateData() override;
157
159
160 bool m_UserSpecifiedImageIO{}; // keep track whether the
161 // ImageIO is user specified
162
163 bool m_UseStreaming{};
164
165private:
166 std::string m_ExceptionMessage{};
167
168 // The region that the ImageIO class will return when we ask to
169 // produce the requested region.
170 ImageIORegion m_ActualIORegion{};
171};
172
173
183template <typename TOutputImage,
184 typename ConvertPixelTraits = DefaultConvertPixelTraits<typename TOutputImage::IOPixelType>>
186ReadImage(const std::string & filename)
187{
189 reader->SetFileName(filename);
190 reader->Update();
191 return reader->GetOutput();
192}
196} // namespace itk
197
198#ifndef ITK_MANUAL_INSTANTIATION
199# include "itkImageFileReader.hxx"
200#endif
201
202#if defined ITK_IMAGEIO_FACTORY_REGISTER_MANAGER || defined ITK_IO_FACTORY_REGISTER_MANAGER
203# include "itkImageIOFactoryRegisterManager.h"
204#endif
205
206#endif // itkImageFileReader_h
Base class for all data objects in ITK.
Data source that reads image data from a single file.
void EnlargeOutputRequestedRegion(DataObject *output) override
void SetImageIO(ImageIOBase *imageIO)
void GenerateOutputInformation() override
void DoConvertBuffer(const void *inputData, vcl_size_t numberOfPixels)
typename TOutputImage::RegionType ImageRegionType
void GenerateData() override
typename TOutputImage::IndexType IndexType
void TestFileExistanceAndReadability()
typename TOutputImage::SizeType SizeType
static Pointer New()
~ImageFileReader() override=default
void PrintSelf(std::ostream &os, Indent indent) const override
Abstract superclass defines image IO interface.
An ImageIORegion represents a structured region of data.
Base class for all process objects that output image data.
typename OutputImageType::PixelType OutputImagePixelType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TOutputImage::Pointer ReadImage(const std::string &filename)