ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkMGHImageIO.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 itkMGHImageIO_h
19 #define itkMGHImageIO_h
20 
21 #include "itkMatrix.h"
22 #include "itkImageIOBase.h"
23 #include <fstream>
24 #include "itk_zlib.h"
25 
26 #include "MGHIOExport.h"
27 
28 namespace itk
29 {
40 class MGHIO_EXPORT MGHImageIO:public ImageIOBase
41 {
42 public:
44  typedef MGHImageIO Self;
47 
49  itkNewMacro(Self);
50 
52  itkTypeMacro(MGHImageIO, Superclass);
53 
54  /*-------- This part of the interfaces deals with reading data. ----- */
55 
61  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
62 
64  virtual void ReadImageInformation() ITK_OVERRIDE;
65 
67  virtual void Read(void *buffer) ITK_OVERRIDE;
68 
69  /*-------- This part of the interfaces deals with writing data. ----- */
70 
76  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
77 
79  virtual void WriteImageInformation() ITK_OVERRIDE;
80 
83  virtual void Write(const void *buffer) ITK_OVERRIDE;
84 
85 protected:
86  MGHImageIO();
87  ~MGHImageIO();
88  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
89 
90  void ReadVolumeHeader();
91 
92 private:
93  static const int MRI_UCHAR = 0;
94  static const int MRI_INT = 1;
95  static const int MRI_FLOAT = 3;
96  static const int MRI_SHORT = 4;
97  static const int MRI_TENSOR = 6;
98  static const unsigned int FS_DIMENSION_HEADER_SIZE = sizeof(int) * 7;
99  static const unsigned int FS_RAS_HEADER_SIZE = (sizeof(float) * 15) + sizeof(short);
100  static const unsigned int FS_UNUSED_HEADER_SIZE = 256 - FS_RAS_HEADER_SIZE;
101  static const unsigned int FS_WHOLE_HEADER_SIZE =
102  FS_RAS_HEADER_SIZE + FS_DIMENSION_HEADER_SIZE + FS_UNUSED_HEADER_SIZE;
103 
105  bool IsCompressedFilename(const std::string fname);
107  void SwapBytesIfNecessary(void * const buffer, const unsigned long numberOfPixels);
109 
111  // void MriDirCos();
112 
113  void WriteHeader();
114 
115  void WriteData(const void* buffer);
116 
117  void PermuteFrameValues(const void* buffer, char* tempmemory);
118 
119  unsigned int GetComponentSize() const ITK_OVERRIDE;
120 
121  std::string GetOrientation( itk::Matrix<double> directions );
122 
123  bool m_IsCompressed;
124  gzFile m_GZFile;
125  std::ofstream m_Output;
126 
127  // Utility function to assist with writing to disk in the
128  // proper format. TInType is static_cast<TDiskType> type.
129  template <typename TInType, typename TDiskType> int TWrite(const TInType inValue);
130  template <typename TDiskType, typename TOutType> int TRead(TOutType &outValue);
131 
132  int TWrite(const char *buf,const unsigned long count);
133  void OpenFile();
134  void CloseFile();
135 };
136 } // end namespace itk
137 
138 #endif // itkMGHImageIO_h
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
Light weight base class for most itk classes.
Abstract superclass defines image IO interface.
SmartPointer< Self > Pointer
Definition: itkMGHImageIO.h:46
ImageIOBase Superclass
Definition: itkMGHImageIO.h:45
Class that defines how to read MGH file format. Originally developed as part of the Slicer software p...
Definition: itkMGHImageIO.h:40
MGHImageIO Self
Definition: itkMGHImageIO.h:44
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:59