diff options
-rw-r--r-- | facetracknoir/facetracknoir.cpp | 161 | ||||
-rw-r--r-- | facetracknoir/facetracknoir.h | 32 | ||||
-rw-r--r-- | facetracknoir/plugin-qt-api.hpp | 67 | ||||
-rw-r--r-- | facetracknoir/plugin-support.cpp | 72 | ||||
-rw-r--r-- | facetracknoir/plugin-support.h | 37 | ||||
-rw-r--r-- | facetracknoir/shortcuts.h | 2 | ||||
-rw-r--r-- | facetracknoir/tracker.cpp | 31 | ||||
-rw-r--r-- | facetracknoir/tracker.h | 9 |
8 files changed, 165 insertions, 246 deletions
diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 06777f94..1ee20547 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -43,13 +43,13 @@ # define LIB_PREFIX "lib" #endif -static bool get_metadata(ptr<DynamicLibrary> lib, QString& longName, QIcon& icon) +static bool get_metadata(ptr<DynamicLibrary> lib, QString& name, QIcon& icon) { Metadata* meta; if (!lib->Metadata || ((meta = lib->Metadata()), !meta)) return false; - meta->getFullName(&longName); - meta->getIcon(&icon); + name = meta->name(); + icon = meta->icon(); delete meta; return true; } @@ -72,7 +72,7 @@ static void fill_combobox(const QString& filter, QList<ptr<DynamicLibrary>>& lis } } -FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : QMainWindow(parent), +FaceTrackNoIR::FaceTrackNoIR() : QMainWindow(nullptr), tracker(nullptr), #if defined(_WIN32) keybindingWorker(NULL), @@ -90,8 +90,6 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : QMainWindow(parent), shortcuts_widget(nullptr), mapping_widget(nullptr), kbd_quit(QKeySequence("Ctrl+Q"), this), - looping(0), - video_frame_layout(new QVBoxLayout()), no_feed_pixmap(":/uielements/no-feed.png") { ui.setupUi(this); @@ -124,7 +122,7 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : QMainWindow(parent), tie_setting(s.protocol_dll, ui.iconcomboProtocol); tie_setting(s.filter_dll, ui.iconcomboFilter); - connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); + connect(ui.btnstart_tracker, SIGNAL(clicked()), this, SLOT(startTracker())); connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); connect(ui.iconcomboProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(profileSelected(int))); @@ -143,12 +141,9 @@ FaceTrackNoIR::~FaceTrackNoIR() { stopTracker(); save(); - if (Libraries) - delete Libraries; - delete video_frame_layout; } -QFrame* FaceTrackNoIR::get_video_widget() { +QFrame* FaceTrackNoIR::video_frame() { return ui.video_frame; } @@ -200,7 +195,6 @@ void FaceTrackNoIR::save() { void FaceTrackNoIR::saveAs() { - looping++; QSettings settings("opentrack"); QString oldFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); @@ -225,7 +219,6 @@ void FaceTrackNoIR::saveAs() save(); } - looping--; fill_profile_cbx(); } @@ -242,12 +235,12 @@ void FaceTrackNoIR::updateButtonState(bool running, bool inertialp) { bool not_running = !running; ui.iconcomboProfile->setEnabled ( not_running ); - ui.btnStartTracker->setEnabled ( not_running ); + ui.btnstart_tracker->setEnabled ( not_running ); ui.btnStopTracker->setEnabled ( running ); ui.iconcomboProtocol->setEnabled ( not_running ); ui.iconcomboFilter->setEnabled ( not_running ); ui.iconcomboTrackerSource->setEnabled(not_running); - ui.btnStartTracker->setEnabled(not_running); + ui.btnstart_tracker->setEnabled(not_running); ui.btnStopTracker->setEnabled(running); ui.video_frame_label->setVisible(not_running || inertialp); } @@ -256,15 +249,18 @@ void FaceTrackNoIR::startTracker( ) { b->save(); loadSettings(); bindKeyboardShortcuts(); + + // Tracker dtor needs run first + tracker = nullptr; + + libs = SelectedLibraries(video_frame(), current_tracker(), current_protocol(), current_filter()); - if (Libraries) - delete Libraries; - Libraries = new SelectedLibraries(this); - - if (!Libraries->correct) + if (!libs.correct) { - QMessageBox::warning(this, "Something went wrong", "Tracking can't be initialized, probably protocol prerequisites missing", QMessageBox::Ok, QMessageBox::NoButton); - stopTracker(); + QMessageBox::warning(this, "Library load error", + "One of libraries failed to load. Check installation.", + QMessageBox::Ok, + QMessageBox::NoButton); return; } @@ -272,25 +268,11 @@ void FaceTrackNoIR::startTracker( ) { keybindingWorker = new KeybindingWorker(*this, keyCenter, keyToggle); keybindingWorker->start(); #endif - - if (tracker) { - delete tracker; - } - - tracker = new Tracker(s, pose); - - if (pTrackerDialog && Libraries->pTracker) { - pTrackerDialog->registerTracker( Libraries->pTracker ); - } - - if (pFilterDialog && Libraries->pFilter) - pFilterDialog->registerFilter(Libraries->pFilter); - - tracker->start(); - + ui.video_frame->show(); - timUpdateHeadPose.start(50); + tracker = std::make_shared<Tracker>(s, pose, libs); + tracker->start(); // NB check valid since SelectedLibraries ctor called // trackers take care of layout state updates @@ -311,32 +293,26 @@ void FaceTrackNoIR::stopTracker( ) { #endif timUpdateHeadPose.stop(); ui.pose_display->rotateBy(0, 0, 0); - - if (pTrackerDialog) { - pTrackerDialog->unRegisterTracker(); - delete pTrackerDialog; + + if (pTrackerDialog) + { + pTrackerDialog->unregister_tracker(); pTrackerDialog = nullptr; } - if (pProtocolDialog) { - pProtocolDialog->unRegisterProtocol(); - delete pProtocolDialog; + + if (pProtocolDialog) + { + pProtocolDialog->unregister_protocol(); pProtocolDialog = nullptr; } + if (pFilterDialog) { pFilterDialog->unregisterFilter(); - delete pFilterDialog; pFilterDialog = nullptr; } - - if ( tracker ) { - delete tracker; - tracker = 0; - if (Libraries) { - delete Libraries; - Libraries = NULL; - } - } + + tracker = nullptr; updateButtonState(false, false); } @@ -371,87 +347,52 @@ void FaceTrackNoIR::showHeadPose() ui.lcdNumOutputRotY->display(mapped[Pitch]); ui.lcdNumOutputRotZ->display(mapped[Roll]); - if (Libraries->pProtocol) + if (libs.pProtocol) { - const QString name = Libraries->pProtocol->getGameName(); + const QString name = libs.pProtocol->game_name(); ui.game_name->setText(name); } } void FaceTrackNoIR::showTrackerSettings() { - if (pTrackerDialog) { - delete pTrackerDialog; - pTrackerDialog = NULL; - } - ptr<DynamicLibrary> lib = dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), nullptr); if (lib) { - pTrackerDialog = (ITrackerDialog*) lib->Dialog(); - if (pTrackerDialog) { - auto foo = dynamic_cast<QWidget*>(pTrackerDialog); - foo->setFixedSize(foo->size()); - if (Libraries && Libraries->pTracker) - pTrackerDialog->registerTracker(Libraries->pTracker); - dynamic_cast<QWidget*>(pTrackerDialog)->show(); - } + pTrackerDialog = ptr<ITrackerDialog>(reinterpret_cast<ITrackerDialog*>(lib->Dialog())); + pTrackerDialog->setFixedSize(pTrackerDialog->size()); + pTrackerDialog->register_tracker(libs.pTracker.get()); + pTrackerDialog->show(); } } void FaceTrackNoIR::showServerControls() { - if (pProtocolDialog) { - delete pProtocolDialog; - pProtocolDialog = NULL; - } - ptr<DynamicLibrary> lib = dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), nullptr); - if (lib && lib->Dialog) { - pProtocolDialog = (IProtocolDialog*) lib->Dialog(); - if (pProtocolDialog) { - auto foo = dynamic_cast<QWidget*>(pProtocolDialog); - foo->setFixedSize(foo->size()); - dynamic_cast<QWidget*>(pProtocolDialog)->show(); - } + if (lib) { + pProtocolDialog = ptr<IProtocolDialog>(reinterpret_cast<IProtocolDialog*>(lib->Dialog())); + pProtocolDialog->setFixedSize(pProtocolDialog->size()); + pProtocolDialog->show(); } } void FaceTrackNoIR::showFilterControls() { - if (pFilterDialog) { - delete pFilterDialog; - pFilterDialog = NULL; - } - ptr<DynamicLibrary> lib = dlopen_filters.value(ui.iconcomboFilter->currentIndex(), nullptr); - if (lib && lib->Dialog) { - pFilterDialog = (IFilterDialog*) lib->Dialog(); - if (pFilterDialog) { - auto foo = dynamic_cast<QWidget*>(pFilterDialog); - foo->setFixedSize(foo->size()); - if (Libraries && Libraries->pFilter) - pFilterDialog->registerFilter(Libraries->pFilter); - dynamic_cast<QWidget*>(pFilterDialog)->show(); - } + if (lib) { + pFilterDialog = ptr<IFilterDialog>(reinterpret_cast<IFilterDialog*>(lib->Dialog())); + pFilterDialog->setFixedSize(pFilterDialog->size()); + pFilterDialog->registerFilter(libs.pFilter.get()); + pFilterDialog->show(); } } void FaceTrackNoIR::showKeyboardShortcuts() { - - if (!shortcuts_widget) - { - shortcuts_widget = new KeyboardShortcutDialog( this, this ); - } - + shortcuts_widget = std::make_shared<KeyboardShortcutDialog>( this, this ); shortcuts_widget->show(); shortcuts_widget->raise(); } void FaceTrackNoIR::showCurveConfiguration() { - if (mapping_widget) - delete mapping_widget; - - mapping_widget = new MapWidget(pose, s, this); - + mapping_widget = std::make_shared<MapWidget>(pose, s, this); mapping_widget->show(); mapping_widget->raise(); } @@ -464,9 +405,6 @@ extern "C" volatile const char* opentrack_version; void FaceTrackNoIR::fill_profile_cbx() { - if (looping) - return; - looping++; QSettings settings("opentrack"); QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); qDebug() << "Config file now" << currentFile; @@ -480,7 +418,6 @@ void FaceTrackNoIR::fill_profile_cbx() for ( int i = 0; i < iniFileList.size(); i++) ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); ui.iconcomboProfile->setCurrentText(pathInfo.fileName()); - looping--; } void FaceTrackNoIR::profileSelected(int index) diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h index b13f73f0..fd5ccebb 100644 --- a/facetracknoir/facetracknoir.h +++ b/facetracknoir/facetracknoir.h @@ -53,27 +53,27 @@ using namespace options; -class FaceTrackNoIR : public QMainWindow, IDynamicLibraryProvider +class FaceTrackNoIR : public QMainWindow { Q_OBJECT public: - FaceTrackNoIR(QWidget *parent = 0); + FaceTrackNoIR(); ~FaceTrackNoIR(); - QFrame *get_video_widget(); - Tracker *tracker; + QFrame *video_frame(); + ptr<Tracker> tracker; void bindKeyboardShortcuts(); // XXX this shit stinks -sh 20141004 // TODO move to separate class representing running tracker state - ptr<DynamicLibrary> current_tracker1() override { + ptr<DynamicLibrary> current_tracker() { return dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), nullptr); } - ptr<DynamicLibrary> current_protocol() override { + ptr<DynamicLibrary> current_protocol() { return dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), nullptr); } - ptr<DynamicLibrary> current_filter() override { + ptr<DynamicLibrary> current_filter() { return dlopen_filters.value(ui.iconcomboFilter->currentIndex(), nullptr); } @@ -96,13 +96,14 @@ private: Mappings pose; Ui::OpentrackUI ui; QTimer timUpdateHeadPose; + + SelectedLibraries libs; + ptr<ITrackerDialog> pTrackerDialog; + ptr<IProtocolDialog> pProtocolDialog; + ptr<IFilterDialog> pFilterDialog; - ITrackerDialog* pTrackerDialog; - IProtocolDialog* pProtocolDialog; - IFilterDialog* pFilterDialog; - - QWidget *shortcuts_widget; - MapWidget* mapping_widget; + ptr<QWidget> shortcuts_widget; + ptr<MapWidget> mapping_widget; void createIconGroupBox(); void loadSettings(); @@ -111,11 +112,10 @@ private: QList<ptr<DynamicLibrary>> dlopen_filters; QList<ptr<DynamicLibrary>> dlopen_trackers; QList<ptr<DynamicLibrary>> dlopen_protocols; + QShortcut kbd_quit; - int looping; - - QLayout* video_frame_layout; QPixmap no_feed_pixmap; + #ifndef _WIN32 void bind_keyboard_shortcut(QxtGlobalShortcut&, key_opts& k); #endif diff --git a/facetracknoir/plugin-qt-api.hpp b/facetracknoir/plugin-qt-api.hpp index 1697d8e7..c268e195 100644 --- a/facetracknoir/plugin-qt-api.hpp +++ b/facetracknoir/plugin-qt-api.hpp @@ -2,67 +2,68 @@ #include <QString> #include <QFrame> +#include <QIcon> struct Metadata { - Metadata() {} - virtual ~Metadata() {} - - virtual void getFullName(QString *strToBeFilled) = 0; - virtual void getShortName(QString *strToBeFilled) = 0; - virtual void getDescription(QString *strToBeFilled) = 0; - virtual void getIcon(QIcon *icon) = 0; +public: + virtual QString name() = 0; + virtual QIcon icon() = 0; + virtual ~Metadata() {}; }; // XXX TODO get rid of QString/QFrame to fix ABI woes // will lead plugins from different C++ runtimes working -sh 20141004 -// XXX TODO make virtual public the mess -sh 20141004 +// XXX TODO make public QWidget the mess -sh 20141004 struct IFilter { - virtual ~IFilter() = 0; - virtual void FilterHeadPoseData(const double *target_camera_position, double *new_camera_position) = 0; +public: + virtual ~IFilter() {}; + virtual void filter(const double *target_camera_position, double *new_camera_position) = 0; }; -inline IFilter::~IFilter() {} -struct IFilterDialog +struct IFilterDialog : public QWidget { - virtual ~IFilterDialog() = 0; + Q_OBJECT +public: + virtual ~IFilterDialog() {} virtual void registerFilter(IFilter* tracker) = 0; virtual void unregisterFilter() = 0; }; -inline IFilterDialog::~IFilterDialog() {} struct IProtocol { - virtual ~IProtocol() = 0; - virtual bool checkServerInstallationOK() = 0; - virtual void sendHeadposeToGame( const double* headpose ) = 0; - virtual QString getGameName() = 0; +public: + virtual ~IProtocol() {}; + virtual bool correct() = 0; + virtual void pose( const double* headpose ) = 0; + virtual QString game_name() = 0; }; -inline IProtocol::~IProtocol() {} -struct IProtocolDialog +struct IProtocolDialog : public QWidget { - virtual ~IProtocolDialog() = 0; - virtual void registerProtocol(IProtocol *protocol) = 0; - virtual void unRegisterProtocol() = 0; + Q_OBJECT +public: + virtual ~IProtocolDialog() {} + virtual void register_protocol(IProtocol *protocol) = 0; + virtual void unregister_protocol() = 0; }; -inline IProtocolDialog::~IProtocolDialog() {} struct ITracker { - virtual ~ITracker() = 0; - virtual void StartTracker( QFrame* frame ) = 0; - virtual void GetHeadPoseData(double *data) = 0; +public: + virtual ~ITracker() {}; + virtual void start_tracker( QFrame* frame ) = 0; + virtual void data(double *data) = 0; }; -inline ITracker::~ITracker() {} -struct ITrackerDialog +struct ITrackerDialog : public QWidget { - virtual ~ITrackerDialog() = 0; - virtual void registerTracker(ITracker *tracker) = 0; - virtual void unRegisterTracker() = 0; + Q_OBJECT +public: + virtual ~ITrackerDialog() {} + virtual void register_tracker(ITracker *tracker) = 0; + virtual void unregister_tracker() = 0; }; -inline ITrackerDialog::~ITrackerDialog() {} diff --git a/facetracknoir/plugin-support.cpp b/facetracknoir/plugin-support.cpp index 5b65df47..b202fc74 100644 --- a/facetracknoir/plugin-support.cpp +++ b/facetracknoir/plugin-support.cpp @@ -1,4 +1,5 @@ #include <cstdio> +#include <cinttypes> #include "plugin-support.h" #include <QCoreApplication> #include <QFile> @@ -7,57 +8,44 @@ # include <dlfcn.h> #endif -SelectedLibraries* Libraries = NULL; - SelectedLibraries::~SelectedLibraries() { - if (pTracker) { - delete pTracker; - pTracker = NULL; - } - - if (pFilter) - delete pFilter; +} - if (pProtocol) - delete pProtocol; +template<typename t> +static ptr<t> make_instance(ptr<DynamicLibrary> lib) +{ + ptr<t> ret = nullptr; + if (lib && lib->Constructor) + ret = ptr<t>(reinterpret_cast<t*>(reinterpret_cast<CTOR_FUNPTR>(lib->Constructor)())); + qDebug() << "lib" << (lib ? lib->filename : "<null>") << "ptr" << (intptr_t)ret.get(); + return ret; } -SelectedLibraries::SelectedLibraries(IDynamicLibraryProvider* mainApp) : - pTracker(NULL), pFilter(NULL), pProtocol(NULL) +SelectedLibraries::SelectedLibraries(QFrame* frame, dylib t, dylib p, dylib f) : + pTracker(nullptr), + pFilter(nullptr), + pProtocol(nullptr), + correct(false) { - correct = false; - if (!mainApp) + pTracker = make_instance<ITracker>(t); + pProtocol = make_instance<IProtocol>(p); + pFilter = make_instance<IFilter>(f); + + if (!pTracker|| !pProtocol) + { + qDebug() << "load failure tracker" << (intptr_t)pTracker.get() << "protocol" << (intptr_t)pProtocol.get(); return; - CTOR_FUNPTR p; - - ptr<DynamicLibrary> lib = mainApp->current_tracker1(); - - if (lib && lib->Constructor) { - p = (CTOR_FUNPTR) lib->Constructor; - pTracker = (ITracker*) p(); - } - - lib = mainApp->current_protocol(); - - if (lib && lib->Constructor) { - p = (CTOR_FUNPTR) lib->Constructor; - pProtocol = (IProtocol*) p(); - } - - lib = mainApp->current_filter(); - - if (lib && lib->Constructor) { - p = (CTOR_FUNPTR) lib->Constructor; - pFilter = (IFilter*) p(); } if (pProtocol) - if(!pProtocol->checkServerInstallationOK()) + if(!pProtocol->correct()) + { + qDebug() << "protocol load failure"; return; - if (pTracker) { - pTracker->StartTracker( mainApp->get_video_widget() ); - } + } + + pTracker->start_tracker(frame); correct = true; } @@ -88,7 +76,7 @@ DynamicLibrary::DynamicLibrary(const QString& filename) : if (_foo::die(handle, !handle->load())) return; - Dialog = (DIALOG_FUNPTR) handle->resolve("GetDialog"); + Dialog = (CTOR_FUNPTR) handle->resolve("GetDialog"); if (_foo::die(handle, !Dialog)) return; @@ -131,7 +119,7 @@ DynamicLibrary::DynamicLibrary(const QString& filename) : { if (_foo::err(handle)) return; - Dialog = (DIALOG_FUNPTR) dlsym(handle, "GetDialog"); + Dialog = (CTOR_FUNPTR) dlsym(handle, "GetDialog"); if (_foo::err(handle)) return; Constructor = (CTOR_FUNPTR) dlsym(handle, "GetConstructor"); diff --git a/facetracknoir/plugin-support.h b/facetracknoir/plugin-support.h index 7f8e3c28..83856922 100644 --- a/facetracknoir/plugin-support.h +++ b/facetracknoir/plugin-support.h @@ -11,31 +11,14 @@ #include <memory> template<typename t> using ptr = std::shared_ptr<t>; -class IDynamicLibraryProvider; - -struct SelectedLibraries { -public: - ITracker* pTracker; - IFilter* pFilter; - IProtocol* pProtocol; - SelectedLibraries(IDynamicLibraryProvider* main = NULL); - ~SelectedLibraries(); - bool correct; -}; - -extern SelectedLibraries* Libraries; - -struct Metadata; - extern "C" typedef void* (*CTOR_FUNPTR)(void); extern "C" typedef Metadata* (*METADATA_FUNPTR)(void); -extern "C" typedef void* (*DIALOG_FUNPTR)(void); class DynamicLibrary { public: DynamicLibrary(const QString& filename); ~DynamicLibrary(); - DIALOG_FUNPTR Dialog; + CTOR_FUNPTR Dialog; CTOR_FUNPTR Constructor; METADATA_FUNPTR Metadata; QString filename; @@ -47,12 +30,14 @@ private: #endif }; +struct SelectedLibraries { + using dylib = ptr<DynamicLibrary>; -// XXX TODO it can die if running tracker state separated into class -sh 20141004 -class IDynamicLibraryProvider { -public: - virtual ptr<DynamicLibrary> current_tracker1() = 0; - virtual ptr<DynamicLibrary> current_protocol() = 0; - virtual ptr<DynamicLibrary> current_filter() = 0; - virtual QFrame* get_video_widget() = 0; -}; + ptr<ITracker> pTracker; + ptr<IFilter> pFilter; + ptr<IProtocol> pProtocol; + SelectedLibraries(QFrame* frame, dylib t, dylib p, dylib f); + SelectedLibraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {} + ~SelectedLibraries(); + bool correct; +};
\ No newline at end of file diff --git a/facetracknoir/shortcuts.h b/facetracknoir/shortcuts.h index f8c34be7..8e665211 100644 --- a/facetracknoir/shortcuts.h +++ b/facetracknoir/shortcuts.h @@ -14,12 +14,10 @@ class KeyboardShortcutDialog: public QWidget { Q_OBJECT public: - KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent ); private: Ui::UICKeyboardShortcutDialog ui; FaceTrackNoIR *mainApp; - private slots: void doOK(); void doCancel(); diff --git a/facetracknoir/tracker.cpp b/facetracknoir/tracker.cpp index c7867d2d..41db7c19 100644 --- a/facetracknoir/tracker.cpp +++ b/facetracknoir/tracker.cpp @@ -12,8 +12,9 @@ * originally written by Wim Vriend. */ -#include "./tracker.h" #include <opencv2/core/core.hpp> + +#include "./tracker.h" #include <cmath> #include <algorithm> @@ -21,12 +22,13 @@ # include <windows.h> #endif -Tracker::Tracker(main_settings& s, Mappings &m) : +Tracker::Tracker(main_settings& s, Mappings &m, SelectedLibraries &libs) : s(s), m(m), centerp(false), enabledp(true), - should_quit(false) + should_quit(false), + libs(libs) { } @@ -45,12 +47,12 @@ double Tracker::map(double pos, Mapping& axis) { return invert * (fc.getValue(pos) + axis.opts.zero); } -void Tracker::t_compensate(const double* input, double* output, bool rz) +static cv::Matx33d euler_to_rmat(const double* input) { static constexpr double pi = 3.141592653; - const auto H = input[Yaw] * pi / -180; - const auto P = input[Pitch] * pi / -180; - const auto B = input[Roll] * pi / 180; + const auto H = input[0] * pi / -180; + const auto P = input[1] * pi / -180; + const auto B = input[2] * pi / 180; const auto cosH = cos(H); const auto sinH = sin(H); @@ -71,7 +73,12 @@ void Tracker::t_compensate(const double* input, double* output, bool rz) cosH * cosP, }; - const cv::Matx33d rmat(foo); + return cv::Matx33d(foo); +} + +void Tracker::t_compensate(const double* input, double* output, bool rz) +{ + const cv::Matx33d rmat = euler_to_rmat(&input[Yaw]); const cv::Vec3d tvec(input); const cv::Vec3d ret = rmat * tvec; @@ -83,7 +90,7 @@ void Tracker::t_compensate(const double* input, double* output, bool rz) void Tracker::logic() { - Libraries->pTracker->GetHeadPoseData(newpose); + libs.pTracker->data(newpose); Pose final_raw; @@ -106,8 +113,8 @@ void Tracker::logic() Pose filtered_pose; - if (Libraries->pFilter) - Libraries->pFilter->FilterHeadPoseData(final_raw, filtered_pose); + if (libs.pFilter) + libs.pFilter->filter(final_raw, filtered_pose); else filtered_pose = final_raw; @@ -130,7 +137,7 @@ void Tracker::logic() if (s.tcomp_p) t_compensate(mapped_pose_precomp, mapped_pose, s.tcomp_tz); - Libraries->pProtocol->sendHeadposeToGame(mapped_pose); + libs.pProtocol->pose(mapped_pose); { QMutexLocker foo(&mtx); diff --git a/facetracknoir/tracker.h b/facetracknoir/tracker.h index afb86802..75f54084 100644 --- a/facetracknoir/tracker.h +++ b/facetracknoir/tracker.h @@ -15,27 +15,30 @@ #include <QMutex> #include <QThread> -class Tracker : protected QThread { +class Tracker : private QThread { Q_OBJECT private: QMutex mtx; main_settings& s; // XXX can be const-cast when functionconfig const-correct -sh 20141004 Mappings& m; + Timer t; Pose output_pose, raw_6dof, raw_center, unstopped_raw; double newpose[6]; std::atomic<bool> centerp; std::atomic<bool> enabledp; std::atomic<bool> should_quit; - + SelectedLibraries const& libs; + double map(double pos, Mapping& axis); void logic(); + static void t_compensate(const double* input, double* output, bool rz); protected: void run() override; public: - Tracker(main_settings& s, Mappings& m); + Tracker(main_settings& s, Mappings& m, SelectedLibraries& libs); ~Tracker(); void get_raw_and_mapped_poses(double* mapped, double* raw) const; |