BagR.cpp
Go to the documentation of this file.
00001 #include "BagR.h"
00002 
00003  std::vector<BagMessage>* rrosBagRead(const char *filename, std::vector<std::string> *topics, unsigned int max_size){
00004 
00005         rosbag::Bag bag;
00006         bag.open(filename, rosbag::bagmode::Read);
00007 
00008         //std::cerr << filename << std::endl;
00009 
00010         std::vector<BagMessage> *vecMsg = new std::vector<BagMessage>();
00011         vecMsg->reserve(1000);
00012         rosbag::View *view;
00013 
00014         if(topics->size() > 0){
00015                 view = new rosbag::View(bag, rosbag::TopicQuery(*topics));
00016         } else {
00017                 view = new rosbag::View(bag);
00018         }
00019 
00020 
00021         BOOST_FOREACH(rosbag::MessageInstance const m, *view)
00022         {
00023                 BagMessage *msg = new BagMessage();
00024                 msg->topic = m.getTopic();
00025                 msg->datatype = m.getDataType();
00026                 msg->time_stamp = m.getTime().toSec();
00027 
00028                 msg->ui8Buffer = boost::shared_array<uint8_t> (new uint8_t[m.size()]);
00029                 msg->isStream  = new ros::serialization::IStream(msg->ui8Buffer.get(), m.size());
00030 
00031                 m.write(*msg->isStream);
00032 
00033                 msg->isStream->advance(-m.size());
00034 
00035                 vecMsg->push_back(*msg);
00036 
00037                 max_size--;
00038                 if(max_size==0) break;
00039         }
00040 
00041         bag.close();
00042 
00043         delete view;
00044 
00045         return vecMsg;
00046 }


rosR
Author(s): André Dietrich, Sebastian Zug
autogenerated on Sun Jan 5 2014 11:10:28