ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
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
86 itkSetStringMacro(FileName);
87 itkGetStringMacro(FileName);
90 virtual void
91 Read() = 0;
92
94 virtual void
95 Write() = 0;
99 virtual bool
100 CanReadFile(const char *) = 0;
101
104 virtual bool
105 CanWriteFile(const char *) = 0;
106
111 {
112 return m_ReadTransformList;
113 }
114 TransformListType &
116 {
117 return m_ReadTransformList;
118 }
119 ConstTransformListType &
124
126 void
128
131 itkSetMacro(AppendMode, bool);
132 itkGetConstMacro(AppendMode, bool);
133 itkBooleanMacro(AppendMode);
137 itkSetMacro(UseCompression, bool);
138 itkGetConstMacro(UseCompression, bool);
139 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 std::string
171 {
172 itkGenericExceptionMacro("Unknown ScalarType" << typeid(ScalarType).name());
173 }
174
175private:
176 std::string m_FileName{};
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 if (begin == std::string::npos)
194 {
195 itkGenericExceptionMacro("Transform type name has neither float nor double precision: " << inputTransformName);
196 }
197 inputTransformName.replace(begin, 6, "float");
198 }
199}
200
201template <>
202inline void
204{
205 // output precision type is not found in input transform.
206 if (inputTransformName.find("double") == std::string::npos)
207 {
208 const std::string::size_type begin = inputTransformName.find("float");
209 if (begin == std::string::npos)
210 {
211 itkGenericExceptionMacro("Transform type name has neither float nor double precision: " << inputTransformName);
212 }
213 inputTransformName.replace(begin, 5, "double");
214 }
215}
216
217template <>
218inline std::string
220{
221 return { "float" };
222}
223
224template <>
225inline std::string
227{
228 return { "double" };
229}
230
233
234} // end namespace itk
235
236#endif // itkTransformIOBase_h
237
239#ifndef ITK_TEMPLATE_EXPLICIT_TransformIOBase
240// Explicit instantiation is required to ensure correct dynamic_cast
241// behavior across shared libraries.
242//
243// IMPORTANT: Since within the same compilation unit,
244// ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
245// need to be considered. This code *MUST* be *OUTSIDE* the header
246// guards.
247//
248#if defined(ITKIOTransformBase_EXPORTS)
249// We are building this library
250# define ITKIOTransformBase_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
251#else
252// We are using this library
253# define ITKIOTransformBase_EXPORT_EXPLICIT ITKIOTransformBase_EXPORT
254#endif
255namespace itk
256{
257
258ITK_GCC_PRAGMA_DIAG_PUSH()
259ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
260
263
264ITK_GCC_PRAGMA_DIAG_POP()
265
266} // end namespace itk
267#undef ITKIOTransformBase_EXPORT_EXPLICIT
268#endif
Control indentation during Print() invocation.
Definition itkIndent.h:51
Implements transparent reference counting.
Abstract superclass defining the Transform IO interface.
TransformBaseTemplate< ParametersValueType > TransformType
void PrintSelf(std::ostream &os, Indent indent) const override
ConstTransformListType & GetWriteTransformList()
virtual bool CanWriteFile(const char *)=0
void SetTransformList(ConstTransformListType &transformList)
TransformListType & GetReadTransformList()
static void CorrectTransformPrecisionType(std::string &inputTransformName)
TransformListType & GetTransformList()
void CreateTransform(TransformPointer &ptr, const std::string &ClassName)
static std::string GetTypeNameString()
std::list< ConstTransformPointer > ConstTransformListType
void OpenStream(std::ofstream &outputStream, bool binary)
typename TransformType::ConstPointer ConstTransformPointer
virtual bool CanReadFile(const char *)=0
#define ITKIOTransformBase_EXPORT_EXPLICIT
#define ITKIOTransformBase_TEMPLATE_EXPORT
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TransformIOBaseTemplate< double > TransformIOBase
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >