ITK  4.8.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 
30 // itk namespace first suppresses
31 // kwstyle error for the H5 namespace below
32 namespace itk
33 {
34 }
35 namespace H5
36 {
37 class H5File;
38 class DataSpace;
39 class DataSet;
40 }
41 
43 
44 namespace itk
45 {
46 class MetaDataObjectBase;
47 class MetaDataDictionary;
86 class ITKIOHDF5_EXPORT HDF5ImageIO:public StreamingImageIOBase
87 {
88 public:
90  typedef HDF5ImageIO Self;
93 
95  itkNewMacro(Self);
96 
98  itkTypeMacro(HDF5ImageIO, Superclass);
99 
100  /*-------- This part of the interfaces deals with reading data. ----- */
101 
108  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
109 
111  virtual void ReadImageInformation() ITK_OVERRIDE;
112 
114  virtual void Read(void *buffer) ITK_OVERRIDE;
115 
116  /*-------- This part of the interfaces deals with writing data. ----- */
117 
124  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
125 
127  virtual void WriteImageInformation() ITK_OVERRIDE;
128 
131  virtual void Write(const void *buffer) ITK_OVERRIDE;
132 
133 protected:
134  HDF5ImageIO();
135  ~HDF5ImageIO();
136 
137  virtual SizeType GetHeaderSize(void) const ITK_OVERRIDE;
138 
139  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
140 
141 private:
142  HDF5ImageIO(const Self &); //purposely not implemented
143  void operator=(const Self &); //purposely not implemented
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  H5::H5File *m_H5File;
191  H5::DataSet *m_VoxelDataSet;
192  bool m_ImageInformationWritten;
193 };
194 } // end namespace itk
195 
196 #endif // itkHDF5ImageIO_h
Light weight base class for most itk classes.
Abstract superclass defines image IO interface.
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...
Base class for most ITK classes.
Definition: itkObject.h:57
ImageIOBase Superclass
The common interface for MetaDataObject&#39;s.