ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkHDF5TransformIO.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  *=========================================================================*/
18 #ifndef itkHDF5TransformIO_h
19 #define itkHDF5TransformIO_h
20 
21 #include "ITKIOTransformHDF5Export.h"
22 
23 #include "itkTransformIOBase.h"
24 #include "itkAutoPointer.h"
25 #include <string>
26 
27 // Avoids KWStyle error from forward declaration below.
28 namespace itk
29 {
30 }
31 
32 // Forward declaration of class H5::H5File
33 namespace H5
34 {
35 class H5File;
36 }
37 
38 namespace itk
39 {
40 
41 
55 struct ITKIOTransformHDF5_EXPORT HDF5CommonPathNames
56  {
57  //
58  // HDF uses hierarchical paths to find particular data
59  // in a file. These strings are used by both reading and
60  // writing.
61  static const std::string transformGroupName;
62  static const std::string transformTypeName;
63  static const std::string transformFixedName;
64  static const std::string transformParamsName;
65  static const std::string ItkVersion;
66  static const std::string HDFVersion;
67  static const std::string OSName;
68  static const std::string OSVersion;
69  };
70 
71 
81 template<typename TParametersValueType>
82 class ITKIOTransformBase_TEMPLATE_EXPORT HDF5TransformIOTemplate:public TransformIOBaseTemplate<TParametersValueType>,
83 private HDF5CommonPathNames
84 {
85 public:
89  typedef typename Superclass::TransformType TransformType;
90  typedef typename Superclass::TransformPointer TransformPointer;
91  typedef typename Superclass::TransformListType TransformListType;
96 
97  typedef typename TransformIOBaseTemplate
100 
103  itkNewMacro( Self );
105 
108  virtual bool CanReadFile(const char *) ITK_OVERRIDE;
109 
112  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
113 
115  virtual void Read() ITK_OVERRIDE;
116 
120  virtual void Write() ITK_OVERRIDE;
121 
122 protected:
124  virtual ~HDF5TransformIOTemplate();
125 
126 private:
128  ParametersType ReadParameters(const std::string &DataSetName) const;
129  FixedParametersType ReadFixedParameters(const std::string &DataSetName) const;
131 
133  void WriteParameters(const std::string &name,
134  const ParametersType &parameters);
135  void WriteFixedParameters(const std::string &name,
136  const FixedParametersType &parameters);
138 
140  void WriteString(const std::string &path, const std::string &value);
141  void WriteString(const std::string &path, const char *value);
142  void WriteOneTransform(const int transformIndex,
143  const TransformType *transform);
145 
146  AutoPointer<H5::H5File> m_H5File;
147 };
148 const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int);
149 
151 typedef HDF5TransformIOTemplate<double> HDF5TransformIO;
152 
153 } // end namespace itk
154 
155 // Note: Explicit instantiation is done in itkHDF5TransformIO.cxx
156 
157 #endif // itkHDF5TransformIO_h
158 
160 #ifndef ITK_TEMPLATE_EXPLICIT_HDF5TransformIO
161 // Explicit instantiation is required to ensure correct dynamic_cast
162 // behavior across shared libraries.
163 //
164 // IMPORTANT: Since within the same compilation unit,
165 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
166 // need to be considered. This code *MUST* be *OUTSIDE* the header
167 // guards.
168 //
169 # if defined( ITKIOTransformHDF5_EXPORTS )
170 // We are building this library
171 # define ITKIOTransformHDF5_EXPORT_EXPLICIT
172 # else
173 // We are using this library
174 # define ITKIOTransformHDF5_EXPORT_EXPLICIT ITKIOTransformHDF5_EXPORT
175 # endif
176 namespace itk
177 {
178 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
179  ITK_GCC_PRAGMA_DIAG_PUSH()
180 #endif
181 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
182 
185 
186 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
187  ITK_GCC_PRAGMA_DIAG_POP()
188 #else
189  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
190 #endif
191 
192 } // end namespace itk
193 # undef ITKIOTransformHDF5_EXPORT_EXPLICIT
194 #endif
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< float >
TransformType::FixedParametersValueType FixedParametersValueType
Light weight base class for most itk classes.
static const std::string transformFixedName
Superclass::TransformType TransformType
TransformIOBaseTemplate< ParametersValueType >::ConstTransformListType ConstTransformListType
TransformIOBaseTemplate< TParametersValueType > Superclass
static const std::string transformParamsName
Read&amp;Write transforms in HDF5 Format.
TParametersValueType ParametersValueType
TransformType::ParametersType ParametersType
static const std::string HDFVersion
const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int)
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< double >
Abstract superclass defining the Transform IO interface.
Superclass::TransformListType TransformListType
#define ITKIOTransformHDF5_EXPORT_EXPLICIT
static const std::string transformTypeName
Superclass::TransformPointer TransformPointer
static const std::string OSVersion
Class to hold and manage different parameter types used during optimization.
Secondary bass class of HDF5CommonPathNames common between templates.
static const std::string ItkVersion
TransformType::FixedParametersType FixedParametersType
SmartPointer< Self > Pointer
std::list< ConstTransformPointer > ConstTransformListType
static const std::string OSName
Implements an Automatic Pointer to an object.
static const std::string transformGroupName
TransformType::ParametersValueType ParametersValueType
TParametersValueType ParametersValueType
HDF5TransformIOTemplate Self