summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_filter_accela/ftnoir_filter_accela.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-08-19 12:43:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-08-19 12:43:22 +0200
commit60ac7c17eb4786949a130099a4ef26af00c2ea4f (patch)
treeec1de61184aa62eb51db7c8bec6bbb1a6291abb3 /ftnoir_filter_accela/ftnoir_filter_accela.cpp
parent54883f543f45e94810ee48108474efad7f0ba2d6 (diff)
Simplify Accela's UI and preset equations
Diffstat (limited to 'ftnoir_filter_accela/ftnoir_filter_accela.cpp')
-rw-r--r--ftnoir_filter_accela/ftnoir_filter_accela.cpp111
1 files changed, 23 insertions, 88 deletions
diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp
index 0aea2f78..66744c2f 100644
--- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp
+++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp
@@ -4,29 +4,16 @@
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*/
-/*
- Modifications (last one on top):
- 20120807 - WVR: FunctionConfig is now also used for the Filter. The extrapolation was adapted from Stanislaw.
- Additional changes: I have added two parameters to the constructor of FunctionConfig and
- renamed 3 member-functions (getFilterFullName is now called getFullName).
-*/
#include "ftnoir_filter_accela/ftnoir_filter_accela.h"
#include "math.h"
#include <QDebug>
#include <float.h>
#include "facetracknoir/global-settings.h"
-#if !defined(_WIN32) && !defined(__WIN32)
-# define _isnan isnan
-#endif
-
-FTNoIR_Filter::FTNoIR_Filter() :
- functionConfig("Accela-Scaling-Rotation", 10, 10),
- translationFunctionConfig("Accela-Scaling-Translation", 10, 10)
+FTNoIR_Filter::FTNoIR_Filter()
{
first_run = true;
- kMagicNumber = 1000;
- loadSettings(); // Load the Settings
+ loadSettings();
}
FTNoIR_Filter::~FTNoIR_Filter()
@@ -40,102 +27,50 @@ void FTNoIR_Filter::loadSettings() {
QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString();
QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file)
- functionConfig.loadSettings(iniFile);
- translationFunctionConfig.loadSettings(iniFile);
-
iniFile.beginGroup ( "Accela" );
- kMagicNumber = iniFile.value ( "Reduction", 1000 ).toFloat();
- kZoomSlowness = iniFile.value("zoom-slowness", 0).toFloat();
+ zoom_factor = iniFile.value("zoom-slowness", 0).toDouble();
+ rotation_alpha = iniFile.value("rotation-alpha", ACCELA_SMOOTHING_ROTATION).toDouble();
+ translation_alpha = iniFile.value("translation-alpha", ACCELA_SMOOTHING_TRANSLATION).toDouble();
iniFile.endGroup ();
}
+static double parabola(const double a, const double x)
+{
+ const double a1 = 1./a;
+ return a1 * a1 * x * x;
+}
+
void FTNoIR_Filter::FilterHeadPoseData(double *current_camera_position,
double *target_camera_position,
double *new_camera_position,
double *last_post_filter_values)
{
- double target[6];
- double prev_output[6];
- float output[6];
-
- for (int i = 0; i < 6; i++)
- {
- prev_output[i] = current_camera_position[i];
- target[i] = target_camera_position[i];
- }
-
if (first_run)
{
for (int i = 0; i < 6; i++)
{
- new_camera_position[i] = target[i];
- current_camera_position[i] = target[i];
+ new_camera_position[i] = target_camera_position[i];
+ current_camera_position[i] = target_camera_position[i];
}
- first_run=false;
+ first_run = false;
return;
}
for (int i=0;i<6;i++)
{
- if (_isnan(target[i]))
- return;
-
- if (_isnan(prev_output[i]))
- return;
-
- double e2 = target[i];
- double start = prev_output[i];
- double vec = e2 - start;
- int sign = vec < 0 ? -1 : 1;
- double x = fabs(vec);
- QList<QPointF> points = (i >= 3 ? functionConfig : translationFunctionConfig).getPoints();
- int extrapolatep = 0;
- double ratio;
- double maxx;
- double add;
- // linear extrapolation of a spline
- if (points.size() > 1) {
- QPointF last = points[points.size() - 1];
- QPointF penultimate = points[points.size() - 2];
- ratio = (last.y() - penultimate.y()) / (last.x() - penultimate.x());
- extrapolatep = 1;
- add = last.y();
- maxx = last.x();
- }
- double foo = extrapolatep && x > maxx ? add + ratio * (x - maxx) : (i >= 3 ? functionConfig : translationFunctionConfig).getValue(x);
- // the idea is that "empty" updates without new head pose data are still
- // useful for filtering, as skipping them would result in jerky output.
- // the magic "100" is the amount of calls to the filter by FTNOIR per sec.
- // WVR: Added kMagicNumber for Patrick
- double velocity = foo / kMagicNumber * (1 / std::max(1.0, 1 + kZoomSlowness * -last_post_filter_values[TZ] / 100));
- double sum = start + velocity * sign;
- bool done = (sign > 0 ? sum >= e2 : sum <= e2);
- if (done) {
- output[i] = e2;
- } else {
- output[i] = sum;
- }
-
- if (_isnan(output[i]))
- return;
+ const double vec = target_camera_position[i] - current_camera_position[i];
+ const int sign = vec < 0 ? -1 : 1;
+ const double x = fabs(vec);
+ const double a = i >= 3 ? rotation_alpha : translation_alpha;
+ const double reduction = 1. / std::max(1., 1. + zoom_factor * -last_post_filter_values[TZ] / 1000);
+ const double velocity = parabola(a, x) * reduction;
+ const double result = current_camera_position[i] + velocity * sign;
+ const bool done = sign > 0 ? result >= target_camera_position[i] : result <= target_camera_position[i];
+ new_camera_position[i] = current_camera_position[i] = done ? target_camera_position[i] : result;
}
-
- for (int i = 0; i < 6; i++)
- {
- new_camera_position[i] = output[i];
- current_camera_position[i] = output[i];
- }
}
-////////////////////////////////////////////////////////////////////////////////
-// Factory function that creates instances if the Filter object.
-
-// Export both decorated and undecorated names.
-// GetFilter - Undecorated name, which can be easily used with GetProcAddress
-// Win32 API function.
-// _GetFilter@0 - Common name decoration for __stdcall functions in C language.
-
extern "C" FTNOIR_FILTER_BASE_EXPORT IFilter* CALLING_CONVENTION GetConstructor()
{
return new FTNoIR_Filter;