diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-25 11:43:10 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-25 11:43:10 +0200 |
commit | 10ac081b3c4ebb9b29b81b30f5efe6622f4212bc (patch) | |
tree | fedfe7efc494145d0b46e91ba5a94c47cb0c1b6f /facetracknoir | |
parent | 6baa8ca1070612e5d7cbae7aa62cbe4a9e51ad40 (diff) | |
parent | 24538cf3a3a91481851618791b11be81437563e4 (diff) |
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'facetracknoir')
-rw-r--r-- | facetracknoir/facetracknoir.rc | 4 | ||||
-rw-r--r-- | facetracknoir/keyboard.h | 37 | ||||
-rw-r--r-- | facetracknoir/keyboard_listener.ui | 37 | ||||
-rw-r--r-- | facetracknoir/options-dialog.cpp | 50 | ||||
-rw-r--r-- | facetracknoir/options-dialog.hpp | 5 | ||||
-rw-r--r-- | facetracknoir/settings.ui | 193 | ||||
-rw-r--r-- | facetracknoir/trans_calib.cpp | 17 |
7 files changed, 144 insertions, 199 deletions
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]); } |