ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkHDF5ImageIO.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  *=========================================================================*/
25 #ifndef itkHDF5ImageIO_h
26 #define itkHDF5ImageIO_h
27 #include "ITKIOHDF5Export.h"
28 
29 #include "itkAutoPointer.h"
30 #include "itkMetaDataObjectBase.h"
31 #include "itkMetaDataDictionary.h"
32 
33 // itk namespace first suppresses
34 // kwstyle error for the H5 namespace below
35 namespace itk
36 {
37 }
38 namespace H5
39 {
40 class H5File;
41 class DataSpace;
42 class DataSet;
43 }
44 
46 
47 namespace itk
48 {
87 class ITKIOHDF5_EXPORT HDF5ImageIO: public StreamingImageIOBase
88 {
89 public:
91  typedef HDF5ImageIO Self;
94 
96  itkNewMacro(Self);
97 
99  itkTypeMacro(HDF5ImageIO, StreamingImageIOBase);
100 
101  /*-------- This part of the interfaces deals with reading data. ----- */
102 
109  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
110 
112  virtual void ReadImageInformation() ITK_OVERRIDE;
113 
115  virtual void Read(void *buffer) ITK_OVERRIDE;
116 
117  /*-------- This part of the interfaces deals with writing data. ----- */
118 
125  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
126 
128  virtual void WriteImageInformation() ITK_OVERRIDE;
129 
132  virtual void Write(const void *buffer) ITK_OVERRIDE;
133 
134 protected:
135  HDF5ImageIO();
136  ~HDF5ImageIO() ITK_OVERRIDE;
137 
138  virtual SizeType GetHeaderSize(void) const ITK_OVERRIDE;
139 
140  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
141 
142 private:
143  ITK_DISALLOW_COPY_AND_ASSIGN(HDF5ImageIO);
144 
145  void WriteString(const std::string &path,
146  const std::string &value);
147  void WriteString(const std::string &path,
148  const char *s);
149  std::string ReadString(const std::string &path);
150 
151  void WriteScalar(const std::string &path,
152  const bool &value);
153  void WriteScalar(const std::string &path,
154  const long &value);
155  void WriteScalar(const std::string &path,
156  const unsigned long &value);
157  void WriteScalar(const std::string &path,
158  const long long &value);
159  void WriteScalar(const std::string &path,
160  const unsigned long long &value);
161 
162  template <typename TScalar>
163  void WriteScalar(const std::string &path,
164  const TScalar &value);
165 
166  template <typename TScalar>
167  TScalar ReadScalar(const std::string &DataSetName);
168 
169  template <typename TScalar>
170  void WriteVector(const std::string &path,
171  const std::vector<TScalar> &vec);
172 
173  template <typename TScalar>
174  std::vector<TScalar> ReadVector(const std::string &DataSetName);
175 
176  void WriteDirections(const std::string &path,
177  const std::vector<std::vector<double> > &dir);
178 
179  std::vector<std::vector<double> > ReadDirections(const std::string &path);
180 
181  template <typename TType>
182  bool WriteMeta(const std::string &name,
183  MetaDataObjectBase *metaObj);
184  template <typename TType>
185  bool WriteMetaArray(const std::string &name,
186  MetaDataObjectBase *metaObj);
187  template <typename TType>
188  void StoreMetaData(MetaDataDictionary *metaDict,
189  const std::string &HDFPath,
190  const std::string &name,
191  unsigned long numElements);
192  void SetupStreaming(H5::DataSpace *imageSpace,
193  H5::DataSpace *slabSpace);
194 
195  void CloseH5File();
196  void CloseDataSet();
197 
198  H5::H5File *m_H5File;
199  H5::DataSet *m_VoxelDataSet;
200  bool m_ImageInformationWritten;
201 };
202 } // end namespace itk
203 
204 #endif // itkHDF5ImageIO_h
Light weight base class for most itk classes.
SmartPointer< Self > Pointer
A base class for specific ImageIO file formats which support streaming.
HDF5ImageIO Self
::itk::intmax_t SizeType
Provides a mechanism for storing a collection of arbitrary data types.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Class that defines how to read HDF5 file format. HDF5 IMAGE FILE FORMAT - As much information as I ca...
StreamingImageIOBase Superclass
The common interface for MetaDataObject&#39;s.