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.
28namespace itk
29{}
30
31// Forward declaration of class H5::H5File
32namespace H5
33{
34class H5File;
35class PredType;
36} // namespace H5
37
38namespace itk
39{
40
41
55struct 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
85template <typename TParametersValueType>
86class ITK_TEMPLATE_EXPORT HDF5TransformIOTemplate
87 : public TransformIOBaseTemplate<TParametersValueType>
88 , private HDF5CommonPathNames
89{
90public:
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
129protected:
132
133private:
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
165};
166
167const std::string ITKIOTransformHDF5_EXPORT
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
196namespace itk
197{
198ITK_GCC_PRAGMA_DIAG_PUSH()
199ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
200
203
204ITK_GCC_PRAGMA_DIAG_POP()
205
206} // end namespace itk
207#undef ITKIOTransformHDF5_EXPORT_EXPLICIT
208#endif
Read&Write transforms in HDF5 Format.
void WriteFixedParameters(const std::string &name, const FixedParametersType &fixedParameters)
ParametersType ReadParameters(const std::string &DataSetName) const
void WriteOneTransform(const int transformIndex, const TransformType *curTransform)
FixedParametersType ReadFixedParameters(const std::string &DataSetName) const
void WriteString(const std::string &path, const char *s)
void WriteParameters(const std::string &name, const ParametersType &parameters)
typename TransformType::FixedParametersType FixedParametersType
void WriteString(const std::string &path, const std::string &value)
H5::PredType GetH5TypeFromString() const
typename TransformType::ParametersType ParametersType
bool CanReadFile(const char *) override
bool CanWriteFile(const char *) override
std::unique_ptr< H5::H5File > m_H5File
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
Class to hold and manage different parameter types used during optimization.
TParametersValueType ParametersValueType
Abstract superclass defining the Transform IO interface.
TParametersValueType ParametersValueType
std::list< ConstTransformPointer > ConstTransformListType
#define ITKIOTransformHDF5_EXPORT_EXPLICIT
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< float >
template class ITKIOTransformHDF5_EXPORT_EXPLICIT HDF5TransformIOTemplate< double >
const std::string ITKIOTransformHDF5_EXPORT GetTransformName(int)
Secondary bass class of HDF5CommonPathNames common between templates.
static const std::string transformParamsNameCorrected
static const std::string ItkVersion
static const std::string OSName
static const std::string transformFixedNameCorrected
static const std::string HDFVersion
static const std::string transformTypeName
static const std::string OSVersion
static const std::string transformGroupName
static const std::string transformFixedNameMisspelled
static const std::string transformParamsNameMisspelled
static const std::string transformParamsName
static const std::string transformFixedName