ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 *=========================================================================*/
24
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{
89
90class ITKIOHDF5_EXPORT HDF5ImageIO : public StreamingImageIOBase
91{
92public:
93 ITK_DISALLOW_COPY_AND_MOVE(HDF5ImageIO);
94
99
101 itkNewMacro(Self);
102
104 itkOverrideGetNameOfClassMacro(HDF5ImageIO);
105
106 /*-------- This part of the interfaces deals with reading data. ----- */
107
114 bool
115 CanReadFile(const char * FileNameToRead) override;
116
118 void
120
122 void
123 Read(void * buffer) override;
124
125 /*-------- This part of the interfaces deals with writing data. ----- */
126
133 bool
134 CanWriteFile(const char * name) override;
135
137 void
139
142 void
143 Write(const void * buffer) override;
144
145protected:
147 ~HDF5ImageIO() override;
148
150 GetHeaderSize() const override;
151
152 void
153 PrintSelf(std::ostream & os, Indent indent) const override;
154
155private:
156 void
157 WriteString(const std::string & path, const std::string & value);
158 void
159 WriteString(const std::string & path, const char * s);
160 std::string
161 ReadString(const std::string & path);
162
163 void
164 WriteScalar(const std::string & path, const bool value);
165 void
166 WriteScalar(const std::string & path, const long value);
167 void
168 WriteScalar(const std::string & path, const unsigned long value);
169 void
170 WriteScalar(const std::string & path, const long long value);
171 void
172 WriteScalar(const std::string & path, const unsigned long long value);
173
174 template <typename TScalar>
175 void
176 WriteScalar(const std::string & path, const TScalar & value);
177
178 template <typename TScalar>
179 TScalar
180 ReadScalar(const std::string & DataSetName);
181
182 template <typename TScalar>
183 void
184 WriteVector(const std::string & path, const std::vector<TScalar> & vec);
185
186 template <typename TScalar>
187 std::vector<TScalar>
188 ReadVector(const std::string & DataSetName);
189
190 void
191 WriteDirections(const std::string & path, const std::vector<std::vector<double>> & dir);
192
193 std::vector<std::vector<double>>
194 ReadDirections(const std::string & path);
195
196 template <typename TType>
197 bool
198 WriteMeta(const std::string & name, MetaDataObjectBase * metaObjBase);
199 template <typename TType>
200 bool
201 WriteMetaArray(const std::string & name, MetaDataObjectBase * metaObjBase);
202 template <typename TType>
203 void
205 const std::string & HDFPath,
206 const std::string & name,
207 unsigned long numElements);
208 void
209 SetupStreaming(H5::DataSpace * imageSpace, H5::DataSpace * slabSpace);
210
211 /* A convenience function to ensure that the
212 * state of the HDF5ImageIO object is returned
213 * to a state similar to constructing a new
214 * object. This is needed to ensure that
215 * an HDF5ImageIO object can be used multiple
216 * times to read/write many images.
217 */
218 void
220
221 std::unique_ptr<H5::H5File> m_H5File;
222 std::unique_ptr<H5::DataSet> m_VoxelDataSet;
224};
225} // end namespace itk
226
227#endif // itkHDF5ImageIO_h
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
StreamingImageIOBase Superclass
void WriteScalar(const std::string &path, const unsigned long value)
void ReadImageInformation() override
SmartPointer< Self > Pointer
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:53
Provides a mechanism for storing a collection of arbitrary data types.
The common interface for MetaDataObject's.
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....