summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_filter_ewma2
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-06-14 12:48:28 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-06-14 12:48:28 +0200
commitb1b442b17a626974c8840dd6a3912e078f00883e (patch)
treebdb29e26a2abe14da26eccd4188d2aa13da5b196 /ftnoir_filter_ewma2
parentb10de6a3dbe1f16e288f049414508c6d84feecde (diff)
update accela, ewma to use lerp class
Diffstat (limited to 'ftnoir_filter_ewma2')
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp55
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2.h3
2 files changed, 24 insertions, 34 deletions
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
index c073bfa4..dcc1475c 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
@@ -64,54 +64,43 @@ void FTNoIR_Filter::FilterHeadPoseData(const double *target_camera_position,
{
double new_delta, new_noise, norm_noise;
double alpha;
+ double pos[6];
//On the first run, initialize to output=target and return.
if (first_run==true) {
for (int i=0;i<6;i++) {
- new_camera_position[i] = target_camera_position[i];
- current_camera_position[i] = target_camera_position[i];
delta[i] = 0.0;
noise[i] = 0.0;
+ l.write(target_camera_position, new_camera_position);
}
first_run=false;
return;
}
- bool new_frame = false;
-
- for (int i = 0; i < 6; i++)
+ if (!l.idempotentp(target_camera_position))
{
- if (target_camera_position[i] != current_camera_position[i])
- {
- new_frame = true;
- break;
+ double cur[6];
+ l.get_state(cur);
+ // Calculate the new camera position.
+ for (int i=0;i<6;i++) {
+ // Calculate the current and smoothed delta.
+ new_delta = target_camera_position[i]-cur[i];
+ delta[i] = delta_smoothing*new_delta + (1.0-delta_smoothing)*delta[i];
+ // Calculate the current and smoothed noise variance.
+ new_noise = delta[i]*delta[i];
+ noise[i] = noise_smoothing*new_noise + (1.0-noise_smoothing)*noise[i];
+ // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs).
+ norm_noise = std::min<double>(new_noise/(9.0*noise[i]), 1.0);
+ // Calculate the alpha from the normalized noise.
+ // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise).
+ alpha = 1.0/(s.kMinSmoothing+(1.0-pow(norm_noise,s.kSmoothingScaleCurve/20.0))*(s.kMaxSmoothing-s.kMinSmoothing));
+ // Update the current camera position to the new position.
+ double value = alpha*target_camera_position[i] + (1.0-alpha)*cur[i];
+ pos[i] = value;
}
}
- if (!new_frame)
- {
- for (int i = 0; i < 6; i++)
- new_camera_position[i] = current_camera_position[i];
- return;
- }
-
- // Calculate the new camera position.
- for (int i=0;i<6;i++) {
- // Calculate the current and smoothed delta.
- new_delta = target_camera_position[i]-current_camera_position[i];
- delta[i] = delta_smoothing*new_delta + (1.0-delta_smoothing)*delta[i];
- // Calculate the current and smoothed noise variance.
- new_noise = delta[i]*delta[i];
- noise[i] = noise_smoothing*new_noise + (1.0-noise_smoothing)*noise[i];
- // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs).
- norm_noise = std::min<double>(new_noise/(9.0*noise[i]), 1.0);
- // Calculate the alpha from the normalized noise.
- // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise).
- alpha = 1.0/(s.kMinSmoothing+(1.0-pow(norm_noise,s.kSmoothingScaleCurve/20.0))*(s.kMaxSmoothing-s.kMinSmoothing));
- // Update the current camera position to the new position.
- double pos = alpha*target_camera_position[i] + (1.0-alpha)*current_camera_position[i];
- new_camera_position[i] = current_camera_position[i] = pos;
- }
+ l.write(pos, new_camera_position);
}
extern "C" FTNOIR_FILTER_BASE_EXPORT IFilter* CALLING_CONVENTION GetConstructor()
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
index bde3e79c..ea25a135 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
@@ -32,6 +32,7 @@
#include <QWidget>
#include <QMutex>
#include "facetracknoir/options.h"
+#include "facetracknoir/lerp.hpp"
using namespace options;
struct settings {
@@ -61,8 +62,8 @@ private:
double noise_smoothing;
double delta[6];
double noise[6];
- double current_camera_position[6];
settings s;
+ lerp l;
};
class FilterControls: public QWidget, public IFilterDialog