ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkNiftiImageIO.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 
19 #ifndef itkNiftiImageIO_h
20 #define itkNiftiImageIO_h
21 #include "ITKIONIFTIExport.h"
22 
23 
24 #include <fstream>
25 #include "itkAutoPointer.h"
26 #include "itkImageIOBase.h"
27 
28 namespace itk
29 {
42 class ITKIONIFTI_EXPORT NiftiImageIO:public ImageIOBase
43 {
44 public:
46  typedef NiftiImageIO Self;
49 
51  itkNewMacro(Self);
52 
54  itkTypeMacro(NiftiImageIO, Superclass);
55 
56  //-------- This part of the interfaces deals with reading data. -----
57 
64  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
65 
67  virtual void ReadImageInformation() ITK_OVERRIDE;
68 
70  virtual void Read(void *buffer) ITK_OVERRIDE;
71 
72  //-------- This part of the interfaces deals with writing data. -----
73 
80  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
81 
87  virtual void WriteImageInformation() ITK_OVERRIDE;
88 
91  virtual void Write(const void *buffer) ITK_OVERRIDE;
92 
95  virtual ImageIORegion
96  GenerateStreamableReadRegionFromRequestedRegion(const ImageIORegion & requestedRegion) const ITK_OVERRIDE;
97 
103  itkSetMacro(LegacyAnalyze75Mode, bool);
104  itkGetConstMacro(LegacyAnalyze75Mode, bool);
106 
107 protected:
108  NiftiImageIO();
109  ~NiftiImageIO() ITK_OVERRIDE;
110  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
111 
112  virtual bool GetUseLegacyModeForTwoFileWriting(void) const { return false; }
113 
114 private:
115  //Try to use the Q and S form codes from MetaDataDictionary if they are specified
116  //there, otherwise default to the backwards compatible values from earlier
117  //versions of ITK. The qform guess would probably been better to have
118  //been guessed as NIFTI_XFORM_SCANNER_ANAT
119  unsigned int getSFormCodeFromDictionary() const;
120  unsigned int getQFormCodeFromDictionary() const;
121 
122  bool MustRescale();
123 
124  void DefineHeaderObjectDataType();
125 
126  void SetNIfTIOrientationFromImageIO(unsigned short int origdims, unsigned short int dims);
127 
128  void SetImageIOOrientationFromNIfTI(unsigned short int dims);
129 
130  void SetImageIOMetadataFromNIfTI();
131 
132  //This proxy class provides a nifti_image pointer interface to the internal implementation
133  //of itk::NiftiImageIO, while hiding the niftilib interface from the external ITK interface.
134  class NiftiImageProxy;
135 
136  //Note that it is essential that m_NiftiImageHolder is defined before m_NiftiImage, to ensure that
137  //m_NiftiImage can directly get a proxy from m_NiftiImageHolder during NiftiImageIO construction.
139 
140  NiftiImageProxy& m_NiftiImage;
141 
144 
146 
148 
149  ITK_DISALLOW_COPY_AND_ASSIGN(NiftiImageIO);
150 };
151 } // end namespace itk
152 
153 #endif // itkNiftiImageIO_h
Light weight base class for most itk classes.
An ImageIORegion represents a structured region of data.
Abstract superclass defines image IO interface.
NiftiImageIO Self
Class that defines how to read Nifti file format. Nifti IMAGE FILE FORMAT - As much information as I ...
IOComponentType m_OnDiskComponentType
NiftiImageProxy & m_NiftiImage
const AutoPointer< NiftiImageProxy > m_NiftiImageHolder
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ImageIOBase Superclass
Base class for most ITK classes.
Definition: itkObject.h:59
SmartPointer< Self > Pointer