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 
23 #include "itkLightProcessObject.h"
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 
40 namespace itk
41 {
42 
57 template <typename TParametersValueType>
59 {
60 public:
65 
68 
70  using ScalarType = TParametersValueType; // For backwards compatibility
71  using ParametersValueType = TParametersValueType;
72  using FixedParametersValueType = double;
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
127  SetTransformList(ConstTransformListType & transformList);
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 
155 protected:
157  ~TransformIOBaseTemplate() override;
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 
175 private:
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 
185 template <>
186 inline 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 
197 template <>
198 inline 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 
209 template <>
210 inline const std::string
212 {
213  return std::string("float");
214 }
215 
216 template <>
217 inline 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
247 namespace itk
248 {
249 
250 ITK_GCC_PRAGMA_DIAG_PUSH()
251 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
252 
255 
256 ITK_GCC_PRAGMA_DIAG_POP()
257 
258 } // end namespace itk
259 #undef ITKIOTransformBase_EXPORT_EXPLICIT
260 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::TransformIOBaseTemplate< double >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >
ITKIOTransformBase_TEMPLATE_EXPORT
#define ITKIOTransformBase_TEMPLATE_EXPORT
Definition: itkTransformIOBase.h:36
itk::TransformIOBaseTemplate< ParametersValueType >::ParametersValueType
ParametersValueType ParametersValueType
Definition: itkTransformIOBase.h:71
itkLightProcessObject.h
itk::TransformIOBaseTemplate< ParametersValueType >::ConstTransformPointer
typename TransformType::ConstPointer ConstTransformPointer
Definition: itkTransformIOBase.h:81
itk::TransformIOBaseTemplate< ParametersValueType >::TransformListType
std::list< TransformPointer > TransformListType
Definition: itkTransformIOBase.h:80
itk::TransformIOBaseTemplate< ParametersValueType >::ConstTransformListType
std::list< ConstTransformPointer > ConstTransformListType
Definition: itkTransformIOBase.h:82
itk::TransformIOBaseTemplate< ParametersValueType >::TransformPointer
typename TransformType::Pointer TransformPointer
Definition: itkTransformIOBase.h:79
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::TransformIOBaseTemplate::GetReadTransformList
TransformListType & GetReadTransformList()
Definition: itkTransformIOBase.h:114
itk::TransformIOBaseTemplate
Abstract superclass defining the Transform IO interface.
Definition: itkTransformIOBase.h:58
itk::TransformIOBaseTemplate< ParametersValueType >::ScalarType
ParametersValueType ScalarType
Definition: itkTransformIOBase.h:70
ITKIOTransformBase_EXPORT_EXPLICIT
#define ITKIOTransformBase_EXPORT_EXPLICIT
Definition: itkTransformIOBase.h:245
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkCommonEnums.h
itk::TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itkTransformBase.h
itk::TransformIOBaseTemplate::GetTypeNameString
static const std::string GetTypeNameString()
Definition: itkTransformIOBase.h:170
itk::TransformIOBaseTemplate::GetWriteTransformList
ConstTransformListType & GetWriteTransformList()
Definition: itkTransformIOBase.h:119
itk::TransformIOBaseTemplate::GetTransformList
TransformListType & GetTransformList()
Definition: itkTransformIOBase.h:109
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::TransformIOBaseTemplate< ParametersValueType >::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformIOBase.h:72
itk::TransformIOBaseTemplate::CorrectTransformPrecisionType
static void CorrectTransformPrecisionType(std::string &)
Definition: itkTransformIOBase.h:150