ITK  5.4.0
Insight Toolkit
itkTransformIOBase.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 itkTransformIOBase_h
19#define itkTransformIOBase_h
20
21#include "ITKIOTransformBaseExport.h"
22
24#include "itkTransformBase.h"
25#include "itkCommonEnums.h"
26#include <list>
27#include <iostream>
28#include <fstream>
29#include <string>
30
31#ifndef ITKIOTransformBase_TEMPLATE_EXPORT
32# if defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) || defined(__linux__) && defined(ITK_BUILD_SHARED_LIBS)
33// Make everything visible
34# define ITKIOTransformBase_TEMPLATE_EXPORT __attribute__((visibility("default")))
35# else
36# define ITKIOTransformBase_TEMPLATE_EXPORT
37# endif
38#endif
39
40namespace itk
41{
42
57template <typename TParametersValueType>
59{
60public:
65
67 itkOverrideGetNameOfClassMacro(TransformIOBaseTemplate);
68
70 using ScalarType = TParametersValueType; // For backwards compatibility
71 using ParametersValueType = TParametersValueType;
73
75
80 using TransformListType = std::list<TransformPointer>;
82 using ConstTransformListType = std::list<ConstTransformPointer>;
83
85 itkSetStringMacro(FileName);
86 itkGetStringMacro(FileName);
90 virtual void
91 Read() = 0;
92
94 virtual void
95 Write() = 0;
96
99 virtual bool
100 CanReadFile(const char *) = 0;
101
104 virtual bool
105 CanWriteFile(const char *) = 0;
106
110 {
111 return m_ReadTransformList;
112 }
113 TransformListType &
115 {
116 return m_ReadTransformList;
117 }
118 ConstTransformListType &
120 {
121 return m_WriteTransformList;
122 }
126 void
128
130 itkSetMacro(AppendMode, bool);
131 itkGetConstMacro(AppendMode, bool);
132 itkBooleanMacro(AppendMode);
136 itkSetMacro(UseCompression, bool);
137 itkGetConstMacro(UseCompression, bool);
138 itkBooleanMacro(UseCompression);
149 static inline void
150 CorrectTransformPrecisionType(std::string & itkNotUsed(inputTransformName))
151 {
152 itkGenericExceptionMacro("Unknown ScalarType" << typeid(ScalarType).name());
153 }
154
155protected:
158 void
159 PrintSelf(std::ostream & os, Indent indent) const override;
160
161 void
162 OpenStream(std::ofstream & outputStream, bool binary);
163
164 void
165 CreateTransform(TransformPointer & ptr, const std::string & ClassName);
166
167 /* The following struct returns the string name of computation type */
168 /* default implementation */
169 static inline const std::string
171 {
172 itkGenericExceptionMacro("Unknown ScalarType" << typeid(ScalarType).name());
173 }
174
175private:
176 std::string m_FileName{};
177 TransformListType m_ReadTransformList{};
178 ConstTransformListType m_WriteTransformList{};
179 bool m_AppendMode{ false };
181 bool m_UseCompression{ false };
182};
183
184
185template <>
186inline void
188{
189 // output precision type is not found in input transform.
190 if (inputTransformName.find("float") == std::string::npos)
191 {
192 const std::string::size_type begin = inputTransformName.find("double");
193 inputTransformName.replace(begin, 6, "float");
194 }
195}
196
197template <>
198inline void
200{
201 // output precision type is not found in input transform.
202 if (inputTransformName.find("double") == std::string::npos)
203 {
204 const std::string::size_type begin = inputTransformName.find("float");
205 inputTransformName.replace(begin, 5, "double");
206 }
207}
208
209template <>
210inline const std::string
212{
213 return std::string("float");
214}
215
216template <>
217inline const std::string
219{
220 return std::string("double");
221}
222
225
226} // end namespace itk
227
228#endif // itkTransformIOBase_h
229
231#ifndef ITK_TEMPLATE_EXPLICIT_TransformIOBase
232// Explicit instantiation is required to ensure correct dynamic_cast
233// behavior across shared libraries.
234//
235// IMPORTANT: Since within the same compilation unit,
236// ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
237// need to be considered. This code *MUST* be *OUTSIDE* the header
238// guards.
239//
240#if defined(ITKIOTransformBase_EXPORTS)
241// We are building this library
242# define ITKIOTransformBase_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
243#else
244// We are using this library
245# define ITKIOTransformBase_EXPORT_EXPLICIT ITKIOTransformBase_EXPORT
246#endif
247namespace itk
248{
249
250ITK_GCC_PRAGMA_DIAG_PUSH()
251ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
252
255
256ITK_GCC_PRAGMA_DIAG_POP()
257
258} // end namespace itk
259#undef ITKIOTransformBase_EXPORT_EXPLICIT
260#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Base class for most ITK classes.
Definition: itkObject.h:62
Abstract superclass defining the Transform IO interface.
static void CorrectTransformPrecisionType(std::string &)
void PrintSelf(std::ostream &os, Indent indent) const override
TParametersValueType ParametersValueType
ConstTransformListType & GetWriteTransformList()
typename TransformType::Pointer TransformPointer
std::list< TransformPointer > TransformListType
virtual bool CanWriteFile(const char *)=0
void SetTransformList(ConstTransformListType &transformList)
TransformListType & GetReadTransformList()
TransformListType & GetTransformList()
TParametersValueType ScalarType
static const std::string GetTypeNameString()
void CreateTransform(TransformPointer &ptr, const std::string &ClassName)
std::list< ConstTransformPointer > ConstTransformListType
void OpenStream(std::ofstream &outputStream, bool binary)
typename TransformType::ConstPointer ConstTransformPointer
virtual bool CanReadFile(const char *)=0
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
#define ITKIOTransformBase_EXPORT_EXPLICIT
#define ITKIOTransformBase_TEMPLATE_EXPORT
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >