From 7b3be452b6be528de753a1a633a3aacdb11be86c Mon Sep 17 00:00:00 2001 From: DaMichel Date: Fri, 29 Jul 2016 11:12:22 +0200 Subject: new track logging: record poses in various stages of processing into a file --- gui/options-dialog.cpp | 21 +++++++++++++ gui/options-dialog.hpp | 3 ++ gui/settings.ui | 82 +++++++++++++++++++++++++++++++++++++++++++++++++- gui/ui.cpp | 61 ++++++++++++++++++++++++++++++++++++- gui/ui.h | 3 ++ 5 files changed, 168 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index 3b54ae9a..8987ba34 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -11,6 +11,7 @@ #include #include #include +#include static QString kopts_to_string(const key_opts& kopts) { @@ -72,6 +73,9 @@ OptionsDialog::OptionsDialog(std::function pause_keybindings) : tie_setting(main.center_method, ui.center_method); + tie_setting(main.tracklogging_enabled, ui.tracklogging_enabled); + tie_setting(main.tracklogging_filename, ui.tracklogging_filenameedit); + struct tmp { key_opts& opt; @@ -102,6 +106,8 @@ OptionsDialog::OptionsDialog(std::function pause_keybindings) : connect(val.button, &QPushButton::pressed, this, [=]() -> void { bind_key(val.opt, val.label); }); } } + + connect(ui.tracklogging_fileselectbtn, SIGNAL(clicked()), this, SLOT(browse_datalogging_file())); } void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) @@ -163,3 +169,18 @@ void OptionsDialog::doCancel() close(); } +void OptionsDialog::browse_datalogging_file() +{ + QString filename = ui.tracklogging_filenameedit->text(); + if (filename.isEmpty()) + filename = QDir::currentPath(); + QString newfilename = QFileDialog::getSaveFileName(this, tr("Select Filename"), filename, tr("CSV File (*.csv)")); + if (!newfilename.isEmpty()) + ui.tracklogging_filenameedit->setText(newfilename); +} + +void OptionsDialog::update_widgets_states(bool tracker_is_running) +{ + ui.tracklogging_enabled->setEnabled(!tracker_is_running); + ui.tracklogging_fileselectbtn->setEnabled(!tracker_is_running); +} \ No newline at end of file diff --git a/gui/options-dialog.hpp b/gui/options-dialog.hpp index 66386a79..f84ee8f6 100644 --- a/gui/options-dialog.hpp +++ b/gui/options-dialog.hpp @@ -13,6 +13,8 @@ signals: void saving(); public: OptionsDialog(std::function pause_keybindings); +public slots: + void update_widgets_states(bool tracker_is_running); private: main_settings main; std::function pause_keybindings; @@ -22,4 +24,5 @@ private slots: void doOK(); void doCancel(); void bind_key(key_opts &kopts, QLabel* label); + void browse_datalogging_file(); }; diff --git a/gui/settings.ui b/gui/settings.ui index 4654dd85..9c573da2 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -33,7 +33,7 @@ - 0 + 2 @@ -1204,6 +1204,86 @@ + + + + + 0 + 0 + + + + + 0 + 20 + + + + Data Logging + + + + + + + 0 + 0 + + + + Record pose data in a csv file. WARNING: overwrites file contents without warning every time the tracker is started. + + + true + + + + + + + Enable + + + + + + + 0 + + + 0 + + + + + Select File ... + + + + + + + false + + + true + + + + + + + + + true + + + + + + + + diff --git a/gui/ui.cpp b/gui/ui.cpp index 85d5d029..3bda6ee2 100644 --- a/gui/ui.cpp +++ b/gui/ui.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef _WIN32 # include @@ -285,6 +286,45 @@ void MainWindow::reload_options() ensure_tray(); } +/* + Allocates a new logger instance depending on main settings. Result is assigned to logger variable of State object. + May open warning dialogs. + May also assign nullptr in case of an error. +*/ +void MainWindow::initialize_logger() +{ + logger = nullptr; + if (s.tracklogging_enabled) + { + if (static_cast(s.tracklogging_filename).isEmpty()) + { + QMessageBox::warning(this, tr("Logging Error"), + tr("No filename given for track logging. Aborting."), + QMessageBox::Ok, + QMessageBox::NoButton); + return; + } + try + { + logger = TrackLoggerCSV::make(s); + } + catch (std::ios_base::failure &) + { + QMessageBox::warning(this, tr("Logging Error"), + tr("Unable to open file: ") + s.tracklogging_filename + tr(". Aborting."), + QMessageBox::Ok, + QMessageBox::NoButton); + return; + } + } + else + { + logger = TrackLogger::make(); + } + assert(logger != nullptr); +} + + void MainWindow::startTracker() { if (work) @@ -310,9 +350,17 @@ void MainWindow::startTracker() return; } + initialize_logger(); + if (logger == nullptr) + { + // error -> rollback + libs = SelectedLibraries(); + return; + } + save_modules(); - work = std::make_shared(pose, libs, winId()); + work = std::make_shared(pose, libs, *logger, winId()); reload_options(); @@ -331,6 +379,12 @@ void MainWindow::startTracker() // trackers take care of layout state updates const bool is_inertial = ui.video_frame->layout() == nullptr; updateButtonState(true, is_inertial); + + // Update the state of the options window directly. + // Might be better to emit signals and allow the options window + // to connect its slots to them (?) + if (options_widget) + options_widget->update_widgets_states(true); ui.btnStopTracker->setFocus(); } @@ -358,12 +412,16 @@ void MainWindow::stopTracker() work = nullptr; libs = SelectedLibraries(); + logger = nullptr; { double p[6] = {0,0,0, 0,0,0}; display_pose(p, p); } updateButtonState(false, false); + + if (options_widget) + options_widget->update_widgets_states(false); set_title(); @@ -495,6 +553,7 @@ void MainWindow::show_options_dialog() if (mk_window(&options_widget, [&](bool flag) -> void { set_keys_enabled(!flag); })) { connect(options_widget.get(), &OptionsDialog::saving, this, &MainWindow::reload_options); + options_widget->update_widgets_states(work != nullptr); } } diff --git a/gui/ui.h b/gui/ui.h index 7415d3d4..acec615e 100644 --- a/gui/ui.h +++ b/gui/ui.h @@ -102,6 +102,9 @@ private slots: void startTracker(); void stopTracker(); void reload_options(); + + void initialize_logger(); + signals: void emit_start_tracker(); void emit_stop_tracker(); -- cgit v1.2.3