11 #include <boost/tuple/tuple.hpp>
20 CrdReader::CrdReader(
const std::string &observationFileName) :
21 observationFileName(observationFileName)
25 CrdReader::~CrdReader()
31 void CrdReader::init_()
34 in_.open(observationFileName.c_str(), std::ios::in);
36 throw ObservationIOError(std::string(
"Could not open file ") +
37 observationFileName +
" for reading.");
44 std::string firstline;
45 if (! std::getline(in_, firstline) )
46 throw ObservationIOError(
"Input does not look like CRD (file read error).");
48 if (firstline ==
"syncpc")
50 if (! std::getline(in_, firstline) )
51 throw ObservationIOError(
"Input does not look like CRD (file read error).");
55 count = numify<int>(firstline);
56 }
catch (BadStrNumConversion &e)
58 throw ObservationIOError(
"Input does not look like CRD (no point count).");
61 throw ObservationIOError(
"Input does not look like CRD (no point count).");
70 in_.open(observationFileName.c_str(), std::ios::in);
71 int lcount = 0; std::string dump;
72 while (std::getline(in_, dump)) lcount++;
73 if (lcount != count+1 + (syncpc?1:0))
74 throw ObservationIOError(
"Input does not look like CRD (wrong count).");
77 in_.open(observationFileName.c_str(), std::ios::in);
79 std::getline(in_, line);
80 if (syncpc) std::getline(in_, line);
84 void CrdReader::reset()
91 NUKLEI_UNIQUE_PTR<Observation> CrdReader::readObservation_()
93 if (!in_.is_open())
NUKLEI_THROW(
"Reader does not seem inited.");
95 if (!in_.good())
return NUKLEI_UNIQUE_PTR<Observation>();
99 while (std::getline(in_, line))
102 std::istringstream iss(line);
104 NUKLEI_UNIQUE_PTR<CrdObservation> observation(
new CrdObservation);
107 if ( ! (iss >> loc[0] >> loc[1] >> loc[2]) )
return NUKLEI_UNIQUE_PTR<Observation>();
108 observation->setLoc(loc);
110 Vector3 rgbColor(.5,.5,.5);
112 if ( (iss >> ix >> iy >> rgbColor[0] >> rgbColor[1] >> rgbColor[2]) )
114 RGBColor c(rgbColor/255.);
115 observation->setColor(c);
119 RGBColor c(.5,.5,.5);
120 observation->setColor(c);
123 return NUKLEI_UNIQUE_PTR<Observation>(NUKLEI_MOVE(observation));
127 return NUKLEI_UNIQUE_PTR<Observation>();
133 CrdWriter::CrdWriter(
const std::string &observationFileName,
bool syncpc) :
134 observationFileName_(observationFileName), syncpc_(syncpc)
136 NUKLEI_TRACE_BEGIN();
140 CrdWriter::~CrdWriter()
144 void CrdWriter::init()
146 NUKLEI_TRACE_BEGIN();
149 }
catch (std::exception& e) {
150 throw ObservationIOError(e.what());
155 void CrdWriter::reset()
157 NUKLEI_TRACE_BEGIN();
163 void CrdWriter::writeBuffer()
165 NUKLEI_TRACE_BEGIN();
167 std::ofstream ofs(observationFileName_.c_str());
172 ofs << points_.size() <<
"\n";
173 for (std::vector<Vector3>::const_iterator i = points_.begin();
174 i != points_.end(); ++i)
175 ofs <<
stringify(*i, PRECISION) << std::endl;
180 void CrdWriter::writeObservation(
const Observation &o)
182 NUKLEI_TRACE_BEGIN();
186 points_.push_back(k->getLoc());