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-2017, 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. */
23 typedef std::pair<mrpt::system::TTimeStamp, CObservation::Ptr>
25 /** For usage with CRawlog classes. */
26 typedef 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  typedef std::vector<mrpt::utils::CSerializable::Ptr> TListObjects;
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::utils::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 (
280  (*m_it)->GetRuntimeClass()->derivedFrom(
282  return etSensoryFrame;
283  else
284  return etActionCollection;
285  }
286 
287  static iterator erase(TListObjects& lst, const iterator& it)
288  {
289  return lst.erase(it.m_it);
290  }
291  };
292 
293  /** A normal iterator, plus the extra method "getType" to determine the type
294  * of each entry in the sequence. */
296  {
297  protected:
299 
300  public:
303  virtual ~const_iterator() {}
304  bool operator==(const const_iterator& o) { return m_it == o.m_it; }
305  bool operator!=(const const_iterator& o) { return m_it != o.m_it; }
307  {
308  return *m_it;
309  }
310 
312  {
313  const_iterator aux = *this;
314  m_it++;
315  return aux;
316  } // Post
318  {
319  m_it++;
320  return *this;
321  } // Pre
323  {
324  const_iterator aux = *this;
325  m_it--;
326  return aux;
327  } // Post
329  {
330  m_it--;
331  return *this;
332  } // Pre
333 
335  {
336  if ((*m_it)->GetRuntimeClass()->derivedFrom(CLASS_ID(CObservation)))
337  return etObservation;
338  else if (
339  (*m_it)->GetRuntimeClass()->derivedFrom(
341  return etSensoryFrame;
342  else
343  return etActionCollection;
344  }
345  };
346 
347  const_iterator begin() const { return m_seqOfActObs.begin(); }
348  iterator begin() { return m_seqOfActObs.begin(); }
349  const_iterator end() const { return m_seqOfActObs.end(); }
350  iterator end() { return m_seqOfActObs.end(); }
352  {
353  return iterator::erase(m_seqOfActObs, it);
354  }
355 
356  /** Returns the sub-set of observations of a given class whose time-stamp t
357  * fulfills time_start <= t < time_end.
358  * This method requires the timestamps of the sensors to be in strict
359  * ascending order (which should be the normal situation).
360  * Otherwise, the output is undeterminate.
361  * \sa findClosestObservationsByClass
362  */
365  const mrpt::utils::TRuntimeClassId* class_type,
366  TListTimeAndObservations& out_found,
367  size_t guess_start_position = 0) const;
368 
369  /** Efficiently copy the contents from other existing object, and remove the
370  * data from the origin (after calling this, the original object will have
371  * no actions/observations).
372  */
373  void moveFrom(CRawlog& obj);
374 
375  /** Efficiently swap the contents of two existing objects.
376  */
377  void swap(CRawlog& obj);
378 
379  /** Reads a consecutive pair action / observation from the rawlog opened at
380  * some input stream.
381  * Previous contents of action and observations are discarded (using
382  * stlplus::smart_ptr::reset), and
383  * at exit they contain the new objects read from the rawlog file.
384  * The input/output variable "rawlogEntry" is just a counter of the last
385  * rawlog entry read, for logging or monitoring purposes.
386  * \return false if there was some error, true otherwise.
387  * \sa getActionObservationPair, getActionObservationPairOrObservation
388  */
389  static bool readActionObservationPair(
390  mrpt::utils::CStream& inStream, CActionCollection::Ptr& action,
391  CSensoryFrame::Ptr& observations, size_t& rawlogEntry);
392 
393  /** Reads a consecutive pair action/sensory_frame OR an observation,
394  *depending of the rawlog format, from the rawlog opened at some input
395  *stream.
396  * Previous contents of action and observations are discarded (using
397  *stlplus::smart_ptr::reset), and
398  * at exit they contain the new objects read from the rawlog file.
399  *
400  * At return, one of this will happen:
401  * - action/observations contain objects (i.e. action() evaluates as
402  *true).
403  * - observation contains an object (i.e. observation evaluates as
404  *true).
405  *
406  * The input/output variable "rawlogEntry" is just a counter of the last
407  *rawlog entry read, for logging or monitoring purposes.
408  * \return false if there was some error, true otherwise.
409  * \sa getActionObservationPair
410  */
412  mrpt::utils::CStream& inStream, CActionCollection::Ptr& action,
413  CSensoryFrame::Ptr& observations, CObservation::Ptr& observation,
414  size_t& rawlogEntry);
415 
416  /** Gets the next consecutive pair action / observation from the rawlog
417  * loaded into this object.
418  * Previous contents of action and observations are discarded (using
419  * stlplus::smart_ptr::reset), and
420  * at exit they contain the new objects read from the rawlog file.
421  * The input/output variable "rawlogEntry" is just a counter of the last
422  * rawlog entry read, for logging or monitoring purposes.
423  * \return false if there was some error, true otherwise.
424  * \sa readActionObservationPair
425  */
427  CActionCollection::Ptr& action, CSensoryFrame::Ptr& observations,
428  size_t& rawlogEntry) const;
429 
430  /** Tries to auto-detect the external-images directory of the given rawlog
431  *file.
432  * This searches for the existence of the directories:
433  * - "<rawlog_file_path>/<rawlog_filename>_Images"
434  * - "<rawlog_file_path>/<rawlog_filename>_images"
435  * - "<rawlog_file_path>/<rawlog_filename>_IMAGES"
436  * - "<rawlog_file_path>/Images" (This one is returned if none of the
437  *choices actually exists).
438  *
439  * The results from this function should be written into
440  *mrpt::utils::CImage::getImagesPathBase() to enable automatic
441  * loading of extenrnally-stored images in rawlogs.
442  */
443  static std::string detectImagesDirectory(const std::string& rawlogFilename);
444 
445 }; // End of class def.
446 
447 } // End of namespace
448 } // End of namespace
449 
450 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
bool operator==(const iterator &o)
Definition: CRawlog.h:249
This "observation" is actually a placeholder for a text block with comments or additional parameters ...
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:349
iterator begin()
Definition: CRawlog.h:348
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:545
static std::string detectImagesDirectory(const std::string &rawlogFilename)
Tries to auto-detect the external-images directory of the given rawlog file.
Definition: CRawlog.cpp:586
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
iterator erase(const iterator &it)
Definition: CRawlog.h:351
const_iterator & operator++()
Definition: CRawlog.h:317
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:328
Scalar * iterator
Definition: eigen_plugins.h:26
const_iterator operator--(int)
Definition: CRawlog.h:322
const_iterator(const TListObjects::const_iterator &it)
Definition: CRawlog.h:302
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
std::vector< mrpt::utils::CSerializable::Ptr > TListObjects
Definition: CRawlog.h:73
TListObjects::const_iterator m_it
Definition: CRawlog.h:298
const Scalar * const_iterator
Definition: eigen_plugins.h:27
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:305
Declares a class for storing a collection of robot actions.
const mrpt::utils::CSerializable::Ptr operator*() const
Definition: CRawlog.h:306
void addGenericObject(const mrpt::utils::CSerializable::Ptr &obj)
Generic add for a smart pointer to a CSerializable object:
Definition: CRawlog.cpp:62
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:305
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
This class implements a config file-like interface over a memory-stored string list.
std::string getCommentText() const
Returns the block of comment text for the rawlog.
Definition: CRawlog.cpp:578
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:206
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
mrpt::utils::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
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
void findObservationsByClassInRange(mrpt::system::TTimeStamp time_start, mrpt::system::TTimeStamp time_end, const mrpt::utils::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:464
iterator & operator=(const iterator &o)
Definition: CRawlog.h:243
const_iterator operator++(int)
Definition: CRawlog.h:311
static bool getActionObservationPairOrObservation(mrpt::utils::CStream &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:402
This class stores a rawlog (robotic datasets) in one of two possible formats:
Definition: CRawlog.h:68
std::multimap< mrpt::system::TTimeStamp, CObservation::Ptr > TListTimeAndObservations
For usage with CRawlog classes.
Definition: CRawlog.h:27
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
void moveFrom(CRawlog &obj)
Efficiently copy the contents from other existing object, and remove the data from the origin (after ...
Definition: CRawlog.cpp:321
void setCommentText(const std::string &t)
Changes the block of comment text for the rawlog.
Definition: CRawlog.cpp:585
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:43
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:295
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
std::shared_ptr< CSerializable > Ptr
Definition: CSerializable.h:47
Declares a class for storing a robot action.
Definition: CAction.h:28
TEntryType getType() const
Definition: CRawlog.h:334
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...
std::shared_ptr< CActionCollection > Ptr
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
TEntryType
The type of each entry in a rawlog.
Definition: CRawlog.h:95
TListObjects::iterator m_it
Definition: CRawlog.h:237
bool operator!=(const iterator &o)
Definition: CRawlog.h:250
iterator end()
Definition: CRawlog.h:350
void swap(CRawlog &obj)
Efficiently swap the contents of two existing objects.
Definition: CRawlog.cpp:333
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
A structure that holds runtime class type information.
Definition: CObject.h:31
iterator(const TListObjects::iterator &it)
Definition: CRawlog.h:241
static iterator erase(TListObjects &lst, const iterator &it)
Definition: CRawlog.h:287
size_t size() const
Returns the number of actions / observations object in the sequence.
Definition: CRawlog.cpp:88
mrpt::utils::CSerializable::Ptr operator*()
Definition: CRawlog.h:251
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:304
static bool readActionObservationPair(mrpt::utils::CStream &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:340
std::pair< mrpt::system::TTimeStamp, CObservation::Ptr > TTimeObservationPair
For usage with CRawlog classes.
Definition: CRawlog.h:24
void getCommentTextAsConfigFile(mrpt::utils::CConfigFileMemory &memCfg) const
Saves the block of comment text for the rawlog into the passed config file object.
Definition: CRawlog.cpp:579
const_iterator begin() const
Definition: CRawlog.h:347
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: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019