ITK  4.8.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 namespace itk
27 {
38 class MGHImageIO:public ImageIOBase
39 {
40 public:
42  typedef MGHImageIO Self;
45 
47  itkNewMacro(Self);
48 
50  itkTypeMacro(MGHImageIO, Superclass);
51 
52  /*-------- This part of the interfaces deals with reading data. ----- */
53 
59  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
60 
62  virtual void ReadImageInformation() ITK_OVERRIDE;
63 
65  virtual void Read(void *buffer) ITK_OVERRIDE;
66 
67  /*-------- This part of the interfaces deals with writing data. ----- */
68 
74  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
75 
77  virtual void WriteImageInformation() ITK_OVERRIDE;
78 
81  virtual void Write(const void *buffer) ITK_OVERRIDE;
82 
83 protected:
84  MGHImageIO();
85  ~MGHImageIO();
86  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
87 
88  void ReadVolumeHeader();
89 
90 private:
91  static const int MRI_UCHAR = 0;
92  static const int MRI_INT = 1;
93  static const int MRI_FLOAT = 3;
94  static const int MRI_SHORT = 4;
95  static const int MRI_TENSOR = 6;
96  static const unsigned int FS_DIMENSION_HEADER_SIZE = sizeof(int) * 7;
97  static const unsigned int FS_RAS_HEADER_SIZE = (sizeof(float) * 15) + sizeof(short);
98  static const unsigned int FS_UNUSED_HEADER_SIZE = 256 - FS_RAS_HEADER_SIZE;
99  static const unsigned int FS_WHOLE_HEADER_SIZE =
100  FS_RAS_HEADER_SIZE + FS_DIMENSION_HEADER_SIZE + FS_UNUSED_HEADER_SIZE;
101 
103  bool IsCompressedFilename(const std::string fname);
105  void SwapBytesIfNecessary(void * const buffer, const unsigned long numberOfPixels);
107 
109  // void MriDirCos();
110 
111  void WriteHeader();
112 
113  void WriteData(const void* buffer);
114 
115  void PermuteFrameValues(const void* buffer, char* tempmemory);
116 
117  unsigned int GetComponentSize() const ITK_OVERRIDE;
118 
119  std::string GetOrientation( itk::Matrix<double> directions );
120 
122  gzFile m_GZFile;
123  std::ofstream m_Output;
124 
125  template <class T> int TWrite(T out);
126  template <class T> int TRead(T &out);
127 
128  int TWrite(const char *buf,unsigned long count);
129  void OpenFile();
130  void CloseFile();
131 };
132 } // end namespace itk
133 
134 #endif // itkMGHImageIO_h
static const unsigned int FS_DIMENSION_HEADER_SIZE
Definition: itkMGHImageIO.h:96
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
virtual void ReadImageInformation() override
static const unsigned int FS_RAS_HEADER_SIZE
Definition: itkMGHImageIO.h:97
Light weight base class for most itk classes.
virtual void Write(const void *buffer) override
Abstract superclass defines image IO interface.
static const int MRI_UCHAR
Definition: itkMGHImageIO.h:91
static const unsigned int FS_UNUSED_HEADER_SIZE
Definition: itkMGHImageIO.h:98
int TRead(T &out)
SmartPointer< Self > Pointer
Definition: itkMGHImageIO.h:44
void SwapBytesIfNecessary(void *const buffer, const unsigned long numberOfPixels)
processes the actual data buffer
int TWrite(T out)
static const int MRI_SHORT
Definition: itkMGHImageIO.h:94
void WriteHeader()
examines the direction cosines and creates encapsulation data
ImageIOBase Superclass
Definition: itkMGHImageIO.h:43
static const int MRI_FLOAT
Definition: itkMGHImageIO.h:93
void WriteData(const void *buffer)
Class that defines how to read MGH file format. Originally developed as part of the Slicer software p...
Definition: itkMGHImageIO.h:38
bool IsCompressedFilename(const std::string fname)
std::ofstream m_Output
MGHImageIO Self
Definition: itkMGHImageIO.h:42
virtual bool CanWriteFile(const char *FileNameToWrite) override
virtual void WriteImageInformation() override
unsigned int GetComponentSize() const override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void PermuteFrameValues(const void *buffer, char *tempmemory)
static const int MRI_TENSOR
Definition: itkMGHImageIO.h:95
virtual bool CanReadFile(const char *FileNameToRead) override
virtual void Read(void *buffer) override
std::string GetOrientation(itk::Matrix< double > directions)
Base class for most ITK classes.
Definition: itkObject.h:57
static const unsigned int FS_WHOLE_HEADER_SIZE
Definition: itkMGHImageIO.h:99
void ReadVolumeHeader()
static const int MRI_INT
Definition: itkMGHImageIO.h:92
void PrintSelf(std::ostream &os, Indent indent) const override