ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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>();