ITK  5.2.0
Insight Toolkit
itkHDF5ImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 namespace H5
36 {
37 class H5File;
38 class DataSpace;
39 class DataSet;
40 } // namespace H5
41 
43 
44 namespace itk
45 {
85 class ITKIOHDF5_EXPORT HDF5ImageIO : public StreamingImageIOBase
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_MOVE(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
110  CanReadFile(const char * FileNameToRead) override;
111 
113  void
114  ReadImageInformation() override;
115 
117  void
118  Read(void * buffer) override;
119 
120  /*-------- This part of the interfaces deals with writing data. ----- */
121 
128  bool
129  CanWriteFile(const char * name) override;
130 
132  void
133  WriteImageInformation() override;
134 
137  void
138  Write(const void * buffer) override;
139 
140 protected:
141  HDF5ImageIO();
142  ~HDF5ImageIO() override;
143 
144  SizeType
145  GetHeaderSize() const override;
146 
147  void
148  PrintSelf(std::ostream & os, Indent indent) const override;
149 
150 private:
151  void
152  WriteString(const std::string & path, const std::string & value);
153  void
154  WriteString(const std::string & path, const char * s);
155  std::string
156  ReadString(const std::string & path);
157 
158  void
159  WriteScalar(const std::string & path, const bool & value);
160  void
161  WriteScalar(const std::string & path, const long & value);
162  void
163  WriteScalar(const std::string & path, const unsigned long & value);
164  void
165  WriteScalar(const std::string & path, const long long & value);
166  void
167  WriteScalar(const std::string & path, const unsigned long long & value);
168 
169  template <typename TScalar>
170  void
171  WriteScalar(const std::string & path, const TScalar & value);
172 
173  template <typename TScalar>
174  TScalar
175  ReadScalar(const std::string & DataSetName);
176 
177  template <typename TScalar>
178  void
179  WriteVector(const std::string & path, const std::vector<TScalar> & vec);
180 
181  template <typename TScalar>
182  std::vector<TScalar>
183  ReadVector(const std::string & DataSetName);
184 
185  void
186  WriteDirections(const std::string & path, const std::vector<std::vector<double>> & dir);
187 
188  std::vector<std::vector<double>>
189  ReadDirections(const std::string & path);
190 
191  template <typename TType>
192  bool
193  WriteMeta(const std::string & name, MetaDataObjectBase * metaObjBase);
194  template <typename TType>
195  bool
196  WriteMetaArray(const std::string & name, MetaDataObjectBase * metaObjBase);
197  template <typename TType>
198  void
199  StoreMetaData(MetaDataDictionary * metaDict,
200  const std::string & HDFPath,
201  const std::string & name,
202  unsigned long numElements);
203  void
204  SetupStreaming(H5::DataSpace * imageSpace, H5::DataSpace * slabSpace);
205 
206  void
207  CloseH5File();
208  void
209  CloseDataSet();
210 
211  H5::H5File * m_H5File{ nullptr };
212  H5::DataSet * m_VoxelDataSet{ nullptr };
213  bool m_ImageInformationWritten{ false };
214 };
215 } // end namespace itk
216 
217 #endif // itkHDF5ImageIO_h
itkStreamingImageIOBase.h
itk::MetaDataObjectBase
The common interface for MetaDataObject's.
Definition: itkMetaDataObjectBase.h:47
itkMetaDataObjectBase.h
itk::StreamingImageIOBase
A base class for specific ImageIO file formats which support streaming.
Definition: itkStreamingImageIOBase.h:52
itk::HDF5ImageIO
Class that defines how to read HDF5 file format. HDF5 IMAGE FILE FORMAT - As much information as I ca...
Definition: itkHDF5ImageIO.h:85
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:53
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
H5
Definition: itkHDF5ImageIO.h:35
itkMetaDataDictionary.h
itk::ImageIOBase::SizeType
::itk::intmax_t SizeType
Definition: itkImageIOBase.h:395
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62