11 #include <boost/tuple/tuple.hpp>
20 OffReader::OffReader(
const std::string &observationFileName) :
21 observationFileName(observationFileName), count_(0)
25 OffReader::~OffReader()
31 void OffReader::init_()
34 in_.open(observationFileName.c_str(), std::ios::in);
36 throw ObservationIOError(std::string(
"Could not open file ") +
37 observationFileName +
" for reading.");
41 std::string firstline;
42 if (! std::getline(in_, firstline) )
43 throw ObservationIOError(
"Input does not look like OFF (file read error).");
45 if (firstline !=
"OFF")
46 throw ObservationIOError(
"Input does not look like OFF (marker error).");
47 if (! std::getline(in_, firstline) )
48 throw ObservationIOError(
"Input does not look like OFF (file read error).");
50 count = numify<int>(firstline,
false);
51 }
catch (BadStrNumConversion &e)
53 throw ObservationIOError(
"Input does not look like OFF (no point count).");
56 throw ObservationIOError(
"Input does not look like OFF (no point count).");
62 void OffReader::reset()
69 NUKLEI_UNIQUE_PTR<Observation> OffReader::readObservation_()
71 if (!in_.is_open())
NUKLEI_THROW(
"Reader does not seem inited.");
73 if (!in_.good())
return NUKLEI_UNIQUE_PTR<Observation>();
79 if (!std::getline(in_, line))
81 throw ObservationIOError(
"Unexpected end of file.");
85 std::istringstream iss(line);
87 NUKLEI_UNIQUE_PTR<OffObservation> observation(
new OffObservation);
90 if ( ! (iss >> loc[0] >> loc[1] >> loc[2]) )
91 throw ObservationIOError(
"Parsing error.");
92 observation->setLoc(loc);
95 observation->setColor(c);
99 return NUKLEI_UNIQUE_PTR<Observation>(NUKLEI_MOVE(observation));
103 return NUKLEI_UNIQUE_PTR<Observation>();
109 OffWriter::OffWriter(
const std::string &observationFileName) :
110 observationFileName_(observationFileName)
112 NUKLEI_TRACE_BEGIN();
116 OffWriter::~OffWriter()
120 void OffWriter::init()
122 NUKLEI_TRACE_BEGIN();
125 }
catch (std::exception& e) {
126 throw ObservationIOError(e.what());
131 void OffWriter::reset()
133 NUKLEI_TRACE_BEGIN();
139 void OffWriter::writeBuffer()
141 NUKLEI_TRACE_BEGIN();
143 std::ofstream ofs(observationFileName_.c_str());
145 ofs << points_.size() <<
" 0 0\n";
146 for (std::vector<Vector3>::const_iterator i = points_.begin();
147 i != points_.end(); ++i)
148 ofs <<
stringify(*i, PRECISION) << std::endl;
153 void OffWriter::writeObservation(
const Observation &o)
155 NUKLEI_TRACE_BEGIN();
157 kernel::base::ptr k = o.getKernel();
159 points_.push_back(k->getLoc());