ITK  4.3.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 
28 
29 // itk namespace first suppresses
30 // kwstyle error for the H5 namespace below
31 namespace itk
32 {
33 }
34 namespace H5
35 {
36 class H5File;
37 class DataSpace;
38 class DataSet;
39 }
40 
42 
43 namespace itk
44 {
45 class MetaDataObjectBase;
46 class MetaDataDictionary;
85 class ITK_EXPORT HDF5ImageIO:public StreamingImageIOBase
86 {
87 public:
89  typedef HDF5ImageIO Self;
92 
94  itkNewMacro(Self);
95 
97  itkTypeMacro(HDF5ImageIO, Superclass);
98 
99  /*-------- This part of the interfaces deals with reading data. ----- */
100 
107  virtual bool CanReadFile(const char *FileNameToRead);
108 
110  virtual void ReadImageInformation();
111 
113  virtual void Read(void *buffer);
114 
115  /*-------- This part of the interfaces deals with writing data. ----- */
116 
123  virtual bool CanWriteFile(const char *FileNameToWrite);
124 
126  virtual void WriteImageInformation();
127 
130  virtual void Write(const void *buffer);
131 
132 protected:
133  HDF5ImageIO();
134  ~HDF5ImageIO();
135 
136  virtual SizeType GetHeaderSize(void) const;
137 
138  void PrintSelf(std::ostream & os, Indent indent) const;
139 
140 private:
141  HDF5ImageIO(const Self &); //purposely not implemented
142  void operator=(const Self &); //purposely not implemented
143 
144  void WriteString(const std::string &path,
145  const std::string &value);
146  void WriteString(const std::string &path,
147  const char *s);
148  std::string ReadString(const std::string &path);
149 
150  void WriteScalar(const std::string &path,
151  const bool &value);
152  void WriteScalar(const std::string &path,
153  const long &value);
154  void WriteScalar(const std::string &path,
155  const unsigned long &value);
156 
157  template <typename TScalar>
158  void WriteScalar(const std::string &path,
159  const TScalar &value);
160 
161  template <typename TScalar>
162  TScalar ReadScalar(const std::string &DataSetName);
163 
164  template <typename TScalar>
165  void WriteVector(const std::string &path,
166  const std::vector<TScalar> &vec);
167 
168  template <typename TScalar>
169  std::vector<TScalar> ReadVector(const std::string &DataSetName);
170 
171  void WriteDirections(const std::string &path,
172  const std::vector<std::vector<double> > &dir);
173 
174  std::vector<std::vector<double> > ReadDirections(const std::string &path);
175 
176  template <typename TType>
177  bool WriteMeta(const std::string &name,
178  MetaDataObjectBase *metaObj);
179  template <typename TType>
180  bool WriteMetaArray(const std::string &name,
181  MetaDataObjectBase *metaObj);
182  template <typename TType>
183  void StoreMetaData(MetaDataDictionary *metaDict,
184  const std::string &HDFPath,
185  const std::string &name,
186  unsigned long numElements);
187  void SetupStreaming(H5::DataSpace *imageSpace,
188  H5::DataSpace *slabSpace);
189  H5::H5File *m_H5File;
190  H5::DataSet *m_VoxelDataSet;
192 };
193 } // end namespace itk
194 
195 #endif // __itkHDF5ImageIO_h
196