fw4spl
TransformationMatrix3DWriter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwDataIO/writer/TransformationMatrix3DWriter.hpp"
8 
9 #include "fwDataIO/writer/registry/macros.hpp"
10 
11 #include <boost/filesystem/convenience.hpp>
12 
13 #include <fstream>
14 #include <iostream>
15 #include <vector>
16 
17 fwDataIOWriterRegisterMacro( ::fwDataIO::writer::TransformationMatrix3DWriter);
18 
19 namespace fwDataIO
20 {
21 
22 namespace writer
23 {
24 
25 //------------------------------------------------------------------------------
26 
28  ::fwData::location::enableSingleFile< ::fwDataIO::writer::IObjectWriter >(this)
29 {
30 }
31 
32 //------------------------------------------------------------------------------
33 
35 {
36 }
37 
38 //------------------------------------------------------------------------------
39 
41 {
42  std::fstream file;
43  file.open(getFile().string().c_str(), std::fstream::out);
44  if (!file.is_open())
45  {
46  OSLM_ERROR( "Trf file writing error for " << getFile());
47  return;
48  }
49  ::fwData::TransformationMatrix3D::TMCoefArray mat = this->getConcreteObject()->getCoefficients();
50  int i = 0;
51  for (auto val : mat)
52  {
53  OSLM_TRACE("MATRIX : " << val);
54  file << val;
55  i++;
56  if (i%4 == 0 && i != 16)
57  {
58  file << std::endl;
59  }
60  else
61  {
62  file << " ";
63  }
64  }
65 
66  file.close();
67 }
68 
69 //------------------------------------------------------------------------------
70 
72 {
73  static std::string ext(".trf");
74  return ext;
75 }
76 
77 //------------------------------------------------------------------------------
78 
79 } // namespace writer
80 
81 } // namespace fwDataIO
virtual FWDATAIO_API void write() override
Write the file with standard iostream API.
virtual FWDATAIO_API std::string extension() override
Defines extension supported by this writer ".trf".
This namespace fwDataIO contains reader and writer for several framework&#39;s data.
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
FWDATAIO_API TransformationMatrix3DWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor. Do nothing.
#define OSLM_TRACE(message)
Definition: spyLog.hpp:230
Writer for transformation of 3D Matrix. Write file format .trf.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
Base class for all object writers.
virtual FWDATAIO_API ~TransformationMatrix3DWriter()
Destructor. Do nothing.
Contains the representation of the data objects used in the framework.