24 ObservationReader::~ObservationReader()
27 NUKLEI_LOG(
"Input stats for reader `" << oc.type_ <<
"':\n " << oc);
30 NUKLEI_UNIQUE_PTR<Observation> ObservationReader::readObservation()
35 NUKLEI_UNIQUE_PTR<Observation> observation = readObservation_();
36 if (observation.get() == NULL)
return observation;
38 if (roi_ && !roi_->contains(observation->getKernel()->getLoc()))
46 NUKLEI_UNIQUE_PTR<KernelCollection> ObservationReader::readObservations()
49 NUKLEI_UNIQUE_PTR<KernelCollection> kcp(
new KernelCollection);
50 readObservations(*kcp);
55 void ObservationReader::readObservations(KernelCollection &kc)
60 NUKLEI_UNIQUE_PTR<Observation> o;
61 while ( (o = readObservation()).get() != NULL )
63 kc.add(*o->getKernel());
70 std::ostream& operator<<(std::ostream &out,
const ObservationReader::Counter &c)
73 typedef ObservationReader::Counter Counter;
74 for (Counter::list_t::const_iterator i = c.labels_.begin();
75 i != c.labels_.end(); ++i)
77 out << *i <<
": " << c.counts_.find(*i)->second <<
"; ";
83 void ObservationReader::Counter::incLabel(
const std::string &label)
87 if (counts_.count(label) == 0)
89 labels_.push_back(label);
90 i = counts_.insert(std::make_pair(label,
unsigned(0))).first;
92 else i = counts_.find(label);
97 bool ObservationReader::Counter::empty()
const
100 return labels_.empty();
104 void ObservationReader::addRegionOfInterest(boost::shared_ptr<RegionOfInterest> roi)
106 NUKLEI_TRACE_BEGIN();
114 NUKLEI_UNIQUE_PTR<ObservationReader>
115 ObservationReader::createReader(
const std::string& arg)
117 NUKLEI_TRACE_BEGIN();
118 NUKLEI_UNIQUE_PTR<ObservationReader> reader;
120 std::string errorsCat = std::string(
"Error in ObservationReader::createReader.") +
121 "\nErrors at each format attempt were:";
123 #ifdef NUKLEI_USE_TICPP
125 reader = createReader(arg, Observation::COVIS3D);
127 }
catch (ObservationIOError &e) {
128 errorsCat +=
"\n" + std::string(e.what());
133 reader = createReader(arg, Observation::NUKLEI);
135 }
catch (ObservationIOError &e) {
136 errorsCat +=
"\n" + std::string(e.what());
139 #ifdef NUKLEI_USE_TICPP
141 reader = createReader(arg, Observation::IIS);
143 }
catch (ObservationIOError &e) {
144 errorsCat +=
"\n" + std::string(e.what());
149 reader = createReader(arg, Observation::OSUTXT);
151 }
catch (ObservationIOError &e) {
152 errorsCat +=
"\n" + std::string(e.what());
156 reader = createReader(arg, Observation::PCD);
158 }
catch (ObservationIOError &e) {
159 errorsCat +=
"\n" + std::string(e.what());
163 reader = createReader(arg, Observation::PLY);
165 }
catch (ObservationIOError &e) {
166 errorsCat +=
"\n" + std::string(e.what());
170 reader = createReader(arg, Observation::RIF);
172 }
catch (ObservationIOError &e) {
173 errorsCat +=
"\n" + std::string(e.what());
177 reader = createReader(arg, Observation::SERIAL);
179 }
catch (ObservationIOError &e) {
180 errorsCat +=
"\n" + std::string(e.what());
184 reader = createReader(arg, Observation::CRD);
186 }
catch (ObservationIOError &e) {
187 errorsCat +=
"\n" + std::string(e.what());
191 reader = createReader(arg, Observation::OFF);
193 }
catch (ObservationIOError &e) {
194 errorsCat +=
"\n" + std::string(e.what());
198 reader = createReader(arg, Observation::BUILTINVTK);
200 }
catch (ObservationIOError &e) {
201 errorsCat +=
"\n" + std::string(e.what());
205 reader = createReader(arg, Observation::TXT);
207 }
catch (ObservationIOError &e) {
208 errorsCat +=
"\n" + std::string(e.what());
211 throw ObservationIOError
212 (
"Error loading observations with automatic type detection. "
213 "Maybe the filename `" + arg +
"' is incorrect. "
214 "Else please try again with a defined type.");
219 NUKLEI_UNIQUE_PTR<ObservationReader>
220 ObservationReader::createReader(
const std::string& arg,
const Observation::Type t)
222 NUKLEI_TRACE_BEGIN();
223 NUKLEI_UNIQUE_PTR<ObservationReader> reader;
226 case Observation::COVIS3D:
228 reader.reset(
new CoViS3DReader(arg));
231 case Observation::NUKLEI:
233 reader.reset(
new NukleiReader(arg));
236 case Observation::OSUTXT:
238 reader.reset(
new OsuTxtReader(arg));
241 case Observation::PCD:
243 reader.reset(
new PCDReader(arg));
246 case Observation::PLY:
248 reader.reset(
new PLYReader(arg));
251 case Observation::RIF:
253 reader.reset(
new RIFReader(arg));
256 case Observation::CRD:
258 reader.reset(
new CrdReader(arg));
261 case Observation::OFF:
263 reader.reset(
new OffReader(arg));
266 case Observation::SERIAL:
268 reader.reset(
new KernelReader(arg));
271 case Observation::BUILTINVTK:
273 reader.reset(
new BuiltinVTKReader(arg));
276 case Observation::TXT:
278 reader.reset(
new TxtReader(arg));
281 case Observation::IIS:
283 reader.reset(
new IisReader(arg));
298 ObservationWriter::~ObservationWriter()
302 void ObservationWriter::writeObservations(
const KernelCollection &kc)
304 NUKLEI_TRACE_BEGIN();
306 NUKLEI_UNIQUE_PTR<Observation> o = templateObservation();
310 writeObservation(*o);
316 NUKLEI_UNIQUE_PTR<ObservationWriter>
317 ObservationWriter::createWriter(
const std::string& arg,
const Observation::Type t)
319 NUKLEI_TRACE_BEGIN();
320 NUKLEI_UNIQUE_PTR<ObservationWriter> writer;
323 case Observation::COVIS3D:
325 writer.reset(
new CoViS3DXMLWriter(arg));
328 case Observation::NUKLEI:
330 writer.reset(
new NukleiWriter(arg));
333 case Observation::OSUTXT:
339 case Observation::PCD:
341 writer.reset(
new PCDWriter(arg));
344 case Observation::PLY:
346 writer.reset(
new PLYWriter(arg));
349 case Observation::RIF:
355 case Observation::CRD:
357 writer.reset(
new CrdWriter(arg));
360 case Observation::OFF:
362 writer.reset(
new OffWriter(arg));
365 case Observation::SERIAL:
367 writer.reset(
new KernelWriter(arg));
370 case Observation::BUILTINVTK:
376 case Observation::TXT:
378 writer.reset(
new TxtWriter(arg));
381 case Observation::IIS:
383 writer.reset(
new IisWriter(arg));
399 r.readObservations(kc);
405 readObservations(s, kc, t);
409 Observation::Type& t)
411 NUKLEI_UNIQUE_PTR<ObservationReader> reader =
412 ObservationReader::createReader(s);
414 readObservations(*reader, kc);
419 const Observation::Type& t)
421 NUKLEI_UNIQUE_PTR<ObservationReader> reader =
422 ObservationReader::createReader(s, t);
423 readObservations(*reader, kc);
434 Observation::Type& t)
437 readObservations(s, kc, t);
439 NUKLEI_THROW(
"File `" << s <<
"' does not contain a single observation.");
440 return kc.
front().clone();
445 const Observation::Type& t)
450 NUKLEI_THROW(
"File `" << s <<
"' does not contain a single observation.");
451 return kc.
front().clone();
456 w.writeObservations(kc);
460 const Observation::Type &t)
462 NUKLEI_UNIQUE_PTR<ObservationWriter> writer =
463 ObservationWriter::createWriter(s, t);
465 writer->writeBuffer();
469 const Observation::Type &t)