ITK  4.13.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 
67 
69  typedef TParametersValueType ScalarType; //For backwards compatibility
70  typedef TParametersValueType ParametersValueType;
71  typedef double FixedParametersValueType;
72 
74 
79  typedef std::list< TransformPointer > TransformListType;
81  typedef std::list< ConstTransformPointer > ConstTransformListType;
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 
125  static inline void CorrectTransformPrecisionType( std::string & itkNotUsed(inputTransformName) )
126  {
127  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
128  }
129 
130 protected:
132  virtual ~TransformIOBaseTemplate() ITK_OVERRIDE;
133  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
134 
135  void OpenStream(std::ofstream & outputStream, bool binary);
136 
137  void CreateTransform(TransformPointer & ptr, const std::string & ClassName);
138 
139  std::string m_FileName;
140  TransformListType m_ReadTransformList;
141  ConstTransformListType m_WriteTransformList;
142  bool m_AppendMode;
143 
144  /* The following struct returns the string name of computation type */
145  /* default implementation */
146  static inline const std::string GetTypeNameString()
147  {
148  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
149  }
150 };
151 
152 
153 template <>
154 inline void
156 ::CorrectTransformPrecisionType( std::string & inputTransformName )
157 {
158  // output precision type is not found in input transform.
159  if(inputTransformName.find("float") == std::string::npos)
160  {
161  const std::string::size_type begin = inputTransformName.find("double");
162  inputTransformName.replace(begin, 6, "float");
163  }
164 }
165 
166 template <>
167 inline void
169 ::CorrectTransformPrecisionType( std::string & inputTransformName )
170 {
171  // output precision type is not found in input transform.
172  if(inputTransformName.find("double") == std::string::npos)
173  {
174  const std::string::size_type begin = inputTransformName.find("float");
175  inputTransformName.replace(begin, 5, "double");
176  }
177 }
178 
179 template <>
180 inline const std::string
183 {
184  return std::string("float");
185 }
186 
187 template <>
188 inline const std::string
191 {
192  return std::string("double");
193 }
194 
197 
198 } // end namespace itk
199 
200 #ifndef ITK_MANUAL_INSTANTIATION
201 #include "itkTransformIOBase.hxx"
202 #endif
203 
204 #endif // itkTransformIOBase_h
205 
207 #ifndef ITK_TEMPLATE_EXPLICIT_TransformIOBase
208 // Explicit instantiation is required to ensure correct dynamic_cast
209 // behavior across shared libraries.
210 //
211 // IMPORTANT: Since within the same compilation unit,
212 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
213 // need to be considered. This code *MUST* be *OUTSIDE* the header
214 // guards.
215 //
216 # if defined( ITKIOTransformBase_EXPORTS )
217 // We are building this library
218 # define ITKIOTransformBase_EXPORT_EXPLICIT ITK_FORWARD_EXPORT
219 # else
220 // We are using this library
221 # define ITKIOTransformBase_EXPORT_EXPLICIT ITKIOTransformBase_EXPORT
222 # endif
223 namespace itk
224 {
225 
226 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
227  ITK_GCC_PRAGMA_DIAG_PUSH()
228 #endif
229 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
230 
233 
234 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
235  ITK_GCC_PRAGMA_DIAG_POP()
236 #else
237  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
238 #endif
239 
240 } // end namespace itk
241 # undef ITKIOTransformBase_EXPORT_EXPLICIT
242 #endif
SmartPointer< Self > Pointer
#define ITKIOTransformBase_EXPORT_EXPLICIT
static void CorrectTransformPrecisionType(std::string &)
TransformIOBaseTemplate Self
ConstTransformListType & GetWriteTransformList()
itk::TransformIOBaseTemplate< double > TransformIOBase
Abstract superclass defining the Transform IO interface.
TransformType::Pointer TransformPointer
std::list< TransformPointer > TransformListType
TransformBaseTemplate< ParametersValueType > TransformType
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >
TransformType::ConstPointer ConstTransformPointer
std::list< ConstTransformPointer > ConstTransformListType
#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
TParametersValueType ParametersValueType
Base class for most ITK classes.
Definition: itkObject.h:59
TParametersValueType ScalarType
TransformListType & GetReadTransformList()