ITK  5.0.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 <memory>
25 #include <string>
26 #include "itk_H5Cpp.h"
27 
28 // Avoids KWStyle error from forward declaration below.
29 namespace itk
30 {
31 }
32 
33 // Forward declaration of class H5::H5File
34 namespace H5
35 {
36 class H5File;
37 }
38 
39 namespace itk
40 {
41 
42 
56 struct ITKIOTransformHDF5_EXPORT HDF5CommonPathNames
57  {
58  //
59  // HDF uses hierarchical paths to find particular data
60  // in a file. These strings are used by both reading and
61  // writing.
62  static const std::string transformGroupName;
63  static const std::string transformTypeName;
64  static const std::string transformFixedNameMisspelled;
65  static const std::string transformParamsNameMisspelled;
66  static const std::string transformFixedName;
67  static const std::string transformParamsName;
68  static const std::string transformFixedNameCorrected;
69  static const std::string transformParamsNameCorrected;
70  static const std::string ItkVersion;
71  static const std::string HDFVersion;
72  static const std::string OSName;
73  static const std::string OSVersion;
74  };
75 
76 
86 template<typename TParametersValueType>
87 class ITK_TEMPLATE_EXPORT HDF5TransformIOTemplate:public TransformIOBaseTemplate<TParametersValueType>,
88 private HDF5CommonPathNames
89 {
90 public:
94  using TransformType = typename Superclass::TransformType;
95  using TransformPointer = typename Superclass::TransformPointer;
96  using TransformListType = typename Superclass::TransformListType;
101 
104 
107  itkNewMacro( Self );
109 
112  bool CanReadFile(const char *) override;
113 
116  bool CanWriteFile(const char *) override;
117 
119  void Read() override;
120 
124  void Write() override;
125 
126 protected:
128  ~HDF5TransformIOTemplate() override;
129 
130 private:
132  ParametersType ReadParameters(const std::string &DataSetName) const;
133  FixedParametersType ReadFixedParameters(const std::string &DataSetName) const;
135 
137  void WriteParameters(const std::string &name,
138  const ParametersType &parameters);
139  void WriteFixedParameters(const std::string &name,
140  const FixedParametersType &parameters);
142 
144  void WriteString(const std::string &path, const std::string &value);
145  void WriteString(const std::string &path, const char *value);
146  void WriteOneTransform(const int transformIndex,
147  const TransformType *transform);
149 
150  std::unique_ptr<H5::H5File> m_H5File;
151 
156  H5::PredType GetH5TypeFromString( ) const;
157 };
158 
159 const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int);
160 
163 
164 } // end namespace itk
165 
166 // Note: Explicit instantiation is done in itkHDF5TransformIO.cxx
167 
168 #endif // itkHDF5TransformIO_h
169 
171 #ifndef ITK_TEMPLATE_EXPLICIT_HDF5TransformIO
172 // Explicit instantiation is required to ensure correct dynamic_cast
173 // behavior across shared libraries.
174 //
175 // IMPORTANT: Since within the same compilation unit,
176 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
177 // need to be considered. This code *MUST* be *OUTSIDE* the header
178 // guards.
179 //
180 # if defined( ITKIOTransformHDF5_EXPORTS )
181 // We are building this library
182 # define ITKIOTransformHDF5_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
183 # else
184 // We are using this library
185 # define ITKIOTransformHDF5_EXPORT_EXPLICIT ITKIOTransformHDF5_EXPORT
186 # endif
187 namespace itk
188 {
189 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
190  ITK_GCC_PRAGMA_DIAG_PUSH()
191 #endif
192 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
193 
196 
197 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
198  ITK_GCC_PRAGMA_DIAG_POP()
199 #else
200  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
201 #endif
202 
203 } // end namespace itk
204 # undef ITKIOTransformHDF5_EXPORT_EXPLICIT
205 #endif
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< float >
Light weight base class for most itk classes.
static const std::string transformFixedName
static const std::string transformParamsName
static const std::string transformFixedNameMisspelled
Read&amp;Write transforms in HDF5 Format.
static const std::string HDFVersion
const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int)
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< double >
static const std::string transformParamsNameCorrected
Abstract superclass defining the Transform IO interface.
std::list< ConstTransformPointer > ConstTransformListType
#define ITKIOTransformHDF5_EXPORT_EXPLICIT
static const std::string transformTypeName
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
typename TransformType::FixedParametersType FixedParametersType
std::list< TransformPointer > TransformListType
typename TransformType::Pointer TransformPointer
static const std::string OSName
static const std::string transformGroupName
static const std::string transformFixedNameCorrected
typename TransformType::ParametersType ParametersType
Base class for most ITK classes.
Definition: itkObject.h:60
static const std::string transformParamsNameMisspelled
std::unique_ptr< H5::H5File > m_H5File
TParametersValueType ParametersValueType
TParametersValueType ParametersValueType