ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkImageFileReader.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 __itkImageFileReader_h
19 #define __itkImageFileReader_h
20 
21 #include "itkImageIOBase.h"
22 #include "itkImageSource.h"
23 #include "itkMacro.h"
24 #include "itkImageRegion.h"
27 
28 namespace itk
29 {
35 class ITK_ABI_EXPORT ImageFileReaderException:public ExceptionObject
36 {
37 public:
40 
42  ImageFileReaderException(const char *file, unsigned int line,
43  const char *message = "Error in IO",
44  const char *loc = "Unknown"):
45  ExceptionObject(file, line, message, loc)
46  {}
47 
49  ImageFileReaderException(const std::string & file, unsigned int line,
50  const char *message = "Error in IO",
51  const char *loc = "Unknown"):
52  ExceptionObject(file, line, message, loc)
53  {}
54 
56  virtual ~ImageFileReaderException() throw( )
57  {}
58 };
60 
100 template< class TOutputImage,
101  class ConvertPixelTraits = DefaultConvertPixelTraits<
102  typename TOutputImage::IOPixelType > >
103 class ITK_EXPORT ImageFileReader:public ImageSource< TOutputImage >
104 {
105 public:
110 
112  itkNewMacro(Self);
113 
115  itkTypeMacro(ImageFileReader, ImageSource);
116 
118  typedef typename TOutputImage::SizeType SizeType;
119 
121  typedef typename TOutputImage::IndexType IndexType;
122 
124  typedef typename TOutputImage::RegionType ImageRegionType;
125 
127  typedef typename TOutputImage::InternalPixelType OutputImagePixelType;
128 
130  itkSetGetDecoratedInputMacro(FileName, std::string);
131 
138  void SetImageIO(ImageIOBase *imageIO);
139  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
141 
144  virtual void GenerateOutputInformation(void);
145 
151  virtual void EnlargeOutputRequestedRegion(DataObject *output);
152 
154  itkSetMacro(UseStreaming, bool);
155  itkGetConstReferenceMacro(UseStreaming, bool);
156  itkBooleanMacro(UseStreaming);
158 
159 protected:
160  ImageFileReader();
161  ~ImageFileReader();
162  void PrintSelf(std::ostream & os, Indent indent) const;
163 
165  void DoConvertBuffer(void *buffer, size_t numberOfPixels);
166 
172  void TestFileExistanceAndReadability();
173 
175  virtual void GenerateData();
176 
178 
179  bool m_UserSpecifiedImageIO; // keep track whether the
180  // ImageIO is user specified
181 
183 
184 private:
185  ImageFileReader(const Self &); //purposely not implemented
186  void operator=(const Self &); //purposely not implemented
187 
188  std::string m_ExceptionMessage;
189 
190  // The region that the ImageIO class will return when we ask to
191  // produce the requested region.
193 };
194 } //namespace ITK
195 
196 #ifndef ITK_MANUAL_INSTANTIATION
197 #include "itkImageFileReader.hxx"
198 #endif
199 
200 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
201 #include "itkImageIOFactoryRegisterManager.h"
202 #endif
203 
204 #endif // __itkImageFileReader_h
205