ITK  5.0.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 <memory>
26 #include "itkImageIOBase.h"
27 
28 namespace itk
29 {
42 class ITKIONIFTI_EXPORT NiftiImageIO:public ImageIOBase
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_ASSIGN(NiftiImageIO);
46 
48  using Self = NiftiImageIO;
51 
53  itkNewMacro(Self);
54 
56  itkTypeMacro(NiftiImageIO, Superclass);
57 
58  //-------- This part of the interfaces deals with reading data. -----
59 
62  enum FileType {
63 
65  TwoFileNifti = 2,
66 
68  OneFileNifti = 1,
69 
71  Analyze75 = 0,
72 
74  OtherOrError = -1,
75  };
76 
83  FileType DetermineFileType(const char *FileNameToRead);
84 
91  bool CanReadFile(const char *FileNameToRead) override;
92 
94  void ReadImageInformation() override;
95 
97  void Read(void *buffer) override;
98 
99  //-------- This part of the interfaces deals with writing data. -----
100 
106  bool CanWriteFile(const char *FileNameToWrite) override;
107 
113  void WriteImageInformation() override;
114 
117  void Write(const void *buffer) override;
118 
122  GenerateStreamableReadRegionFromRequestedRegion(const ImageIORegion & requestedRegion) const override;
123 
125  itkSetMacro(RescaleSlope, double);
126  itkSetMacro(RescaleIntercept, double);
128 
133  itkSetMacro(LegacyAnalyze75Mode, bool);
134  itkGetConstMacro(LegacyAnalyze75Mode, bool);
136 
137 protected:
138  NiftiImageIO();
139  ~NiftiImageIO() override;
140  void PrintSelf(std::ostream & os, Indent indent) const override;
141 
142  virtual bool GetUseLegacyModeForTwoFileWriting() const { return false; }
143 
144 private:
145  //Try to use the Q and S form codes from MetaDataDictionary if they are specified
146  //there, otherwise default to the backwards compatible values from earlier
147  //versions of ITK. The qform guess would probably been better to have
148  //been guessed as NIFTI_XFORM_SCANNER_ANAT
149  unsigned int getSFormCodeFromDictionary() const;
150  unsigned int getQFormCodeFromDictionary() const;
151 
152  bool MustRescale();
153 
154  void DefineHeaderObjectDataType();
155 
156  void SetNIfTIOrientationFromImageIO(unsigned short int origdims, unsigned short int dims);
157 
158  void SetImageIOOrientationFromNIfTI(unsigned short int dims);
159 
160  void SetImageIOMetadataFromNIfTI();
161 
162  //This proxy class provides a nifti_image pointer interface to the internal implementation
163  //of itk::NiftiImageIO, while hiding the niftilib interface from the external ITK interface.
164  class NiftiImageProxy;
165 
166  //Note that it is essential that m_NiftiImageHolder is defined before m_NiftiImage, to ensure that
167  //m_NiftiImage can directly get a proxy from m_NiftiImageHolder during NiftiImageIO construction.
168  const std::unique_ptr<NiftiImageProxy> m_NiftiImageHolder;
169 
170  NiftiImageProxy& m_NiftiImage;
171 
172  double m_RescaleSlope{1.0};
173  double m_RescaleIntercept{0.0};
174 
175  IOComponentType m_OnDiskComponentType{UNKNOWNCOMPONENTTYPE};
176 
177  bool m_LegacyAnalyze75Mode{true};
178 
179 };
180 } // end namespace itk
181 
182 #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.
Class that defines how to read Nifti file format. Nifti IMAGE FILE FORMAT - As much information as I ...
NiftiImageProxy & m_NiftiImage
virtual bool GetUseLegacyModeForTwoFileWriting() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
const std::unique_ptr< NiftiImageProxy > m_NiftiImageHolder