ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkHDF5ImageIO.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00025 #ifndef __itkHDF5ImageIO_h
00026 #define __itkHDF5ImageIO_h
00027 
00028 
00029 // itk namespace first suppresses
00030 // kwstyle error for the H5 namespace below
00031 namespace itk
00032 {
00033 }
00034 namespace H5
00035 {
00036 class H5File;
00037 class DataSpace;
00038 class DataSet;
00039 }
00040 
00041 #include "itkStreamingImageIOBase.h"
00042 
00043 namespace itk
00044 {
00045 class MetaDataObjectBase;
00046 class MetaDataDictionary;
00085 class ITK_EXPORT HDF5ImageIO:public StreamingImageIOBase
00086 {
00087 public:
00089   typedef HDF5ImageIO          Self;
00090   typedef ImageIOBase          Superclass;
00091   typedef SmartPointer< Self > Pointer;
00092 
00094   itkNewMacro(Self);
00095 
00097   itkTypeMacro(HDF5ImageIO, Superclass);
00098 
00099   /*-------- This part of the interfaces deals with reading data. ----- */
00100 
00107   virtual bool CanReadFile(const char *FileNameToRead);
00108 
00110   virtual void ReadImageInformation();
00111 
00113   virtual void Read(void *buffer);
00114 
00115   /*-------- This part of the interfaces deals with writing data. ----- */
00116 
00123   virtual bool CanWriteFile(const char *FileNameToWrite);
00124 
00126   virtual void WriteImageInformation();
00127 
00130   virtual void Write(const void *buffer);
00131 
00132 protected:
00133   HDF5ImageIO();
00134   ~HDF5ImageIO();
00135 
00136   virtual SizeType GetHeaderSize(void) const;
00137 
00138   void PrintSelf(std::ostream & os, Indent indent) const;
00139 
00140 private:
00141   HDF5ImageIO(const Self &);   //purposely not implemented
00142   void operator=(const Self &); //purposely not implemented
00143 
00144   void WriteString(const std::string &path,
00145                    const std::string &value);
00146   void WriteString(const std::string &path,
00147                    const char *s);
00148   std::string ReadString(const std::string &path);
00149 
00150   void WriteScalar(const std::string &path,
00151                    const bool &value);
00152   void WriteScalar(const std::string &path,
00153                    const long &value);
00154   void WriteScalar(const std::string &path,
00155                    const unsigned long &value);
00156 
00157   template <typename TScalar>
00158   void WriteScalar(const std::string &path,
00159                    const TScalar &value);
00160 
00161   template <typename TScalar>
00162   TScalar ReadScalar(const std::string &DataSetName);
00163 
00164   template <typename TScalar>
00165   void WriteVector(const std::string &path,
00166                    const std::vector<TScalar> &vec);
00167 
00168   template <typename TScalar>
00169   std::vector<TScalar> ReadVector(const std::string &DataSetName);
00170 
00171   void WriteDirections(const std::string &path,
00172                        const std::vector<std::vector<double> > &dir);
00173 
00174   std::vector<std::vector<double> > ReadDirections(const std::string &path);
00175 
00176   template <typename TType>
00177     bool WriteMeta(const std::string &name,
00178                    MetaDataObjectBase *metaObj);
00179   template <typename TType>
00180     bool WriteMetaArray(const std::string &name,
00181                    MetaDataObjectBase *metaObj);
00182   template <typename TType>
00183     void StoreMetaData(MetaDataDictionary *metaDict,
00184                        const std::string &HDFPath,
00185                        const std::string &name,
00186                        unsigned long numElements);
00187   void SetupStreaming(H5::DataSpace *imageSpace,
00188                       H5::DataSpace *slabSpace);
00189   H5::H5File  *m_H5File;
00190   H5::DataSet *m_VoxelDataSet;
00191   bool         m_ImageInformationWritten;
00192 };
00193 } // end namespace itk
00194 
00195 #endif // __itkHDF5ImageIO_h
00196