ITK  6.0.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 * https://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"
30#include <memory> // For unique_ptr.
31
32// itk namespace first suppresses
33// kwstyle error for the H5 namespace below
34namespace itk
35{}
36namespace H5
37{
38class H5File;
39class DataSpace;
40class DataSet;
41} // namespace H5
42
44
45namespace itk
46{
86class ITKIOHDF5_EXPORT HDF5ImageIO : public StreamingImageIOBase
87{
88public:
89 ITK_DISALLOW_COPY_AND_MOVE(HDF5ImageIO);
90
95
97 itkNewMacro(Self);
98
100 itkOverrideGetNameOfClassMacro(HDF5ImageIO);
101
102 /*-------- This part of the interfaces deals with reading data. ----- */
103
110 bool
111 CanReadFile(const char * FileNameToRead) override;
112
114 void
116
118 void
119 Read(void * buffer) override;
120
121 /*-------- This part of the interfaces deals with writing data. ----- */
122
129 bool
130 CanWriteFile(const char * name) override;
131
133 void
135
138 void
139 Write(const void * buffer) override;
140
141protected:
143 ~HDF5ImageIO() override;
144
146 GetHeaderSize() const override;
147
148 void
149 PrintSelf(std::ostream & os, Indent indent) const override;
150
151private:
152 void
153 WriteString(const std::string & path, const std::string & value);
154 void
155 WriteString(const std::string & path, const char * s);
156 std::string
157 ReadString(const std::string & path);
158
159 void
160 WriteScalar(const std::string & path, const bool value);
161 void
162 WriteScalar(const std::string & path, const long value);
163 void
164 WriteScalar(const std::string & path, const unsigned long value);
165 void
166 WriteScalar(const std::string & path, const long long value);
167 void
168 WriteScalar(const std::string & path, const unsigned long long value);
169
170 template <typename TScalar>
171 void
172 WriteScalar(const std::string & path, const TScalar & value);
173
174 template <typename TScalar>
175 TScalar
176 ReadScalar(const std::string & DataSetName);
177
178 template <typename TScalar>
179 void
180 WriteVector(const std::string & path, const std::vector<TScalar> & vec);
181
182 template <typename TScalar>
183 std::vector<TScalar>
184 ReadVector(const std::string & DataSetName);
185
186 void
187 WriteDirections(const std::string & path, const std::vector<std::vector<double>> & dir);
188
189 std::vector<std::vector<double>>
190 ReadDirections(const std::string & path);
191
192 template <typename TType>
193 bool
194 WriteMeta(const std::string & name, MetaDataObjectBase * metaObjBase);
195 template <typename TType>
196 bool
197 WriteMetaArray(const std::string & name, MetaDataObjectBase * metaObjBase);
198 template <typename TType>
199 void
201 const std::string & HDFPath,
202 const std::string & name,
203 unsigned long numElements);
204 void
205 SetupStreaming(H5::DataSpace * imageSpace, H5::DataSpace * slabSpace);
206
207 /* A convenience function to ensure that the
208 * state of the HDF5ImageIO object is returned
209 * to a state similar to constructing a new
210 * object. This is needed to ensure that
211 * an HDF5ImageIO object can be used multiple
212 * times to read/write many images.
213 */
214 void
216
217 std::unique_ptr<H5::H5File> m_H5File;
218 std::unique_ptr<H5::DataSet> m_VoxelDataSet;
219 bool m_ImageInformationWritten{ false };
220};
221} // end namespace itk
222
223#endif // itkHDF5ImageIO_h
Class that defines how to read HDF5 file format. HDF5 IMAGE FILE FORMAT - As much information as I ca...
bool CanWriteFile(const char *name) override
void WriteString(const std::string &path, const std::string &value)
void WriteScalar(const std::string &path, const long long value)
void WriteVector(const std::string &path, const std::vector< TScalar > &vec)
void Write(const void *buffer) override
std::unique_ptr< H5::DataSet > m_VoxelDataSet
void StoreMetaData(MetaDataDictionary *metaDict, const std::string &HDFPath, const std::string &name, unsigned long numElements)
std::vector< std::vector< double > > ReadDirections(const std::string &path)
void WriteScalar(const std::string &path, const TScalar &value)
~HDF5ImageIO() override
void WriteScalar(const std::string &path, const unsigned long value)
void ReadImageInformation() override
void WriteImageInformation() override
bool WriteMeta(const std::string &name, MetaDataObjectBase *metaObjBase)
SizeType GetHeaderSize() const override
Returns the size of the header in the file.
void ResetToInitialState()
void Read(void *buffer) override
void PrintSelf(std::ostream &os, Indent indent) const override
std::vector< TScalar > ReadVector(const std::string &DataSetName)
void WriteScalar(const std::string &path, const long value)
bool WriteMetaArray(const std::string &name, MetaDataObjectBase *metaObjBase)
std::unique_ptr< H5::H5File > m_H5File
void WriteScalar(const std::string &path, const unsigned long long value)
std::string ReadString(const std::string &path)
bool CanReadFile(const char *FileNameToRead) override
TScalar ReadScalar(const std::string &DataSetName)
void WriteDirections(const std::string &path, const std::vector< std::vector< double > > &dir)
void SetupStreaming(H5::DataSpace *imageSpace, H5::DataSpace *slabSpace)
void WriteScalar(const std::string &path, const bool value)
void WriteString(const std::string &path, const char *s)
itk::intmax_t SizeType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Provides a mechanism for storing a collection of arbitrary data types.
The common interface for MetaDataObject's.
Base class for most ITK classes.
Definition: itkObject.h:62
A base class for specific ImageIO file formats which support streaming.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....