ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkTransformIOBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 <list>
26 #include <iostream>
27 #include <fstream>
28 #include <string>
29 
30 #ifndef ITKIOTransformBase_TEMPLATE_EXPORT
31  #if defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) || defined(__linux__) && defined(ITK_BUILD_SHARED_LIBS)
32  // Make everything visible
33  #define ITKIOTransformBase_TEMPLATE_EXPORT __attribute__ ((visibility ("default")))
34  #else
35  #define ITKIOTransformBase_TEMPLATE_EXPORT
36  #endif
37 #endif
38 
39 namespace itk
40 {
41 
56 template<typename TParametersValueType>
58 {
59 public:
64 
66  itkTypeMacro(TransformIOBaseTemplate, Superclass);
67 
69  using ScalarType = TParametersValueType; //For backwards compatibility
70  using ParametersValueType = TParametersValueType;
71  using FixedParametersValueType = double;
72 
74 
79  using TransformListType = std::list< TransformPointer >;
81  using ConstTransformListType = std::list< ConstTransformPointer >;
82 
84  itkSetStringMacro(FileName);
85  itkGetStringMacro(FileName);
87 
89  virtual void Read() = 0;
90 
92  virtual void Write() = 0;
93 
96  virtual bool CanReadFile(const char *) = 0;
97 
100  virtual bool CanWriteFile(const char *) = 0;
101 
103  TransformListType & GetTransformList() { return m_ReadTransformList; }
104  TransformListType & GetReadTransformList() { return m_ReadTransformList; }
105  ConstTransformListType & GetWriteTransformList() { return m_WriteTransformList; }
107 
109  void SetTransformList(ConstTransformListType & transformList);
110 
112  itkSetMacro(AppendMode, bool);
113  itkGetConstMacro(AppendMode, bool);
114  itkBooleanMacro(AppendMode);
116 
118  itkSetMacro(UseCompression, bool);
119  itkGetConstMacro(UseCompression, bool);
120  itkBooleanMacro(UseCompression);
122 
131  static inline void CorrectTransformPrecisionType( std::string & itkNotUsed(inputTransformName) )
132  {
133  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
134  }
135 
136 protected:
138  ~TransformIOBaseTemplate() override;
139  void PrintSelf(std::ostream & os, Indent indent) const override;
140 
141  void OpenStream(std::ofstream & outputStream, bool binary);
142 
143  void CreateTransform(TransformPointer & ptr, const std::string & ClassName);
144 
145  /* The following struct returns the string name of computation type */
146  /* default implementation */
147  static inline const std::string GetTypeNameString()
148  {
149  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
150  }
151 
152 private:
153  std::string m_FileName;
156  bool m_AppendMode{false};
158  bool m_UseCompression{false};
159 
160 };
161 
162 
163 template <>
164 inline void
166 ::CorrectTransformPrecisionType( std::string & inputTransformName )
167 {
168  // output precision type is not found in input transform.
169  if(inputTransformName.find("float") == std::string::npos)
170  {
171  const std::string::size_type begin = inputTransformName.find("double");
172  inputTransformName.replace(begin, 6, "float");
173  }
174 }
175 
176 template <>
177 inline void
179 ::CorrectTransformPrecisionType( std::string & inputTransformName )
180 {
181  // output precision type is not found in input transform.
182  if(inputTransformName.find("double") == std::string::npos)
183  {
184  const std::string::size_type begin = inputTransformName.find("float");
185  inputTransformName.replace(begin, 5, "double");
186  }
187 }
188 
189 template <>
190 inline const std::string
193 {
194  return std::string("float");
195 }
196 
197 template <>
198 inline const std::string
201 {
202  return std::string("double");
203 }
204 
207 
208 } // end namespace itk
209 
210 #endif // itkTransformIOBase_h
211 
213 #ifndef ITK_TEMPLATE_EXPLICIT_TransformIOBase
214 // Explicit instantiation is required to ensure correct dynamic_cast
215 // behavior across shared libraries.
216 //
217 // IMPORTANT: Since within the same compilation unit,
218 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
219 // need to be considered. This code *MUST* be *OUTSIDE* the header
220 // guards.
221 //
222 # if defined( ITKIOTransformBase_EXPORTS )
223 // We are building this library
224 # define ITKIOTransformBase_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
225 # else
226 // We are using this library
227 # define ITKIOTransformBase_EXPORT_EXPLICIT ITKIOTransformBase_EXPORT
228 # endif
229 namespace itk
230 {
231 
232 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
233  ITK_GCC_PRAGMA_DIAG_PUSH()
234 #endif
235 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
236 
239 
240 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
241  ITK_GCC_PRAGMA_DIAG_POP()
242 #else
243  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
244 #endif
245 
246 } // end namespace itk
247 # undef ITKIOTransformBase_EXPORT_EXPLICIT
248 #endif
Light weight base class for most itk classes.
#define ITKIOTransformBase_EXPORT_EXPLICIT
static void CorrectTransformPrecisionType(std::string &)
ConstTransformListType & GetWriteTransformList()
Abstract superclass defining the Transform IO interface.
TransformListType m_ReadTransformList
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >
ConstTransformListType m_WriteTransformList
#define ITKIOTransformBase_TEMPLATE_EXPORT
TransformListType & GetTransformList()
static const std::string GetTypeNameString()
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
TransformListType & GetReadTransformList()