diff options
51 files changed, 487 insertions, 481 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 17179cb3..fd5ed7b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,14 +112,14 @@ macro(opentrack_library n dir) set(link-mode STATIC) endif() add_library(${n} ${link-mode} ${${n}-all}) - target_link_libraries(${n} opentrack-api ${MY_QT_LIBS}) + target_link_libraries(${n} opentrack-api ${MY_QT_LIBS} opentrack-compat) if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) set(visibility "-fvisibility=hidden -fvisibility-inlines-hidden") if (foolib_STATIC) set(visibility) endif() SET_TARGET_PROPERTIES(${n} PROPERTIES - LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack/${version-script}-version-script.txt\"" + LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack-compat/${version-script}-version-script.txt\"" COMPILE_FLAGS "${foolib_COMPILE} ${foolib_GNU-COMPILE} -fvisibility=hidden -fvisibility-inlines-hidden" ) else() @@ -129,7 +129,7 @@ macro(opentrack_library n dir) endif() set_target_properties(${n} PROPERTIES LINK_FLAGS "${link-flags} ${foolib_LINK}" COMPILE_FLAGS "${foolib_COMPILE}") endif() - if (NOT foolib_STATIC) + if(NOT foolib_STATIC) install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) endif() endmacro() @@ -200,13 +200,19 @@ opentrack_qt(opentrack-api) add_library(opentrack-api STATIC ${opentrack-api-all}) opentrack_compat(opentrack-api) target_link_libraries(opentrack-api ${MY_QT_LIBS}) - if(NOT WIN32) target_link_libraries(opentrack-api dl) else() target_link_libraries(opentrack-api winmm) endif() +opentrack_module(opentrack-compat opentrack-compat) +add_library(opentrack-compat STATIC ${opentrack-compat-c}) +opentrack_compat(opentrack-compat) # uh... +if(NOT WIN32 AND NOT APPLE) + target_link_libraries(opentrack-compat rt) +endif() + # ---- # conditional targets @@ -223,7 +229,6 @@ if(WIN32) ENABLE_LANGUAGE(RC) endif(WIN32) -opentrack_module(opentrack-compat compat) opentrack_module(opentrack-xplane-plugin x-plane-plugin) if(SDK_XPLANE) @@ -250,12 +255,6 @@ if(SDK_XPLANE) endif() endif() -add_library(opentrack-compat STATIC ${opentrack-compat-c}) -opentrack_compat(opentrack-compat) # uh... -if(NOT WIN32 AND NOT APPLE) - target_link_libraries(opentrack-compat rt) -endif() - opentrack_module(opentrack-csv csv) add_library(opentrack-csv STATIC ${opentrack-csv-c}) opentrack_compat(opentrack-csv) diff --git a/facetracknoir/facetracknoir.rc b/facetracknoir/facetracknoir.rc index 655baa9d..020ffe97 100644 --- a/facetracknoir/facetracknoir.rc +++ b/facetracknoir/facetracknoir.rc @@ -1,2 +1,2 @@ -#include <windows.h>
-IDI_ICON1 ICON "facetracknoir.ico"
+#include <windows.h> +IDI_ICON1 ICON "facetracknoir.ico" diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h new file mode 100644 index 00000000..a7673f8f --- /dev/null +++ b/facetracknoir/keyboard.h @@ -0,0 +1,37 @@ +#pragma once +#include "ui_keyboard_listener.h" +#include <QLabel> +#include <QKeyEvent> +#include <QDebug> + +class KeyboardListener : public QLabel +{ + Q_OBJECT + Ui_keyboard_listener ui; +public: + KeyboardListener(QWidget* parent = nullptr) : QLabel(parent) + { + ui.setupUi(this); + setFocusPolicy(Qt::StrongFocus); + } + void keyPressEvent(QKeyEvent* event) override + { + //qDebug() << "k" << (event->key() | event->modifiers()); + switch (event->key() | event->modifiers()) + { + case 83886113: // ctrl + case 50331680: // shift + case 150994979: // alt + case 218103841: // ctrl+alt + case 117440545: // ctrl+shift + case 184549408: // alt+shift + case 251658272: // ctrl+alt+shift + break; + default: + emit key_pressed(QKeySequence(event->key() | event->modifiers())); + break; + } + } +signals: + void key_pressed(QKeySequence k); +}; diff --git a/facetracknoir/keyboard_listener.ui b/facetracknoir/keyboard_listener.ui new file mode 100644 index 00000000..b6977df0 --- /dev/null +++ b/facetracknoir/keyboard_listener.ui @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>keyboard_listener</class> + <widget class="QLabel" name="keyboard_listener"> + <property name="windowModality"> + <enum>Qt::ApplicationModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>224</width> + <height>33</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>Bind a shortcut</string> + </property> + <property name="text"> + <string><html><head/><body><p>Press a key or close this window to remove the keybinding.</p></body></html></string> + </property> + <property name="textFormat"> + <enum>Qt::RichText</enum> + </property> + <property name="margin"> + <number>10</number> + </property> + </widget> + <resources/> + <connections/> +</ui> diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index f77c7cc1..207c1afb 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -8,6 +8,9 @@ #include "options-dialog.hpp" #include "ftnoir_tracker_pt/camera.h" +#include "keyboard.h" +#include <QPushButton> +#include <QLayout> OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(false) { @@ -16,27 +19,6 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - for ( int i = 0; i < global_key_sequences.size(); i++) { - ui.cbxCenterKey->addItem(global_key_sequences.at(i)); - ui.cbxToggleKey->addItem(global_key_sequences.at(i)); - ui.cbxZeroKey->addItem(global_key_sequences.at(i)); - } - - tie_setting(s.center.key_index, ui.cbxCenterKey); - tie_setting(s.center.alt, ui.chkCenterAlt); - tie_setting(s.center.shift, ui.chkCenterShift); - tie_setting(s.center.ctrl, ui.chkCenterCtrl); - - tie_setting(s.toggle.key_index, ui.cbxToggleKey); - tie_setting(s.toggle.alt, ui.chkToggleAlt); - tie_setting(s.toggle.shift, ui.chkToggleShift); - tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); - - tie_setting(s.zero.key_index, ui.cbxZeroKey); - tie_setting(s.zero.alt, ui.chkZeroAlt); - tie_setting(s.zero.shift, ui.chkZeroShift); - tie_setting(s.zero.ctrl, ui.chkZeroCtrl); - tie_setting(s.s_main.tray_enabled, ui.trayp); tie_setting(s.s_main.center_at_startup, ui.center_at_startup); @@ -102,6 +84,32 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); timer.start(100); + + connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(s.center.keycode, ui.center_text); }); + connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); }); + connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); }); + + ui.center_text->setText(s.center.keycode == "" ? "None" : static_cast<QString>(s.center.keycode)); + ui.toggle_text->setText(s.toggle.keycode == "" ? "None" : static_cast<QString>(s.toggle.keycode)); + ui.zero_text->setText(s.zero.keycode == "" ? "None" : static_cast<QString>(s.zero.keycode)); +} + +void OptionsDialog::bind_key(value<QString>& ret, QLabel* label) +{ + ret = ""; + QDialog d; + auto l = new QHBoxLayout; + l->setMargin(0); + auto k = new KeyboardListener; + l->addWidget(k); + d.setLayout(l); + d.setFixedSize(QSize(500, 300)); + d.setWindowFlags(Qt::Dialog); + connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); }); + d.exec(); + label->setText(ret == "" ? "None" : static_cast<QString>(ret)); + delete k; + delete l; } void OptionsDialog::doOK() { diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp index a2dec093..af3e185c 100644 --- a/facetracknoir/options-dialog.hpp +++ b/facetracknoir/options-dialog.hpp @@ -25,8 +25,8 @@ private: settings_accela acc; QTimer timer; State& state; - TranslationCalibrator trans_calib; - bool trans_calib_running; + TranslationCalibrator trans_calib; + bool trans_calib_running; Tracker_PT* get_pt(); private slots: @@ -41,4 +41,5 @@ private slots: void startstop_trans_calib(bool start); void poll_tracker_info(); void trans_calib_step(); + void bind_key(value<QString>& ret, QLabel* label); }; diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui index 523829f6..4341d10d 100644 --- a/facetracknoir/settings.ui +++ b/facetracknoir/settings.ui @@ -62,82 +62,48 @@ <string notr="true">QGroupBox { border: 0; }</string> </property> <layout class="QGridLayout" name="gridLayout_8"> - <item row="3" column="0"> - <widget class="QLabel" name="textLabel2_5"> + <item row="0" column="1"> + <widget class="QLabel" name="center_text"> <property name="text"> - <string>Toggle</string> - </property> - <property name="wordWrap"> - <bool>false</bool> + <string/> </property> </widget> </item> - <item row="2" column="1"> - <widget class="QCheckBox" name="chkCenterShift"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> + <item row="0" column="0"> + <widget class="QLabel" name="textLabel2_3"> <property name="text"> - <string>Shift</string> + <string>Center</string> + </property> + <property name="wordWrap"> + <bool>false</bool> </property> </widget> </item> - <item row="2" column="2"> - <widget class="QCheckBox" name="chkCenterCtrl"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> + <item row="6" column="1"> + <widget class="QLabel" name="zero_text"> <property name="text"> - <string>Ctrl</string> + <string/> </property> </widget> </item> - <item row="2" column="4"> - <widget class="QComboBox" name="cbxCenterKey"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Select Number</string> - </property> - <property name="insertPolicy"> - <enum>QComboBox::InsertAlphabetically</enum> + <item row="5" column="1"> + <widget class="QLabel" name="toggle_text"> + <property name="text"> + <string/> </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="textLabel2_3"> + <item row="5" column="0"> + <widget class="QLabel" name="textLabel2_5"> <property name="text"> - <string>Center</string> + <string>Toggle</string> </property> <property name="wordWrap"> <bool>false</bool> </property> </widget> </item> - <item row="2" column="3"> - <widget class="QCheckBox" name="chkCenterAlt"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Alt</string> - </property> - </widget> - </item> - <item row="4" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="textLabel2_6"> <property name="text"> <string>Zero</string> @@ -147,113 +113,24 @@ </property> </widget> </item> - <item row="4" column="3"> - <widget class="QCheckBox" name="chkZeroAlt"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Alt</string> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QCheckBox" name="chkToggleCtrl"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Ctrl</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QCheckBox" name="chkToggleAlt"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Alt</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="QCheckBox" name="chkZeroCtrl"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> + <item row="0" column="2"> + <widget class="QPushButton" name="bind_center"> <property name="text"> - <string>Ctrl</string> + <string>Bind</string> </property> </widget> </item> - <item row="4" column="1"> - <widget class="QCheckBox" name="chkZeroShift"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> + <item row="5" column="2"> + <widget class="QPushButton" name="bind_toggle"> <property name="text"> - <string>Shift</string> + <string>Bind</string> </property> </widget> </item> - <item row="4" column="4"> - <widget class="QComboBox" name="cbxZeroKey"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Select Number</string> - </property> - <property name="insertPolicy"> - <enum>QComboBox::InsertAlphabetically</enum> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QCheckBox" name="chkToggleShift"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> + <item row="6" column="2"> + <widget class="QPushButton" name="bind_zero"> <property name="text"> - <string>Shift</string> - </property> - </widget> - </item> - <item row="3" column="4"> - <widget class="QComboBox" name="cbxToggleKey"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Select Number</string> - </property> - <property name="insertPolicy"> - <enum>QComboBox::InsertAlphabetically</enum> + <string>Bind</string> </property> </widget> </item> @@ -1665,21 +1542,9 @@ </customwidget> </customwidgets> <tabstops> - <tabstop>chkCenterShift</tabstop> <tabstop>tabWidget</tabstop> - <tabstop>chkCenterAlt</tabstop> - <tabstop>cbxCenterKey</tabstop> - <tabstop>chkToggleShift</tabstop> - <tabstop>chkToggleCtrl</tabstop> - <tabstop>chkToggleAlt</tabstop> - <tabstop>cbxToggleKey</tabstop> - <tabstop>chkZeroShift</tabstop> - <tabstop>chkZeroCtrl</tabstop> - <tabstop>chkZeroAlt</tabstop> - <tabstop>cbxZeroKey</tabstop> <tabstop>center_at_startup</tabstop> <tabstop>trayp</tabstop> - <tabstop>chkCenterCtrl</tabstop> <tabstop>camera_yaw</tabstop> <tabstop>camera_pitch</tabstop> <tabstop>camera_roll</tabstop> diff --git a/facetracknoir/trans_calib.cpp b/facetracknoir/trans_calib.cpp index 2994eb48..a1a4b641 100644 --- a/facetracknoir/trans_calib.cpp +++ b/facetracknoir/trans_calib.cpp @@ -7,9 +7,6 @@ #include "trans_calib.h" -using namespace cv; - -//----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { reset(); @@ -17,13 +14,13 @@ TranslationCalibrator::TranslationCalibrator() void TranslationCalibrator::reset() { - P = Matx66f::zeros(); - y = Vec6f(0,0,0, 0,0,0); + P = cv::Matx66f::zeros(); + y = cv::Vec6f(0,0,0, 0,0,0); } -void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) +void TranslationCalibrator::update(const cv::Matx33f& R_CM_k, const cv::Vec3f& t_CM_k) { - Matx<float, 6,3> H_k_T = Matx<float, 6,3>::zeros(); + cv::Matx<float, 6,3> H_k_T = cv::Matx<float, 6,3>::zeros(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { H_k_T(i,j) = R_CM_k(j,i); @@ -37,8 +34,8 @@ void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) y += H_k_T * t_CM_k; } -Vec3f TranslationCalibrator::get_estimate() +cv::Vec3f TranslationCalibrator::get_estimate() { - Vec6f x = P.inv() * y; - return Vec3f(-x[0], -x[1], -x[2]); + cv::Vec6f x = P.inv() * y; + return cv::Vec3f(-x[0], -x[1], -x[2]); } diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 1529169b..360ca7f3 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -13,7 +13,7 @@ #include "opentrack/options.hpp" using namespace options; -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" struct settings_accela : opts { value<int> rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; diff --git a/ftnoir_protocol_ft/ftnoir_protocol_ft.h b/ftnoir_protocol_ft/ftnoir_protocol_ft.h index f80a511b..6010de90 100644 --- a/ftnoir_protocol_ft/ftnoir_protocol_ft.h +++ b/ftnoir_protocol_ft/ftnoir_protocol_ft.h @@ -44,7 +44,7 @@ #include <QString> #include <QMutex> #include <QMutexLocker> -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "opentrack/options.hpp" #include "freetrackclient/fttypes.h" using namespace options; diff --git a/ftnoir_protocol_sc/scserver.manifest b/ftnoir_protocol_sc/scserver.manifest index 60311d6e..d342cfda 100644 --- a/ftnoir_protocol_sc/scserver.manifest +++ b/ftnoir_protocol_sc/scserver.manifest @@ -1,13 +1,13 @@ -<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
-<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect' version='10.0.61259.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' />
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
- </dependentAssembly>
- </dependency>
-</assembly>
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?> +<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect' version='10.0.61259.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' /> + </dependentAssembly> + </dependency> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> + </dependentAssembly> + </dependency> +</assembly> diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine.h b/ftnoir_protocol_wine/ftnoir_protocol_wine.h index 528c4dd3..72897f1f 100644 --- a/ftnoir_protocol_wine/ftnoir_protocol_wine.h +++ b/ftnoir_protocol_wine/ftnoir_protocol_wine.h @@ -9,7 +9,7 @@ #include <QMutexLocker> #include <QFile> #include "opentrack/plugin-api.hpp" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "ftnoir_protocol_wine/wine-shm.h" class FTNoIR_Protocol : public IProtocol diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx index 026135f0..ffe8938d 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx @@ -6,13 +6,13 @@ #include <cstdio> #include "freetrackclient/fttypes.h" #include "ftnoir_protocol_wine/wine-shm.h" -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" enum Axis { TX = 0, TY, TZ, Yaw, Pitch, Roll }; -#include "compat/compat.h" +#include "opentrack-compat/shm.h" void create_registry_key(void); diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx index 6f43f899..50cce728 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx @@ -3,5 +3,5 @@ #endif #define PortableLockedShm ShmPosix -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx index 6592fbe6..19ee8ffd 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx @@ -3,8 +3,8 @@ #endif #define PortableLockedShm ShmWine -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" #include "wine-shm.h" static void write_path(const char* key, const char* subkey) diff --git a/ftnoir_tracker_aruco/ar_video_widget.cpp b/ftnoir_tracker_aruco/ar_video_widget.cpp index 70c26e55..1c3af262 100644 --- a/ftnoir_tracker_aruco/ar_video_widget.cpp +++ b/ftnoir_tracker_aruco/ar_video_widget.cpp @@ -7,8 +7,6 @@ #include "ar_video_widget.h" -using namespace std; - void ArucoVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 05f3e3a4..08ddd3b2 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -17,7 +17,7 @@ #include <opencv2/highgui/highgui.hpp> #include <opencv2/videoio.hpp> #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_aruco/include/board.h b/ftnoir_tracker_aruco/include/board.h index c1d79292..ec7dd43f 100644 --- a/ftnoir_tracker_aruco/include/board.h +++ b/ftnoir_tracker_aruco/include/board.h @@ -32,8 +32,8 @@ or implied, of Rafael Muñoz Salinas. #include <vector> #include "exports.h" #include "marker.h" -using namespace std; namespace aruco { +using namespace std; /** * 3d representation of a marker */ diff --git a/ftnoir_tracker_aruco/include/boarddetector.h b/ftnoir_tracker_aruco/include/boarddetector.h index a0ee2361..619b4798 100644 --- a/ftnoir_tracker_aruco/include/boarddetector.h +++ b/ftnoir_tracker_aruco/include/boarddetector.h @@ -32,11 +32,10 @@ or implied, of Rafael Muñoz Salinas. #include "board.h" #include "cameraparameters.h" #include "markerdetector.h" -using namespace std; namespace aruco { - +using namespace std; /**\brief This class detects AR boards * Version 1.2 * There are two modes for board detection. diff --git a/ftnoir_tracker_aruco/include/cameraparameters.h b/ftnoir_tracker_aruco/include/cameraparameters.h index a419afbe..083d5f96 100644 --- a/ftnoir_tracker_aruco/include/cameraparameters.h +++ b/ftnoir_tracker_aruco/include/cameraparameters.h @@ -30,9 +30,10 @@ or implied, of Rafael Muñoz Salinas. #include "exports.h" #include <opencv2/core/core.hpp> #include <string> -using namespace std; + namespace aruco { +using namespace std; /**\brief Parameters of the camera */ diff --git a/ftnoir_tracker_aruco/include/marker.h b/ftnoir_tracker_aruco/include/marker.h index 89961002..efc3e5fe 100644 --- a/ftnoir_tracker_aruco/include/marker.h +++ b/ftnoir_tracker_aruco/include/marker.h @@ -32,8 +32,8 @@ or implied, of Rafael Muñoz Salinas. #include <opencv2/core/core.hpp> #include "exports.h" #include "cameraparameters.h" -using namespace std; namespace aruco { +using namespace std; /**\brief This class represents a marker. It is a vector of the fours corners ot the marker * */ diff --git a/ftnoir_tracker_aruco/include/markerdetector.h b/ftnoir_tracker_aruco/include/markerdetector.h index 8a351f7c..ac120b18 100644 --- a/ftnoir_tracker_aruco/include/markerdetector.h +++ b/ftnoir_tracker_aruco/include/markerdetector.h @@ -33,11 +33,10 @@ or implied, of Rafael Muñoz Salinas. #include "cameraparameters.h" #include "exports.h" #include "marker.h" -using namespace std; namespace aruco { - +using namespace std; /**\brief Main class for marker detection * */ diff --git a/ftnoir_tracker_aruco/trans_calib.cpp b/ftnoir_tracker_aruco/trans_calib.cpp index a562763a..176cf24c 100644 --- a/ftnoir_tracker_aruco/trans_calib.cpp +++ b/ftnoir_tracker_aruco/trans_calib.cpp @@ -7,8 +7,6 @@ #include "trans_calib.h" -using namespace cv; - //----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { @@ -17,13 +15,13 @@ TranslationCalibrator::TranslationCalibrator() void TranslationCalibrator::reset() { - P = Matx66f::zeros(); - y = Vec6f(0,0,0, 0,0,0); + P = cv::Matx66f::zeros(); + y = cv::Vec6f(0,0,0, 0,0,0); } -void TranslationCalibrator::update(const Matx33d& R_CM_k, const Vec3d& t_CM_k) +void TranslationCalibrator::update(const cv::Matx33d& R_CM_k, const cv::Vec3d& t_CM_k) { - Matx<double, 6,3> H_k_T = Matx<double, 6,3>::zeros(); + cv::Matx<double, 6,3> H_k_T = cv::Matx<double, 6,3>::zeros(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { H_k_T(i,j) = R_CM_k(j,i); @@ -37,8 +35,8 @@ void TranslationCalibrator::update(const Matx33d& R_CM_k, const Vec3d& t_CM_k) y += H_k_T * t_CM_k; } -Vec3f TranslationCalibrator::get_estimate() +cv::Vec3f TranslationCalibrator::get_estimate() { - Vec6f x = P.inv() * y; - return Vec3f(x[0], x[1], x[2]); + cv::Vec6f x = P.inv() * y; + return cv::Vec3f(x[0], x[1], x[2]); } diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index ad13d716..cc9d2ba1 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -4,7 +4,7 @@ #include "opentrack/plugin-api.hpp" #include <cmath> #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index 32fb6949..16fdbe5c 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -10,7 +10,7 @@ #include "headtracker-ftnoir.h" #include "ui_ht-trackercontrols.h" #include "ht_video_widget.h" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include <QObject> #include "opentrack/options.hpp" #include "opentrack/plugin-api.hpp" diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp index ef58c98f..02fe71d1 100644 --- a/ftnoir_tracker_ht/ht_video_widget.cpp +++ b/ftnoir_tracker_ht/ht_video_widget.cpp @@ -7,8 +7,6 @@ #include "ht_video_widget.h" -using namespace std; - void HTVideoWidget::update_image(unsigned char *frame, int width, int height) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 2989c1fe..9e11b815 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -8,9 +8,7 @@ #include "camera.h" #include <string> #include <QDebug> -#include "opentrack/sleep.hpp" - -using namespace cv; +#include "opentrack-compat/sleep.hpp" void Camera::set_device_index(int index) { @@ -74,7 +72,7 @@ void CVCamera::start() { if (cap) delete cap; - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); _set_res(); _set_fps(); // extract camera info @@ -103,11 +101,11 @@ void CVCamera::stop() active = false; } -bool CVCamera::_get_frame(Mat* frame) +bool CVCamera::_get_frame(cv::Mat* frame) { if (cap && cap->isOpened()) { - Mat img; + cv::Mat img; for (int i = 0; i < 100 && !cap->read(img); i++) ;; @@ -142,5 +140,5 @@ void CVCamera::_set_device_index() cap->release(); delete cap; } - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); } diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 8c478824..07600646 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -13,9 +13,6 @@ #include <QCoreApplication> #include "opentrack/camera-names.hpp" -using namespace std; -using namespace cv; - //#define PT_PERF_LOG //log performance //----------------------------------------------------------------------------- @@ -114,7 +111,7 @@ void Tracker_PT::run() { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below + Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below Affine X_GH = X_CM * X_MH; cv::Vec3f p = X_GH.t; // head (center?) position in global space float fx = get_focal_length(); @@ -210,17 +207,17 @@ void Tracker_PT::data(double *data) { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); + Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); Affine X_GH = X_CM * X_MH; - Matx33f R = X_GH.R; - Vec3f t = X_GH.t; + cv::Matx33f R = X_GH.R; + cv::Vec3f t = X_GH.t; // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame // -z -> x, y -> z, x -> -y - Matx33f R_EG(0, 0,-1, - -1, 0, 0, - 0, 1, 0); + cv::Matx33f R_EG(0, 0,-1, + -1, 0, 0, + 0, 1, 0); R = R_EG * R * R_EG.t(); // extract rotation angles diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index b303a913..3291c7fc 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -14,7 +14,7 @@ #include "point_extractor.h" #include "point_tracker.h" #include "pt_video_widget.h" -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "opentrack/opencv-camera-dialog.hpp" #include <QThread> diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index e81e3aa0..7174d719 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -9,13 +9,9 @@ #include <QDebug> #ifdef DEBUG_EXTRACTION -# include "opentrack/timer.hpp" +# include "opentrack-compat/timer.hpp" #endif -using namespace cv; -using namespace std; - - PointExtractor::PointExtractor(){ //if (!AllocConsole()){} //else SetConsoleTitle("debug"); @@ -23,20 +19,20 @@ PointExtractor::PointExtractor(){ //freopen("CON", "w", stderr); } // ---------------------------------------------------------------------------- -std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) +std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) { - const int W = frame.cols; - const int H = frame.rows; + const int W = frame.cols; + const int H = frame.rows; + + // convert to grayscale + cv::Mat frame_gray; + cv::cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - // convert to grayscale - Mat frame_gray; - cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - int min_size = s.min_point_size; int max_size = s.max_point_size; - unsigned int region_size_min = 3.14*min_size*min_size/4.0; - unsigned int region_size_max = 3.14*max_size*max_size/4.0; + unsigned int region_size_min = 3.14*min_size*min_size/4.0; + unsigned int region_size_max = 3.14*max_size*max_size/4.0; // testing indicates threshold difference of 45 from lowest to highest // that's applicable to poor lighting conditions. @@ -144,7 +140,7 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) }; // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) - Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); + cv::Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); const int min = std::max(0, thres - diff/2); const int max = std::min(255, thres + diff/2); @@ -155,8 +151,8 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) // this code is based on OpenCV SimpleBlobDetector for (int i = min; i < max; i += step) { - Mat frame_bin_; - threshold(frame_gray, frame_bin_, i, 255, THRESH_BINARY); + cv::Mat frame_bin_; + cv::threshold(frame_gray, frame_bin_, i, 255, cv::THRESH_BINARY); frame_bin.setTo(170, frame_bin_); std::vector<std::vector<cv::Point>> contours; @@ -211,19 +207,19 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) for (auto& b : simple_blob::merge(blobs)) { auto pos = b.effective_pos(); - Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); + cv::Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); points.push_back(p); } - vector<Mat> channels_; + std::vector<cv::Mat> channels_; cv::split(frame, channels_); // draw output image - Mat frame_bin_ = frame_bin * .5; - vector<Mat> channels; + cv::Mat frame_bin_ = frame_bin * .5; + std::vector<cv::Mat> channels; channels.push_back(channels_[0] + frame_bin_); channels.push_back(channels_[1] - frame_bin_); channels.push_back(channels_[2] - frame_bin_); - merge(channels, frame); + cv::merge(channels, frame); - return points; + return points; } diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index b4283d37..cedf1979 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -13,46 +13,43 @@ #include <QDebug> -using namespace cv; -using namespace std; - const float PI = 3.14159265358979323846f; // ---------------------------------------------------------------------------- -static void get_row(const Matx33f& m, int i, Vec3f& v) +static void get_row(const cv::Matx33f& m, int i, cv::Vec3f& v) { v[0] = m(i,0); v[1] = m(i,1); v[2] = m(i,2); } -static void set_row(Matx33f& m, int i, const Vec3f& v) +static void set_row(cv::Matx33f& m, int i, const cv::Vec3f& v) { m(i,0) = v[0]; m(i,1) = v[1]; m(i,2) = v[2]; } -static bool d_vals_sort(const pair<float,int> a, const pair<float,int> b) +static bool d_vals_sort(const std::pair<float,int> a, const std::pair<float,int> b) { return a.first < b.first; } void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[], cv::Vec2f d) const { - // fit line to orthographically projected points - vector< pair<float,int> > d_vals; + // fit line to orthographically projected points + std::vector<std::pair<float,int>> d_vals; // get sort indices with respect to d scalar product - for (unsigned i = 0; i<points.size(); ++i) - d_vals.push_back(pair<float, int>(d.dot(points[i]), i)); + for (unsigned i = 0; i<points.size(); ++i) + d_vals.push_back(std::pair<float, int>(d.dot(points[i]), i)); std::sort(d_vals.begin(), d_vals.end(), d_vals_sort ); - for (unsigned i = 0; i<points.size(); ++i) - d_order[i] = d_vals[i].second; + for (unsigned i = 0; i<points.size(); ++i) + d_order[i] = d_vals[i].second; } @@ -60,10 +57,10 @@ PointTracker::PointTracker() : init_phase(true) { } -PointTracker::PointOrder PointTracker::find_correspondences_previous(const vector<Vec2f>& points, const PointModel& model, float f) +PointTracker::PointOrder PointTracker::find_correspondences_previous(const std::vector<cv::Vec2f>& points, const PointModel& model, float f) { PointTracker::PointOrder p; - p.points[0] = project(Vec3f(0,0,0), f); + p.points[0] = project(cv::Vec3f(0,0,0), f); p.points[1] = project(model.M01, f); p.points[2] = project(model.M02, f); @@ -79,7 +76,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto // find closest point to projected model point i for (int j=0; j<PointModel::N_POINTS; ++j) { - Vec2f d = p.points[i]-points[j]; + cv::Vec2f d = p.points[i]-points[j]; float sdist = d.dot(d); if (sdist < min_sdist || j==0) { @@ -99,7 +96,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto return p; } -void PointTracker::track(const vector<Vec2f>& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) +void PointTracker::track(const std::vector<cv::Vec2f>& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) { PointOrder order; @@ -129,9 +126,9 @@ PointTracker::PointOrder PointTracker::find_correspondences(const std::vector<cv model.get_d_order(points, point_d_order, d); // calculate d and d_order for simple freetrack-like point correspondence model.get_d_order(std::vector<cv::Vec2f> { - Vec2f{0,0}, - Vec2f(model.M01[0], model.M01[1]), - Vec2f(model.M02[0], model.M02[1]) + cv::Vec2f{0,0}, + cv::Vec2f(model.M01[0], model.M01[1]), + cv::Vec2f(model.M02[0], model.M02[1]) }, model_d_order, d); @@ -151,10 +148,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // The expected rotation used for resolving the ambiguity in POSIT: // In every iteration step the rotation closer to R_expected is taken - Matx33f R_expected = Matx33f::eye(); + cv::Matx33f R_expected = cv::Matx33f::eye(); // initial pose = last (predicted) pose - Vec3f k; + cv::Vec3f k; get_row(R_expected, 2, k); float Z0 = 1000.f; @@ -163,17 +160,17 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float epsilon_1 = 1; float epsilon_2 = 1; - Vec3f I0, J0; - Vec2f I0_coeff, J0_coeff; + cv::Vec3f I0, J0; + cv::Vec2f I0_coeff, J0_coeff; - Vec3f I_1, J_1, I_2, J_2; - Matx33f R_1, R_2; - Matx33f* R_current; + cv::Vec3f I_1, J_1, I_2, J_2; + cv::Matx33f R_1, R_2; + cv::Matx33f* R_current; const int MAX_ITER = 100; const float EPS_THRESHOLD = 1e-4; - const cv::Vec2f* order = order_.points; + const cv::Vec2f* order = order_.points; int i=1; for (; i<MAX_ITER; ++i) @@ -182,10 +179,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float epsilon_2 = k.dot(model.M02)/Z0; // vector of scalar products <I0, M0i> and <J0, M0i> - Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], - order[2][0]*(1.0 + epsilon_2) - order[0][0]); - Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], - order[2][1]*(1.0 + epsilon_2) - order[0][1]); + cv::Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], + order[2][0]*(1.0 + epsilon_2) - order[0][0]); + cv::Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], + order[2][1]*(1.0 + epsilon_2) - order[0][1]); // construct projection of I, J onto M0i plane: I0 and J0 I0_coeff = model.P * I0_M0i; @@ -199,7 +196,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float JJ0 = J0.dot(J0); float rho, theta; if (JJ0 == II0) { - rho = sqrt(abs(2*IJ0)); + rho = std::sqrt(std::abs(2*IJ0)); theta = -PI/4; if (IJ0<0) theta *= -1; } @@ -217,7 +214,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float J_1 = J0 + rho*sin(theta)*model.u; J_2 = J0 - rho*sin(theta)*model.u; - float norm_const = 1.0/norm(I_1); // all have the same norm + float norm_const = 1.0/cv::norm(I_1); // all have the same norm // create rotation matrices I_1 *= norm_const; J_1 *= norm_const; @@ -236,8 +233,8 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // pick the rotation solution closer to the expected one // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = norm(Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = norm(Matx33f::eye() - R_expected * R_2.t()); + float R_1_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_1.t()); + float R_2_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_2.t()); if (R_1_deviation < R_2_deviation) R_current = &R_1; @@ -247,7 +244,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float get_row(*R_current, 2, k); // check for convergence condition - if (abs(epsilon_1 - old_epsilon_1) + abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) + if (std::abs(epsilon_1 - old_epsilon_1) + std::abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) break; old_epsilon_1 = epsilon_1; old_epsilon_2 = epsilon_2; @@ -259,7 +256,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float X_CM.t[1] = order[0][1] * Z0/focal_length; X_CM.t[2] = Z0; - //qDebug() << "iter:" << i; + //qDebug() << "iter:" << i; return i; } diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index 49ff577e..96a448de 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -15,7 +15,7 @@ # include <memory> #endif #include <vector> -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "ftnoir_tracker_pt_settings.h" #include <QObject> diff --git a/ftnoir_tracker_pt/pt_video_widget.cpp b/ftnoir_tracker_pt/pt_video_widget.cpp index 15fc5a86..9f2b90f6 100644 --- a/ftnoir_tracker_pt/pt_video_widget.cpp +++ b/ftnoir_tracker_pt/pt_video_widget.cpp @@ -9,9 +9,6 @@ #include "pt_video_widget.h" -using namespace cv; -using namespace std; - void PTVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); diff --git a/opentrack/export.hpp b/opentrack-compat/export.hpp index f0983b75..f0983b75 100644 --- a/opentrack/export.hpp +++ b/opentrack-compat/export.hpp diff --git a/opentrack/mingw-version-script.txt b/opentrack-compat/mingw-version-script.txt index fe20ad37..fe20ad37 100644 --- a/opentrack/mingw-version-script.txt +++ b/opentrack-compat/mingw-version-script.txt diff --git a/opentrack/posix-version-script.txt b/opentrack-compat/posix-version-script.txt index 97edb9aa..97edb9aa 100644 --- a/opentrack/posix-version-script.txt +++ b/opentrack-compat/posix-version-script.txt diff --git a/opentrack/qcopyable-mutex.hpp b/opentrack-compat/qcopyable-mutex.hpp index f7f36f93..f7f36f93 100644 --- a/opentrack/qcopyable-mutex.hpp +++ b/opentrack-compat/qcopyable-mutex.hpp diff --git a/compat/compat.cpp b/opentrack-compat/shm.cpp index 9000b453..b18a9933 100644 --- a/compat/compat.cpp +++ b/opentrack-compat/shm.cpp @@ -6,7 +6,7 @@ */ #include <cstring> -#include "compat.h" +#include "shm.h" #if defined(_WIN32) PortableLockedShm::PortableLockedShm(const char* shmName, const char* mutexName, int mapSize) diff --git a/compat/compat.h b/opentrack-compat/shm.h index 17a0d843..17a0d843 100644 --- a/compat/compat.h +++ b/opentrack-compat/shm.h diff --git a/opentrack/sleep.hpp b/opentrack-compat/sleep.hpp index 27920842..27920842 100644 --- a/opentrack/sleep.hpp +++ b/opentrack-compat/sleep.hpp diff --git a/opentrack/timer.hpp b/opentrack-compat/timer.hpp index fd710499..fd710499 100644 --- a/opentrack/timer.hpp +++ b/opentrack-compat/timer.hpp diff --git a/opentrack/global-shortcuts.cpp b/opentrack/global-shortcuts.cpp deleted file mode 100644 index 7569fd9a..00000000 --- a/opentrack/global-shortcuts.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include <QList> -#include <QString> - -extern QList<QString> global_key_sequences; -extern QList<int> global_windows_key_sequences; - -#if defined(_WIN32) -# ifndef DIRECTINPUT_VERSION -# define DIRECTINPUT_VERSION 0x800 -# endif -# include <windows.h> -# include <dinput.h> - -QList<int> global_windows_key_sequences = - QList<int>() - << 0 - << DIK_F1 - << DIK_F2 - << DIK_F3 - << DIK_F4 - << DIK_F5 - << DIK_F6 - << DIK_F7 - << DIK_F8 - << DIK_F9 - << DIK_F10 - << DIK_F11 - << DIK_F12 - << DIK_LEFT - << DIK_RIGHT - << DIK_UP - << DIK_DOWN - << DIK_PGUP - << DIK_PGDN - << DIK_HOME - << DIK_END - << DIK_BACK - << DIK_DELETE - << DIK_RETURN; -#endif - -QList<QString> global_key_sequences = - QList<QString>() - << "" - << "F1" - << "F2" - << "F3" - << "F4" - << "F5" - << "F6" - << "F7" - << "F8" - << "F9" - << "F10" - << "F11" - << "F12" - << "Left" - << "Right" - << "Up" - << "Down" - << "PgUp" - << "PgDown" - << "Home" - << "End" - << "Del" -; - - diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp index b0da4950..572b7f31 100644 --- a/opentrack/plugin-api.hpp +++ b/opentrack/plugin-api.hpp @@ -8,7 +8,7 @@ #pragma once -#include "export.hpp" +#include "../opentrack-compat/export.hpp" #include <QString> #include <QWidget> #include <QFrame> @@ -59,7 +59,7 @@ struct IFilter // optional destructor virtual ~IFilter() {} // perform filtering step. - // you have to take care of dt on your own, try "opentrack/timer.hpp" + // you have to take care of dt on your own, try "opentrack-compat/timer.hpp" virtual void filter(const double *input, double *output) = 0; }; diff --git a/opentrack/pose.hpp b/opentrack/pose.hpp deleted file mode 100644 index 93d467a9..00000000 --- a/opentrack/pose.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include <utility> -#include <algorithm> -#include "./plugin-api.hpp" - -class Pose { -private: - static constexpr double pi = 3.141592653; - static constexpr double d2r = pi/180.0; - static constexpr double r2d = 180./pi; - - double axes[6]; -public: - Pose() : axes {0,0,0, 0,0,0} {} - - inline operator double*() { return axes; } - inline operator const double*() const { return axes; } - - inline double& operator()(int i) { return axes[i]; } - inline double operator()(int i) const { return axes[i]; } -}; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index ed1701c7..63cd9088 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -11,6 +11,7 @@ #if defined(_WIN32) #include <windows.h> +#include "win32-shortcuts.h" void KeybindingWorker::set_keys(Key kCenter_, Key kToggle_, Key kZero_) { @@ -124,59 +125,40 @@ void KeybindingWorker::run() { void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k) { #if !defined(_WIN32) - const int idx = k.key_index; if (!key) key = std::make_shared<QxtGlobalShortcut>(); else { - key->setEnabled(false); key->setShortcut(QKeySequence::UnknownKey); + key->setEnabled(false); } - if (idx > 0) + + if (k.keycode != "") { - QString seq(global_key_sequences.value(idx, "")); - if (!seq.isEmpty()) - { - if (k.shift) - seq = "Shift+" + seq; - if (k.alt) - seq = "Alt+" + seq; - if (k.ctrl) - seq = "Ctrl+" + seq; - key->setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText)); - key->setEnabled(); - } + key->setShortcut(QKeySequence::fromString(k.keycode, QKeySequence::PortableText)); + key->setEnabled(); } +} #else key = K(); - int idx = k.key_index; - key.keycode = 0; - key.shift = key.alt = key.ctrl = 0; - if (idx > 0 && idx < global_windows_key_sequences.size()) - key.keycode = global_windows_key_sequences[idx]; - key.shift = k.shift; - key.alt = k.alt; - key.ctrl = k.ctrl; -#endif + int idx = 0; + QKeySequence code; + + if (k.keycode == "") + code = QKeySequence(Qt::Key_unknown); + else + code = QKeySequence::fromString(k.keycode, QKeySequence::PortableText); + + Qt::KeyboardModifiers mods = Qt::NoModifier; + if (code != Qt::Key_unknown) + win_key::from_qt(code, idx, mods); + key.shift = !!(mods & Qt::ShiftModifier); + key.alt = !!(mods & Qt::AltModifier); + key.ctrl = !!(mods & Qt::ControlModifier); + key.keycode = idx; } +#endif void Shortcuts::reload() { -#ifndef _WIN32 - if (keyCenter) - { - keyCenter->setShortcut(QKeySequence::UnknownKey); - keyCenter->setEnabled(false); - } - if (keyToggle) - { - keyToggle->setShortcut(QKeySequence::UnknownKey); - keyToggle->setEnabled(false); - } - if (keyZero) - { - keyZero->setShortcut(QKeySequence::UnknownKey); - keyZero->setEnabled(false); - } -#endif bind_keyboard_shortcut(keyCenter, s.center); bind_keyboard_shortcut(keyToggle, s.toggle); bind_keyboard_shortcut(keyZero, s.zero); diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 520042f0..2d7fec54 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -27,14 +27,10 @@ using namespace options; extern QList<QString> global_key_sequences; struct key_opts { - value<int> key_index; - value<bool> ctrl, alt, shift; + value<QString> keycode; key_opts(pbundle b, const QString& name) : - key_index(b, QString("key-index-%1").arg(name), 0), - ctrl(b, QString("key-ctrl-%1").arg(name), 0), - alt(b, QString("key-alt-%1").arg(name), 0), - shift(b, QString("key-shift-%1").arg(name), 0) + keycode(b, QString("keycode-%1").arg(name), "") {} }; diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 453357c4..c5c39797 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -10,10 +10,9 @@ #include <vector> -#include "timer.hpp" +#include "opentrack-compat/timer.hpp" #include "plugin-support.hpp" #include "mappings.hpp" -#include "pose.hpp" #include "simple-mat.hpp" #include "selected-libraries.hpp" @@ -24,6 +23,23 @@ #include <QMutex> #include <QThread> +class Pose { +private: + static constexpr double pi = 3.141592653; + static constexpr double d2r = pi/180.0; + static constexpr double r2d = 180./pi; + + double axes[6]; +public: + Pose() : axes {0,0,0, 0,0,0} {} + + inline operator double*() { return axes; } + inline operator const double*() const { return axes; } + + inline double& operator()(int i) { return axes[i]; } + inline double operator()(int i) const { return axes[i]; } +}; + class Tracker : private QThread { Q_OBJECT private: diff --git a/opentrack/version.cc b/opentrack/version.cc index 026ad057..13bc5dc5 100644 --- a/opentrack/version.cc +++ b/opentrack/version.cc @@ -1,4 +1,4 @@ -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" #ifdef __cplusplus extern "C" diff --git a/opentrack/win32-shortcuts.cpp b/opentrack/win32-shortcuts.cpp new file mode 100644 index 00000000..dbf4f9fd --- /dev/null +++ b/opentrack/win32-shortcuts.cpp @@ -0,0 +1,162 @@ +#if defined(_WIN32) +# ifndef DIRECTINPUT_VERSION +# define DIRECTINPUT_VERSION 0x800 +# endif +# include <windows.h> +# include <dinput.h> + +#include <QList> +#include <QKeySequence> +#include <QVariant> +#include <QDebug> +#include "win32-shortcuts.h" + +QList<win_key> windows_key_mods = + QList<win_key>({ + win_key(DIK_LCONTROL, Qt::Key::Key_Control), + win_key(DIK_RCONTROL, Qt::Key::Key_Control), + win_key(DIK_LALT, Qt::Key::Key_Alt), + win_key(DIK_RALT, Qt::Key::Key_Alt), + win_key(DIK_LSHIFT, Qt::Key::Key_Shift), + win_key(DIK_RSHIFT, Qt::Key::Key_Shift), + win_key(DIK_LWIN, Qt::Key::Key_unknown), + win_key(DIK_RWIN, Qt::Key::Key_unknown) + }); + +QList<win_key> windows_key_sequences = + QList<win_key>({ + win_key(DIK_F1, Qt::Key::Key_F1 ), + win_key(DIK_F2, Qt::Key::Key_F2 ), + win_key(DIK_F3, Qt::Key::Key_F3 ), + win_key(DIK_F4, Qt::Key::Key_F4 ), + win_key(DIK_F5, Qt::Key::Key_F5 ), + win_key(DIK_F6, Qt::Key::Key_F6 ), + win_key(DIK_F7, Qt::Key::Key_F7 ), + win_key(DIK_F8, Qt::Key::Key_F8 ), + win_key(DIK_F9, Qt::Key::Key_F9 ), + win_key(DIK_F10, Qt::Key::Key_F10 ), + win_key(DIK_F11, Qt::Key::Key_F11 ), + win_key(DIK_F12, Qt::Key::Key_F12 ), + win_key(DIK_LEFT, Qt::Key::Key_Left ), + win_key(DIK_RIGHT, Qt::Key::Key_Right ), + win_key(DIK_UP, Qt::Key::Key_Up ), + win_key(DIK_DOWN, Qt::Key::Key_Down ), + win_key(DIK_PRIOR, Qt::Key::Key_PageUp ), + win_key(DIK_NEXT, Qt::Key::Key_PageDown ), + win_key(DIK_HOME, Qt::Key::Key_Home ), + win_key(DIK_END, Qt::Key::Key_End ), + win_key(DIK_BACK, Qt::Key::Key_Backspace ), + win_key(DIK_COMMA, Qt::Key::Key_Comma ), + win_key(DIK_PERIOD, Qt::Key::Key_Period ), + win_key(DIK_LBRACKET, Qt::Key::Key_BracketLeft ), + win_key(DIK_RBRACKET, Qt::Key::Key_BracketRight ), + win_key(DIK_SEMICOLON, Qt::Key::Key_Semicolon ), + win_key(DIK_SLASH, Qt::Key::Key_Slash ), + win_key(DIK_BACKSLASH, Qt::Key::Key_Backslash ), + win_key(DIK_BACKSPACE, Qt::Key::Key_Backspace ), + win_key(DIK_APOSTROPHE, Qt::Key::Key_Apostrophe ), + win_key(DIK_GRAVE, Qt::Key::Key_QuoteLeft ), + win_key(DIK_MINUS, Qt::Key::Key_Minus ), + win_key(DIK_EQUALS, Qt::Key::Key_Equal ), + win_key(DIK_PERIOD, Qt::Key::Key_Period ), + win_key(DIK_F1, Qt::Key::Key_F1 ), + win_key(DIK_F2, Qt::Key::Key_F2 ), + win_key(DIK_F3, Qt::Key::Key_F3 ), + win_key(DIK_F4, Qt::Key::Key_F4 ), + win_key(DIK_F5, Qt::Key::Key_F5 ), + win_key(DIK_F6, Qt::Key::Key_F6 ), + win_key(DIK_F7, Qt::Key::Key_F7 ), + win_key(DIK_F8, Qt::Key::Key_F8 ), + win_key(DIK_F9, Qt::Key::Key_F9 ), + win_key(DIK_F10, Qt::Key::Key_F10 ), + win_key(DIK_F11, Qt::Key::Key_F11 ), + win_key(DIK_F12, Qt::Key::Key_F12 ), + win_key(DIK_0, Qt::Key::Key_0 ), + win_key(DIK_1, Qt::Key::Key_1 ), + win_key(DIK_2, Qt::Key::Key_2 ), + win_key(DIK_3, Qt::Key::Key_3 ), + win_key(DIK_4, Qt::Key::Key_4 ), + win_key(DIK_5, Qt::Key::Key_5 ), + win_key(DIK_6, Qt::Key::Key_6 ), + win_key(DIK_7, Qt::Key::Key_7 ), + win_key(DIK_8, Qt::Key::Key_8 ), + win_key(DIK_9, Qt::Key::Key_9 ), + win_key(DIK_A, Qt::Key::Key_A ), + win_key(DIK_B, Qt::Key::Key_B ), + win_key(DIK_C, Qt::Key::Key_C ), + win_key(DIK_D, Qt::Key::Key_D ), + win_key(DIK_E, Qt::Key::Key_E ), + win_key(DIK_F, Qt::Key::Key_F ), + win_key(DIK_G, Qt::Key::Key_G ), + win_key(DIK_H, Qt::Key::Key_H ), + win_key(DIK_I, Qt::Key::Key_I ), + win_key(DIK_J, Qt::Key::Key_J ), + win_key(DIK_K, Qt::Key::Key_K ), + win_key(DIK_L, Qt::Key::Key_L ), + win_key(DIK_M, Qt::Key::Key_M ), + win_key(DIK_N, Qt::Key::Key_N ), + win_key(DIK_O, Qt::Key::Key_O ), + win_key(DIK_P, Qt::Key::Key_P ), + win_key(DIK_Q, Qt::Key::Key_Q ), + win_key(DIK_R, Qt::Key::Key_R ), + win_key(DIK_S, Qt::Key::Key_S ), + win_key(DIK_T, Qt::Key::Key_T ), + win_key(DIK_U, Qt::Key::Key_U ), + win_key(DIK_V, Qt::Key::Key_V ), + win_key(DIK_W, Qt::Key::Key_W ), + win_key(DIK_X, Qt::Key::Key_X ), + win_key(DIK_Y, Qt::Key::Key_Y ), + win_key(DIK_Z, Qt::Key::Key_Z ), + win_key(DIK_RETURN, Qt::Key::Key_Return), + win_key(DIK_INSERT, Qt::Key::Key_Insert), + }); + +bool win_key::from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers& mods) +{ + auto qt = static_cast<QVariant>(qt_).toInt(); + auto our_mods = qt & Qt::KeyboardModifierMask; +#ifdef _WIN32 + const auto our_mods_ = our_mods; + our_mods |= Qt::ShiftModifier; + switch (qt & ~Qt::ShiftModifier) + { + case Qt::Key::Key_BraceLeft: qt = Qt::Key::Key_BracketLeft; break; + case Qt::Key::Key_BraceRight: qt = Qt::Key::Key_BracketRight; break; + case Qt::Key::Key_ParenLeft: qt = Qt::Key::Key_9; break; + case Qt::Key::Key_ParenRight: qt = Qt::Key::Key_0; break; + + case Qt::Key::Key_Exclam: qt = Qt::Key::Key_1; break; + case Qt::Key::Key_At: qt = Qt::Key::Key_2; break; + case Qt::Key::Key_NumberSign: qt = Qt::Key::Key_3; break; + case Qt::Key::Key_Dollar: qt = Qt::Key::Key_4; break; + case Qt::Key::Key_Percent: qt = Qt::Key::Key_5; break; + case Qt::Key::Key_AsciiCircum: qt = Qt::Key::Key_6; break; + case Qt::Key::Key_Ampersand: qt = Qt::Key::Key_7; break; + case Qt::Key::Key_Asterisk: qt = Qt::Key::Key_8; break; + + case Qt::Key::Key_Underscore: qt = Qt::Key::Key_Minus; break; + case Qt::Key::Key_Plus: qt = Qt::Key::Key_Equal; break; + + case Qt::Key::Key_Colon: qt = Qt::Key::Key_Semicolon; break; + case Qt::Key::Key_QuoteDbl: qt = Qt::Key::Key_Apostrophe; break; + case Qt::Key::Key_Less: qt = Qt::Key::Key_Comma; break; + case Qt::Key::Key_Question: qt = Qt::Key::Key_Slash; break; + case Qt::Key::Key_Bar: qt = Qt::Key::Key_Backslash; break; + default: our_mods = our_mods_; break; + } +#endif + + const auto key = qt & ~Qt::KeyboardModifierMask; + for (auto& wk : windows_key_sequences) + { + if (wk.qt == key) + { + dik = wk.win; + mods = static_cast<Qt::KeyboardModifiers>(our_mods); + return true; + } + } + return false; +} + +#endif diff --git a/opentrack/win32-shortcuts.h b/opentrack/win32-shortcuts.h new file mode 100644 index 00000000..8167036d --- /dev/null +++ b/opentrack/win32-shortcuts.h @@ -0,0 +1,18 @@ +#pragma once + +#ifdef _WIN32 + +struct win_key; + +extern QList<win_key> windows_key_mods; +extern QList<win_key> windows_key_sequences; + +struct win_key +{ + win_key(int win, Qt::Key qt) : win(win), qt(qt) {} + int win; + Qt::Key qt; + static bool from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers &mods); +}; + +#endif diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h index 7ead2c5d..a8b46597 100644 --- a/qfunctionconfigurator/functionconfig.h +++ b/qfunctionconfigurator/functionconfig.h @@ -14,7 +14,7 @@ #include <QSettings> #include <QMutex> #include <vector> -#include "opentrack/qcopyable-mutex.hpp" +#include "opentrack-compat/qcopyable-mutex.hpp" class Map { private: |