diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-30 11:02:53 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-30 11:02:53 +0100 |
commit | 2a3b4460da901256a60fc2e4bc90adc14284bbf3 (patch) | |
tree | fe47fa7515510defc9756f5f4cae7a7ab5ea63b6 | |
parent | eaeb86205a04a2159de3e55fb7105195962249db (diff) |
accela: bundle settings to reduce boilerplate
-rw-r--r-- | ftnoir_filter_accela/ftnoir_filter_accela.cpp | 22 | ||||
-rw-r--r-- | ftnoir_filter_accela/ftnoir_filter_accela.h | 37 | ||||
-rw-r--r-- | ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp | 28 |
3 files changed, 39 insertions, 48 deletions
diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp index 2e70c1b0..1e12e4de 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp @@ -12,15 +12,7 @@ #include "facetracknoir/global-settings.h"
using namespace std;
-FTNoIR_Filter::FTNoIR_Filter() :
- first_run(true),
- b(bundle("Accela")),
- rotation_alpha(b, "rotation-alpha", ACCELA_SMOOTHING_ROTATION),
- translation_alpha(b, "translation-alpha", ACCELA_SMOOTHING_TRANSLATION),
- second_order_alpha(b, "second-order-alpha", ACCELA_SECOND_ORDER_ALPHA),
- third_order_alpha(b, "third-order-alpha", ACCELA_THIRD_ORDER_ALPHA),
- deadzone(b, "deadzone", 0),
- expt(b, "exponent", 2)
+FTNoIR_Filter::FTNoIR_Filter() : first_run(true)
{
}
@@ -94,13 +86,13 @@ void FTNoIR_Filter::FilterHeadPoseData(const double* target_camera_position, const double vec2 = target_camera_position[i] - last_output[1][i];
const double vec3 = target_camera_position[i] - last_output[2][i];
const int sign = vec < 0 ? -1 : 1;
- const double a = i >= 3 ? rotation_alpha : translation_alpha;
- const double a2 = a * second_order_alpha;
- const double a3 = a * third_order_alpha;
+ const double a = i >= 3 ? s.rotation_alpha : s.translation_alpha;
+ const double a2 = a * s.second_order_alpha;
+ const double a3 = a * s.third_order_alpha;
const double velocity =
- parabola(a, vec, deadzone, expt) +
- parabola(a2, vec2, deadzone, expt) +
- parabola(a3, vec3, deadzone, expt);
+ parabola(a, vec, s.deadzone, s.expt) +
+ parabola(a2, vec2, s.deadzone, s.expt) +
+ parabola(a3, vec3, s.deadzone, s.expt);
const double result = last_output[0][i] + velocity;
const bool done = sign > 0 ? result >= target_camera_position[i] : result <= target_camera_position[i];
new_camera_position[i] = done ? target_camera_position[i] : result;
diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 43564bd8..2b93f550 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -13,6 +13,25 @@ #include "facetracknoir/options.hpp"
using namespace options;
+struct settings {
+ pbundle b;
+ value<double> rotation_alpha,
+ translation_alpha,
+ second_order_alpha,
+ third_order_alpha,
+ deadzone,
+ expt;
+ settings() :
+ b(bundle("Accela")),
+ rotation_alpha(b, "rotation-alpha", ACCELA_SMOOTHING_ROTATION),
+ translation_alpha(b, "translation-alpha", ACCELA_SMOOTHING_TRANSLATION),
+ second_order_alpha(b, "second-order-alpha", ACCELA_SECOND_ORDER_ALPHA),
+ third_order_alpha(b, "third-order-alpha", ACCELA_THIRD_ORDER_ALPHA),
+ deadzone(b, "deadzone", 0),
+ expt(b, "exponent", 2)
+ {}
+};
+
class FTNoIR_Filter : public IFilter
{
public:
@@ -22,19 +41,13 @@ public: first_run = true;
}
void receiveSettings() {
- b->reload();
+ s.b->reload();
}
private:
+ settings s;
QMutex mutex;
bool first_run;
- pbundle b;
- value<double> rotation_alpha,
- translation_alpha,
- second_order_alpha,
- third_order_alpha,
- deadzone,
- expt;
double last_input[6];
double last_output[3][6];
QElapsedTimer timer;
@@ -59,13 +72,7 @@ private: void discard();
void save();
FTNoIR_Filter* accela_filter;
- pbundle b;
- value<double> rotation_alpha,
- translation_alpha,
- second_order_alpha,
- third_order_alpha,
- deadzone,
- expt;
+ settings s;
private slots:
void doOK();
void doCancel();
diff --git a/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp b/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp index 256f35b4..cc759bcb 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp @@ -6,26 +6,18 @@ #include "facetracknoir/global-settings.h" FilterControls::FilterControls() : - accela_filter(NULL), - b(bundle("Accela")), - rotation_alpha(b, "rotation-alpha", ACCELA_SMOOTHING_ROTATION), - translation_alpha(b, "translation-alpha", ACCELA_SMOOTHING_TRANSLATION), - second_order_alpha(b, "second-order-alpha", ACCELA_SECOND_ORDER_ALPHA), - third_order_alpha(b, "third-order-alpha", ACCELA_THIRD_ORDER_ALPHA), - deadzone(b, "deadzone", 0), - expt(b, "exponent", 2) - + accela_filter(nullptr) { ui.setupUi( this ); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - tie_setting(rotation_alpha, ui.rotation_alpha); - tie_setting(translation_alpha, ui.translation_alpha); - tie_setting(second_order_alpha, ui.order_2nd); - tie_setting(third_order_alpha, ui.order_3rd); - tie_setting(deadzone, ui.deadzone); - tie_setting(expt, ui.expt); + tie_setting(s.rotation_alpha, ui.rotation_alpha); + tie_setting(s.translation_alpha, ui.translation_alpha); + tie_setting(s.second_order_alpha, ui.order_2nd); + tie_setting(s.third_order_alpha, ui.order_3rd); + tie_setting(s.deadzone, ui.deadzone); + tie_setting(s.expt, ui.expt); } void FilterControls::Initialize(QWidget *) { @@ -48,7 +40,7 @@ void FilterControls::doOK() { } void FilterControls::doCancel() { - if (!b->modifiedp()) + if (!s.b->modifiedp()) { close(); return; @@ -77,11 +69,11 @@ void FilterControls::doCancel() { void FilterControls::discard() { - b->revert(); + s.b->revert(); } void FilterControls::save() { - b->save(); + s.b->save(); if (accela_filter) accela_filter->receiveSettings(); } |