ITK  4.9.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 namespace itk
31 {
32 
47 template<typename TParametersValueType>
48 class ITKIOTransformBase_TEMPLATE_EXPORT TransformIOBaseTemplate:public LightProcessObject
49 {
50 public:
55 
58 
60  typedef TParametersValueType ScalarType; //For backwards compatibility
61  typedef TParametersValueType ParametersValueType;
62  typedef double FixedParametersValueType;
63 
65 
70  typedef std::list< TransformPointer > TransformListType;
72  typedef std::list< ConstTransformPointer > ConstTransformListType;
73 
75  itkSetStringMacro(FileName);
76  itkGetStringMacro(FileName);
78 
80  virtual void Read() = 0;
81 
83  virtual void Write() = 0;
84 
87  virtual bool CanReadFile(const char *) = 0;
88 
91  virtual bool CanWriteFile(const char *) = 0;
92 
94  TransformListType & GetTransformList() { return m_ReadTransformList; }
95  TransformListType & GetReadTransformList() { return m_ReadTransformList; }
96  ConstTransformListType & GetWriteTransformList() { return m_WriteTransformList; }
98 
100  void SetTransformList(ConstTransformListType & transformList);
101 
103  itkSetMacro(AppendMode, bool);
104  itkGetConstMacro(AppendMode, bool);
105  itkBooleanMacro(AppendMode);
107 
116  static inline void CorrectTransformPrecisionType( std::string & itkNotUsed(inputTransformName) )
117  {
118  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
119  }
120 
121 protected:
123  virtual ~TransformIOBaseTemplate();
124  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
125 
126  void OpenStream(std::ofstream & outputStream, bool binary);
127 
128  void CreateTransform(TransformPointer & ptr, const std::string & ClassName);
129 
130  std::string m_FileName;
134 
135  /* The following struct returns the string name of computation type */
136  /* default implementation */
137  static inline const std::string GetTypeNameString()
138  {
139  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
140  }
141 };
142 
143 
144 template <>
145 inline void
147 ::CorrectTransformPrecisionType( std::string & inputTransformName )
148 {
149  // output precision type is not found in input transform.
150  if(inputTransformName.find("float") == std::string::npos)
151  {
152  const std::string::size_type begin = inputTransformName.find("double");
153  inputTransformName.replace(begin, 6, "float");
154  }
155 }
156 
157 template <>
158 inline void
160 ::CorrectTransformPrecisionType( std::string & inputTransformName )
161 {
162  // output precision type is not found in input transform.
163  if(inputTransformName.find("double") == std::string::npos)
164  {
165  const std::string::size_type begin = inputTransformName.find("float");
166  inputTransformName.replace(begin, 5, "double");
167  }
168 }
169 
170 template <>
171 inline const std::string
174 {
175  return std::string("float");
176 }
177 
178 template <>
179 inline const std::string
182 {
183  return std::string("double");
184 }
185 
188 
189 } // end namespace itk
190 
191 #ifndef ITK_MANUAL_INSTANTIATION
192 #include "itkTransformIOBase.hxx"
193 #endif
194 
195 #endif // itkTransformIOBase_h
196 
198 #ifndef ITK_TEMPLATE_EXPLICIT_TransformIOBase
199 // Explicit instantiation is required to ensure correct dynamic_cast
200 // behavior across shared libraries.
201 //
202 // IMPORTANT: Since within the same compilation unit,
203 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
204 // need to be considered. This code *MUST* be *OUTSIDE* the header
205 // guards.
206 //
207 # if defined( ITKIOTransformBase_EXPORTS )
208 // We are building this library
209 # define ITKIOTransformBase_EXPORT_EXPLICIT
210 # else
211 // We are using this library
212 # define ITKIOTransformBase_EXPORT_EXPLICIT ITKIOTransformBase_EXPORT
213 # endif
214 namespace itk
215 {
216 
217 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
218  ITK_GCC_PRAGMA_DIAG_PUSH()
219 #endif
220 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
221 
224 
225 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
226  ITK_GCC_PRAGMA_DIAG_POP()
227 #else
228  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
229 #endif
230 
231 } // end namespace itk
232 # undef ITKIOTransformBase_EXPORT_EXPLICIT
233 #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.
TransformListType m_ReadTransformList
TransformType::Pointer TransformPointer
std::list< TransformPointer > TransformListType
TransformBaseTemplate< ParametersValueType > TransformType
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< float >
template class ITKIOTransformBase_EXPORT_EXPLICIT TransformIOBaseTemplate< double >
ConstTransformListType m_WriteTransformList
TransformType::ConstPointer ConstTransformPointer
std::list< ConstTransformPointer > ConstTransformListType
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:57
TParametersValueType ScalarType
TransformListType & GetReadTransformList()