ITK  4.2.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 
140  itkGetObjectMacro(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);
157 protected:
158  ImageFileReader();
159  ~ImageFileReader();
160  void PrintSelf(std::ostream & os, Indent indent) const;
162 
164  void DoConvertBuffer(void *buffer, size_t numberOfPixels);
165 
171  void TestFileExistanceAndReadability();
172 
174  virtual void GenerateData();
175 
177 
178  bool m_UserSpecifiedImageIO; // keep track whether the
179  // ImageIO is user specified
180 
182 private:
183  ImageFileReader(const Self &); //purposely not implemented
184  void operator=(const Self &); //purposely not implemented
185 
186  std::string m_ExceptionMessage;
187 
188  // The region that the ImageIO class will return when we ask to
189  // produce the requested region.
191 };
192 } //namespace ITK
193 
194 #ifndef ITK_MANUAL_INSTANTIATION
195 #include "itkImageFileReader.hxx"
196 #endif
197 
198 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
199 #include "itkImageIOFactoryRegisterManager.h"
200 #endif
201 
202 #endif // __itkImageFileReader_h
203