ITK  4.6.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 "itkLightProcessObject.h"
22 #include "itkTransformBase.h"
23 #include <list>
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27 
28 namespace itk
29 {
30 
45 template<typename TScalar>
47 {
48 public:
53 
56 
58  typedef TScalar ScalarType;
60 
65  typedef std::list< TransformPointer > TransformListType;
67  typedef std::list< ConstTransformPointer > ConstTransformListType;
68 
70  itkSetStringMacro(FileName);
71  itkGetStringMacro(FileName);
73 
75  virtual void Read() = 0;
76 
78  virtual void Write() = 0;
79 
82  virtual bool CanReadFile(const char *) = 0;
83 
86  virtual bool CanWriteFile(const char *) = 0;
87 
93 
95  void SetTransformList(ConstTransformListType & transformList);
96 
98  itkSetMacro(AppendMode, bool);
99  itkGetConstMacro(AppendMode, bool);
100  itkBooleanMacro(AppendMode);
102 
111  static inline void CorrectTransformPrecisionType( std::string & itkNotUsed(inputTransformName) )
112  {
113  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
114  }
115 
116 protected:
118  virtual ~TransformIOBaseTemplate();
119  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
120 
121  void OpenStream(std::ofstream & outputStream, bool binary);
122 
123  void CreateTransform(TransformPointer & ptr, const std::string & ClassName);
124 
125  std::string m_FileName;
129 
130  /* The following struct returns the string name of computation type */
131  /* default implementation */
132  static inline const std::string GetTypeNameString()
133  {
134  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
135  }
136 };
137 
138 
139 template <>
140 inline void
142 ::CorrectTransformPrecisionType( std::string & inputTransformName )
143 {
144  // output precision type is not found in input transform.
145  if(inputTransformName.find("float") == std::string::npos)
146  {
147  const std::string::size_type begin = inputTransformName.find("double");
148  inputTransformName.replace(begin, 6, "float");
149  }
150 }
151 
152 template <>
153 inline void
155 ::CorrectTransformPrecisionType( std::string & inputTransformName )
156 {
157  // output precision type is not found in input transform.
158  if(inputTransformName.find("double") == std::string::npos)
159  {
160  const std::string::size_type begin = inputTransformName.find("float");
161  inputTransformName.replace(begin, 5, "double");
162  }
163 }
164 
165 template <>
166 inline const std::string
169 {
170  return std::string("float");
171 }
172 
173 template <>
174 inline const std::string
177 {
178  return std::string("double");
179 }
180 
183 
184 } // end namespace itk
185 
186 #ifndef ITK_MANUAL_INSTANTIATION
187 #include "itkTransformIOBase.hxx"
188 #endif
189 
190 #endif // __itkTransformIOBase.h
SmartPointer< Self > Pointer
ConstTransformListType & GetWriteTransformList()
TransformType::ConstPointer ConstTransformPointer
static void CorrectTransformPrecisionType(std::string &)
TransformListType & GetReadTransformList()
void OpenStream(std::ofstream &outputStream, bool binary)
TransformType::Pointer TransformPointer
itk::TransformIOBaseTemplate< double > TransformIOBase
Abstract superclass defining the Transform IO interface.
ConstTransformListType m_WriteTransformList
static const std::string GetTypeNameString()
std::list< TransformPointer > TransformListType
TransformBaseTemplate< ScalarType > TransformType
void SetTransformList(ConstTransformListType &transformList)
TransformIOBaseTemplate Self
std::list< ConstTransformPointer > ConstTransformListType
TransformListType m_ReadTransformList
virtual bool CanReadFile(const char *)=0
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void CreateTransform(TransformPointer &ptr, const std::string &ClassName)
Base class for most ITK classes.
Definition: itkObject.h:57
virtual bool CanWriteFile(const char *)=0
TransformListType & GetTransformList()