ITK  5.4.0
Insight Toolkit
itkHDF5TransformIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 
27 // Avoids KWStyle error from forward declaration below.
28 namespace itk
29 {}
30 
31 // Forward declaration of class H5::H5File
32 namespace H5
33 {
34 class H5File;
35 class PredType;
36 } // namespace H5
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 transformFixedNameMisspelled;
64  static const std::string transformParamsNameMisspelled;
65  static const std::string transformFixedName;
66  static const std::string transformParamsName;
67  static const std::string transformFixedNameCorrected;
68  static const std::string transformParamsNameCorrected;
69  static const std::string ItkVersion;
70  static const std::string HDFVersion;
71  static const std::string OSName;
72  static const std::string OSVersion;
73 };
74 
75 
85 template <typename TParametersValueType>
86 class ITK_TEMPLATE_EXPORT HDF5TransformIOTemplate
87  : public TransformIOBaseTemplate<TParametersValueType>
88  , private HDF5CommonPathNames
89 {
90 public:
94  using typename Superclass::TransformType;
95  using typename Superclass::TransformPointer;
96  using typename Superclass::TransformListType;
101 
103 
105  itkOverrideGetNameOfClassMacro(HDF5TransformIOTemplate);
106  itkNewMacro(Self);
111  bool
112  CanReadFile(const char *) override;
113 
116  bool
117  CanWriteFile(const char *) override;
118 
120  void
121  Read() override;
122 
126  void
127  Write() override;
128 
129 protected:
131  ~HDF5TransformIOTemplate() override;
132 
133 private:
136  ReadParameters(const std::string & DataSetName) const;
138  ReadFixedParameters(const std::string & DataSetName) const;
142  void
143  WriteParameters(const std::string & name, const ParametersType & parameters);
144  void
145  WriteFixedParameters(const std::string & name, const FixedParametersType & fixedParameters);
149  void
150  WriteString(const std::string & path, const std::string & value);
151  void
152  WriteString(const std::string & path, const char * s);
153  void
154  WriteOneTransform(const int transformIndex, const TransformType * curTransform);
157  std::unique_ptr<H5::H5File> m_H5File;
158 
163  H5::PredType
164  GetH5TypeFromString() const;
165 };
166 
167 const std::string ITKIOTransformHDF5_EXPORT
168  GetTransformName(int);
169 
172 
173 } // end namespace itk
174 
175 // Note: Explicit instantiation is done in itkHDF5TransformIO.cxx
176 
177 #endif // itkHDF5TransformIO_h
178 
180 #ifndef ITK_TEMPLATE_EXPLICIT_HDF5TransformIO
181 // Explicit instantiation is required to ensure correct dynamic_cast
182 // behavior across shared libraries.
183 //
184 // IMPORTANT: Since within the same compilation unit,
185 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
186 // need to be considered. This code *MUST* be *OUTSIDE* the header
187 // guards.
188 //
189 #if defined(ITKIOTransformHDF5_EXPORTS)
190 // We are building this library
191 # define ITKIOTransformHDF5_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
192 #else
193 // We are using this library
194 # define ITKIOTransformHDF5_EXPORT_EXPLICIT ITKIOTransformHDF5_EXPORT
195 #endif
196 namespace itk
197 {
198 ITK_GCC_PRAGMA_DIAG_PUSH()
199 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
200 
203 
204 ITK_GCC_PRAGMA_DIAG_POP()
205 
206 } // end namespace itk
207 #undef ITKIOTransformHDF5_EXPORT_EXPLICIT
208 #endif
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:36
itk::TransformIOBaseTemplate::ParametersValueType
TParametersValueType ParametersValueType
Definition: itkTransformIOBase.h:71
itk::HDF5CommonPathNames::transformTypeName
static const std::string transformTypeName
Definition: itkHDF5TransformIO.h:62
itkTransformIOBase.h
itk::HDF5CommonPathNames::transformParamsNameCorrected
static const std::string transformParamsNameCorrected
Definition: itkHDF5TransformIO.h:68
itk::TransformIOBaseTemplate::ConstTransformListType
std::list< ConstTransformPointer > ConstTransformListType
Definition: itkTransformIOBase.h:82
itk::HDF5CommonPathNames::transformFixedName
static const std::string transformFixedName
Definition: itkHDF5TransformIO.h:65
ITKIOTransformHDF5_EXPORT_EXPLICIT
#define ITKIOTransformHDF5_EXPORT_EXPLICIT
Definition: itkHDF5TransformIO.h:194
itk::SmartPointer< Self >
itk::HDF5TransformIOTemplate::FixedParametersType
typename TransformType::FixedParametersType FixedParametersType
Definition: itkHDF5TransformIO.h:99
itk::HDF5CommonPathNames::transformParamsName
static const std::string transformParamsName
Definition: itkHDF5TransformIO.h:66
itk::HDF5TransformIOTemplate::m_H5File
std::unique_ptr< H5::H5File > m_H5File
Definition: itkHDF5TransformIO.h:157
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::HDF5CommonPathNames::transformParamsNameMisspelled
static const std::string transformParamsNameMisspelled
Definition: itkHDF5TransformIO.h:64
itk::HDF5CommonPathNames::OSName
static const std::string OSName
Definition: itkHDF5TransformIO.h:71
itk::HDF5CommonPathNames::transformFixedNameMisspelled
static const std::string transformFixedNameMisspelled
Definition: itkHDF5TransformIO.h:63
itk::TransformIOBaseTemplate
Abstract superclass defining the Transform IO interface.
Definition: itkTransformIOBase.h:58
itk::HDF5CommonPathNames::transformGroupName
static const std::string transformGroupName
Definition: itkHDF5TransformIO.h:61
H5
Definition: itkHDF5ImageIO.h:36
itk::HDF5TransformIOTemplate::ParametersType
typename TransformType::ParametersType ParametersType
Definition: itkHDF5TransformIO.h:97
itk::HDF5CommonPathNames
Secondary bass class of HDF5CommonPathNames common between templates.
Definition: itkHDF5TransformIO.h:55
itk::HDF5CommonPathNames::OSVersion
static const std::string OSVersion
Definition: itkHDF5TransformIO.h:72
itk::HDF5CommonPathNames::transformFixedNameCorrected
static const std::string transformFixedNameCorrected
Definition: itkHDF5TransformIO.h:67
itk::TransformBaseTemplate::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformBase.h:83
itk::GetTransformName
const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int)
itk::HDF5TransformIOTemplate
Read&Write transforms in HDF5 Format.
Definition: itkHDF5TransformIO.h:86
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::HDF5CommonPathNames::ItkVersion
static const std::string ItkVersion
Definition: itkHDF5TransformIO.h:69
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::HDF5TransformIOTemplate< float >
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< float >
itk::TransformBaseTemplate::ParametersValueType
TParametersValueType ParametersValueType
Definition: itkTransformBase.h:81
itk::HDF5TransformIOTemplate< double >
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< double >
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::TransformIOBaseTemplate::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformIOBase.h:72
itk::HDF5CommonPathNames::HDFVersion
static const std::string HDFVersion
Definition: itkHDF5TransformIO.h:70