ITK  4.12.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();
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 
158  template <typename TScalar>
159  void WriteScalar(const std::string &path,
160  const TScalar &value);
161 
162  template <typename TScalar>
163  TScalar ReadScalar(const std::string &DataSetName);
164 
165  template <typename TScalar>
166  void WriteVector(const std::string &path,
167  const std::vector<TScalar> &vec);
168 
169  template <typename TScalar>
170  std::vector<TScalar> ReadVector(const std::string &DataSetName);
171 
172  void WriteDirections(const std::string &path,
173  const std::vector<std::vector<double> > &dir);
174 
175  std::vector<std::vector<double> > ReadDirections(const std::string &path);
176 
177  template <typename TType>
178  bool WriteMeta(const std::string &name,
179  MetaDataObjectBase *metaObj);
180  template <typename TType>
181  bool WriteMetaArray(const std::string &name,
182  MetaDataObjectBase *metaObj);
183  template <typename TType>
184  void StoreMetaData(MetaDataDictionary *metaDict,
185  const std::string &HDFPath,
186  const std::string &name,
187  unsigned long numElements);
188  void SetupStreaming(H5::DataSpace *imageSpace,
189  H5::DataSpace *slabSpace);
190 
191  void CloseH5File();
192  void CloseDataSet();
193 
194  H5::H5File *m_H5File;
195  H5::DataSet *m_VoxelDataSet;
196  bool m_ImageInformationWritten;
197 };
198 } // end namespace itk
199 
200 #endif // itkHDF5ImageIO_h
virtual void PrintSelf(std::ostream &os, Indent indent) const override
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.