Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /tf_static filter #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/filter_frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include "ui_filter_frames.h"

FilterFrames::FilterFrames(const rosbag::Bag& bag,
const std::string& tf,
FilterFrames::FramesSet& filtered_frames,
QWidget* parent)
: QDialog(parent), ui(new Ui::FilterFrames), _bag(bag), _frames_to_filter(filtered_frames)
{
ui->setupUi(this);

std::vector<std::string> topics = {"/tf"};
std::vector<std::string> topics = {tf};
rosbag::View bag_view(bag, rosbag::TopicQuery(topics));

QProgressDialog progress_dialog;
Expand Down
1 change: 1 addition & 0 deletions src/filter_frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FilterFrames : public QDialog
using FramesSet = std::set<std::pair<std::string,std::string>>;

explicit FilterFrames(const rosbag::Bag& bag,
const std::string& tf,
FramesSet &filtered_frames,
QWidget *parent = nullptr );

Expand Down
55 changes: 46 additions & 9 deletions src/rosbag_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <topic_tools/shape_shifter.h>
#include <tf/tfMessage.h>
#include <tf2_msgs/TFMessage.h>
#include <sensor_msgs/PointCloud2.h>

#include <QDir>
#include <QString>
Expand Down Expand Up @@ -133,6 +134,9 @@ void RosbagEditor::changeEnabledWidgets()

bool contains_tf = !ui->tableWidgetInput->findItems( "/tf", Qt::MatchExactly ).empty();
ui->pushButtonFilterTF->setEnabled( ui->checkBoxFilterTF->isChecked() && contains_tf );

bool contains_tf_static = !ui->tableWidgetInput->findItems( "/tf_static", Qt::MatchExactly ).empty();
ui->pushButtonFilterTFStatic->setEnabled( ui->checkBoxFilterTFStatic->isChecked() && contains_tf_static );
}

void RosbagEditor::on_pushButtonMove_pressed()
Expand All @@ -156,6 +160,8 @@ void RosbagEditor::on_pushButtonMove_pressed()
ui->tableWidgetOutput->setItem(row, 0, new QTableWidgetItem(topic_name) );
QLineEdit* topic_editor = new QLineEdit(ui->tableWidgetOutput);
ui->tableWidgetOutput->setCellWidget(row, 1, topic_editor);
QLineEdit* topic_editor2 = new QLineEdit(ui->tableWidgetOutput);
ui->tableWidgetOutput->setCellWidget(row, 2, topic_editor2);
}
}

Expand Down Expand Up @@ -240,13 +246,19 @@ void RosbagEditor::on_pushButtonSave_pressed()

std::vector<std::string> input_topics;
std::map<std::string,std::string> topis_renamed;
std::map<std::string,std::string> frameid_renamed;

for(int row = 0; row < ui->tableWidgetOutput->rowCount(); ++row)
{
std::string name = ui->tableWidgetOutput->item(row,0)->text().toStdString();
QLineEdit* line_edit = qobject_cast<QLineEdit*>(ui->tableWidgetOutput->cellWidget(row, 1));
std::string renamed = line_edit->text().toStdString();
QLineEdit* line_edit2 = qobject_cast<QLineEdit*>(ui->tableWidgetOutput->cellWidget(row, 2));
std::string frameid = line_edit2->text().toStdString();
input_topics.push_back( name );
if( ! frameid.empty()){
frameid_renamed.insert(std::make_pair(name, frameid));
}
if( renamed.empty())
{
topis_renamed.insert( std::make_pair(name,name));
Expand All @@ -272,6 +284,7 @@ void RosbagEditor::on_pushButtonSave_pressed()
progress_dialog.setRange(0, bag_view.size()-1);

bool do_tf_filtering = _filtered_frames.size() > 0 && ui->checkBoxFilterTF->isChecked();
bool do_tf_static_filtering = _filtered_frames.size() > 0 && ui->checkBoxFilterTFStatic->isChecked();

for(const rosbag::MessageInstance& msg: bag_view)
{
Expand All @@ -298,24 +311,35 @@ void RosbagEditor::on_pushButtonSave_pressed()
};


if( msg.getTopic() == "/tf" && do_tf_filtering )
const std::string& datatype = msg.getDataType();
if( (msg.getTopic() == "/tf" && do_tf_filtering) || (msg.getTopic() == "/tf_static" && do_tf_static_filtering) )
{
tf::tfMessage::Ptr tf = msg.instantiate<tf::tfMessage>();
if (tf)
if (datatype == "tf/tfMessage")
{
tf::tfMessage::Ptr tf = msg.instantiate<tf::tfMessage>();
removeTransform(tf->transforms);
out_bag.write( name, msg.getTime(), tf, msg.getConnectionHeader());
if(!tf->transforms.empty())
out_bag.write( name, msg.getTime(), tf, msg.getConnectionHeader());
}

tf2_msgs::TFMessage::Ptr tf2 = msg.instantiate<tf2_msgs::TFMessage>();
if (tf2)
if (datatype == "tf2_msgs/TFMessage")
{
tf2_msgs::TFMessage::Ptr tf2 = msg.instantiate<tf2_msgs::TFMessage>();
removeTransform(tf2->transforms);
out_bag.write( name, msg.getTime(), tf2, msg.getConnectionHeader());
if(!tf2->transforms.empty())
out_bag.write( name, msg.getTime(), tf2, msg.getConnectionHeader());
}
}
else{
out_bag.write( name, msg.getTime(), msg, msg.getConnectionHeader());
if(frameid_renamed.find(msg.getTopic()) != frameid_renamed.end()){
if( datatype == "sensor_msgs/PointCloud2"){
sensor_msgs::PointCloud2::Ptr mm = msg.instantiate<sensor_msgs::PointCloud2>();
mm->header.frame_id=frameid_renamed.find(msg.getTopic())->second;
out_bag.write( name, msg.getTime(), mm, msg.getConnectionHeader());
}
}else{
out_bag.write( name, msg.getTime(), msg, msg.getConnectionHeader());
}
}
}
out_bag.close();
Expand Down Expand Up @@ -352,7 +376,20 @@ void RosbagEditor::on_checkBoxFilterTF_toggled(bool checked)

void RosbagEditor::on_pushButtonFilterTF_pressed()
{
FilterFrames dialog(_bag, _filtered_frames, this);
FilterFrames dialog(_bag, "/tf", _filtered_frames, this);
dialog.exec();

}

void RosbagEditor::on_checkBoxFilterTFStatic_toggled(bool checked)
{
bool contains_tf_static = !ui->tableWidgetInput->findItems( "/tf_static", Qt::MatchExactly ).empty();
ui->pushButtonFilterTFStatic->setEnabled( checked && contains_tf_static );
}

void RosbagEditor::on_pushButtonFilterTFStatic_pressed()
{
FilterFrames dialog(_bag, "/tf_static", _filtered_frames, this);
dialog.exec();

}
4 changes: 4 additions & 0 deletions src/rosbag_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ private slots:

void on_pushButtonFilterTF_pressed();

void on_checkBoxFilterTFStatic_toggled(bool checked);

void on_pushButtonFilterTFStatic_pressed();

private:
Ui::RosbagEditor *ui;
QString _loade_filename;
Expand Down
47 changes: 31 additions & 16 deletions src/rosbag_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>150</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>200</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>150</number>
</attribute>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
Expand Down Expand Up @@ -282,12 +282,12 @@
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>150</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>200</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>150</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
Expand All @@ -304,6 +304,11 @@
<string>Renamed topic (optional)</string>
</property>
</column>
<column>
<property name="text">
<string>Renamed frame_id (optional)</string>
</property>
</column>
</widget>
</item>
<item>
Expand Down Expand Up @@ -453,22 +458,32 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Edit filter</string>
<string>Edit /tf filter</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QCheckBox" name="checkBoxFilterTFStatic">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<property name="text">
<string>Filter /tf_static frames</string>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonFilterTFStatic">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Edit /tf_static filter</string>
</property>
</widget>
</item>
</layout>
</widget>
Expand Down