From fd86eebdd12158d80e4af190e7e7a474b410ce5a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 7 Aug 2016 12:19:20 +0200 Subject: tracker/tobii: remove existing mapping code. maybe later revert this. It doesn't work good enough. Try use splines instead. --- tracker-tobii-eyex/CMakeLists.txt | 1 + tracker-tobii-eyex/tobii-eyex.cpp | 108 ++++++++++++++------------------------ tracker-tobii-eyex/tobii-eyex.hpp | 21 ++++---- 3 files changed, 48 insertions(+), 82 deletions(-) (limited to 'tracker-tobii-eyex') diff --git a/tracker-tobii-eyex/CMakeLists.txt b/tracker-tobii-eyex/CMakeLists.txt index a5fb3404..465801ac 100644 --- a/tracker-tobii-eyex/CMakeLists.txt +++ b/tracker-tobii-eyex/CMakeLists.txt @@ -2,6 +2,7 @@ if(WIN32) set(SDK_TOBII_EYEX "" CACHE PATH "") if(SDK_TOBII_EYEX) opentrack_boilerplate(opentrack-tracker-tobii-eyex) + target_link_libraries(opentrack-tracker-tobii-eyex opentrack-spline-widget) set(tobii-libdir ${SDK_TOBII_EYEX}/lib/x86/) set(tobii-dll ${tobii-libdir}/Tobii.EyeX.Client.dll) # we only care about the .lib for MSVC++ build anyway diff --git a/tracker-tobii-eyex/tobii-eyex.cpp b/tracker-tobii-eyex/tobii-eyex.cpp index d668a4e2..709f1b8f 100644 --- a/tracker-tobii-eyex/tobii-eyex.cpp +++ b/tracker-tobii-eyex/tobii-eyex.cpp @@ -42,13 +42,46 @@ static constexpr t clamp(t datum, t min, t max) return ((datum > max) ? max : ((datum < min) ? min : datum)); } +void rel_settings::draw_spline() +{ + Map& spline = acc_mode_spline; + + spline.removeAllPoints(); + + static constexpr float std_norm_expt = 1.f/3; + const float norm_expt = std_norm_expt * float(expt_norm.get()); + static constexpr float std_norm_lin = 2.f/3; + const float norm_lin = clamp((1-norm_expt) * lin_norm.get() * std_norm_lin, 0, 1); + +} + rel_settings::rel_settings() : opts("tobii-eyex-relative-mode"), speed(b, "speed", s(5, .1, 10)), - dz_end_pt(b, "deadzone-length", s(.05, 0, .2)), - expt_val(b, "exponent", s(1.75, 1.25, 2.25)), - log_base(b, "logarithm-base", s(1.75, 1.1, 5)) -{} + dz_end_pt(b, "deadzone-length", s(4, 0, 15)), + expt_slope(b, "exponent-slope", s(1.5, 1.25, 3)), + expt_norm(b, "exponent-norm", s(1, .25, 4)), + lin_norm(b, "linear-norm", s(1, .25, 4)), + acc_mode_spline(100, 100) +{ + QObject::connect(&dz_end_pt, + static_cast(&base_value::valueChanged), + this, + &rel_settings::draw_spline); + QObject::connect(&expt_slope, + static_cast(&base_value::valueChanged), + this, + &rel_settings::draw_spline); + QObject::connect(&expt_norm, + static_cast(&base_value::valueChanged), + this, + &rel_settings::draw_spline); + QObject::connect(&lin_norm, + static_cast(&base_value::valueChanged), + this, + &rel_settings::draw_spline); + draw_spline(); +} tobii_eyex_tracker::tobii_eyex_tracker() : dev_ctx(TX_EMPTY_HANDLE), @@ -310,74 +343,9 @@ plot_fn(lambda x: piecewise(x, [zero, f, g, h], [.05, .25, .7, 1.])) */ -template -tobii_eyex_tracker::num tobii_eyex_tracker::piecewise(num x, const funs_seq& funs, const bounds_seq& bounds) -{ - using fn = std::function; - - auto funs_it = std::begin(funs); - auto bounds_it = std::begin(bounds); - - auto funs_end = std::end(funs); - auto bounds_end = std::end(bounds); - - num norm = 0; - - for (const fn& f : funs) - { - norm += f(1); - } - - norm = std::max(num(1e-4), norm); - - num last_bound = 0, y = 0; - - for (; - bounds_it != bounds_end && funs_it != funs_end; - bounds_it++, funs_it++) - { - const fn& fun = *funs_it; - const num bound = *bounds_it; - - if (x > bound) - { - y += fun(1); - last_bound = bound; - } - else - { - const num b = bound - last_bound; - // rescale x to 0->1 - const num x_ = (x - last_bound) / b; - y += fun(x_); - break; - } - } - return clamp(y / norm, num(0), num(1)); -} - tobii_eyex_tracker::num tobii_eyex_tracker::gain(num x_) { - const num x = std::fabs(x_); - - static const fun_t funs[] = - { - [](num) -> num { return num(0); }, - [](num x) -> num { return std::pow(x, 1.1)*.08; }, - [](num x) -> num { return x*.5; }, - }; - - static constexpr num dz_l = .1, expt_l = .3; - - static constexpr num ends[] = - { - dz_l, - expt_l, - 1, - }; - - const num ret = piecewise(x, funs, ends); - return std::copysign(clamp(ret, num(0), num(1)), x_); + return 1; } void tobii_eyex_tracker::data(double* data) diff --git a/tracker-tobii-eyex/tobii-eyex.hpp b/tracker-tobii-eyex/tobii-eyex.hpp index d8bb3606..f64f2495 100644 --- a/tracker-tobii-eyex/tobii-eyex.hpp +++ b/tracker-tobii-eyex/tobii-eyex.hpp @@ -16,7 +16,7 @@ using namespace options; #include "opentrack-compat/timer.hpp" #include "spline-widget/functionconfig.h" -#include "spline-widget/qfunctionconfigurator.h" +#include "qfunctionconfigurator.h" #include #include @@ -28,17 +28,19 @@ enum tobii_mode tobii_absolute, }; -struct rel_settings : public QObject, public opts +class rel_settings final : public QObject, public opts { + Q_OBJECT +public: using s = slider_value; - value speed, dz_end_pt, expt_val, log_base; + value speed, dz_end_pt, expt_slope, expt_norm, lin_norm; + Map acc_mode_spline; rel_settings(); -private: - // linear coefficient to be the same as exponent - Map spline; +private slots: + void draw_spline(); }; -struct settings : public opts +struct settings final : public opts { value mode; settings() : @@ -75,11 +77,6 @@ private: using num = double; - template - static num piecewise(num x, const funs_seq& funs, const bounds_seq& bounds); - - using fun_t = std::function; - num gain(num x); settings s; -- cgit v1.2.3