Ask Your Question

rosbag reverse

asked 2011-10-05 11:48:59 -0600

Kyle Strabala gravatar image

updated 2014-01-28 17:10:30 -0600

ngrennan gravatar image

In the C++ API for rosbag, you can open a rosbag and then step forwards through messages using the following loop (taken from the rosbag API website):

BOOST_FOREACH(rosbag::MessageInstance const m, view)

Is there a way to reverse through the messages?

I have tried the following:

for(rosbag::View::iterator iter = view.end(); iter != view.begin(); --iter)

but the compiler complains that ‘class rosbag::View::iterator’ has no member named ‘decrement’

I tried to add a "decrement" function to view.h/cpp in the rosbag API based on the "increment" function, but my C++ isn't good enough to figure out what is going on.

Any suggestions? Thanks, Kyle.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2011-10-05 14:31:30 -0600

Kyle Strabala gravatar image

I found a workaround that works for me. Still, I wish there was a decrement function to step through the messages.

#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <rosbag/query.h>


// Open rosbag file
rosbag::Bag input_bag;, rosbag::bagmode::Read);

// Setup View
std::vector<std::string> topics;
rosbag::View view(input_bag, rosbag::TopicQuery(topics));

// Make a vector with instances of the View::iterator class pointing to each message
std::vector<rosbag::View::iterator> iters;
for(rosbag::View::iterator iter = view.begin(); iter != view.end(); ++iter)
    rosbag::View::iterator new_iter(iter);
    iters.push_back( new_iter );

// Reverse iterate through the message pointers
for(std::vector<rosbag::View::iterator>::reverse_iterator r_iter = iters.rbegin(); r_iter != iters.rend(); ++r_iter)
    sensor_msgs::Image::ConstPtr image_msg = (*(*r_iter)).instantiate<sensor_msgs::Image>();
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-10-05 11:48:59 -0600

Seen: 2,302 times

Last updated: Jan 28 '14