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