ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkImageFileReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkImageFileReader_h
00019 #define __itkImageFileReader_h
00020 
00021 #include "itkImageIOBase.h"
00022 #include "itkImageSource.h"
00023 #include "itkMacro.h"
00024 #include "itkImageRegion.h"
00025 #include "itkDefaultConvertPixelTraits.h"
00026 #include "itkSimpleDataObjectDecorator.h"
00027 
00028 namespace itk
00029 {
00035 class ITK_ABI_EXPORT ImageFileReaderException:public ExceptionObject
00036 {
00037 public:
00039   itkTypeMacro(ImageFileReaderException, ExceptionObject);
00040 
00042   ImageFileReaderException(const char *file, unsigned int line,
00043                            const char *message = "Error in IO",
00044                            const char *loc = "Unknown"):
00045     ExceptionObject(file, line, message, loc)
00046   {}
00047 
00049   ImageFileReaderException(const std::string & file, unsigned int line,
00050                            const char *message = "Error in IO",
00051                            const char *loc = "Unknown"):
00052     ExceptionObject(file, line, message, loc)
00053   {}
00054 };
00056 
00096 template< class TOutputImage,
00097           class ConvertPixelTraits = DefaultConvertPixelTraits<
00098             typename TOutputImage::IOPixelType > >
00099 class ITK_EXPORT ImageFileReader:public ImageSource< TOutputImage >
00100 {
00101 public:
00103   typedef ImageFileReader             Self;
00104   typedef ImageSource< TOutputImage > Superclass;
00105   typedef SmartPointer< Self >        Pointer;
00106 
00108   itkNewMacro(Self);
00109 
00111   itkTypeMacro(ImageFileReader, ImageSource);
00112 
00114   typedef typename TOutputImage::SizeType SizeType;
00115 
00117   typedef typename TOutputImage::IndexType IndexType;
00118 
00120   typedef typename TOutputImage::RegionType ImageRegionType;
00121 
00123   typedef typename TOutputImage::InternalPixelType OutputImagePixelType;
00124 
00126   itkSetGetDecoratedInputMacro(FileName, std::string);
00127 
00134   void  SetImageIO(ImageIOBase *imageIO);
00135 
00136   itkGetObjectMacro(ImageIO, ImageIOBase);
00137 
00140   virtual void GenerateOutputInformation(void);
00141 
00147   virtual void EnlargeOutputRequestedRegion(DataObject *output);
00148 
00150   itkSetMacro(UseStreaming, bool);
00151   itkGetConstReferenceMacro(UseStreaming, bool);
00152   itkBooleanMacro(UseStreaming);
00153 protected:
00154   ImageFileReader();
00155   ~ImageFileReader();
00156   void PrintSelf(std::ostream & os, Indent indent) const;
00158 
00160   void DoConvertBuffer(void *buffer, size_t numberOfPixels);
00161 
00167   void TestFileExistanceAndReadability();
00168 
00170   virtual void GenerateData();
00171 
00172   ImageIOBase::Pointer m_ImageIO;
00173 
00174   bool m_UserSpecifiedImageIO; // keep track whether the
00175                                // ImageIO is user specified
00176 
00177   bool m_UseStreaming;
00178 private:
00179   ImageFileReader(const Self &); //purposely not implemented
00180   void operator=(const Self &);  //purposely not implemented
00181 
00182   std::string m_ExceptionMessage;
00183 
00184   // The region that the ImageIO class will return when we ask to
00185   // produce the requested region.
00186   ImageIORegion m_ActualIORegion;
00187 };
00188 } //namespace ITK
00189 
00190 #ifndef ITK_MANUAL_INSTANTIATION
00191 #include "itkImageFileReader.hxx"
00192 #endif
00193 
00194 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
00195 #include "itkImageIOFactoryRegisterManager.h"
00196 #endif
00197 
00198 #endif // __itkImageFileReader_h
00199