BuiltinVTKObservationIO.cpp
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #include <fstream>
8 #include <cassert>
9 #include <algorithm>
10 #include <cmath>
11 #include <boost/tuple/tuple.hpp>
12 
15 #include <nuklei/Common.h>
16 #include <nuklei/Match.h>
17 #include <nuklei/Indenter.h>
18 
19 namespace nuklei {
20 
21 
22 
23  BuiltinVTKReader::BuiltinVTKReader(const std::string &observationFileName) :
24  idx_(-1), n_(0), observationFileName_(observationFileName)
25  {
26  }
27 
28  BuiltinVTKReader::~BuiltinVTKReader()
29  {
30  }
31 
32 
33 
34  void BuiltinVTKReader::init_()
35  {
36  NUKLEI_TRACE_BEGIN();
37  NUKLEI_ASSERT(!in_.is_open());
38  in_.open(observationFileName_.c_str(), std::ios::in);
39  if (!in_.is_open())
40  throw ObservationIOError(std::string("Could not open file ") +
41  observationFileName_ + " for reading.");
42  try {
43  std::string dump;
44  std::getline(in_, dump);
45  std::getline(in_, dump);
46  if ( !(in_ >> Match("ASCII") >> Match("DATASET") >> Match("POLYDATA") ) )
47  throw ObservationIOError("Non-OsuTxt format.");
48  if ( !(in_ >> Match("POINTS") >> n_ >> Match("float") ) )
49  throw ObservationIOError("Non-OsuTxt format.");
50  } catch (std::exception &e) {
51  throw ObservationIOError("Non-OsuTxt format.");
52  }
53  idx_ = 0;
54  NUKLEI_TRACE_END();
55  }
56 
57 
58  void BuiltinVTKReader::reset()
59  {
60  NUKLEI_TRACE_BEGIN();
61  in_.close();
62  idx_ = -1;
63  n_ = 0;
64  init();
65  NUKLEI_TRACE_END();
66  }
67 
68 
69  NUKLEI_UNIQUE_PTR<Observation> BuiltinVTKReader::readObservation_()
70  {
71  NUKLEI_TRACE_BEGIN();
72  if (idx_ < 0) NUKLEI_THROW("Reader does not seem inited.");
73 
74  if (idx_ >= n_)
75  return NUKLEI_UNIQUE_PTR<Observation>();
76 
77  idx_++;
78 
79  Vector3 loc;
80  NUKLEI_ASSERT(in_ >> loc[0] >> loc[1] >> loc[2]);
81 
82  NUKLEI_UNIQUE_PTR<BuiltinVTKObservation> observation(new BuiltinVTKObservation);
83  observation->setLoc(loc);
84 
85  return NUKLEI_UNIQUE_PTR<Observation>(NUKLEI_MOVE(observation));
86 
87  NUKLEI_TRACE_END();
88  }
89 
90 
91 }
Public namespace.
Definition: Color.cpp:9
#define NUKLEI_ASSERT(expression)
Throws an Error if expression is not true.
Definition: Common.h:113
#define NUKLEI_THROW(x)
Throws an Error.
Definition: Common.h:94
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.