fw4spl
TransformationMatrix3DReader.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/reader/TransformationMatrix3DReader.hpp"
8 
9 #include "fwDataIO/reader/registry/macros.hpp"
10 
11 #include <fwData/location/SingleFile.hpp>
12 
13 #include <boost/filesystem/convenience.hpp>
14 
15 #include <fstream>
16 #include <iostream>
17 
18 fwDataIOReaderRegisterMacro( ::fwDataIO::reader::TransformationMatrix3DReader );
19 
20 namespace fwDataIO
21 {
22 namespace reader
23 {
24 
26  ::fwData::location::enableSingleFile< IObjectReader >(this)
27 {
28 }
29 
30 //------------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //------------------------------------------------------------------------------
37 
39 {
40  assert( ::std::dynamic_pointer_cast< ::fwData::location::SingleFile >(m_location) );
41  ::boost::filesystem::path file =
42  ::std::dynamic_pointer_cast< ::fwData::location::SingleFile >(m_location)->getPath();
43 
44  assert( ::boost::filesystem::exists(file) );
45 
46  std::ifstream inFile(file.string().c_str(), std::ifstream::in );
47  assert( inFile.good() );
48 
49  char readedValue = 0;
50  double value;
51 
52  while ( !inFile.eof() && readedValue < 16 )
53  {
54  inFile >> value;
55  this->getConcreteObject()->getCoefficients()[readedValue] = value;
56  readedValue++;
57  }
58 
59  assert(this->getConcreteObject()->getCoefficients().size() == 16 );
60 }
61 
62 //------------------------------------------------------------------------------
63 
65 {
66  return (".trf");
67 }
68 
69 //------------------------------------------------------------------------------
70 
71 } // namespace reader
72 } // namespace fwDataIO
Reader for transformation of 3D Matrix. Read file format .trf.
This class defines a single file location.
Definition: SingleFile.hpp:25
This namespace fwDataIO contains reader and writer for several framework&#39;s data.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
FWDATAIO_API TransformationMatrix3DReader(::fwDataIO::reader::IObjectReader::Key key)
Constructor. Do nothing.
virtual FWDATAIO_API void read() override
Read the file with standard iostream API.
virtual FWDATAIO_API ~TransformationMatrix3DReader()
Destructor. Do nothing.
virtual std::shared_ptr< DataType > getConcreteObject()
m_object getter.
virtual FWDATAIO_API std::string extension() override
Defines extension supported by this reader ".trf".
Contains the representation of the data objects used in the framework.
::fwData::location::ILocation::sptr m_location
Object location ( file path, directory path, url, etc )