diff options
-rw-r--r-- | tracker-tobii-eyex/tobii-eyex-dialog.cpp | 2 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-eyex-dialog.hpp | 23 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-eyex-dialog.ui | 6 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-eyex.cpp | 84 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-eyex.hpp | 63 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-settings.cpp | 97 | ||||
-rw-r--r-- | tracker-tobii-eyex/tobii-settings.hpp | 52 |
7 files changed, 180 insertions, 147 deletions
diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.cpp b/tracker-tobii-eyex/tobii-eyex-dialog.cpp index 7f69fa16..0388ddfb 100644 --- a/tracker-tobii-eyex/tobii-eyex-dialog.cpp +++ b/tracker-tobii-eyex/tobii-eyex-dialog.cpp @@ -1,4 +1,4 @@ -#include "tobii-eyex.hpp" +#include "tobii-eyex-dialog.hpp" tobii_eyex_dialog::tobii_eyex_dialog() { diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.hpp b/tracker-tobii-eyex/tobii-eyex-dialog.hpp new file mode 100644 index 00000000..51957bf2 --- /dev/null +++ b/tracker-tobii-eyex/tobii-eyex-dialog.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "tobii-settings.hpp" + +#include "api/plugin-api.hpp" +#include "ui_tobii-eyex-dialog.h" +#include <QObject> + +class tobii_eyex_dialog final : public ITrackerDialog +{ + Q_OBJECT +public: + tobii_eyex_dialog(); + void register_tracker(ITracker*) override {} + void unregister_tracker() override {} +private: + Ui::tobii_eyex_dialog_widgets ui; + settings s; + rel_settings rs; +private slots: + void do_ok(); + void do_cancel(); +}; diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.ui b/tracker-tobii-eyex/tobii-eyex-dialog.ui index 7a8c92aa..1e622f93 100644 --- a/tracker-tobii-eyex/tobii-eyex-dialog.ui +++ b/tracker-tobii-eyex/tobii-eyex-dialog.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>710</width> + <width>702</width> <height>440</height> </rect> </property> @@ -88,8 +88,8 @@ </property> <property name="sizeHint" stdset="0"> <size> - <width>510</width> - <height>17</height> + <width>10</width> + <height>0</height> </size> </property> </spacer> diff --git a/tracker-tobii-eyex/tobii-eyex.cpp b/tracker-tobii-eyex/tobii-eyex.cpp index 1a2f922b..d748cc2b 100644 --- a/tracker-tobii-eyex/tobii-eyex.cpp +++ b/tracker-tobii-eyex/tobii-eyex.cpp @@ -2,12 +2,6 @@ #include <cstdlib> #include <cstdio> #include <cmath> -#include <functional> -#include <vector> -#include <algorithm> -#include <iterator> -#include <utility> -#include <numeric> #include <QDebug> #include <QMutexLocker> #include <QMessageBox> @@ -38,82 +32,6 @@ static inline tobii_eyex_tracker& to_self(TX_USERPARAM param) return *reinterpret_cast<tobii_eyex_tracker*>(param); } -// there's an underflow in spline code, can't use 1e0 -static constexpr const double spline_max = 1e2; - -void rel_settings::make_spline_(part* functors, unsigned len) -{ - acc_mode_spline.removeAllPoints(); - - double lastx = 0, lasty = 0; - - using std::accumulate; - - const double inv_norm_y = 1./accumulate(functors, functors + len, 1e-4, [](double acc, const part& functor) { return acc + functor.norm; }); - const double inv_norm_x = 1./accumulate(functors, functors + len, 1e-4, [](double acc, const part& functor) { return acc + functor.len; }); - - for (unsigned k = 0; k < len; k++) - { - part& fun = functors[k]; - - const double xscale = fun.len * spline_max * inv_norm_x; - const double maxx = fun.f(1); - const double yscale = fun.norm * spline_max * inv_norm_y * (maxx < 1e-3 ? 0 : 1./maxx); - - for (unsigned i = 0; i <= fun.nparts; i++) - { - const double x = lastx + (fun.nparts == 0 ? 1 : i) / (1.+fun.nparts) * xscale; - const double y = lasty + clamp(fun.f(x) * yscale, 0, spline_max); - qDebug() << k << i << x << y; - acc_mode_spline.addPoint(x, y); - } - - lastx += xscale; - lasty += yscale; - } -} - -/* - def plot(f): - rng = arange(-1 + .01, 1, 1e-4) - plt.plot(rng, map(f, rng)) -*/ - -double rel_settings::gain(double value) -{ - return acc_mode_spline.get_value_no_save(value * spline_max) / spline_max; -} - -void rel_settings::make_spline() -{ - const double log_c = 1./std::log(log_slope()); - - part functors[] - { - { 1, dz_len(), 0, [](double) { return 0; } }, - { 5, expt_len(), expt_norm(), [=](double x) { return std::pow(x, expt_slope()); } }, - { 7, 1 - dz_len() - expt_len() - log_len(), std::max(0., 1 - expt_norm() - log_norm()), [](double x) { return x; } }, - { 7, log_len(), log_norm(), [=](double x) { return std::log(1+x)*log_c; } }, - }; - - make_spline_(functors, std::distance(std::begin(functors), std::end(functors))); -} - -rel_settings::rel_settings() : - opts("tobii-eyex-relative-mode"), - speed(b, "speed", s(3, .1, 10)), - dz_len(b, "deadzone-length", s(.04, 0, .2)), - expt_slope(b, "exponent-slope", s(1.75, 1.25, 3)), - expt_len(b, "exponent-length", s(.25, 0, .5)), - expt_norm(b, "exponent-norm", s(.3, .1, .5)), - log_slope(b, "log-slope", s(2.75, 1.25, 10)), - log_len(b, "log-len", s(.1, 0, .2)), - log_norm(b, "log-norm", s(.1, .05, .3)), - acc_mode_spline(100, 100, "") -{ - make_spline(); -} - tobii_eyex_tracker::tobii_eyex_tracker() : dev_ctx(TX_EMPTY_HANDLE), conn_state_changed_ticket(TX_INVALID_TICKET), @@ -391,4 +309,6 @@ void tobii_eyex_tracker::data(double* data) // .7 is 40 degrees which is already quite a lot from the monitor. } +#include "tobii-eyex-dialog.hpp" + OPENTRACK_DECLARE_TRACKER(tobii_eyex_tracker, tobii_eyex_dialog, tobii_eyex_metadata) diff --git a/tracker-tobii-eyex/tobii-eyex.hpp b/tracker-tobii-eyex/tobii-eyex.hpp index 68acb25c..23173f22 100644 --- a/tracker-tobii-eyex/tobii-eyex.hpp +++ b/tracker-tobii-eyex/tobii-eyex.hpp @@ -8,62 +8,19 @@ * notice appear in all copies. */ +#include "tobii-settings.hpp" + #include <EyeX.h> -#include "ui_tobii-eyex-dialog.h" #include "api/plugin-api.hpp" #include "options/options.hpp" using namespace options; #include "compat/timer.hpp" -#include "spline-widget/spline.hpp" -#include "spline-widget/spline-widget.hpp" #include <functional> #include <atomic> #include <QObject> #include <QMutex> -#include <QTimer> - -enum tobii_mode -{ - tobii_relative, - tobii_absolute, -}; - -class rel_settings final : public QObject, public opts -{ - Q_OBJECT - - using functor = std::function<double(double)>; - - struct part - { - int nparts; - double len, norm; - functor f; - }; - - void make_spline_(part* functors, unsigned len); - -public: - using s = slider_value; - value<slider_value> speed, dz_len, expt_slope, expt_len, expt_norm, log_slope, log_len, log_norm; - spline acc_mode_spline; - rel_settings(); - double gain(double value); - -public slots: - void make_spline(); -}; - -struct settings final : public opts -{ - value<tobii_mode> mode; - settings() : - opts("tobii-eyex"), - mode(b, "mode", tobii_relative) - {} -}; class tobii_eyex_tracker : public ITracker { @@ -123,22 +80,6 @@ private: volatile bool do_center; }; -class tobii_eyex_dialog final : public ITrackerDialog -{ - Q_OBJECT -public: - tobii_eyex_dialog(); - void register_tracker(ITracker *) override {} - void unregister_tracker() override {} -private: - Ui::tobii_eyex_dialog_widgets ui; - settings s; - rel_settings rs; -private slots: - void do_ok(); - void do_cancel(); -}; - class tobii_eyex_metadata : public Metadata { public: diff --git a/tracker-tobii-eyex/tobii-settings.cpp b/tracker-tobii-eyex/tobii-settings.cpp new file mode 100644 index 00000000..fb5bb8f6 --- /dev/null +++ b/tracker-tobii-eyex/tobii-settings.cpp @@ -0,0 +1,97 @@ +#include "tobii-settings.hpp" +#include <cmath> +#include <iterator> +#include <utility> +#include <numeric> + +/* + def plot(f, max=None, min=None): + if max is None and min is None: + min, max = -1.5, 1.5 + elif max is None: + max=-min + elif min is None: + min=-max + + assert max > min + c = 1e-4*(max-min) + if c < 1e-12: + c = 1e-6 + rng = arange(min, max, c) + plt.plot(rng, map(f, rng)) +*/ + +/* + def richards(b, q, v, c=1): + return lambda x: 1./((c + q * exp(-b * x) ** (1./v))) +*/ + +void rel_settings::make_spline() +{ + const double log_c = 1./std::log(log_slope()); + + part functors[] + { + { 1, dz_len(), 0, [](double) { return 0; } }, + { 5, expt_len(), expt_norm(), [=](double x) { return std::pow(x, expt_slope()); } }, + { 7, 1 - dz_len() - expt_len() - log_len(), std::max(0., 1 - expt_norm() - log_norm()), [](double x) { return x; } }, + { 7, log_len(), log_norm(), [=](double x) { return std::log(1+x)*log_c; } }, + }; + + make_spline_(functors, std::distance(std::begin(functors), std::end(functors))); +} + +rel_settings::rel_settings() : + opts("tobii-eyex-relative-mode"), + speed(b, "speed", s(3, .1, 10)), + dz_len(b, "deadzone-length", s(.04, 0, .2)), + expt_slope(b, "exponent-slope", s(1.75, 1.25, 3)), + expt_len(b, "exponent-length", s(.25, 0, .5)), + expt_norm(b, "exponent-norm", s(.3, .1, .5)), + log_slope(b, "log-slope", s(2.75, 1.25, 10)), + log_len(b, "log-len", s(.1, 0, .2)), + log_norm(b, "log-norm", s(.1, .05, .3)), + acc_mode_spline(100, 100, "") +{ + make_spline(); +} + +// there's an underflow in spline code, can't use 1e0 +static constexpr const double spline_max = 1e2; + +double rel_settings::gain(double value) +{ + return acc_mode_spline.get_value_no_save(value * spline_max) / spline_max; +} + +void rel_settings::make_spline_(part* functors, unsigned len) +{ + acc_mode_spline.removeAllPoints(); + + double lastx = 0, lasty = 0; + + using std::accumulate; + + const double inv_norm_y = 1./accumulate(functors, functors + len, 1e-4, [](double acc, const part& functor) { return acc + functor.norm; }); + const double inv_norm_x = 1./accumulate(functors, functors + len, 1e-4, [](double acc, const part& functor) { return acc + functor.len; }); + + for (unsigned k = 0; k < len; k++) + { + part& fun = functors[k]; + + const double xscale = fun.len * spline_max * inv_norm_x; + const double maxx = fun.f(1); + const double yscale = fun.norm * spline_max * inv_norm_y * (maxx < 1e-3 ? 0 : 1./maxx); + + for (unsigned i = 0; i <= fun.nparts; i++) + { + const double x = lastx + (fun.nparts == 0 ? 1 : i) / (1.+fun.nparts) * xscale; + const double y = lasty + clamp(fun.f(x) * yscale, 0, spline_max); + qDebug() << k << i << x << y; + acc_mode_spline.addPoint(x, y); + } + + lastx += xscale; + lasty += yscale; + } +} diff --git a/tracker-tobii-eyex/tobii-settings.hpp b/tracker-tobii-eyex/tobii-settings.hpp new file mode 100644 index 00000000..4346a156 --- /dev/null +++ b/tracker-tobii-eyex/tobii-settings.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include "api/plugin-api.hpp" +#include "options/options.hpp" +using namespace options; +#include "spline-widget/spline.hpp" +#include "spline-widget/spline-widget.hpp" + +#include <functional> + +#include <QObject> + +enum tobii_mode +{ + tobii_relative, + tobii_absolute, +}; + +class rel_settings final : public QObject, public opts +{ + Q_OBJECT + + using functor = std::function<double(double)>; + + struct part + { + int nparts; + double len, norm; + functor f; + }; + + void make_spline_(part* functors, unsigned len); + +public: + using s = slider_value; + value<slider_value> speed, dz_len, expt_slope, expt_len, expt_norm, log_slope, log_len, log_norm; + spline acc_mode_spline; + rel_settings(); + double gain(double value); + +public slots: + void make_spline(); +}; + +struct settings final : public opts +{ + value<tobii_mode> mode; + settings() : + opts("tobii-eyex"), + mode(b, "mode", tobii_relative) + {} +}; |