diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-26 07:10:49 +0100 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-26 07:10:49 +0100 | 
| commit | 20f83ad3149237087d2d0a81a27e6d511a5e7973 (patch) | |
| tree | 3aaf2bc964a026292451efaa553744165d3e1c93 | |
| parent | a815d8dfe1b452e0cab9b588a9d4ec4650a5bdda (diff) | |
| parent | 8f7e5c0441237a9c8c187f24a424f6c77c5e397e (diff) | |
Merge branch 'unstable' into trackhat
* unstable:
  main: use camera-based centering by default
  settings: clarify center method usage
  accela: fix typo
  win32: try win_key with modifier first
  shortcuts: remove obsolete code on win32
  shortcuts: allow for numpad on win32
  qfc: drop nan check
  pt: drop nan check
  shortcuts: allow for numlock on win32
  accela: remove too many nan checks
  timer: guard against overflow on win32
  accela: remove "done" logic
  timer: sprinkle some const
  shortcuts: allow for binding same key to multiple functions
  qfc: guard against unlikely division by zero
  cmake: update toolchain file
| -rw-r--r-- | facetracknoir/settings.ui | 4 | ||||
| -rw-r--r-- | ftnoir_filter_accela/ftnoir_filter_accela.cpp | 27 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 30 | ||||
| -rw-r--r-- | opentrack-compat/timer.hpp | 10 | ||||
| -rw-r--r-- | opentrack/shortcuts.cpp | 18 | ||||
| -rw-r--r-- | opentrack/win32-shortcuts.cpp | 73 | ||||
| -rw-r--r-- | qfunctionconfigurator/functionconfig.cpp | 16 | 
7 files changed, 61 insertions, 117 deletions
diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui index 5ab857db..0810fd98 100644 --- a/facetracknoir/settings.ui +++ b/facetracknoir/settings.ui @@ -157,12 +157,12 @@             <widget class="QComboBox" name="center_method">              <item>               <property name="text"> -              <string>Relative</string> +              <string>Relative (inertial device)</string>               </property>              </item>              <item>               <property name="text"> -              <string>Absolute</string> +              <string>Absolute (camera device)</string>               </property>              </item>             </widget> diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp index 51e79ec2..f0659d76 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp @@ -58,29 +58,13 @@ FTNoIR_Filter::FTNoIR_Filter() : first_run(true)      }  } -static inline bool nanp(double value) -{ -    return std::isnan(value) || std::isinf(value); -} - -static inline double elide_nan(double value, double def) -{ -    if (nanp(value)) -    { -        if (nanp(def)) -            return 0; -        return def; -    } -    return value; -} -  void FTNoIR_Filter::filter(const double* input, double *output)  {      if (first_run)      {          for (int i = 0; i < 6; i++)          { -            const double f = nanp(input[i]) ? 0 : input[i]; +            const double f = input[i];              output[i] = f;              last_output[i] = f;              smoothed_input[i] = f; @@ -105,7 +89,7 @@ void FTNoIR_Filter::filter(const double* input, double *output)      {          Map& m = i >= 3 ? rot : trans; -        smoothed_input[i] = smoothed_input[i] * (1.-alpha) + elide_nan(input[i], smoothed_input[i]) * alpha; +        smoothed_input[i] = smoothed_input[i] * (1.-alpha) + input[i] * alpha;          const double in = smoothed_input[i]; @@ -115,12 +99,7 @@ void FTNoIR_Filter::filter(const double* input, double *output)          const double thres = i >= 3 ? rot_t : trans_t;          const double val = m.getValue(vec_ / thres);          const double result = last_output[i] + (vec < 0 ? -1 : 1) * dt * val; -        const bool negp = vec < 0.; -        const bool done = negp -            ? result <= in -            : result >= in; -        const double ret = done ? in : result; -        last_output[i] = output[i] = elide_nan(ret, last_output[i]); +        last_output[i] = output[i] = result;      }  } diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 9a5f11c4..956f639e 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -79,11 +79,6 @@ bool Tracker_PT::get_focal_length(float& ret)      return false;  } -static inline bool nanp(double value) -{ -    return std::isnan(value) || std::isinf(value); -} -  void Tracker_PT::run()  {  #ifdef PT_PERF_LOG @@ -122,8 +117,6 @@ void Tracker_PT::run()              if (!get_focal_length(fx))                  continue; -            Affine X_CM_ = pose(); -                          if (success)              {                  point_tracker.track(points, PointModel(s), fx, s.dynamic_pose, s.init_phase_timeout); @@ -131,28 +124,7 @@ void Tracker_PT::run()              Affine X_CM = pose(); -            { -                int j = 0; -                 -                for (int i = 0; i < 3; i++) -                { -                    if (nanp(X_CM.t(i))) -                        goto nannan; -                    for (; j < 3; j++) -                        if (nanp(X_CM.R(i, j))) -                        { -nannan:                     success = false; -                            X_CM = X_CM_; -                            { -                                QMutexLocker lock(&mutex); -                                point_tracker.reset(X_CM_); -                            } -                            goto nannannan; -                        } -                } -            } -             -nannannan:  ever_success |= success; +            ever_success |= success;              {                  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 diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp index 8192aa83..f0741295 100644 --- a/opentrack-compat/timer.hpp +++ b/opentrack-compat/timer.hpp @@ -24,9 +24,7 @@ static inline void opentrack_clock_gettime(int, struct timespec* ts)      (void) QueryPerformanceCounter(&d); -    long long part = d.QuadPart; -    part *= 1000000000ULL; -    part /= freq.QuadPart; +    long long part = d.QuadPart / ((long double)freq.QuadPart) * 1000000000.L;      ts->tv_sec = part / 1000000000ULL;      ts->tv_nsec = part % 1000000000ULL; @@ -54,7 +52,7 @@ static inline void clock_gettime(int, struct timespec* ts)  class Timer {  private:      struct timespec state; -    long long conv(const struct timespec& cur) +    long long conv(const struct timespec& cur) const      {          return (cur.tv_sec - state.tv_sec) * 1000000000LL + (cur.tv_nsec - state.tv_nsec);      } @@ -65,12 +63,12 @@ public:      void start() {          (void) clock_gettime(CLOCK_MONOTONIC, &state);      } -    long long elapsed() { +    long long elapsed() const {          struct timespec cur;          (void) clock_gettime(CLOCK_MONOTONIC, &cur);          return conv(cur);      } -    long elapsed_ms() { +    long elapsed_ms() const {          return elapsed() / 1000000L;      }  }; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index 91480d16..91d449f1 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -154,21 +154,21 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)  void Shortcuts::receiver(Key &k)  {      std::vector<K*> ks { &keyCenter, &keyToggle, &keyZero }; -    for (auto& k_ : ks) +    for (K* k_ : ks)      {          if (k.keycode != k_->keycode)              continue;          if (!k_->should_process()) -            return; -        if (k_->alt && !k.alt) return; -        if (k_->ctrl && !k.ctrl) return; -        if (k_->shift && !k.shift) return; - -        if (k.keycode == keyCenter.keycode) +            continue; +        if (k_->alt && !k.alt) continue; +        if (k_->ctrl && !k.ctrl) continue; +        if (k_->shift && !k.shift) continue; +         +        if (k_ == &keyCenter)              emit center(); -        else if (k.keycode == keyToggle.keycode) +        else if (k_ == &keyToggle)              emit toggle(); -        else if (k.keycode == keyZero.keycode) +        else if (k_ == &keyZero)              emit zero();      }  } diff --git a/opentrack/win32-shortcuts.cpp b/opentrack/win32-shortcuts.cpp index 96232631..a0ed51b3 100644 --- a/opentrack/win32-shortcuts.cpp +++ b/opentrack/win32-shortcuts.cpp @@ -120,6 +120,27 @@ QList<win_key> windows_key_sequences =         win_key(DIK_SYSRQ, Qt::Key::Key_Print),         win_key(DIK_SCROLL, Qt::Key::Key_ScrollLock),         win_key(DIK_PAUSE, Qt::Key::Key_Pause), +       win_key(DIK_NUMLOCK, Qt::Key::Key_NumLock), +#define mod(x, y) static_cast<Qt::Key>(x | y) +       win_key(DIK_NUMPAD0,      mod(Qt::Key::Key_0,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD0,      mod(Qt::Key::Key_0,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD1,      mod(Qt::Key::Key_1,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD2,      mod(Qt::Key::Key_2,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD3,      mod(Qt::Key::Key_3,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD4,      mod(Qt::Key::Key_4,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD5,      mod(Qt::Key::Key_5,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD6,      mod(Qt::Key::Key_6,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD7,      mod(Qt::Key::Key_7,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD8,      mod(Qt::Key::Key_8,        Qt::KeypadModifier)), +       win_key(DIK_NUMPAD9,      mod(Qt::Key::Key_9,        Qt::KeypadModifier)), +       win_key(DIK_NUMPADCOMMA,  mod(Qt::Key::Key_Comma,    Qt::KeypadModifier)), +       win_key(DIK_NUMPADENTER,  mod(Qt::Key::Key_Enter,    Qt::KeypadModifier)), +       win_key(DIK_NUMPADEQUALS, mod(Qt::Key::Key_Equal,    Qt::KeypadModifier)), +       win_key(DIK_NUMPADMINUS,  mod(Qt::Key::Key_Minus,    Qt::KeypadModifier)), +       win_key(DIK_NUMPADPERIOD, mod(Qt::Key::Key_Period,   Qt::KeypadModifier)), +       win_key(DIK_NUMPADPLUS,   mod(Qt::Key::Key_Plus,     Qt::KeypadModifier)), +       win_key(DIK_NUMPADSLASH,  mod(Qt::Key::Key_Slash,    Qt::KeypadModifier)), +       win_key(DIK_NUMPADSTAR,   mod(Qt::Key::Key_multiply, Qt::KeypadModifier)),      });  bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods) @@ -143,43 +164,29 @@ 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; -    const auto our_mods_ = our_mods; -    our_mods |= Qt::ShiftModifier; -    switch (qt & ~Qt::KeyboardModifierMask) -    { -    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; +    { +        const auto key_ = qt; +        for (auto& wk : windows_key_sequences) +        { +            if (wk.qt == key_) +            { +                dik = wk.win; +                mods = Qt::NoModifier; +                return true; +            } +        }      } - -    const auto key = qt & ~Qt::KeyboardModifierMask; -    for (auto& wk : windows_key_sequences)      { -        if (wk.qt == key) +        const auto key = qt & ~Qt::KeyboardModifierMask; +        for (auto& wk : windows_key_sequences)          { -            dik = wk.win; -            mods = static_cast<Qt::KeyboardModifiers>(our_mods); -            return true; +            if (wk.qt == key) +            { +                dik = wk.win; +                mods = static_cast<Qt::KeyboardModifiers>(our_mods); +                return true; +            }          }      }      return false; diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp index cac8121c..27f3bf40 100644 --- a/qfunctionconfigurator/functionconfig.cpp +++ b/qfunctionconfigurator/functionconfig.cpp @@ -75,18 +75,6 @@ static bool sortFn(const QPointF& one, const QPointF& two) {      return one.x() < two.x();  } -static inline bool nanp(double value) -{ -    return std::isnan(value) || std::isinf(value); -} - -static inline double elide_nan(double value) -{ -    if (nanp(value)) -        return -1; -    return value; -} -  void Map::reload() {      if (cur.input.size())      { @@ -104,7 +92,7 @@ void Map::reload() {          for (int i = 0; i < sz; i++)              data[i] = -1; -        if (input.size() == 1) +        if (input.size() == 1 && input[0].x() > 1e-2)          {              for (int k = 0; k < input[0].x() * mult; k++) {                  if (k < sz) @@ -144,7 +132,7 @@ void Map::reload() {                                        (-p0_y + 3. * p1_y - 3. * p2_y + p3_y) * t3);                  if (x >= 0 && x < sz) -                    data[x] = elide_nan(y); +                    data[x] = y;              }          }  | 
