30 m_seqOfActObs.clear();
31 m_commentTexts.text.clear();
36 m_seqOfActObs.push_back(std::dynamic_pointer_cast<CSerializable>(
42 m_seqOfActObs.push_back(std::dynamic_pointer_cast<CSerializable>(
50 std::dynamic_pointer_cast<CObservationComment>(obj);
54 m_seqOfActObs.push_back(obj);
61 m_seqOfActObs.push_back(temp);
69 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
74 return std::dynamic_pointer_cast<CActionCollection>(obj);
77 "Element at index %i is not a CActionCollection", (
int)index);
85 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
90 return std::dynamic_pointer_cast<CObservation>(obj);
93 "Element at index %i is not a CObservation", (
int)index);
100 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
102 return m_seqOfActObs[index];
109 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
114 return etObservation;
116 return etActionCollection;
118 return etSensoryFrame;
128 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
133 return std::dynamic_pointer_cast<CSensoryFrame>(obj);
136 "Element at index %i is not a CSensoryFrame", (
int)index);
140 uint8_t CRawlog::serializeGetVersion()
const {
return 1; }
143 out.WriteAs<uint32_t>(m_seqOfActObs.size());
144 for (
const auto& a : m_seqOfActObs)
out << a;
145 out << m_commentTexts;
156 m_seqOfActObs.resize(in.
ReadAs<uint32_t>());
157 for (
auto& a : m_seqOfActObs) a = in.
ReadObject();
158 in >> m_commentTexts;
166 bool CRawlog::loadFromRawLogFile(
167 const std::string& fileName,
bool non_obs_objects_are_legal)
171 if (!fi.
open(fileName))
return false;
177 bool keepReading =
true;
184 bool add_obj =
false;
189 CRawlog::Ptr ao = std::dynamic_pointer_cast<CRawlog>(newObj);
193 else if (newObj->GetRuntimeClass()->derivedFrom(
199 std::dynamic_pointer_cast<CObservationComment>(newObj);
218 if (non_obs_objects_are_legal)
227 if (add_obj) m_seqOfActObs.push_back(newObj);
233 catch (
const std::exception& e)
246 void CRawlog::remove(
size_t index)
249 if (index >= m_seqOfActObs.size())
THROW_EXCEPTION(
"Index out of bounds");
250 m_seqOfActObs.erase(m_seqOfActObs.begin() + index);
254 void CRawlog::remove(
size_t first_index,
size_t last_index)
257 if (first_index >= m_seqOfActObs.size() ||
258 last_index >= m_seqOfActObs.size())
261 m_seqOfActObs.begin() + first_index,
262 m_seqOfActObs.begin() + last_index + 1);
266 bool CRawlog::saveToRawLogFile(
const std::string& fileName)
const
272 if (!m_commentTexts.text.empty()) f << m_commentTexts;
273 for (
const auto& m_seqOfActOb : m_seqOfActObs) f << *m_seqOfActOb;
276 catch (
const std::exception& e)
285 if (
this == &obj)
return;
290 bool CRawlog::readActionObservationPair(
304 action = std::dynamic_pointer_cast<CActionCollection>(obj);
314 observations.reset();
315 while (!observations)
321 observations = std::dynamic_pointer_cast<CSensoryFrame>(obj);
335 catch (
const std::exception& e)
337 std::cerr <<
"[CRawlog::readActionObservationPair] Found exception:"
344 std::cerr <<
"Untyped exception reading rawlog file!!" << std::endl;
349 bool CRawlog::getActionObservationPairOrObservation(
357 observations.reset();
366 action = std::dynamic_pointer_cast<CActionCollection>(obj);
370 observation = std::dynamic_pointer_cast<CObservation>(obj);
380 observations.reset();
381 while (!observations)
387 observations = std::dynamic_pointer_cast<CSensoryFrame>(obj);
397 catch (
const std::exception& e)
399 std::cerr <<
"[CRawlog::readActionObservationPair] Found exception:"
406 std::cerr <<
"Untyped exception reading rawlog file!!" << std::endl;
411 void CRawlog::findObservationsByClassInRange(
415 [[maybe_unused]]
size_t guess_start_position)
const
421 if (m_seqOfActObs.empty())
return;
425 auto first = m_seqOfActObs.begin();
426 const auto last = m_seqOfActObs.end();
435 std::advance(it, step);
442 std::dynamic_pointer_cast<CObservation>(*it);
443 this_timestamp = o->timestamp;
448 "Element found which is not derived from CObservation");
450 if (this_timestamp < time_start)
462 while (first != last)
468 std::dynamic_pointer_cast<CObservation>(*first);
469 this_timestamp = o->timestamp;
472 if (this_timestamp < time_end)
474 if (o->GetRuntimeClass()->derivedFrom(class_type))
484 "Element found which is not derived from CObservation");
492 bool CRawlog::getActionObservationPair(
494 size_t& rawlogEntry)
const
498 while (getType(rawlogEntry) != CRawlog::etActionCollection)
502 action = getAsAction(rawlogEntry++);
504 while (getType(rawlogEntry) != CRawlog::etSensoryFrame)
508 observations = getAsObservations(rawlogEntry++);
512 catch (
const std::exception& e)
519 std::cerr <<
"Untyped exception getting act-obs pair from rawlog!!"
525 void CRawlog::getCommentText(std::string& t)
const { t = m_commentTexts.text; }
526 std::string CRawlog::getCommentText()
const {
return m_commentTexts.text; }
527 void CRawlog::getCommentTextAsConfigFile(
533 void CRawlog::setCommentText(
const std::string& t) { m_commentTexts.text = t; }
534 std::string CRawlog::detectImagesDirectory(
const std::string& str)
537 std::string temptative_img_path =
540 return temptative_img_path;
542 temptative_img_path =
544 std::string(
"_images"))))
545 return temptative_img_path;
547 temptative_img_path =
549 std::string(
"_IMAGES"))))
550 return temptative_img_path;
552 return rawlog_path +
"Images";