Orfeo Toolbox  3.16
itkTransformIOBase.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTransformIOBase.cxx,v $
5  Language: C++
6  Date: $Date: 2010-06-22 17:29:12 $
7  Version: $Revision: 1.3 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #include "itkTransformIOBase.h"
19 #include <iostream>
20 #include <fstream>
21 #include <string>
22 
23 namespace itk
24 {
27 {
28  this->m_AppendMode = false;
29 }
32 {
33 }
34 
35 void
38  const std::string &ClassName)
39 {
40  // Instantiate the transform
41  itkDebugMacro ( "About to call ObjectFactory" );
43  i = ObjectFactoryBase::CreateInstance ( ClassName.c_str() );
44  itkDebugMacro ( "After call ObjectFactory");
45  ptr = dynamic_cast<TransformBase*> ( i.GetPointer() );
46  if ( ptr.IsNull() )
47  {
48  OStringStream msg;
49  msg << "Could not create an instance of " << ClassName << std::endl
50  << "The usual cause of this error is not registering the "
51  << "transform with TransformFactory" << std::endl;
52  msg << "Currently registered Transforms: " << std::endl;
53  std::list<std::string> names = TransformFactoryBase::GetFactory()->GetClassOverrideWithNames();
54  std::list<std::string>::iterator it;
55  for ( it = names.begin(); it != names.end(); it++ )
56  {
57  msg << "\t\"" << *it << "\"" << std::endl;
58  }
59  itkExceptionMacro ( << msg.str() );
60  }
61 }
62 
63 void
65 ::OpenStream(std::ofstream &outputStream, bool binary)
66 {
67 #ifdef __sgi
68  // Create the file. This is required on some older sgi's
69  if (this->m_AppendMode)
70  {
71  std::ofstream tFile(m_FileName.c_str(),std::ios::out | std::ios::app);
72  tFile.close();
73  }
74  else
75  {
76  std::ofstream tFile(m_FileName.c_str(),std::ios::out);
77  tFile.close();
78  }
79 #endif
80  std::ios::openmode mode(std::ios::out);
81  if(binary)
82  {
83  mode |= std::ios::binary;
84  }
85  if (this->m_AppendMode)
86  {
87  mode |= std::ios::app;
88  }
89 
90  outputStream.open(m_FileName.c_str(), mode);
91 
92  if( outputStream.fail() )
93  {
94  outputStream.close();
95  itkExceptionMacro("Failed opening file" << m_FileName );
96  }
97 }
98 
100 {
101  this->m_WriteTransformList = transformList;
102 }
103 
104 void TransformIOBase::PrintSelf(std::ostream& os, Indent indent) const
105 {
106  Superclass::PrintSelf(os, indent);
107 
108  os << indent << "FileName: " << m_FileName << std::endl;
109  os << indent << "AppendMode: " <<
110  (m_AppendMode ? "true" : "false") << std::endl;
111  if(m_ReadTransformList.size() > 0)
112  {
113  os << indent << "ReadTransformList: " << std::endl;
114  TransformListType::const_iterator it = m_ReadTransformList.begin();
115  while( it != m_ReadTransformList.end() )
116  {
117  (*it)->Print(os,indent.GetNextIndent());
118  ++it;
119  }
120  }
121  if(m_WriteTransformList.size() > 0)
122  {
123  os << indent << "WriteTransformList: " << std::endl;
124 
125  ConstTransformListType::const_iterator it = m_WriteTransformList.begin();
126  while( it != m_WriteTransformList.end() )
127  {
128  (*it)->Print(os,indent.GetNextIndent());
129  ++it;
130  }
131  }
132 }
133 
134 } // itk

Generated at Sun Feb 3 2013 00:10:17 for Orfeo Toolbox with doxygen 1.8.1.1