From f79bdb633abf5d6925b2851adab48ed24d3ab30a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 24 May 2017 17:26:05 +0200 Subject: tracker/fusion: add back "second tracker" functionality It only took us five years to implement again, following removal after the fork from facetracknoir. --- tracker-fusion/CMakeLists.txt | 1 + tracker-fusion/fusion-tracker-logo.png | Bin 0 -> 1985 bytes tracker-fusion/fusion.cpp | 182 +++++++++++++++++++++++++++++++++ tracker-fusion/fusion.h | 59 +++++++++++ tracker-fusion/fusion.qrc | 5 + tracker-fusion/fusion.ui | 180 ++++++++++++++++++++++++++++++++ tracker-fusion/fusion_dialog.cpp | 2 + 7 files changed, 429 insertions(+) create mode 100644 tracker-fusion/CMakeLists.txt create mode 100644 tracker-fusion/fusion-tracker-logo.png create mode 100644 tracker-fusion/fusion.cpp create mode 100644 tracker-fusion/fusion.h create mode 100644 tracker-fusion/fusion.qrc create mode 100644 tracker-fusion/fusion.ui create mode 100644 tracker-fusion/fusion_dialog.cpp diff --git a/tracker-fusion/CMakeLists.txt b/tracker-fusion/CMakeLists.txt new file mode 100644 index 00000000..4125d630 --- /dev/null +++ b/tracker-fusion/CMakeLists.txt @@ -0,0 +1 @@ +otr_module(tracker-fusion) diff --git a/tracker-fusion/fusion-tracker-logo.png b/tracker-fusion/fusion-tracker-logo.png new file mode 100644 index 00000000..63d541e1 Binary files /dev/null and b/tracker-fusion/fusion-tracker-logo.png differ diff --git a/tracker-fusion/fusion.cpp b/tracker-fusion/fusion.cpp new file mode 100644 index 00000000..e8e48372 --- /dev/null +++ b/tracker-fusion/fusion.cpp @@ -0,0 +1,182 @@ +/* Copyright (c) 2017 Stanislaw Halik + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ + +#include "compat/ndebug-guard.hpp" +#include "fusion.h" + +#include "opentrack-library-path.h" + +#include +#include +#include + +static const QString own_name = fusion_metadata().name(); + +fusion_tracker::fusion_tracker() : + rot_tracker_data{}, + pos_tracker_data{}, + other_frame(new QFrame) +{ +} + +fusion_tracker::~fusion_tracker() +{ + rot_tracker = nullptr; + pos_tracker = nullptr; + rot_dylib = nullptr; + pos_dylib = nullptr; + + if (other_frame) + { + assert(other_frame->layout()); + delete other_frame->layout(); + other_frame = nullptr; + } +} + +void fusion_tracker::start_tracker(QFrame* frame) +{ + assert(!rot_tracker && !pos_tracker); + assert(!rot_dylib && !pos_dylib); + + fusion_settings s; + const QString rot_tracker_name = s.rot_tracker_name; + const QString pos_tracker_name = s.pos_tracker_name; + + assert(rot_tracker_name != own_name); + assert(pos_tracker_name != own_name); + + if (rot_tracker_name.isEmpty() || pos_tracker_name.isEmpty()) + { + QMessageBox::warning(nullptr, + "Fusion tracker", "Select rotation and position trackers.", + QMessageBox::Close); + other_frame = nullptr; + return; + } + + if (rot_tracker_name == pos_tracker_name) + { + QMessageBox::warning(nullptr, + "Fusion tracker", "Select different trackers for rotation and position.", + QMessageBox::Close); + other_frame = nullptr; + return; + } + + for (auto& t : modules.trackers()) + { + if (t->name == rot_tracker_name) + { + assert(!rot_dylib); + rot_dylib = t; + } + if (t->name == pos_tracker_name) + { + assert(!pos_dylib); + pos_dylib = t; + } + } + + rot_tracker = make_dylib_instance(rot_dylib); + pos_tracker = make_dylib_instance(pos_dylib); + + pos_tracker->start_tracker(frame); + + if (frame->layout() == nullptr) + { + rot_tracker->start_tracker(frame); + other_frame = nullptr; + } + else + { + rot_tracker->start_tracker(other_frame.get()); + if (!other_frame->layout()) + other_frame = nullptr; + } + + +} + +void fusion_tracker::data(double *data) +{ + if (pos_tracker && rot_tracker) + { + rot_tracker->data(rot_tracker_data); + pos_tracker->data(pos_tracker_data); + + for (unsigned k = 0; k < 3; k++) + data[k] = pos_tracker_data[k]; + for (unsigned k = 3; k < 6; k++) + data[k] = rot_tracker_data[k]; + } +} + +fusion_dialog::fusion_dialog() +{ + ui.setupUi(this); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + + ui.rot_tracker->addItem(""); + ui.pos_tracker->addItem(""); + + for (auto &m : modules.trackers()) + { + if (m->name == own_name) + continue; + + ui.rot_tracker->addItem(m->icon, m->name); + ui.pos_tracker->addItem(m->icon, m->name); + } + + ui.rot_tracker->setCurrentIndex(0); + ui.pos_tracker->setCurrentIndex(0); + + tie_setting(s.rot_tracker_name, ui.rot_tracker); + tie_setting(s.pos_tracker_name, ui.pos_tracker); +} + +void fusion_dialog::doOK() +{ + const int rot_idx = ui.rot_tracker->currentIndex() - 1; + const int pos_idx = ui.pos_tracker->currentIndex() - 1; + + if (rot_idx == -1 || pos_idx == -1 || rot_idx == pos_idx) + { + QMessageBox::warning(this, + "Fusion tracker", + "Fusion tracker only works when distinct trackers are selected " + "for rotation and position.", + QMessageBox::Close); + } + + s.b->save(); + close(); +} + +void fusion_dialog::doCancel() +{ + close(); +} + +fusion_settings::fusion_settings() : + opts("fusion-tracker"), + rot_tracker_name(b, "rot-tracker", ""), + pos_tracker_name(b, "pos-tracker", "") +{ +} + +has_modules::has_modules() : + modules(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) +{ +} + + +OPENTRACK_DECLARE_TRACKER(fusion_tracker, fusion_dialog, fusion_metadata) \ No newline at end of file diff --git a/tracker-fusion/fusion.h b/tracker-fusion/fusion.h new file mode 100644 index 00000000..a943fe06 --- /dev/null +++ b/tracker-fusion/fusion.h @@ -0,0 +1,59 @@ +#pragma once +#include "api/plugin-api.hpp" +#include "api/plugin-support.hpp" +#include +#include + +#include "options/options.hpp" +using namespace options; + +struct fusion_settings final : opts +{ + value rot_tracker_name; + value pos_tracker_name; + + fusion_settings(); +}; + +struct has_modules +{ + Modules modules; + has_modules(); +}; + +struct fusion_tracker : public ITracker, has_modules +{ + fusion_tracker(); + ~fusion_tracker() override; + void start_tracker(QFrame *) override; + void data(double *data) override; + + double rot_tracker_data[6], pos_tracker_data[6]; + + std::unique_ptr other_frame; + std::shared_ptr rot_dylib, pos_dylib; + std::shared_ptr rot_tracker, pos_tracker; +}; + +#include "ui_fusion.h" + +class fusion_dialog : public ITrackerDialog, has_modules +{ + Q_OBJECT + + fusion_settings s; + Ui::fusion_ui ui; +public: + fusion_dialog(); +private slots: + void doOK(); + void doCancel(); +}; + +class fusion_metadata : public Metadata +{ +public: + QString name() { return QString(QCoreApplication::translate("fusion_metadata", "Fusion")); } + QIcon icon() { return QIcon(":/images/fusion-tracker-logo.png"); } +}; + diff --git a/tracker-fusion/fusion.qrc b/tracker-fusion/fusion.qrc new file mode 100644 index 00000000..32a5913e --- /dev/null +++ b/tracker-fusion/fusion.qrc @@ -0,0 +1,5 @@ + + + fusion-tracker-logo.png + + diff --git a/tracker-fusion/fusion.ui b/tracker-fusion/fusion.ui new file mode 100644 index 00000000..1eb8992e --- /dev/null +++ b/tracker-fusion/fusion.ui @@ -0,0 +1,180 @@ + + + fusion_ui + + + Qt::NonModal + + + + 0 + 0 + 397 + 180 + + + + + 0 + 0 + + + + Fusion + + + + :/fusion-tracker-logo.png:/fusion-tracker-logo.png + + + Qt::LeftToRight + + + false + + + + + + QFrame::Raised + + + + + + + 0 + 0 + + + + Set distinct trackers for rotation and position input. + + + + + + + + 0 + 0 + + + + Configure the trackers on the main window. It's required that they're both distinct, and both are set to something. + + + true + + + + + + + + + + + 0 + 0 + + + + + + + + 1 + 0 + + + + + 89 + 0 + + + + Rotation + + + + + + + + 3 + 0 + + + + + 266 + 0 + + + + + + + + + 1 + 0 + + + + + 89 + 0 + + + + Position + + + + + + + + 3 + 0 + + + + + 266 + 0 + + + + + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/tracker-fusion/fusion_dialog.cpp b/tracker-fusion/fusion_dialog.cpp new file mode 100644 index 00000000..ca05531a --- /dev/null +++ b/tracker-fusion/fusion_dialog.cpp @@ -0,0 +1,2 @@ +#include "fusion.h" + -- cgit v1.2.3