bag_player.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, Open Source Robotics Foundation
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #ifndef ROSBAG_BAG_PLAYER_H
36 #define ROSBAG_BAG_PLAYER_H
37 
38 #include <boost/foreach.hpp>
39 
40 #include "rosbag/bag.h"
41 #include "rosbag/view.h"
42 
43 namespace rosbag
44 {
45 
46 
47 // A helper struct
49 {
50  virtual ~BagCallback() {};
51  virtual void call(MessageInstance m) = 0;
52 };
53 
54 // A helper class for the callbacks
55 template<class T>
56 class BagCallbackT : public BagCallback
57 {
58 public:
60 
62  cb_(cb)
63  {}
64 
66  cb_(m.instantiate<T>());
67  }
68 
69 private:
71 };
72 #ifdef _MSC_VER
73 #pragma warning( disable : 4290 ) // Suppress warning C4290:C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
74 #endif
75 /* A class for playing back bag files at an API level. It supports
76  relatime, as well as accelerated and slowed playback. */
77 class BagPlayer
78 {
79 public:
80  /* Constructor expecting the filename of a bag */
82 
83  /* Register a callback for a specific topic and type */
84  template<class T>
85  void register_callback(const std::string &topic,
86  typename BagCallbackT<T>::Callback f);
87 
88  /* Unregister a callback for a topic already registered */
89  void unregister_callback(const std::string &topic);
90 
91  /* Set the time in the bag to start.
92  * Default is the first message */
93  void set_start(const rs2rosinternal::Time &start);
94 
95  /* Set the time in the bag to stop.
96  * Default is the last message */
97  void set_end(const rs2rosinternal::Time &end);
98 
99  /* Set the speed to playback. 1.0 is the default.
100  * 2.0 would be twice as fast, 0.5 is half realtime. */
101  void set_playback_speed(double scale);
102 
103  /* Start playback of the bag file using the parameters previously
104  set */
105  void start_play();
106 
107  /* Get the current time of the playback */
109 
110  // Destructor
111  virtual ~BagPlayer();
112 
113 
114  // The bag file interface loaded in the constructor.
116 
117 private:
118  rs2rosinternal::Time real_time(const rs2rosinternal::Time &msg_time);
119 
120  std::map<std::string, BagCallback *> cbs_;
126 };
127 
128 template<class T>
130  typename BagCallbackT<T>::Callback cb) {
131  cbs_[topic] = new BagCallbackT<T>(cb);
132 }
133 
134 }
135 
136 #endif
virtual void call(MessageInstance m)=0
std::map< std::string, BagCallback * > cbs_
Definition: bag_player.h:120
GLuint GLuint end
const GLfloat * m
Definition: glext.h:6814
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
Base class for rosbag exceptions.
Definition: exceptions.h:43
GLsizei const GLchar *const * string
BagCallbackT(Callback cb)
Definition: bag_player.h:61
GLdouble f
rs2rosinternal::Time bag_start_
Definition: bag_player.h:121
void register_callback(const std::string &topic, typename BagCallbackT< T >::Callback f)
Definition: bag_player.h:129
void call(MessageInstance m)
Definition: bag_player.h:65
A class pointing into a bag file.
Time representation. May either represent wall clock time or ROS clock time.
Definition: time.h:177
GLuint start
virtual ~BagCallback()
Definition: bag_player.h:50
rs2rosinternal::Time bag_end_
Definition: bag_player.h:122
double playback_speed_
Definition: bag_player.h:124
rs2rosinternal::Time last_message_time_
Definition: bag_player.h:123
Definition: bag.h:66
rs2rosinternal::Time play_start_
Definition: bag_player.h:125
std::shared_ptr< T > instantiate() const
Templated call to instantiate a message.
double get_time()
Definition: rs_internal.hpp:62


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:45:07