31 CRawlog::~CRawlog() {
clear(); }
34 m_seqOfActObs.clear();
35 m_commentTexts.text.clear();
40 m_seqOfActObs.push_back(
41 std::dynamic_pointer_cast<CSerializable>(
47 m_seqOfActObs.push_back(
48 std::dynamic_pointer_cast<CSerializable>(
54 m_seqOfActObs.push_back(action);
57 void CRawlog::addObservationsMemoryReference(
60 m_seqOfActObs.push_back(observations);
64 m_seqOfActObs.push_back(
obj);
67 void CRawlog::addObservationMemoryReference(
73 std::dynamic_pointer_cast<CObservationComment>(observation);
77 m_seqOfActObs.push_back(observation);
83 mrpt::make_aligned_shared<CActionCollection>();
85 m_seqOfActObs.push_back(temp);
98 return std::dynamic_pointer_cast<CActionCollection>(
obj);
101 "Element at index %i is not a CActionCollection", (
int)
index);
114 return std::dynamic_pointer_cast<CObservation>(
obj);
117 "Element at index %i is not a CObservation", (
int)
index);
126 return m_seqOfActObs[
index];
138 return etObservation;
140 return etActionCollection;
142 return etSensoryFrame;
157 return std::dynamic_pointer_cast<CSensoryFrame>(
obj);
160 "Element at index %i is not a CSensoryFrame", (
int)
index);
164 uint8_t CRawlog::serializeGetVersion()
const {
return 1; }
168 for (
const auto&
a : m_seqOfActObs) out <<
a;
169 out << m_commentTexts;
181 for (
auto&
a : m_seqOfActObs)
a =
in.ReadObject();
182 in >> m_commentTexts;
190 bool CRawlog::loadFromRawLogFile(
191 const std::string& fileName,
bool non_obs_objects_are_legal)
201 bool keepReading =
true;
208 bool add_obj =
false;
213 CRawlog::Ptr ao = std::dynamic_pointer_cast<CRawlog>(newObj);
223 std::dynamic_pointer_cast<CObservationComment>(newObj);
242 if (non_obs_objects_are_legal)
251 if (add_obj) m_seqOfActObs.push_back(newObj);
257 catch (std::exception& e)
259 std::cerr << e.what() << std::endl;
274 m_seqOfActObs.erase(m_seqOfActObs.begin() +
index);
278 void CRawlog::remove(
size_t first_index,
size_t last_index)
281 if (first_index >= m_seqOfActObs.size() ||
282 last_index >= m_seqOfActObs.size())
285 m_seqOfActObs.begin() + first_index,
286 m_seqOfActObs.begin() + last_index + 1);
296 if (!m_commentTexts.text.empty()) f << m_commentTexts;
297 for (
size_t i = 0; i < m_seqOfActObs.size(); i++)
298 f << *m_seqOfActObs[i];
309 if (
this == &
obj)
return;
310 m_seqOfActObs.swap(
obj.m_seqOfActObs);
311 std::swap(m_commentTexts,
obj.m_commentTexts);
314 bool CRawlog::readActionObservationPair(
328 action = std::dynamic_pointer_cast<CActionCollection>(
obj);
338 observations.reset();
339 while (!observations)
345 observations = std::dynamic_pointer_cast<CSensoryFrame>(
obj);
359 catch (std::exception& e)
361 std::cerr <<
"[CRawlog::readActionObservationPair] Found exception:"
363 << e.what() << std::endl;
368 std::cerr <<
"Untyped exception reading rawlog file!!" << std::endl;
373 bool CRawlog::getActionObservationPairOrObservation(
381 observations.reset();
390 action = std::dynamic_pointer_cast<CActionCollection>(
obj);
394 observation = std::dynamic_pointer_cast<CObservation>(
obj);
404 observations.reset();
405 while (!observations)
411 observations = std::dynamic_pointer_cast<CSensoryFrame>(
obj);
421 catch (std::exception& e)
423 std::cerr <<
"[CRawlog::readActionObservationPair] Found exception:"
425 << e.what() << std::endl;
430 std::cerr <<
"Untyped exception reading rawlog file!!" << std::endl;
435 void CRawlog::findObservationsByClassInRange(
445 if (m_seqOfActObs.empty())
return;
459 std::advance(it, step);
466 std::dynamic_pointer_cast<CObservation>(*it);
467 this_timestamp = o->timestamp;
472 "Element found which is not derived from CObservation");
474 if (this_timestamp < time_start)
486 while (
first != last)
492 std::dynamic_pointer_cast<CObservation>(*
first);
493 this_timestamp = o->timestamp;
496 if (this_timestamp < time_end)
498 if (o->GetRuntimeClass()->derivedFrom(class_type))
508 "Element found which is not derived from CObservation");
516 bool CRawlog::getActionObservationPair(
518 size_t& rawlogEntry)
const
522 while (getType(rawlogEntry) != CRawlog::etActionCollection)
526 action = getAsAction(rawlogEntry++);
528 while (getType(rawlogEntry) != CRawlog::etSensoryFrame)
532 observations = getAsObservations(rawlogEntry++);
536 catch (std::exception&)
542 std::cerr <<
"Untyped exception getting act-obs pair from rawlog!!"
548 void CRawlog::getCommentText(
std::string&
t)
const {
t = m_commentTexts.text; }
549 std::string CRawlog::getCommentText()
const {
return m_commentTexts.text; }
550 void CRawlog::getCommentTextAsConfigFile(
556 void CRawlog::setCommentText(
const std::string&
t) { m_commentTexts.text =
t; }
563 return temptative_img_path;
566 temptative_img_path =
568 return temptative_img_path;
571 temptative_img_path =
573 return temptative_img_path;
575 return rawlog_path +
"Images";