src
bag_reader.cpp
Go to the documentation of this file.
1
// *****************************************************************************
2
//
3
// Copyright (c) 2015, Southwest Research Institute® (SwRI®)
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above copyright
11
// notice, this list of conditions and the following disclaimer in the
12
// documentation and/or other materials provided with the distribution.
13
// * Neither the name of Southwest Research Institute® (SwRI®) nor the
14
// names of its contributors may be used to endorse or promote products
15
// derived from this software without specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
// ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
21
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27
// DAMAGE.
28
//
29
// *****************************************************************************
30
31
#include <QFileDialog>
32
#include <QDir>
33
34
#include "
include/swri_console/bag_reader.h
"
35
36
#include <
rosbag/bag.h
>
37
#include <
rosbag/view.h
>
38
39
using namespace
swri_console
;
40
41
void
BagReader::readBagFile
(
const
QString& filename)
42
{
43
bool
log_messages_found =
true
;
44
rosbag::Bag
bag;
45
bag.
open
(filename.toStdString(),
rosbag::bagmode::Read
);
46
47
rosbag::View
view(bag,
rosbag::TopicQuery
(
"/rosout"
));
48
if
(view.
size
() == 0)
49
{
50
// This implies we have no messages on /rosout, let's try /rosout_agg
51
view.
addQuery
(bag,
rosbag::TopicQuery
(
"/rosout_agg"
));
52
if
(view.
size
() == 0)
53
{
54
qWarning(
"Could not find any messages on either '/rosout' or '/rosout_agg' in bag file '%s'"
,
55
filename.toStdString().c_str());
56
log_messages_found =
false
;
57
}
58
}
59
60
if
(log_messages_found)
61
{
62
rosbag::View::const_iterator
iter;
63
64
for
(iter = view.
begin
(); iter != view.
end
(); ++iter)
65
{
66
rosgraph_msgs::LogConstPtr log = iter->instantiate<rosgraph_msgs::Log>();
67
if
(log != NULL ) {
68
emit
logReceived
(log);
69
}
70
else
{
71
qWarning(
"Got a message that was not a log message but a: %s"
, iter->getDataType().c_str());
72
}
73
}
74
}
75
76
emit
finishedReading
();
77
}
78
79
void
BagReader::promptForBagFile
()
80
{
81
QString filename = QFileDialog::getOpenFileName(NULL,
82
tr(
"Open Bag File"
),
83
QDir::homePath(),
84
tr(
"Bag Files (*.bag)"
));
85
86
if
(filename != NULL)
87
{
88
readBagFile
(filename);
89
}
90
}
rosbag::Bag
rosbag::View::size
uint32_t size()
bag.h
rosbag::bagmode::Read
Read
swri_console::BagReader::logReceived
void logReceived(const rosgraph_msgs::LogConstPtr &msg)
rosbag::View::const_iterator
iterator const_iterator
swri_console::BagReader::readBagFile
void readBagFile(const QString &filename)
Definition:
bag_reader.cpp:41
rosbag::TopicQuery
rosbag::View::addQuery
void addQuery(Bag const &bag, boost::function< bool(ConnectionInfo const *)> query, ros::Time const &start_time=ros::TIME_MIN, ros::Time const &end_time=ros::TIME_MAX)
view.h
swri_console
Definition:
bag_reader.h:40
rosbag::View
bag_reader.h
swri_console::BagReader::promptForBagFile
void promptForBagFile()
Definition:
bag_reader.cpp:79
rosbag::Bag::open
void open(std::string const &filename, uint32_t mode=bagmode::Read)
rosbag::View::end
iterator end()
rosbag::View::begin
iterator begin()
swri_console::BagReader::finishedReading
void finishedReading()
swri_console
Author(s): P. J. Reed
, Jerry Towler
, David Anthony
autogenerated on Sat Sep 23 2023 02:55:36