ITK  4.8.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 TParametersValueType>
47 {
48 public:
53 
56 
58  typedef TParametersValueType ScalarType; //For backwards compatibility
59  typedef TParametersValueType ParametersValueType;
60  typedef double FixedParametersValueType;
61 
63 
68  typedef std::list< TransformPointer > TransformListType;
70  typedef std::list< ConstTransformPointer > ConstTransformListType;
71 
73  itkSetStringMacro(FileName);
74  itkGetStringMacro(FileName);
76 
78  virtual void Read() = 0;
79 
81  virtual void Write() = 0;
82 
85  virtual bool CanReadFile(const char *) = 0;
86 
89  virtual bool CanWriteFile(const char *) = 0;
90 
96 
98  void SetTransformList(ConstTransformListType & transformList);
99 
101  itkSetMacro(AppendMode, bool);
102  itkGetConstMacro(AppendMode, bool);
103  itkBooleanMacro(AppendMode);
105 
114  static inline void CorrectTransformPrecisionType( std::string & itkNotUsed(inputTransformName) )
115  {
116  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
117  }
118 
119 protected:
121  virtual ~TransformIOBaseTemplate();
122  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
123 
124  void OpenStream(std::ofstream & outputStream, bool binary);
125 
126  void CreateTransform(TransformPointer & ptr, const std::string & ClassName);
127 
128  std::string m_FileName;
132 
133  /* The following struct returns the string name of computation type */
134  /* default implementation */
135  static inline const std::string GetTypeNameString()
136  {
137  itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(ScalarType).name());
138  }
139 };
140 
141 
142 template <>
143 inline void
145 ::CorrectTransformPrecisionType( std::string & inputTransformName )
146 {
147  // output precision type is not found in input transform.
148  if(inputTransformName.find("float") == std::string::npos)
149  {
150  const std::string::size_type begin = inputTransformName.find("double");
151  inputTransformName.replace(begin, 6, "float");
152  }
153 }
154 
155 template <>
156 inline void
158 ::CorrectTransformPrecisionType( std::string & inputTransformName )
159 {
160  // output precision type is not found in input transform.
161  if(inputTransformName.find("double") == std::string::npos)
162  {
163  const std::string::size_type begin = inputTransformName.find("float");
164  inputTransformName.replace(begin, 5, "double");
165  }
166 }
167 
168 template <>
169 inline const std::string
172 {
173  return std::string("float");
174 }
175 
176 template <>
177 inline const std::string
180 {
181  return std::string("double");
182 }
183 
186 
187 } // end namespace itk
188 
189 #ifndef ITK_MANUAL_INSTANTIATION
190 #include "itkTransformIOBase.hxx"
191 #endif
192 
193 #endif // itkTransformIOBase_h
SmartPointer< Self > Pointer
static void CorrectTransformPrecisionType(std::string &)
TransformIOBaseTemplate Self
ConstTransformListType & GetWriteTransformList()
itk::TransformIOBaseTemplate< double > TransformIOBase
virtual void PrintSelf(std::ostream &os, Indent indent) const override
Abstract superclass defining the Transform IO interface.
void SetTransformList(ConstTransformListType &transformList)
void CreateTransform(TransformPointer &ptr, const std::string &ClassName)
virtual bool CanWriteFile(const char *)=0
TransformListType m_ReadTransformList
TransformType::Pointer TransformPointer
virtual bool CanReadFile(const char *)=0
std::list< TransformPointer > TransformListType
TransformBaseTemplate< ParametersValueType > TransformType
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
void OpenStream(std::ofstream &outputStream, bool binary)
TParametersValueType ParametersValueType
Base class for most ITK classes.
Definition: itkObject.h:57
TParametersValueType ScalarType
TransformListType & GetReadTransformList()