summaryrefslogtreecommitdiffhomepage
path: root/tracker-tobii-eyex/tobii-settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-tobii-eyex/tobii-settings.cpp')
-rw-r--r--tracker-tobii-eyex/tobii-settings.cpp74
1 files changed, 48 insertions, 26 deletions
diff --git a/tracker-tobii-eyex/tobii-settings.cpp b/tracker-tobii-eyex/tobii-settings.cpp
index fb5bb8f6..0dcb377f 100644
--- a/tracker-tobii-eyex/tobii-settings.cpp
+++ b/tracker-tobii-eyex/tobii-settings.cpp
@@ -28,14 +28,45 @@
void rel_settings::make_spline()
{
- const double log_c = 1./std::log(log_slope());
+ const double dz_len_ = dz_len(),
+ expt_len_ = expt_len(),
+ expt_norm_ = expt_norm(),
+ expt_slope_ = expt_slope(),
+ log_len_ = log_len();
+
+ const double expt_deriv_at_end = expt_norm_ * expt_slope_ * std::pow(expt_len_, expt_slope_ - 1); // cnx^(n-1)
+ const double expt_at_end = expt_norm_ * std::pow(expt_len_, expt_slope_); // cx^n
+
+ const double lin_len = 1 - dz_len_ - expt_len_ - log_len_;
+
+ // this isn't correct but works.
+ // we use exponentiation of the linear part to get logarithmic approximation of the linear
+ // part rather than linear approximation of the linear part
+
+ const double lin_at_end = std::pow(M_E, lin_len * expt_deriv_at_end - expt_at_end); // e^(cx + a)
+ const double lin_deriv_at_end = expt_deriv_at_end * std::exp(-expt_at_end + expt_deriv_at_end * lin_len); // ce^(a + cx)
+
+ // this was all derived by the awesome linear approximation
+ // calculator <http://www.emathhelp.net/calculators/calculus-1/linear-approximation-calculator/>
+
+ auto expt_part = [=](double x) { return expt_norm_ * std::pow(x, expt_slope_); };
+ const double expt_inv_norm = expt_norm_/expt_part(expt_len_);
+
+ auto lin_part = [=](double x) { return expt_inv_norm * (expt_at_end + expt_deriv_at_end * (x - expt_len_)); };
+ const double lin_inv_norm = (1 - expt_norm_ - .25)/lin_part(lin_len);
+
+ // TODO needs norm for log/lin parts
+ auto log_part = [=](double x) { return expt_inv_norm * lin_inv_norm * std::log(lin_at_end + lin_deriv_at_end * (x - lin_len)); };
+ const double log_inv_norm = .25/log_part(expt_len_);
+
+ qDebug() << "lin" << expt_deriv_at_end << lin_inv_norm;
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; } },
+ { dz_len_, [](double) { return 0; } },
+ { expt_len_, [=](double x) { return expt_inv_norm * expt_part(x); } }, // cx^n
+ { lin_len, [=](double x) { return lin_inv_norm * lin_part(x); } }, // cx + a
+ { log_len_, [=](double x) { return log_inv_norm * log_part(x); } }, // ln(cx + a)
};
make_spline_(functors, std::distance(std::begin(functors), std::end(functors)));
@@ -45,12 +76,10 @@ 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)),
+ expt_slope(b, "exponent-slope", s(1.75, 1.5, 3)),
+ expt_len(b, "exponent-length", s(.2, 0, .5)),
+ expt_norm(b, "exponent-norm", s(.4, .1, .5)),
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();
@@ -68,30 +97,23 @@ 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; });
+ double lastx = 0;
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);
+ static constexpr unsigned nparts = 7;
- for (unsigned i = 0; i <= fun.nparts; i++)
+ for (unsigned i = 1; i <= 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);
+ const double x = i*fun.len/nparts;
+ const double y = clamp(fun.f(x), 0, 1);
+ if (i == nparts/2)
+ qDebug() << k << i << x << y;
+ acc_mode_spline.addPoint((lastx + x) * spline_max, y * spline_max);
}
- lastx += xscale;
- lasty += yscale;
+ lastx += fun.len;
}
}