MRPT  1.9.9
CRawlog.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CRawlog_H
10 #define CRawlog_H
11 
12 #include <mrpt/poses/CPose2D.h>
13 #include <mrpt/obs/CSensoryFrame.h>
17 
18 namespace mrpt::obs
19 {
20 /** For usage with CRawlog classes. */
22  std::pair<mrpt::system::TTimeStamp, CObservation::Ptr>;
23 /** For usage with CRawlog classes. */
25  std::multimap<mrpt::system::TTimeStamp, CObservation::Ptr>;
26 
27 /** This class stores a rawlog (robotic datasets) in one of two possible
28  *formats:
29  * - Format #1: A sequence of actions and observations. There is a sequence
30  *of objects, where each one can be of one type:
31  * - An action: Implemented as a CActionCollection object, the
32  *actuation
33  *of the robot (i.e. odometry increment).
34  * - Observations: Implemented as a CSensoryFrame, refering to a set of
35  *robot observations from the same pose.
36  * - Format #2: A sequence of actions and observations. There is a sequence
37  *of objects, where each one can be of one type:
38  *
39  * Refer to the wiki page about <a href="http://www.mrpt.org/Rawlog_Format"
40  *>rawlog files</a>.
41  *
42  * See also the application <a
43  *href="http://www.mrpt.org/Application:RawLogViewer" >RawLogViewer</a > for the
44  *GUI program that visualizes and manages rawlogs.
45  *
46  * This class also publishes a static helper method for loading rawlog files in
47  *format #1: see CRawlog::readActionObservationPair
48  *
49  * There is a field for comments and blocks of parameters (in ini-like format)
50  *accessible through getCommentText and setCommentText
51  * (introduced in MRPT 0.6.4). When serialized to a rawlog file, the comments
52  *are saved as an additional observation of the
53  * type CObservationComments at the beginning of the file, but this
54  *observation does not appear after loading for clarity.
55  *
56  * \note Since MRPT version 0.5.5, this class also provides a STL container-like
57  *interface (see CRawlog::begin, CRawlog::iterator, ...).
58  * \note The format #2 is supported since MRPT version 0.6.0.
59  * \note There is a static helper method "detectImagesDirectory" for localizing
60  *the external images directory of a rawlog.
61  *
62  * \sa CSensoryFrame, CPose2D, <a href="http://www.mrpt.org/Rawlog_Format">
63  *RawLog file format</a>.
64  * \ingroup mrpt_obs_grp
65  */
67 {
69 
70  private:
71  using TListObjects = std::vector<mrpt::serialization::CSerializable::Ptr>;
72  /** The list where the objects really are in. */
74 
75  /** Comments of the rawlog. */
77 
78  public:
79  /** Returns the block of comment text for the rawlog */
80  void getCommentText(std::string& t) const;
81  /** Returns the block of comment text for the rawlog */
83  /** Changes the block of comment text for the rawlog */
84  void setCommentText(const std::string& t);
85  /** Saves the block of comment text for the rawlog into the passed config
86  * file object. */
88  mrpt::config::CConfigFileMemory& memCfg) const;
89 
90  /** The type of each entry in a rawlog.
91  * \sa CRawlog::getType
92  */
94  {
99  };
100 
101  /** Default constructor */
102  CRawlog();
103 
104  /** Destructor: */
105  virtual ~CRawlog();
106 
107  /** Clear the sequence of actions/observations. Smart pointers to objects
108  * previously in the rawlog will remain being valid. */
109  void clear();
110 
111  /** Add an action to the sequence: a collection of just one element is
112  * created.
113  * The object is duplicated, so the original one can be freed if desired.
114  */
115  void addAction(CAction& action);
116 
117  /** Add a set of actions to the sequence; the object is duplicated, so the
118  * original one can be freed if desired.
119  * \sa addObservations, addActionsMemoryReference
120  */
121  void addActions(CActionCollection& action);
122 
123  /** Add a set of observations to the sequence; the object is duplicated, so
124  * the original one can be free if desired.
125  * \sa addActions, addObservationsMemoryReference
126  */
127  void addObservations(CSensoryFrame& observations);
128 
129  /** Add a set of actions to the sequence, using a smart pointer to the
130  * object to add.
131  * \sa addActions, addObservationsMemoryReference,
132  * addObservationMemoryReference
133  */
135 
136  /** Add a set of observations to the sequence, using a smart pointer to the
137  * object to add.
138  * \sa addObservations, addActionsMemoryReference,
139  * addObservationMemoryReference
140  */
141  void addObservationsMemoryReference(const CSensoryFrame::Ptr& observations);
142 
143  /** Add a single observation to the sequence, using a smart pointer to the
144  * object to add.
145  * \sa addObservations, addActionsMemoryReference
146  */
147  void addObservationMemoryReference(const CObservation::Ptr& observation);
148 
149  /** Generic add for a smart pointer to a CSerializable object:
150  * \sa addObservations, addActionsMemoryReference,
151  * addObservationMemoryReference
152  */
154 
155  /** Load the contents from a file containing one of these possibilities:
156  * - A "CRawlog" object.
157  * - Directly the sequence of objects (pairs
158  * `CSensoryFrame`/`CActionCollection` or `CObservation*` objects). In this
159  * case the method stops reading on EOF of an unrecogniced class name.
160  * - Only if `non_obs_objects_are_legal` is true, any `CSerializable`
161  * object is allowed in the log file. Otherwise, the read stops on classes
162  * different from the ones listed in the item above.
163  * \returns It returns false upon error reading or accessing the file.
164  */
165  bool loadFromRawLogFile(
166  const std::string& fileName, bool non_obs_objects_are_legal = false);
167 
168  /** Saves the contents to a rawlog-file, compatible with RawlogViewer (As
169  * the sequence of internal objects).
170  * The file is saved with gz-commpressed if MRPT has gz-streams.
171  * \returns It returns false if any error is found while writing/creating
172  * the target file.
173  */
174  bool saveToRawLogFile(const std::string& fileName) const;
175 
176  /** Returns the number of actions / observations object in the sequence. */
177  size_t size() const;
178 
179  /** Returns the type of a given element.
180  * \sa isAction, isObservation
181  */
182  TEntryType getType(size_t index) const;
183 
184  /** Delete the action or observation stored in the given index.
185  * \exception std::exception If index is out of bounds
186  */
187  void remove(size_t index);
188 
189  /** Delete the elements stored in the given range of indices (including both
190  * the first and last one).
191  * \exception std::exception If any index is out of bounds
192  */
193  void remove(size_t first_index, size_t last_index);
194 
195  /** Returns the i'th element in the sequence, as being actions, where
196  * index=0 is the first object.
197  * If it is not a CActionCollection, it throws an exception. Do neighter
198  * modify nor delete the returned pointer.
199  * \sa size, isAction, getAsObservations, getAsObservation
200  * \exception std::exception If index is out of bounds
201  */
203 
204  /** Returns the i'th element in the sequence, as being an action, where
205  * index=0 is the first object.
206  * If it is not an CSensoryFrame, it throws an exception. Do neighter
207  * modify nor delete the returned pointer.
208  * \sa size, isAction, getAsAction, getAsObservation
209  * \exception std::exception If index is out of bounds
210  */
212 
213  /** Returns the i'th element in the sequence, being its class whatever.
214  * \sa size, isAction, getAsAction, getAsObservations
215  * \exception std::exception If index is out of bounds
216  */
218 
219  /** Returns the i'th element in the sequence, as being an observation, where
220  * index=0 is the first object.
221  * If it is not an CObservation, it throws an exception. Do neighter
222  * modify nor delete the returned pointer.
223  * This is the proper method to obtain the objects stored in a "only
224  * observations"-rawlog file (named "format #2" above.
225  * \sa size, isAction, getAsAction
226  * \exception std::exception If index is out of bounds
227  */
229 
230  /** A normal iterator, plus the extra method "getType" to determine the type
231  * of each entry in the sequence. */
232  class iterator
233  {
234  protected:
236 
237  public:
238  iterator() : m_it() {}
240  virtual ~iterator() {}
242  {
243  m_it = o.m_it;
244  return *this;
245  }
246 
247  bool operator==(const iterator& o) { return m_it == o.m_it; }
248  bool operator!=(const iterator& o) { return m_it != o.m_it; }
250  inline iterator operator++(int)
251  {
252  iterator aux = *this;
253  m_it++;
254  return aux;
255  } // Post
257  {
258  m_it++;
259  return *this;
260  } // Pre
261  inline iterator operator--(int)
262  {
263  iterator aux = *this;
264  m_it--;
265  return aux;
266  } // Post
268  {
269  m_it--;
270  return *this;
271  } // Pre
272 
274  {
275  if ((*m_it)->GetRuntimeClass()->derivedFrom(CLASS_ID(CObservation)))
276  return etObservation;
277  else if ((*m_it)->GetRuntimeClass()->derivedFrom(
279  return etSensoryFrame;
280  else
281  return etActionCollection;
282  }
283 
284  static iterator erase(TListObjects& lst, const iterator& it)
285  {
286  return lst.erase(it.m_it);
287  }
288  };
289 
290  /** A normal iterator, plus the extra method "getType" to determine the type
291  * of each entry in the sequence. */
293  {
294  protected:
296 
297  public:
300  virtual ~const_iterator() {}
301  bool operator==(const const_iterator& o) { return m_it == o.m_it; }
302  bool operator!=(const const_iterator& o) { return m_it != o.m_it; }
304  {
305  return *m_it;
306  }
307 
309  {
310  const_iterator aux = *this;
311  m_it++;
312  return aux;
313  } // Post
315  {
316  m_it++;
317  return *this;
318  } // Pre
320  {
321  const_iterator aux = *this;
322  m_it--;
323  return aux;
324  } // Post
326  {
327  m_it--;
328  return *this;
329  } // Pre
330 
332  {
333  if ((*m_it)->GetRuntimeClass()->derivedFrom(CLASS_ID(CObservation)))
334  return etObservation;
335  else if ((*m_it)->GetRuntimeClass()->derivedFrom(
337  return etSensoryFrame;
338  else
339  return etActionCollection;
340  }
341  };
342 
343  const_iterator begin() const { return m_seqOfActObs.begin(); }
344  iterator begin() { return m_seqOfActObs.begin(); }
345  const_iterator end() const { return m_seqOfActObs.end(); }
346  iterator end() { return m_seqOfActObs.end(); }
348  {
349  return iterator::erase(m_seqOfActObs, it);
350  }
351 
352  /** Returns the sub-set of observations of a given class whose time-stamp t
353  * fulfills time_start <= t < time_end.
354  * This method requires the timestamps of the sensors to be in strict
355  * ascending order (which should be the normal situation).
356  * Otherwise, the output is undeterminate.
357  * \sa findClosestObservationsByClass
358  */
361  const mrpt::rtti::TRuntimeClassId* class_type,
362  TListTimeAndObservations& out_found,
363  size_t guess_start_position = 0) const;
364 
365  /** Efficiently swap the contents of two existing objects.
366  */
367  void swap(CRawlog& obj);
368 
369  /** Reads a consecutive pair action / observation from the rawlog opened at
370  * some input stream.
371  * Previous contents of action and observations are discarded (using
372  * stlplus::smart_ptr::reset), and
373  * at exit they contain the new objects read from the rawlog file.
374  * The input/output variable "rawlogEntry" is just a counter of the last
375  * rawlog entry read, for logging or monitoring purposes.
376  * \return false if there was some error, true otherwise.
377  * \sa getActionObservationPair, getActionObservationPairOrObservation
378  */
379  static bool readActionObservationPair(
381  CSensoryFrame::Ptr& observations, size_t& rawlogEntry);
382 
383  /** Reads a consecutive pair action/sensory_frame OR an observation,
384  *depending of the rawlog format, from the rawlog opened at some input
385  *stream.
386  * Previous contents of action and observations are discarded (using
387  *stlplus::smart_ptr::reset), and
388  * at exit they contain the new objects read from the rawlog file.
389  *
390  * At return, one of this will happen:
391  * - action/observations contain objects (i.e. action() evaluates as
392  *true).
393  * - observation contains an object (i.e. observation evaluates as
394  *true).
395  *
396  * The input/output variable "rawlogEntry" is just a counter of the last
397  *rawlog entry read, for logging or monitoring purposes.
398  * \return false if there was some error, true otherwise.
399  * \sa getActionObservationPair
400  */
403  CSensoryFrame::Ptr& observations, CObservation::Ptr& observation,
404  size_t& rawlogEntry);
405 
406  /** Gets the next consecutive pair action / observation from the rawlog
407  * loaded into this object.
408  * Previous contents of action and observations are discarded (using
409  * stlplus::smart_ptr::reset), and
410  * at exit they contain the new objects read from the rawlog file.
411  * The input/output variable "rawlogEntry" is just a counter of the last
412  * rawlog entry read, for logging or monitoring purposes.
413  * \return false if there was some error, true otherwise.
414  * \sa readActionObservationPair
415  */
417  CActionCollection::Ptr& action, CSensoryFrame::Ptr& observations,
418  size_t& rawlogEntry) const;
419 
420  /** Tries to auto-detect the external-images directory of the given rawlog
421  *file.
422  * This searches for the existence of the directories:
423  * - "<rawlog_file_path>/<rawlog_filename>_Images"
424  * - "<rawlog_file_path>/<rawlog_filename>_images"
425  * - "<rawlog_file_path>/<rawlog_filename>_IMAGES"
426  * - "<rawlog_file_path>/Images" (This one is returned if none of the
427  *choices actually exists).
428  *
429  * The results from this function should be written into
430  *mrpt::img::CImage::getImagesPathBase() to enable automatic
431  * loading of extenrnally-stored images in rawlogs.
432  */
433  static std::string detectImagesDirectory(const std::string& rawlogFilename);
434 
435 }; // End of class def.
436 
437 }
438 #endif
439 
440 
This class implements a config file-like interface over a memory-stored string list.
Scalar * iterator
Definition: eigen_plugins.h:26
bool operator==(const iterator &o)
Definition: CRawlog.h:247
This "observation" is actually a placeholder for a text block with comments or additional parameters ...
void findObservationsByClassInRange(mrpt::system::TTimeStamp time_start, mrpt::system::TTimeStamp time_end, const mrpt::rtti::TRuntimeClassId *class_type, TListTimeAndObservations &out_found, size_t guess_start_position=0) const
Returns the sub-set of observations of a given class whose time-stamp t fulfills time_start <= t < ti...
Definition: CRawlog.cpp:435
GLdouble GLdouble t
Definition: glext.h:3689
TListObjects m_seqOfActObs
The list where the objects really are in.
Definition: CRawlog.h:73
const_iterator end() const
Definition: CRawlog.h:345
std::vector< mrpt::serialization::CSerializable::Ptr > TListObjects
Definition: CRawlog.h:71
iterator begin()
Definition: CRawlog.h:344
bool getActionObservationPair(CActionCollection::Ptr &action, CSensoryFrame::Ptr &observations, size_t &rawlogEntry) const
Gets the next consecutive pair action / observation from the rawlog loaded into this object...
Definition: CRawlog.cpp:516
static std::string detectImagesDirectory(const std::string &rawlogFilename)
Tries to auto-detect the external-images directory of the given rawlog file.
Definition: CRawlog.cpp:557
iterator erase(const iterator &it)
Definition: CRawlog.h:347
const_iterator & operator++()
Definition: CRawlog.h:314
A normal iterator, plus the extra method "getType" to determine the type of each entry in the sequenc...
Definition: CRawlog.h:232
const_iterator & operator--()
Definition: CRawlog.h:325
const_iterator operator--(int)
Definition: CRawlog.h:319
A structure that holds runtime class type information.
Definition: CObject.h:30
mrpt::serialization::CSerializable::Ptr operator*()
Definition: CRawlog.h:249
const_iterator(const TListObjects::const_iterator &it)
Definition: CRawlog.h:299
void addObservationsMemoryReference(const CSensoryFrame::Ptr &observations)
Add a set of observations to the sequence, using a smart pointer to the object to add...
Definition: CRawlog.cpp:57
void addActions(CActionCollection &action)
Add a set of actions to the sequence; the object is duplicated, so the original one can be freed if d...
Definition: CRawlog.cpp:45
TListObjects::const_iterator m_it
Definition: CRawlog.h:295
void addGenericObject(const mrpt::serialization::CSerializable::Ptr &obj)
Generic add for a smart pointer to a CSerializable object:
Definition: CRawlog.cpp:62
TEntryType getType() const
Definition: CRawlog.h:273
CRawlog()
Default constructor.
Definition: CRawlog.cpp:29
void addObservations(CSensoryFrame &observations)
Add a set of observations to the sequence; the object is duplicated, so the original one can be free ...
Definition: CRawlog.cpp:38
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
iterator operator--(int)
Definition: CRawlog.h:261
bool operator!=(const const_iterator &o)
Definition: CRawlog.h:302
Declares a class for storing a collection of robot actions.
static bool getActionObservationPairOrObservation(mrpt::serialization::CArchive &inStream, CActionCollection::Ptr &action, CSensoryFrame::Ptr &observations, CObservation::Ptr &observation, size_t &rawlogEntry)
Reads a consecutive pair action/sensory_frame OR an observation, depending of the rawlog format...
Definition: CRawlog.cpp:373
bool saveToRawLogFile(const std::string &fileName) const
Saves the contents to a rawlog-file, compatible with RawlogViewer (As the sequence of internal object...
Definition: CRawlog.cpp:290
CActionCollection::Ptr getAsAction(size_t index) const
Returns the i&#39;th element in the sequence, as being actions, where index=0 is the first object...
Definition: CRawlog.cpp:89
std::string getCommentText() const
Returns the block of comment text for the rawlog.
Definition: CRawlog.cpp:549
std::pair< mrpt::system::TTimeStamp, CObservation::Ptr > TTimeObservationPair
For usage with CRawlog classes.
Definition: CRawlog.h:22
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
bool loadFromRawLogFile(const std::string &fileName, bool non_obs_objects_are_legal=false)
Load the contents from a file containing one of these possibilities:
Definition: CRawlog.cpp:190
mrpt::serialization::CSerializable::Ptr getAsGeneric(size_t index) const
Returns the i&#39;th element in the sequence, being its class whatever.
Definition: CRawlog.cpp:121
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:84
std::multimap< mrpt::system::TTimeStamp, CObservation::Ptr > TListTimeAndObservations
For usage with CRawlog classes.
Definition: CRawlog.h:25
CObservation::Ptr getAsObservation(size_t index) const
Returns the i&#39;th element in the sequence, as being an observation, where index=0 is the first object...
Definition: CRawlog.cpp:105
GLuint index
Definition: glext.h:4054
iterator & operator=(const iterator &o)
Definition: CRawlog.h:241
const_iterator operator++(int)
Definition: CRawlog.h:308
This class stores a rawlog (robotic datasets) in one of two possible formats:
Definition: CRawlog.h:66
This namespace contains representation of robot actions and observations.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:52
void setCommentText(const std::string &t)
Changes the block of comment text for the rawlog.
Definition: CRawlog.cpp:556
GLsizei const GLchar ** string
Definition: glext.h:4101
A normal iterator, plus the extra method "getType" to determine the type of each entry in the sequenc...
Definition: CRawlog.h:292
CSensoryFrame::Ptr getAsObservations(size_t index) const
Returns the i&#39;th element in the sequence, as being an action, where index=0 is the first object...
Definition: CRawlog.cpp:149
Declares a class for storing a robot action.
Definition: CAction.h:27
TEntryType getType() const
Definition: CRawlog.h:331
void addActionsMemoryReference(const CActionCollection::Ptr &action)
Add a set of actions to the sequence, using a smart pointer to the object to add. ...
Definition: CRawlog.cpp:52
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
TEntryType
The type of each entry in a rawlog.
Definition: CRawlog.h:93
TListObjects::iterator m_it
Definition: CRawlog.h:235
bool operator!=(const iterator &o)
Definition: CRawlog.h:248
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
iterator end()
Definition: CRawlog.h:346
void swap(CRawlog &obj)
Efficiently swap the contents of two existing objects.
Definition: CRawlog.cpp:307
void clear()
Clear the sequence of actions/observations.
Definition: CRawlog.cpp:32
TEntryType getType(size_t index) const
Returns the type of a given element.
Definition: CRawlog.cpp:130
void addAction(CAction &action)
Add an action to the sequence: a collection of just one element is created.
Definition: CRawlog.cpp:80
iterator operator++(int)
Definition: CRawlog.h:250
iterator(const TListObjects::iterator &it)
Definition: CRawlog.h:239
static iterator erase(TListObjects &lst, const iterator &it)
Definition: CRawlog.h:284
static bool readActionObservationPair(mrpt::serialization::CArchive &inStream, CActionCollection::Ptr &action, CSensoryFrame::Ptr &observations, size_t &rawlogEntry)
Reads a consecutive pair action / observation from the rawlog opened at some input stream...
Definition: CRawlog.cpp:314
size_t size() const
Returns the number of actions / observations object in the sequence.
Definition: CRawlog.cpp:88
void getCommentTextAsConfigFile(mrpt::config::CConfigFileMemory &memCfg) const
Saves the block of comment text for the rawlog into the passed config file object.
Definition: CRawlog.cpp:550
const Scalar * const_iterator
Definition: eigen_plugins.h:27
virtual ~CRawlog()
Destructor:
Definition: CRawlog.cpp:31
CObservationComment m_commentTexts
Comments of the rawlog.
Definition: CRawlog.h:76
bool operator==(const const_iterator &o)
Definition: CRawlog.h:301
const mrpt::serialization::CSerializable::Ptr operator*() const
Definition: CRawlog.h:303
const_iterator begin() const
Definition: CRawlog.h:343
void addObservationMemoryReference(const CObservation::Ptr &observation)
Add a single observation to the sequence, using a smart pointer to the object to add.
Definition: CRawlog.cpp:67



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020