ITK  5.0.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 #include "itkMetaDataObjectBase.h"
29 #include "itkMetaDataDictionary.h"
30 
31 // itk namespace first suppresses
32 // kwstyle error for the H5 namespace below
33 namespace itk
34 {
35 }
36 namespace H5
37 {
38 class H5File;
39 class DataSpace;
40 class DataSet;
41 }
42 
44 
45 namespace itk
46 {
85 class ITKIOHDF5_EXPORT HDF5ImageIO: public StreamingImageIOBase
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_ASSIGN(HDF5ImageIO);
89 
91  using Self = HDF5ImageIO;
94 
96  itkNewMacro(Self);
97 
99  itkTypeMacro(HDF5ImageIO, StreamingImageIOBase);
100 
101  /*-------- This part of the interfaces deals with reading data. ----- */
102 
109  bool CanReadFile(const char *FileNameToRead) override;
110 
112  void ReadImageInformation() override;
113 
115  void Read(void *buffer) override;
116 
117  /*-------- This part of the interfaces deals with writing data. ----- */
118 
125  bool CanWriteFile(const char *FileNameToWrite) override;
126 
128  void WriteImageInformation() override;
129 
132  void Write(const void *buffer) override;
133 
134 protected:
135  HDF5ImageIO();
136  ~HDF5ImageIO() override;
137 
138  SizeType GetHeaderSize() const override;
139 
140  void PrintSelf(std::ostream & os, Indent indent) const override;
141 
142 private:
143  void WriteString(const std::string &path,
144  const std::string &value);
145  void WriteString(const std::string &path,
146  const char *s);
147  std::string ReadString(const std::string &path);
148 
149  void WriteScalar(const std::string &path,
150  const bool &value);
151  void WriteScalar(const std::string &path,
152  const long &value);
153  void WriteScalar(const std::string &path,
154  const unsigned long &value);
155  void WriteScalar(const std::string &path,
156  const long long &value);
157  void WriteScalar(const std::string &path,
158  const unsigned long long &value);
159 
160  template <typename TScalar>
161  void WriteScalar(const std::string &path,
162  const TScalar &value);
163 
164  template <typename TScalar>
165  TScalar ReadScalar(const std::string &DataSetName);
166 
167  template <typename TScalar>
168  void WriteVector(const std::string &path,
169  const std::vector<TScalar> &vec);
170 
171  template <typename TScalar>
172  std::vector<TScalar> ReadVector(const std::string &DataSetName);
173 
174  void WriteDirections(const std::string &path,
175  const std::vector<std::vector<double> > &dir);
176 
177  std::vector<std::vector<double> > ReadDirections(const std::string &path);
178 
179  template <typename TType>
180  bool WriteMeta(const std::string &name,
181  MetaDataObjectBase *metaObj);
182  template <typename TType>
183  bool WriteMetaArray(const std::string &name,
184  MetaDataObjectBase *metaObj);
185  template <typename TType>
186  void StoreMetaData(MetaDataDictionary *metaDict,
187  const std::string &HDFPath,
188  const std::string &name,
189  unsigned long numElements);
190  void SetupStreaming(H5::DataSpace *imageSpace,
191  H5::DataSpace *slabSpace);
192 
193  void CloseH5File();
194  void CloseDataSet();
195 
196  H5::H5File *m_H5File{nullptr};
197  H5::DataSet *m_VoxelDataSet{nullptr};
198  bool m_ImageInformationWritten{false};
199 };
200 } // end namespace itk
201 
202 #endif // itkHDF5ImageIO_h
Light weight base class for most itk classes.
A base class for specific ImageIO file formats which support streaming.
::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...
Base class for most ITK classes.
Definition: itkObject.h:60
The common interface for MetaDataObject&#39;s.