From 1e6f070677ebcf2649924f682aa66b939fa874f8 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 9 Aug 2015 04:03:40 +0200 Subject: main: remap axis before mapping Issue: #213 --- opentrack/tracker.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index e03342e4..acbfded5 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -81,7 +81,12 @@ void Tracker::logic() if (!zero_) for (int i = 0; i < 6; i++) { - value(i) = newpose[i]; + auto& axis = m(i); + int k = axis.opts.src; + if (k < 0 || k >= 6) + value(i) = 0; + else + value(i) = newpose[k]; raw(i) = newpose[i]; } else @@ -157,23 +162,10 @@ void Tracker::logic() for (int i = 0; i < 6; i++) value[i] *= inverts[i] ? -1. : 1.; - Pose output_pose_; - - for (int i = 0; i < 6; i++) - { - auto& axis = m(i); - int k = axis.opts.src; - if (k < 0 || k >= 6) - output_pose_(i) = 0; - else - output_pose_(i) = value(k); - } - - - libs.pProtocol->pose(output_pose_); + libs.pProtocol->pose(value); QMutexLocker foo(&mtx); - output_pose = output_pose_; + output_pose = value; raw_6dof = raw; } -- cgit v1.2.3 From 573a78eeda6423ff4ce72dda9f00c366b20672d5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 9 Aug 2015 04:04:32 +0200 Subject: main: apply center pose after compensation Issue: #212 --- opentrack/tracker.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) mode change 100644 => 100755 opentrack/tracker.cpp (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp old mode 100644 new mode 100755 index acbfded5..f31e1185 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -46,7 +46,7 @@ double Tracker::map(double pos, Mapping& axis) axis.curve.setTrackingActive( !altp ); axis.curveAlt.setTrackingActive( altp ); auto& fc = altp ? axis.curveAlt : axis.curve; - return fc.getValue(pos) + axis.opts.zero; + return fc.getValue(pos); } void Tracker::t_compensate(const rmat& rmat, const double* xyz, double* output, bool rz) @@ -149,7 +149,7 @@ void Tracker::logic() if (libs.pFilter) libs.pFilter->filter(tmp, value); } - + for (int i = 0; i < 6; i++) value(i) = map(value(i), m(i)); @@ -158,7 +158,10 @@ void Tracker::logic() value, value, s.tcomp_tz); - + + for (int i = 0; i < 6; i++) + value(i) += m(i).opts.zero; + for (int i = 0; i < 6; i++) value[i] *= inverts[i] ? -1. : 1.; -- cgit v1.2.3 From 32c7d8370faca901162500a26f43a445f4f8e095 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 11 Aug 2015 03:32:23 +0200 Subject: simple-mat: open-code operator()(x, y) calls --- opentrack/simple-mat.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) mode change 100644 => 100755 opentrack/simple-mat.hpp (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp old mode 100644 new mode 100755 index 7432e665..1d3b10e1 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -90,7 +90,7 @@ struct Mat num ret = 0; constexpr int len = vector_len::value; for (int i = 0; i < len; i++) - ret += operator()(i) * p2.operator ()(i); + ret += operator()(i) * p2(i); return ret; } @@ -108,7 +108,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = this->operator ()(j, i) + other(j, i); + ret(j, i) = data[j][i] + other(j, i); return ret; } @@ -117,7 +117,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = this->operator ()(j, i) - other(j, i); + ret(j, i) = data[j][i] - other(j, i); return ret; } @@ -126,7 +126,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = this->operator ()(j, i) + other; + ret(j, i) = data[j][i] + other; return ret; } @@ -135,7 +135,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = this->operator ()(j, i) - other; + ret(j, i) = data[j][i] - other; return ret; } @@ -144,7 +144,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = operator()(j, i) * other; + ret(j, i) = data[j][i] * other; return ret; } -- cgit v1.2.3 From f0f18a08e2f4a82902098df8d54578811919fa67 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 11 Aug 2015 06:41:02 +0200 Subject: simple-mat: open-code more, add comment --- opentrack/simple-mat.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index 1d3b10e1..49bf4feb 100755 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -47,6 +47,9 @@ template struct Mat { num data[h_][w_]; + + // parameters w_ and h_ are rebound so that SFINAE occurs + // removing them causes a compile-time error -sh 20150811 template typename std::enable_if::value, num>::type __inline operator()(int i) const { return data[i][0]; } @@ -108,7 +111,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = data[j][i] + other(j, i); + ret(j, i) = data[j][i] + other.data[j][i]; return ret; } @@ -117,7 +120,7 @@ struct Mat Mat ret; for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - ret(j, i) = data[j][i] - other(j, i); + ret(j, i) = data[j][i] - other.data[j][i]; return ret; } -- cgit v1.2.3 From 0f89e2439ac7a89baf371ce3dd522e96bb933c83 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 13 Aug 2015 09:42:56 +0200 Subject: tracker: use concise syntax for vector access --- opentrack/tracker.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index f31e1185..e79d32c1 100755 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -55,11 +55,11 @@ void Tracker::t_compensate(const rmat& rmat, const double* xyz, double* output, dmat<3, 1> tvec({ xyz[2], -xyz[0], -xyz[1] }); const dmat<3, 1> ret = rmat * tvec; if (!rz) - output[2] = ret(0, 0); + output[2] = ret(0); else output[2] = xyz[2]; - output[1] = -ret(2, 0); - output[0] = -ret(1, 0); + output[1] = -ret(2); + output[0] = -ret(1); } void Tracker::logic() @@ -95,7 +95,7 @@ void Tracker::logic() for (int i = 0; i < 3; i++) { - raw(i+3) = value(i+3) = mat(i, 0) * r2d; + raw(i+3) = value(i+3) = mat(i) * r2d; raw(i) = value(i) = t_b[i]; } } @@ -127,19 +127,19 @@ void Tracker::logic() { centerp = false; for (int i = 0; i < 3; i++) - t_b[i] = t(i, 0); + t_b[i] = t(i); r_b = r; } { - double tmp[3] = { t(0, 0) - t_b[0], t(1, 0) - t_b[1], t(2, 0) - t_b[2] }; + double tmp[3] = { t(0) - t_b[0], t(1) - t_b[1], t(2) - t_b[2] }; t_compensate(cam, tmp, tmp, false); const rmat m_ = r_b.t() * r; const dmat<3, 1> euler = rmat::rmat_to_euler(m_); for (int i = 0; i < 3; i++) { value(i) = tmp[i]; - value(i+3) = euler(i, 0) * r2d; + value(i+3) = euler(i) * r2d; } } -- cgit v1.2.3 From 1ea849d0f6f934beb69ed72790f02d079a7ba435 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 13 Aug 2015 09:43:13 +0200 Subject: tracker: no need to run logic() at all --- opentrack/tracker.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index e79d32c1..22a8933c 100755 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -197,10 +197,6 @@ void Tracker::run() { } { - // do one last pass with origin pose - for (int i = 0; i < 6; i++) - newpose[i] = 0; - logic(); // filter may inhibit exact origin Pose p; libs.pProtocol->pose(p); -- cgit v1.2.3 From dfc157dfba05985caa963ccb22240e238133e066 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 18 Aug 2015 05:50:15 +0200 Subject: simple-mat: don't inline so much --- opentrack/simple-mat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index 49bf4feb..af23d01e 100755 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -89,7 +89,7 @@ struct Mat template typename std::enable_if::value, num>::type - __inline dot(const Mat& p2) const { + dot(const Mat& p2) const { num ret = 0; constexpr int len = vector_len::value; for (int i = 0; i < len; i++) @@ -99,7 +99,7 @@ struct Mat template typename std::enable_if::value, Mat::P, is_dim3::Q>>::type - __inline cross(const Mat& p2) const + cross(const Mat& p2) const { return Mat({y() * p2.z() - p2.y() * z(), p2.x() * z() - x() * p2.z(), -- cgit v1.2.3 From a2c881e36e8522d94831f5486f7408dc58321a42 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 18 Aug 2015 05:50:32 +0200 Subject: simple-mat: __inline -> inline for C++ --- opentrack/simple-mat.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index af23d01e..9f0911cb 100755 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -52,40 +52,40 @@ struct Mat // removing them causes a compile-time error -sh 20150811 template typename std::enable_if::value, num>::type - __inline operator()(int i) const { return data[i][0]; } + inline operator()(int i) const { return data[i][0]; } template typename std::enable_if::value, num>::type - __inline operator()(int i) const { return data[0][i]; } + inline operator()(int i) const { return data[0][i]; } template typename std::enable_if::value, num&>::type - __inline operator()(int i) { return data[i][0]; } + inline operator()(int i) { return data[i][0]; } template typename std::enable_if::value, num&>::type - __inline operator()(int i) { return data[0][i]; } + inline operator()(int i) { return data[0][i]; } template typename std::enable_if::value, num>::type - __inline x() const { return operator()(0); } + inline x() const { return operator()(0); } template typename std::enable_if::value, num>::type - __inline y() const { return operator()(1); } + inline y() const { return operator()(1); } template typename std::enable_if::value, num>::type - __inline z() const { return operator()(2); } + inline z() const { return operator()(2); } template typename std::enable_if::value, num>::type - __inline w() const { return operator()(3); } + inline w() const { return operator()(3); } template typename std::enable_if::value, num&>::type - __inline x() { return operator()(0); } + inline x() { return operator()(0); } template typename std::enable_if::value, num&>::type - __inline y() { return operator()(1); } + inline y() { return operator()(1); } template typename std::enable_if::value, num&>::type - __inline z() { return operator()(2); } + inline z() { return operator()(2); } template typename std::enable_if::value, num&>::type - __inline w() { return operator()(3); } + inline w() { return operator()(3); } template typename std::enable_if::value, num>::type @@ -169,8 +169,8 @@ struct Mat return ret; } - __inline num operator()(int j, int i) const { return data[j][i]; } - __inline num& operator()(int j, int i) { return data[j][i]; } + inline num operator()(int j, int i) const { return data[j][i]; } + inline num& operator()(int j, int i) { return data[j][i]; } Mat(std::initializer_list&& list) { -- cgit v1.2.3 From cfed344344b996aea1e6388031dc20b1d15a25f3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 18 Aug 2015 08:51:28 +0200 Subject: simple-mat: replace initializer_list with variadic ctor Gives us type safety rather than argument count mismatch. Also there's no more narrowing conversion issue. Replace usages. Explicitly delete initializer_list ctor. --- opentrack/simple-mat.hpp | 70 ++++++++++++++++++++++++++++++++++++++---------- opentrack/tracker.cpp | 4 +-- pose-widget/glwidget.cpp | 40 +++++++++++++-------------- 3 files changed, 76 insertions(+), 38 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index 9f0911cb..2b4cb72e 100755 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -41,13 +41,43 @@ namespace { enum { P = a == 1 ? 1 : 3 }; enum { Q = a == 1 ? 3 : 1 }; }; + + template struct assignable; + + template + struct assignable { + enum { value = true }; + }; + + template + struct assignable { + enum { value = std::is_assignable::value && assignable::value }; + }; + + template + struct is_arglist_correct + { + enum { value = h * w == sizeof...(ts) && assignable::value }; + }; } template -struct Mat +class Mat { num data[h_][w_]; + static_assert(h_ > 0 && w_ > 0, "must have positive mat dimensions"); + + struct cast + { + template + static num _(u x) { return static_cast(x); } + }; + + Mat(std::initializer_list&& xs) = delete; + +public: + // parameters w_ and h_ are rebound so that SFINAE occurs // removing them causes a compile-time error -sh 20150811 @@ -101,9 +131,9 @@ struct Mat typename std::enable_if::value, Mat::P, is_dim3::Q>>::type cross(const Mat& p2) const { - return Mat({y() * p2.z() - p2.y() * z(), - p2.x() * z() - x() * p2.z(), - x() * p2.y() - y() * p2.x()}); + return Mat(y() * p2.z() - p2.y() * z(), + p2.x() * z() - x() * p2.z(), + x() * p2.y() - y() * p2.x()); } Mat operator+(const Mat& other) const @@ -161,9 +191,9 @@ struct Mat num sum = num(0); for (int k = 0; k < h_; k++) - sum += data[j][k]*other.data[k][i]; + sum += data[j][k]*other(k, i); - ret.data[j][i] = sum; + ret(j, i) = sum; } return ret; @@ -172,19 +202,29 @@ struct Mat inline num operator()(int j, int i) const { return data[j][i]; } inline num& operator()(int j, int i) { return data[j][i]; } - Mat(std::initializer_list&& list) + template::value>> + Mat(ts const&... xs) { - auto iter = list.begin(); - for (int i = 0; i < h_; i++) - for (int j = 0; j < w_; j++) - data[i][j] = *iter++; + const std::initializer_list init = { cast::_(xs)... }; + auto iter = init.begin(); + for (int j = 0; j < h_; j++) + for (int i = 0; i < w_; i++) + data[j][i] = *iter++; + } + + template + Mat(const t* xs) + { + for (int j = 0; j < h_; j++) + for (int i = 0; i < w_; i++) + data[j][i] = num(*xs++); } Mat() { for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) - data[j][i] = 0; + data[j][i] = num(0); } Mat(const num* mem) @@ -194,6 +234,8 @@ struct Mat data[j][i] = mem[i*h_+j]; } + Mat(num* mem) : Mat(const_cast(mem)) {} + // XXX add more operators as needed, third-party dependencies mostly // not needed merely for matrix algebra -sh 20141030 @@ -237,10 +279,10 @@ struct Mat if (std::abs(pitch_1) + std::abs(roll_1) + std::abs(yaw_1) > std::abs(pitch_2) + std::abs(roll_2) + std::abs(yaw_2)) { bool fix_neg_pitch = pitch_1 < 0; - return dmat<3, 1>({yaw_2, std::fmod(fix_neg_pitch ? -pi - pitch_1 : pitch_2, pi), roll_2}); + return dmat<3, 1>(yaw_2, std::fmod(fix_neg_pitch ? -pi - pitch_1 : pitch_2, pi), roll_2); } else - return dmat<3, 1>({yaw_1, pitch_1, roll_1}); + return dmat<3, 1>(yaw_1, pitch_1, roll_1); } // tait-bryan angles, not euler diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index 22a8933c..403e87c5 100755 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -52,7 +52,7 @@ double Tracker::map(double pos, Mapping& axis) void Tracker::t_compensate(const rmat& rmat, const double* xyz, double* output, bool rz) { // TY is really yaw axis. need swapping accordingly. - dmat<3, 1> tvec({ xyz[2], -xyz[0], -xyz[1] }); + dmat<3, 1> tvec( xyz[2], -xyz[0], -xyz[1] ); const dmat<3, 1> ret = rmat * tvec; if (!rz) output[2] = ret(0); @@ -107,7 +107,7 @@ void Tracker::logic() }; const rmat cam = rmat::euler_to_rmat(off); rmat r = rmat::euler_to_rmat(&value[Yaw]); - dmat<3, 1> t { value(0), value(1), value(2) }; + dmat<3, 1> t(value(0), value(1), value(2)); r = cam * r; diff --git a/pose-widget/glwidget.cpp b/pose-widget/glwidget.cpp index 6c04c4e6..334c845b 100755 --- a/pose-widget/glwidget.cpp +++ b/pose-widget/glwidget.cpp @@ -45,14 +45,10 @@ void GLWidget::rotateBy(float xAngle, float yAngle, float zAngle, float x, float float c3 = cos(zAngle / 57.295781); float s3 = sin(zAngle / 57.295781); - float foo[] = { - c2*c3, -c2*s3, s2, - c1*s3+c3*s1*s2, c1*c3-s1*s2*s3, -c2*s1, - s1*s3-c1*c3*s2, c3*s1+c1*s2*s3, c1*c2, - }; - - rotation = rmat(foo); - translation = vec3({x, y, z}); + rotation = rmat(c2*c3, -c2*s3, s2, + c1*s3+c3*s1*s2, c1*c3-s1*s2*s3, -c2*s1, + s1*s3-c1*c3*s2, c3*s1+c1*s2*s3, c1*c2); + translation = vec3(x, y, z); update(); } @@ -68,8 +64,8 @@ public: const vec2& p3) { origin = p1; - v0 = vec2({ p3.x() - p1.x(), p3.y() - p1.y() }); - v1 = vec2({ p2.x() - p1.x(), p2.y() - p1.y() }); + v0 = vec2(p3.x() - p1.x(), p3.y() - p1.y()); + v1 = vec2(p2.x() - p1.x(), p2.y() - p1.y()); dot00 = v0.dot(v0); dot01 = v0.dot(v1); dot11 = v1.dot(v1); @@ -82,7 +78,7 @@ public: const num dot02 = v0.dot(v2); const num u = (dot11 * dot02 - dot01 * dot12) * invDenom; const num v = (dot00 * dot12 - dot01 * dot02) * invDenom; - uv = vec2({u, v}); + uv = vec2(u, v); return (u >= 0) && (v >= 0) && (u + v <= 1); } @@ -107,19 +103,19 @@ void GLWidget::project_quad_texture() { const int sx = width(), sy = height(); vec2 pt[4]; const vec3 corners[] = { - vec3({0., 0, 0}), - vec3({sx-1, 0, 0}), - vec3({0, sy-1, 0}), - vec3({sx-1, sy-1, 0.}) + vec3(0., 0, 0), + vec3(sx-1, 0, 0), + vec3(0, sy-1, 0), + vec3(sx-1, sy-1, 0.) }; for (int i = 0; i < 4; i++) { - pt[i] = project(vec3({corners[i].x() - sx/2, corners[i].y() - sy/2, 0})); + pt[i] = project(vec3(corners[i].x() - sx/2, corners[i].y() - sy/2, 0)); pt[i].x() += sx/2.; pt[i].y() += sy/2.; } - vec3 normal1({0, 0, 1}); + vec3 normal1(0, 0, 1); vec3 normal2; { vec3 foo[3]; @@ -137,15 +133,15 @@ void GLWidget::project_quad_texture() { vec2 p2[4]; for (int i = 0; i < 4; i++) - p2[i] = vec2({pt[i].x(), pt[i].y()}); + p2[i] = vec2(pt[i].x(), pt[i].y()); QImage texture(QSize(sx, sy), QImage::Format_RGB888); QColor bgColor = palette().color(QPalette::Current, QPalette::Window); texture.fill(bgColor); const vec2 projected[2][3] = { { p2[0], p2[1], p2[2] }, { p2[3], p2[1], p2[2] } }; const vec2 origs[2][3] = { - { vec2({0, 0}), vec2({ow-1, 0}), vec2({0, oh-1}) }, - { vec2({ow-1, oh-1}), vec2({ow-1, 0}), vec2({0, oh-1}) } + { vec2(0, 0), vec2(ow-1, 0), vec2(0, oh-1) }, + { vec2(ow-1, oh-1), vec2(ow-1, 0), vec2(0, oh-1) } }; const Triangle triangles[2] = { Triangle(projected[0][0], projected[0][1], projected[0][2]), @@ -167,7 +163,7 @@ void GLWidget::project_quad_texture() { for (int y = 0; y < sy; y++) for (int x = 0; x < sx; x++) { - vec2 pos({x, y}); + vec2 pos(x, y); for (int i = 0; i < 2; i++) { vec2 uv; if (triangles[i].barycentric_coords(pos, uv)) @@ -205,7 +201,7 @@ GLWidget::vec2 GLWidget::project(const vec3 &point) num y = h * translation.y() / 2 / -40; if (std::abs(y) > h/2) y = y > 0 ? h/2 : h/-2; - return vec2 { z * (ret.x() + x), z * (ret.y() + y) }; + return vec2(z * (ret.x() + x), z * (ret.y() + y)); } GLWidget::vec3 GLWidget::project2(const vec3 &point) -- cgit v1.2.3 From 4ab33fdfbb23fdfed5327d402989fd53d79f5380 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 22 Aug 2015 19:02:25 +0200 Subject: main, ui: store config files in a predefined directory Settings files are now stored in Documents/opentrack-version. The transition path is to copy all .ini files into that directory, accessible through the "Profile" menu dropdown. Issue: #179 --- facetracknoir/main.ui | 1900 ++++++++++---------- facetracknoir/new_config.ui | 45 + facetracknoir/new_file_dialog.h | 48 + facetracknoir/ui.cpp | 172 +- facetracknoir/ui.h | 15 +- .../ftnoir_tracker_hat_settings.cpp | 21 +- opentrack/options.hpp | 53 +- 7 files changed, 1207 insertions(+), 1047 deletions(-) create mode 100644 facetracknoir/new_config.ui create mode 100644 facetracknoir/new_file_dialog.h mode change 100755 => 100644 facetracknoir/ui.cpp (limited to 'opentrack') diff --git a/facetracknoir/main.ui b/facetracknoir/main.ui index 2328be40..f240a510 100644 --- a/facetracknoir/main.ui +++ b/facetracknoir/main.ui @@ -7,8 +7,8 @@ 0 0 - 708 - 504 + 707 + 492 @@ -53,13 +53,7 @@ 0 - - - 0 - - - 0 - + 0 @@ -72,728 +66,755 @@ 0 + + 0 + - - - - 0 - 0 - - - - - 480 - 360 - - - - - 480 - 360 - - - - - - 0 - 0 - 480 - 360 - - - - - 0 - 0 - - - - - - 0 - 0 - 480 - 360 - - - - - 0 - 0 - - - - - 480 - 360 - - - - - 480 - 360 - - - - - - - - - - - + QFrame::NoFrame - - 0 - - + - 12 + 0 - 6 + 0 - 12 + 0 - 8 + 0 - 4 + 0 - + - + 0 0 - + - 80 - 90 + 480 + 360 - - - - - - - 0 - 0 - - - - Raw tracker data + + + 480 + 360 + - - - 0 - - - 0 + + + + 0 + 0 + 480 + 360 + - - 0 - - - 0 + + + 0 + 0 + - - 3 - - - 2 - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - yaw - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - roll - - - - - - - true - - - - 0 - 0 - - - - false - - - QFrame::Raised - - - TZ - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - pitch - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - TX - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - true - - - 4 - - - QLCDNumber::Outline - - - - - - - true - - - - 0 - 0 - - - - false - - - QFrame::Raised - - - TY - - - - + + + + 0 + 0 + 480 + 360 + + + + + 0 + 0 + + + + + 480 + 360 + + + + + 480 + 360 + + + + + + + - - - - 0 - 0 - + + + QFrame::NoFrame - - Game data + + 0 - + + + 12 + - 0 + 6 - 0 - - - 0 - - - 0 - - - 3 - - - 2 - - - - - true - - - - 0 - 0 - - - - false - - - QFrame::Raised - - - TY - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - pitch - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - yaw - - - - - - - - 0 - 0 - - - - QFrame::Raised - - - roll - - - - - - - true - - - - 0 - 0 - - - - false - - - QFrame::Raised - - - TZ - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat - - - - - - - true - - - - 0 - 0 - - - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat - - - - - - - true - + 12 + + + 8 + + + 4 + + + - + 0 0 - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat + + + 80 + 90 + - - + + - + 0 0 - - QFrame::Raised - - - TX - + + Raw tracker data + + + + 0 + + + 0 + + + 0 + + + 0 + + + 3 + + + 2 + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + yaw + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + roll + + + + + + + true + + + + 0 + 0 + + + + false + + + QFrame::Raised + + + TZ + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + pitch + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + TX + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + true + + + 4 + + + QLCDNumber::Outline + + + + + + + true + + + + 0 + 0 + + + + false + + + QFrame::Raised + + + TY + + + + - - - - true - + + - + 0 0 - - QFrame::NoFrame - - - true - - - 4 - - - QLCDNumber::Flat - + + Game data + + + + 0 + + + 0 + + + 0 + + + 0 + + + 3 + + + 2 + + + + + true + + + + 0 + 0 + + + + false + + + QFrame::Raised + + + TY + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + pitch + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + yaw + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + roll + + + + + + + true + + + + 0 + 0 + + + + false + + + QFrame::Raised + + + TZ + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + + + + + 0 + 0 + + + + QFrame::Raised + + + TX + + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + true + + + 4 + + + QLCDNumber::Flat + + + + @@ -802,112 +823,142 @@ - + + + + 0 + 0 + + + + 4 + - 0 + 8 + + + 10 0 - 6 + 4 0 - - + + + + + 4 + 0 + + - Controls + Settings true - + + + 3 + 4 - 12 + 2 - 4 + 0 - 12 + 6 - - - - false - - - - 0 - 0 - - - - Stop - - - - - + + - + 0 - 0 + 2 - - Start - + + + 0 + + + 0 + + + 2 + + + 2 + + + + + true + + + + 0 + 0 + + + + Profile + + + QToolButton::InstantPopup + + + Qt::ToolButtonTextBesideIcon + + + true + + + Qt::DownArrow + + + + + + + + 0 + 0 + + + + 10 + + + + - - - - - - - Settings - - - true - - - - 4 - - - 0 - - - 4 - - - 4 - - - 2 - - - + + - + 0 - 0 + 3 - Options + Mapping - :/images/tools.png:/images/tools.png + :/images/curves.png:/images/curves.png @@ -917,20 +968,20 @@ - - + + - + 0 - 0 + 3 - Mapping + Options - :/images/curves.png:/images/curves.png + :/images/tools.png:/images/tools.png @@ -943,230 +994,225 @@ - - + + + + + 3 + 0 + + - Filter + Controls true - + + + 8 + - 4 + 0 - 0 + 8 - 4 + 0 - 4 - - - 3 - - - 2 + 9 - - - - - - - true + + + + + 0 + 0 + - ... - - - false + Start - - - - - - - Tracker - - - true - - - - 4 - - - 0 - - - 4 - - - 4 - - - 3 - - - 2 - - - - - - + + - true - - - ... - - false - - - - - - - - - Protocol - - - true - - - - 4 - - - 0 - - - 4 - - - 4 - - - 3 - - - 2 - - - - - true + + + 0 + 0 + - ... - - - false + Stop - - - - + - - 0 + + 4 0 - - Profile + + QFrame::NoFrame - - true + + QFrame::Raised - + + + 2 + - 4 + 3 - 0 + 2 - 4 + 3 - 4 + 8 - - 2 - - - - - - 0 - 0 - - - - 10 - - - - - - - - 0 - 0 - - - - Load - + + + + Tracker + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + + + true + + + ... + + + false + + + + - - - - true - - - - 0 - 0 - - - - Save - + + + + Protocol + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + + + true + + + ... + + + false + + + + - - - - true - - - - 0 - 0 - - - - Save... - + + + + Filter + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + + + true + + + ... + + + false + + + + @@ -1197,10 +1243,6 @@ btnShowServerControls iconcomboFilter btnShowFilterControls - iconcomboProfile - btnLoad - btnSave - btnSaveAs btnEditCurves btnShortcuts diff --git a/facetracknoir/new_config.ui b/facetracknoir/new_config.ui new file mode 100644 index 00000000..27dce0f8 --- /dev/null +++ b/facetracknoir/new_config.ui @@ -0,0 +1,45 @@ + + + UI_new_config + + + Qt::ApplicationModal + + + + 0 + 0 + 269 + 67 + + + + Config filename + + + + images/facetracknoir.pngimages/facetracknoir.png + + + + + + New file name: + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/facetracknoir/new_file_dialog.h b/facetracknoir/new_file_dialog.h new file mode 100644 index 00000000..dc821592 --- /dev/null +++ b/facetracknoir/new_file_dialog.h @@ -0,0 +1,48 @@ +#pragma once + +#include "ui_new_config.h" +#include "opentrack/options.hpp" +#include +#include +#include +#include + +class new_file_dialog : public QDialog +{ + Q_OBJECT +public: + new_file_dialog(QWidget* parent = 0) : QDialog(parent), ok(false) + { + ui.setupUi(this); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(ok_clicked())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(cancel_clicked())); + setFixedSize(size()); + } + bool is_ok(QString& name_) + { + name_ = name; + return ok; + } +private: + Ui::UI_new_config ui; + bool ok; + QString name; +private slots: + void cancel_clicked() { close(); } + void ok_clicked() + { + QString text = ui.lineEdit->text(); + text = text.replace('/', ""); + text = text.replace('\\', ""); + if (text == "" || QFile(options::group::ini_directory() + "/" + text).exists()) + { + QMessageBox::warning(this, + "File exists", "This file already exists. Pick another name.", + QMessageBox::Ok, QMessageBox::NoButton); + return; + } + ok = true; + close(); + name = text; + } +}; diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp old mode 100755 new mode 100644 index 3f87ca2f..958a2439 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -33,7 +33,10 @@ #include "ui.h" #include "opentrack/tracker.h" #include "opentrack/options.hpp" +#include "facetracknoir/new_file_dialog.h" #include +#include +#include #ifndef _WIN32 # include @@ -53,10 +56,6 @@ MainWindow::MainWindow() : updateButtonState(false, false); ui.video_frame_label->setPixmap(no_feed_pixmap); - connect(ui.btnLoad, SIGNAL(clicked()), this, SLOT(open())); - connect(ui.btnSave, SIGNAL(clicked()), this, SLOT(save())); - connect(ui.btnSaveAs, SIGNAL(clicked()), this, SLOT(saveAs())); - connect(ui.btnEditCurves, SIGNAL(clicked()), this, SLOT(showCurveConfiguration())); connect(ui.btnShortcuts, SIGNAL(clicked()), this, SLOT(showKeyboardShortcuts())); connect(ui.btnShowEngineControls, SIGNAL(clicked()), this, SLOT(showTrackerSettings())); @@ -74,7 +73,7 @@ MainWindow::MainWindow() : for (auto x : modules.filters()) ui.iconcomboFilter->addItem(x->icon, x->name); - fill_profile_combobox(); + refresh_config_list(); tie_setting(s.tracker_dll, ui.iconcomboTrackerSource); tie_setting(s.protocol_dll, ui.iconcomboProtocol); @@ -82,15 +81,15 @@ MainWindow::MainWindow() : connect(ui.iconcomboTrackerSource, static_cast(&QComboBox::currentIndexChanged), - [&](int) -> void { if (pTrackerDialog) pTrackerDialog = nullptr; }); + [&](int) -> void { if (pTrackerDialog) pTrackerDialog = nullptr; save(); }); connect(ui.iconcomboProtocol, static_cast(&QComboBox::currentIndexChanged), - [&](int) -> void { if (pProtocolDialog) pProtocolDialog = nullptr; }); + [&](int) -> void { if (pProtocolDialog) pProtocolDialog = nullptr; save(); }); connect(ui.iconcomboFilter, static_cast(&QComboBox::currentIndexChanged), - [&](int) -> void { if (pFilterDialog) pFilterDialog = nullptr; }); + [&](int) -> void { if (pFilterDialog) pFilterDialog = nullptr; save(); }); connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); @@ -98,14 +97,46 @@ MainWindow::MainWindow() : connect(&pose_update_timer, SIGNAL(timeout()), this, SLOT(showHeadPose())); connect(&kbd_quit, SIGNAL(activated()), this, SLOT(exit())); + + auto menu = new QMenu; + menu->addAction("Create new empty config", this, SLOT(make_empty_config())); + menu->addAction("Create new copied config", this, SLOT(make_copied_config())); + menu->addAction("Open configuration directory", this, SLOT(open_config_directory())); + menu->addAction("Refresh configuration list", this, SLOT(refresh_config_list())); + ui.profile_button->setMenu(menu); + kbd_quit.setEnabled(true); connect(&det_timer, SIGNAL(timeout()), this, SLOT(maybe_start_profile_from_executable())); det_timer.start(1000); ensure_tray(); - set_working_directory(); + + if (!QFile(group::ini_pathname()).exists()) + { + set_profile(OPENTRACK_DEFAULT_CONFIG); + if (!QFile(group::ini_pathname()).exists()) + { + const auto pathname = group::ini_pathname(); + QFile file(pathname); + if (file.open(QFile::ReadWrite)) + { + QTextStream stream(&file); + stream << "\n"; + } + } + } +} + +bool MainWindow::get_new_config_name_from_dialog(QString& ret) +{ + new_file_dialog dlg; + dlg.exec(); + bool b = dlg.is_ok(ret); + if (b && !ret.endsWith(".ini")) + ret += ".ini"; + return b; } MainWindow::~MainWindow() @@ -121,27 +152,6 @@ void MainWindow::set_working_directory() QDir::setCurrent(QCoreApplication::applicationDirPath()); } -void MainWindow::open() { - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::ExistingFile); - QString dir_path = QFileInfo(group::ini_pathname()).absolutePath(); - QString fileName = dialog.getOpenFileName( - this, - tr("Open the settings file"), - dir_path, - tr("Settings file (*.ini);;All Files (*)")); - set_working_directory(); - - if (!fileName.isEmpty()) { - { - QSettings settings(OPENTRACK_ORG); - settings.setValue(OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(fileName)); - } - fill_profile_combobox(); - load_settings(); - } -} - void MainWindow::save_mappings() { pose.save_mappings(); } @@ -164,29 +174,6 @@ void MainWindow::save() { #endif } -void MainWindow::saveAs() -{ - QString oldFile = group::ini_pathname(); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), - oldFile, - tr("Settings file (*.ini);;All Files (*)")); - set_working_directory(); - - if (fileName.isEmpty()) - return; - - (void) QFile::remove(fileName); - - { - (void) QFile::copy(oldFile, fileName); - QSettings settings(OPENTRACK_ORG); - settings.setValue (OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(fileName)); - } - - save(); - fill_profile_combobox(); -} - void MainWindow::load_mappings() { pose.load_mappings(); } @@ -196,10 +183,59 @@ void MainWindow::load_settings() { load_mappings(); } +void MainWindow::make_empty_config() +{ + QString name; + const QString dir = group::ini_directory(); + if (dir != "" && get_new_config_name_from_dialog(name)) + { + QFile filename(dir + "/" + name); + if (filename.open(QFile::ReadWrite)) + { + QTextStream stream(&filename); + stream << "\n"; + refresh_config_list(); + } + } +} + +void MainWindow::make_copied_config() +{ + const QString dir = group::ini_directory(); + const QString cur = group::ini_pathname(); + QString name; + if (cur != "" && dir != "" && get_new_config_name_from_dialog(name)) + { + const QString new_name = dir + "/" + name; + (void) QFile::remove(new_name); + (void) QFile::copy(cur, new_name); + refresh_config_list(); + } +} + +void MainWindow::open_config_directory() +{ + const QString path = group::ini_directory(); + if (path != "") + { + QDesktopServices::openUrl("file:///" + QDir::toNativeSeparators(path)); + } +} + extern "C" volatile const char* opentrack_version; -void MainWindow::fill_profile_combobox() +void MainWindow::refresh_config_list() { + if (group::ini_list().size() == 0) + { + QFile filename(group::ini_directory() + "/" OPENTRACK_DEFAULT_CONFIG); + if (filename.open(QFile::ReadWrite)) + { + QTextStream stream(&filename); + stream << "\n"; + } + } + QStringList ini_list = group::ini_list(); set_title(); QString current = QFileInfo(group::ini_pathname()).fileName(); @@ -219,8 +255,7 @@ void MainWindow::updateButtonState(bool running, bool inertialp) ui.iconcomboFilter->setEnabled ( not_running ); ui.iconcomboTrackerSource->setEnabled(not_running); ui.video_frame_label->setVisible(not_running || inertialp); - ui.btnSaveAs->setEnabled(not_running); - ui.btnLoad->setEnabled(not_running); + ui.profile_button->setEnabled(not_running); } void MainWindow::bindKeyboardShortcuts() @@ -440,26 +475,6 @@ void MainWindow::exit() { QCoreApplication::exit(0); } -QString MainWindow::remove_app_path(const QString full_path) -{ - QFileInfo path_info(full_path); - QString path = path_info.absolutePath(); - - QFileInfo app_path(QCoreApplication::applicationDirPath()); - QString app_prefix(app_path.absoluteFilePath()); - - if (path == app_prefix) - { - path = "."; - } - else if (path.startsWith(app_prefix + "/")) - { - path = "./" + path.mid(app_prefix.size() + 1); - } - - return path + "/" + path_info.fileName(); -} - void MainWindow::profileSelected(int index) { if (index == -1) @@ -467,8 +482,7 @@ void MainWindow::profileSelected(int index) { QSettings settings(OPENTRACK_ORG); - settings.setValue (OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(QFileInfo(group::ini_pathname()).absolutePath() + "/" + - ui.iconcomboProfile->itemText(index))); + settings.setValue (OPENTRACK_CONFIG_FILENAME_KEY, ui.iconcomboProfile->itemText(index)); } set_title(); @@ -550,5 +564,5 @@ void MainWindow::maybe_start_profile_from_executable() void MainWindow::set_profile(const QString &profile) { QSettings settings(OPENTRACK_ORG); - settings.setValue(OPENTRACK_CONFIG_FILENAME_KEY, MainWindow::remove_app_path(profile)); + settings.setValue(OPENTRACK_CONFIG_FILENAME_KEY, profile); } diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h index 097b2439..0c3063d4 100644 --- a/facetracknoir/ui.h +++ b/facetracknoir/ui.h @@ -93,22 +93,20 @@ class MainWindow : public QMainWindow, private State void changeEvent(QEvent* e) override; - void createIconGroupBox(); void load_settings(); void updateButtonState(bool running, bool inertialp); - void fill_profile_combobox(); void display_pose(const double* mapped, const double* raw); void ensure_tray(); void set_title(const QString& game_title = QStringLiteral("")); + void save(); + static bool get_new_config_name_from_dialog(QString &ret); + static void set_profile(const QString& profile); public slots: void shortcutRecentered(); void shortcutToggled(); void shortcutZeroed(); void bindKeyboardShortcuts(); private slots: - void open(); - void save(); - void saveAs(); void exit(); void profileSelected(int index); @@ -121,6 +119,11 @@ private slots: void restore_from_tray(QSystemTrayIcon::ActivationReason); void maybe_start_profile_from_executable(); + + void make_empty_config(); + void make_copied_config(); + void open_config_directory(); + void refresh_config_list(); public slots: void startTracker(); void stopTracker(); @@ -129,7 +132,5 @@ public: ~MainWindow(); void save_mappings(); void load_mappings(); - static QString remove_app_path(const QString full_path); static void set_working_directory(); - static void set_profile(const QString& profile); }; diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp index 80543e7a..0a4454e4 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp @@ -35,15 +35,11 @@ void TrackerSettings::load_ini() { -#ifdef OPENTRACK_API +#ifndef OPENTRACK_API QSettings settings(OPENTRACK_ORG); // Registry settings (in HK_USER) + QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); #else - QSettings settings("opentrack"); // Registry settings (in HK_USER) -#endif -#ifdef OPENTRACK_API - QString currentFile = settings.value( OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH ).toString(); -#else - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); + QString currentFile = options::group::ini_pathname(); #endif QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) @@ -101,19 +97,14 @@ void TrackerSettings::load_ini() iniFile.endGroup(); } - void TrackerSettings::save_ini() const { -#ifdef OPENTRACK_API +#ifndef OPENTRACK_API QSettings settings(OPENTRACK_ORG); // Registry settings (in HK_USER) + QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); #else - QSettings settings("opentrack"); // Registry settings (in HK_USER) -#endif -#ifdef OPENTRACK_API - QString currentFile = settings.value( OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH ).toString(); -#else - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); + QString currentFile = options::group::ini_pathname(); #endif QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) diff --git a/opentrack/options.hpp b/opentrack/options.hpp index f4deb8a1..8e623092 100644 --- a/opentrack/options.hpp +++ b/opentrack/options.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -38,8 +39,8 @@ #include template using mem = std::shared_ptr; -#define OPENTRACK_CONFIG_FILENAME_KEY "settings-file" -#define OPENTRACK_DEFAULT_CONFIG_PATH "/settings/default.ini" +#define OPENTRACK_CONFIG_FILENAME_KEY "settings-filename" +#define OPENTRACK_DEFAULT_CONFIG "default.ini" #define OPENTRACK_ORG "opentrack-2.3" namespace options { @@ -90,30 +91,30 @@ namespace options { public: group(const string& name) : name(name) { - QSettings conf(ini_pathname(), QSettings::IniFormat); + auto conf = ini_file(); auto q_name = QString::fromStdString(name); - conf.beginGroup(q_name); - for (auto& k_ : conf.childKeys()) + conf->beginGroup(q_name); + for (auto& k_ : conf->childKeys()) { auto tmp = k_.toUtf8(); string k(tmp); - kvs[k] = conf.value(k_); + kvs[k] = conf->value(k_); } - conf.endGroup(); + conf->endGroup(); } void save() { - QSettings s(ini_pathname(), QSettings::IniFormat); + auto s = ini_file(); auto q_name = QString::fromStdString(name); - s.beginGroup(q_name); + s->beginGroup(q_name); for (auto& i : kvs) { auto k = QString::fromStdString(i.first); - s.setValue(k, i.second); + s->setValue(k, i.second); } - s.endGroup(); - s.sync(); + s->endGroup(); + s->sync(); } template @@ -132,22 +133,40 @@ namespace options { return kvs.count(s) != 0; } - static const QString ini_pathname() + static QString ini_directory() { + const auto dirs = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + if (dirs.size() == 0) + return ""; + if (QDir(dirs[0]).mkpath(OPENTRACK_ORG)) + return dirs[0] + "/" OPENTRACK_ORG; + return ""; + } + + static QString ini_pathname() + { + const auto dir = ini_directory(); + if (dir == "") + return ""; QSettings settings(OPENTRACK_ORG); - return settings.value(OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH).toString(); + return dir + "/" + settings.value(OPENTRACK_CONFIG_FILENAME_KEY, OPENTRACK_DEFAULT_CONFIG).toString(); } static const QStringList ini_list() { - QFileInfo info(group::ini_pathname()); - QDir settings_dir(info.dir()); + const auto dirname = ini_directory(); + if (dirname == "") + return QStringList(); + QDir settings_dir(dirname); return settings_dir.entryList( QStringList { "*.ini" } , QDir::Files, QDir::Name ); } static const mem ini_file() { - return std::make_shared(ini_pathname(), QSettings::IniFormat); + const auto pathname = ini_pathname(); + if (pathname != "") + return std::make_shared(ini_pathname(), QSettings::IniFormat); + return std::make_shared(); } }; -- cgit v1.2.3 From 21cd2c012ef23ec3f4b374d82056f1fa1694d904 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 22 Aug 2015 19:02:57 +0200 Subject: props changed only Some source files had executable bit on. Remove it. --- CMakeLists.txt | 0 bin/NPClient.dll | Bin bin/NPClient64.dll | Bin bin/freetrackclient.dll | Bin clientfiles/make-csv.pl | 0 csv/csv.cpp | 0 facetracknoir/keyboard.h | 0 facetracknoir/process_detector.cpp | 0 facetracknoir/process_detector.h | 0 ftnoir_filter_kalman/ftnoir_filter_kalman.h | 0 ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp | 0 ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 0 ftnoir_tracker_aruco/include/markerdetector.h | 0 ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 0 ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | 0 opentrack-compat/process-list.hpp | 0 opentrack/simple-mat.hpp | 0 opentrack/tracker.cpp | 0 opentrack/win32-shortcuts.cpp | 0 opentrack/win32-shortcuts.h | 0 pose-widget/glwidget.cpp | 0 pose-widget/glwidget.h | 0 qfunctionconfigurator/functionconfig.cpp | 0 23 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 CMakeLists.txt mode change 100755 => 100644 bin/NPClient.dll mode change 100755 => 100644 bin/NPClient64.dll mode change 100755 => 100644 bin/freetrackclient.dll mode change 100755 => 100644 clientfiles/make-csv.pl mode change 100755 => 100644 csv/csv.cpp mode change 100755 => 100644 facetracknoir/keyboard.h mode change 100755 => 100644 facetracknoir/process_detector.cpp mode change 100755 => 100644 facetracknoir/process_detector.h mode change 100755 => 100644 ftnoir_filter_kalman/ftnoir_filter_kalman.h mode change 100755 => 100644 ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp mode change 100755 => 100644 ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp mode change 100755 => 100644 ftnoir_tracker_aruco/include/markerdetector.h mode change 100755 => 100644 ftnoir_tracker_pt/ftnoir_tracker_pt.cpp mode change 100755 => 100644 ftnoir_tracker_udp/ftnoir_tracker_udp.cpp mode change 100755 => 100644 opentrack-compat/process-list.hpp mode change 100755 => 100644 opentrack/simple-mat.hpp mode change 100755 => 100644 opentrack/tracker.cpp mode change 100755 => 100644 opentrack/win32-shortcuts.cpp mode change 100755 => 100644 opentrack/win32-shortcuts.h mode change 100755 => 100644 pose-widget/glwidget.cpp mode change 100755 => 100644 pose-widget/glwidget.h mode change 100755 => 100644 qfunctionconfigurator/functionconfig.cpp (limited to 'opentrack') diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/bin/NPClient.dll b/bin/NPClient.dll old mode 100755 new mode 100644 diff --git a/bin/NPClient64.dll b/bin/NPClient64.dll old mode 100755 new mode 100644 diff --git a/bin/freetrackclient.dll b/bin/freetrackclient.dll old mode 100755 new mode 100644 diff --git a/clientfiles/make-csv.pl b/clientfiles/make-csv.pl old mode 100755 new mode 100644 diff --git a/csv/csv.cpp b/csv/csv.cpp old mode 100755 new mode 100644 diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h old mode 100755 new mode 100644 diff --git a/facetracknoir/process_detector.cpp b/facetracknoir/process_detector.cpp old mode 100755 new mode 100644 diff --git a/facetracknoir/process_detector.h b/facetracknoir/process_detector.h old mode 100755 new mode 100644 diff --git a/ftnoir_filter_kalman/ftnoir_filter_kalman.h b/ftnoir_filter_kalman/ftnoir_filter_kalman.h old mode 100755 new mode 100644 diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_aruco/include/markerdetector.h b/ftnoir_tracker_aruco/include/markerdetector.h old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp old mode 100755 new mode 100644 diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp old mode 100755 new mode 100644 diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp old mode 100755 new mode 100644 diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp old mode 100755 new mode 100644 diff --git a/opentrack/win32-shortcuts.cpp b/opentrack/win32-shortcuts.cpp old mode 100755 new mode 100644 diff --git a/opentrack/win32-shortcuts.h b/opentrack/win32-shortcuts.h old mode 100755 new mode 100644 diff --git a/pose-widget/glwidget.cpp b/pose-widget/glwidget.cpp old mode 100755 new mode 100644 diff --git a/pose-widget/glwidget.h b/pose-widget/glwidget.h old mode 100755 new mode 100644 diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp old mode 100755 new mode 100644 -- cgit v1.2.3 From 48339aa148200f0f9cdf8ff61b17413ff1dacc87 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 22 Aug 2015 20:23:35 +0200 Subject: simple-mat: can use static_cast here --- opentrack/simple-mat.hpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index 2b4cb72e..ca60c54d 100644 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -68,12 +68,6 @@ class Mat static_assert(h_ > 0 && w_ > 0, "must have positive mat dimensions"); - struct cast - { - template - static num _(u x) { return static_cast(x); } - }; - Mat(std::initializer_list&& xs) = delete; public: @@ -205,7 +199,7 @@ public: template::value>> Mat(ts const&... xs) { - const std::initializer_list init = { cast::_(xs)... }; + const std::initializer_list init = { static_cast(xs)... }; auto iter = init.begin(); for (int j = 0; j < h_; j++) for (int i = 0; i < w_; i++) -- cgit v1.2.3 From 9cd5ab67dbe347d1f4dcf4a6eb3f4fd7e3d89dab Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 22 Aug 2015 20:25:32 +0200 Subject: simple-mat: fix arglist SFINAE Constructor was always available, enable_if faultily allowed it to accept an arbitrary amount of parameters. The `assignable' bit is redundant and broken, anyway static_cast(x)... takes care of type compatibility. --- opentrack/simple-mat.hpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index ca60c54d..c603a2cb 100644 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -42,22 +42,10 @@ namespace { enum { Q = a == 1 ? 3 : 1 }; }; - template struct assignable; - - template - struct assignable { - enum { value = true }; - }; - - template - struct assignable { - enum { value = std::is_assignable::value && assignable::value }; - }; - template struct is_arglist_correct { - enum { value = h * w == sizeof...(ts) && assignable::value }; + enum { value = h * w == sizeof...(ts) }; }; } @@ -196,7 +184,8 @@ public: inline num operator()(int j, int i) const { return data[j][i]; } inline num& operator()(int j, int i) { return data[j][i]; } - template::value>> + template::value>::type> Mat(ts const&... xs) { const std::initializer_list init = { static_cast(xs)... }; -- cgit v1.2.3 From 8f61232b36e5988e3bb89ad42b821c89c57073d7 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Aug 2015 10:05:27 +0200 Subject: plugin-support: free modules from address space when needed This is groundwork for #226, even though modules still need not to load all at once and persist till program stop. This issue only affects Linux. --- opentrack/plugin-support.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack') diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index ec8bb3c8..c2c1b048 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -103,7 +103,7 @@ struct dylib { # if defined(__APPLE__) RTLD_LOCAL|RTLD_FIRST|RTLD_NOW # else - RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE + RTLD_NOW|RTLD_GLOBAL # endif ); -- cgit v1.2.3 From 0d9427dd929ca51d65a1ab08b26710647769793c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Aug 2015 10:07:46 +0200 Subject: plugin-support: set more sane RTLD flags We might need RTLD_DEEPBIND if there are symbol-related crashes. --- opentrack/plugin-support.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack') diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index c2c1b048..a9008840 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -103,7 +103,7 @@ struct dylib { # if defined(__APPLE__) RTLD_LOCAL|RTLD_FIRST|RTLD_NOW # else - RTLD_NOW|RTLD_GLOBAL + RTLD_LOCAL|RTLD_NOW|RTLD_NOW // XXX RTLD_DEEPBIND on Linux? # endif ); -- cgit v1.2.3 From b1c4466ddeb84ec9b6c19f64906458754f68b135 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Aug 2015 10:11:29 +0200 Subject: plugin-support: fix typo --- opentrack/plugin-support.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack') diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index a9008840..8b9cf58a 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -103,7 +103,7 @@ struct dylib { # if defined(__APPLE__) RTLD_LOCAL|RTLD_FIRST|RTLD_NOW # else - RTLD_LOCAL|RTLD_NOW|RTLD_NOW // XXX RTLD_DEEPBIND on Linux? + RTLD_LOCAL|RTLD_NOW // XXX RTLD_DEEPBIND on Linux? # endif ); -- cgit v1.2.3 From 8adcd7acc7280c84a959db0da2d79a0ed918a1ca Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 26 Aug 2015 19:53:40 +0200 Subject: options: return .ini basename easier --- facetracknoir/ui.cpp | 4 ++-- opentrack/options.hpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'opentrack') diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index 6aa47fb6..15c94bd7 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -203,7 +203,7 @@ void MainWindow::refresh_config_list() QStringList ini_list = group::ini_list(); set_title(); - QString current = QFileInfo(group::ini_pathname()).fileName(); + QString current = group::ini_filename(); ui.iconcomboProfile->clear(); for (auto x : ini_list) ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), x); @@ -343,7 +343,7 @@ void MainWindow::set_title(const QString& game_title_) QString game_title; if (game_title_ != "") game_title = " :: " + game_title_; - QString current = QFileInfo(group::ini_pathname()).fileName(); + QString current = group::ini_filename(); setWindowTitle(const_cast(opentrack_version) + QStringLiteral(" :: ") + current + game_title); } diff --git a/opentrack/options.hpp b/opentrack/options.hpp index 8e623092..f8475877 100644 --- a/opentrack/options.hpp +++ b/opentrack/options.hpp @@ -143,6 +143,12 @@ namespace options { return ""; } + static QString ini_filename() + { + QSettings settings(OPENTRACK_ORG); + return settings.value(OPENTRACK_CONFIG_FILENAME_KEY, OPENTRACK_DEFAULT_CONFIG).toString(); + } + static QString ini_pathname() { const auto dir = ini_directory(); -- cgit v1.2.3 From c5463fcedf2ed6e6cf75c7056071b26a3f3da08f Mon Sep 17 00:00:00 2001 From: Stanisław Halik Date: Fri, 28 Aug 2015 10:20:08 +0200 Subject: fix typo --- opentrack/plugin-api.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack') diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp index 572b7f31..732dbb3d 100644 --- a/opentrack/plugin-api.hpp +++ b/opentrack/plugin-api.hpp @@ -42,7 +42,7 @@ signals: } // implement this in all plugins -// also you must link against "opentrack-api" in CMakeList.txt to avoid vtable link errors +// also you must link against "opentrack-api" in CMakeLists.txt to avoid vtable link errors struct Metadata { // plugin name to be displayed in the interface -- cgit v1.2.3 From e07a72493f6145b55efb305c955032ffd73e94c3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 28 Aug 2015 12:28:29 +0200 Subject: tracker: change centering order again Needs more testing with PT and other non-inertial trackers. Issue: #227 --- opentrack/tracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index 403e87c5..c9e34c2d 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -134,7 +134,7 @@ void Tracker::logic() { double tmp[3] = { t(0) - t_b[0], t(1) - t_b[1], t(2) - t_b[2] }; t_compensate(cam, tmp, tmp, false); - const rmat m_ = r_b.t() * r; + const rmat m_ = r * r_b.t(); const dmat<3, 1> euler = rmat::rmat_to_euler(m_); for (int i = 0; i < 3; i++) { -- cgit v1.2.3 From f3708cf6a85f4447e2333642453a4a0232986942 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 28 Aug 2015 13:49:29 +0200 Subject: save axis opts, not just spline control points This caused the "invert axis got switched on" bug. --- opentrack/main-settings.hpp | 2 ++ opentrack/mappings.hpp | 3 +++ 2 files changed, 5 insertions(+) (limited to 'opentrack') diff --git a/opentrack/main-settings.hpp b/opentrack/main-settings.hpp index 8c49f86a..b973e7af 100644 --- a/opentrack/main-settings.hpp +++ b/opentrack/main-settings.hpp @@ -15,10 +15,12 @@ using namespace options; struct axis_opts { + pbundle b; value zero; value invert, altp; value src; axis_opts(pbundle b, QString pfx, int idx) : + b(b), zero(b, n(pfx, "zero-pos"), 0), invert(b, n(pfx, "invert-sign"), false), altp(b, n(pfx, "alt-axis-sign"), false), diff --git a/opentrack/mappings.hpp b/opentrack/mappings.hpp index 85d9900c..2391efd1 100644 --- a/opentrack/mappings.hpp +++ b/opentrack/mappings.hpp @@ -62,6 +62,7 @@ public: { axes[i].curve.loadSettings(*iniFile, axes[i].name1); axes[i].curveAlt.loadSettings(*iniFile, axes[i].name2); + axes[i].opts.b->reload(); } } void save_mappings() @@ -72,6 +73,7 @@ public: { axes[i].curve.saveSettings(*iniFile, axes[i].name1); axes[i].curveAlt.saveSettings(*iniFile, axes[i].name2); + axes[i].opts.b->save(); } } @@ -81,6 +83,7 @@ public: { axes[i].curve.invalidate_unsaved_settings(); axes[i].curveAlt.invalidate_unsaved_settings(); + axes[i].opts.b->reload(); } } }; -- cgit v1.2.3 From b9df697d6de0bd1ba4e9fbb40a7b3a5ab8e7cfdd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 31 Aug 2015 05:12:23 +0200 Subject: simple-mat: add __restrict for GNU --- opentrack/simple-mat.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'opentrack') diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index c603a2cb..e462812b 100644 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -52,6 +52,9 @@ namespace { template class Mat { +#ifdef __GNUC__ + __restrict +#endif num data[h_][w_]; static_assert(h_ > 0 && w_ > 0, "must have positive mat dimensions"); -- cgit v1.2.3 From bed620cc85b71e5c02c86613d22624a5c12189ce Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 5 Sep 2015 07:46:47 +0200 Subject: plugin-support: workaround multiple copies of modules TrackHat dist contained two copies of every module by packaging error. Workaround similar errors by not loading more than one copy of a module at a time. Sponsored-by: TrackHat --- opentrack/plugin-support.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'opentrack') diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index 8b9cf58a..8efda800 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -187,6 +187,14 @@ struct dylib { std::cout.flush(); if (!get_metadata(lib, longName, icon)) continue; + using d = const mem&; + if (std::any_of(ret.cbegin(), + ret.cend(), + [&](d a) {return a->type == lib->type && a->name == lib->name;})) + { + qDebug() << "Duplicate lib" << lib->filename; + continue; + } ret.push_back(lib); } } -- cgit v1.2.3