diff options
author | Donovan Baarda <abo@minkirri.apana.org.au> | 2014-06-12 14:53:43 +1000 |
---|---|---|
committer | Donovan Baarda <abo@minkirri.apana.org.au> | 2014-06-12 14:53:43 +1000 |
commit | 0669a40347ffa233bc6042b0f65d244509a61394 (patch) | |
tree | 36a4577bdaa1ed28ca1ad222a54777012dd2dda8 /ftnoir_filter_ewma2 | |
parent | 72540e0a96a3120a5d02271e714aba29e136ab78 (diff) | |
parent | 7454496476ba17ea622781d280606161581c9544 (diff) |
Merge branch 'master' of https://github.com/opentrack/opentrack into dev/ewma2
Resolved conflicts manually in files:
ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
Diffstat (limited to 'ftnoir_filter_ewma2')
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui | 16 | ||||
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp | 47 | ||||
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma2.h | 60 | ||||
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp | 264 | ||||
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp | 88 |
5 files changed, 151 insertions, 324 deletions
diff --git a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui index 0f31bcd3..8ee633cc 100644 --- a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui +++ b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui @@ -2,11 +2,14 @@ <ui version="4.0"> <class>UICFilterControls</class> <widget class="QWidget" name="UICFilterControls"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>371</width> + <width>477</width> <height>380</height> </rect> </property> @@ -17,12 +20,11 @@ </size> </property> <property name="windowTitle"> - <string>EWMA2 Filter settings FaceTrackNoIR</string> + <string>EWMA2 filter settings</string> </property> <property name="windowIcon"> - <iconset> - images/facetracknoir.png - </iconset> + <iconset resource="ewma-filter.qrc"> + <normaloff>:/images/filter-16.png</normaloff>:/images/filter-16.png</iconset> </property> <property name="layoutDirection"> <enum>Qt::LeftToRight</enum> @@ -480,7 +482,9 @@ p, li { white-space: pre-wrap; } <tabstop>btnOK</tabstop> <tabstop>btnCancel</tabstop> </tabstops> - <resources/> + <resources> + <include location="ewma-filter.qrc"/> + </resources> <connections> <connection> <sender>minSmooth</sender> diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp index 8e9196ba..e2196a01 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp @@ -28,6 +28,7 @@ #include <QWidget>
#include "facetracknoir/global-settings.h"
#include <algorithm>
+#include <QMutexLocker>
//#define LOG_OUTPUT
///////////////////////////////////////////////////////////////////////////////
@@ -43,48 +44,22 @@ //
///////////////////////////////////////////////////////////////////////////////
-FTNoIR_Filter::FTNoIR_Filter()
-{
- first_run = true;
+FTNoIR_Filter::FTNoIR_Filter() :
+ first_run(true),
// Deltas are smoothed over the last 3 frames (0.1sec at 30fps).
- delta_smoothing = 1.0 / 3.0;
+ delta_smoothing(1.0/3.0),
// Noise is smoothed over the last 3600 frames (~2mins at 30fps).
- noise_smoothing = 1.0 / 3600.0;
- loadSettings(); // Load the Settings
-}
-
-FTNoIR_Filter::~FTNoIR_Filter()
+ noise_smoothing(1.0/3600.0)
{
}
-//
-// Load the current Settings from the currently 'active' INI-file.
-//
-void FTNoIR_Filter::loadSettings() {
- qDebug() << "FTNoIR_Filter::loadSettings says: Starting ";
- QSettings settings("opentrack"); // Registry settings (in HK_USER)
-
- QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString();
- QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file)
-
- qDebug() << "FTNoIR_Filter::loadSettings says: iniFile = " << currentFile;
-
- //
- // The EWMA2-filter-settings are in the Tracking group: this is because they used to be on the Main Form of FaceTrackNoIR
- //
- iniFile.beginGroup ( "Tracking" );
- // TODO(abo): change UI to have range 1-120 frames.
- kMinSmoothing = iniFile.value ( "minSmooth", 2 ).toInt();
- kMaxSmoothing = iniFile.value ( "maxSmooth", 15 ).toInt();
- // TODO(abo): change powCurve to a float with default=1.0.
- kSmoothingScaleCurve = iniFile.value ( "powCurve", 10 ).toInt();
- iniFile.endGroup ();
+void FTNoIR_Filter::receiveSettings()
+{
+ s.b->reload();
}
-void FTNoIR_Filter::FilterHeadPoseData(double *current_camera_position,
- double *target_camera_position,
- double *new_camera_position,
- double *last_post_filter)
+void FTNoIR_Filter::FilterHeadPoseData(const double *target_camera_position,
+ double *new_camera_position)
{
double new_delta, new_noise, norm_noise;
double alpha;
@@ -113,7 +88,7 @@ void FTNoIR_Filter::FilterHeadPoseData(double *current_camera_position, 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/(kMinSmoothing+(1.0-pow(norm_noise,kSmoothingScaleCurve/20.0))*(kMaxSmoothing-kMinSmoothing));
+ alpha = 1.0/(s.kMinSmoothing+(1.0-pow(norm_noise,s.kSmoothingScaleCurve/20.0))*(s.kMaxSmoothing-s.kMinSmoothing));
new_camera_position[i] = alpha*target_camera_position[i] + (1.0-alpha)*current_camera_position[i];
}
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h index 72dc6f0a..e49b7a6d 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h @@ -30,37 +30,38 @@ #include "facetracknoir/global-settings.h"
#include "ui_ftnoir_ewma_filtercontrols.h"
#include <QWidget>
+#include <QMutex>
+#include "facetracknoir/options.h"
+using namespace options;
+
+struct settings {
+ pbundle b;
+ value<int> kMinSmoothing, kMaxSmoothing, kSmoothingScaleCurve;
+ settings() :
+ b(bundle("ewma-filter")),
+ kMinSmoothing(b, "min-smoothing", 15),
+ kMaxSmoothing(b, "max-smoothing", 50),
+ kSmoothingScaleCurve(b, "smoothing-scale-curve", 10)
+ {}
+};
+
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter
-//
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FTNoIR_Filter : public IFilter
{
public:
FTNoIR_Filter();
- ~FTNoIR_Filter();
- void Initialize() {}
-
- void FilterHeadPoseData(double *current_camera_position,
- double *target_camera_position,
- double *new_camera_position,
- double *last_post_filter);
-
+ void reset() {}
+ void FilterHeadPoseData(const double *target_camera_position,
+ double *new_camera_position);
+ void receiveSettings();
private:
- void loadSettings(); // Load the settings from the INI-file
- double newHeadPose; // Structure with new headpose
-
bool first_run;
double delta_smoothing;
double noise_smoothing;
double delta[6];
double noise[6];
-
- double kMinSmoothing;
- double kMaxSmoothing;
- double kSmoothingScaleCurve;
+ double current_camera_position[6];
+ settings s;
};
//*******************************************************************************************************
@@ -72,26 +73,19 @@ class FilterControls: public QWidget, public IFilterDialog {
Q_OBJECT
public:
- explicit FilterControls();
- virtual ~FilterControls();
- void showEvent ( QShowEvent * event );
- void Initialize(QWidget *parent, IFilter* ptr);
+ FilterControls();
+ void registerFilter(IFilter* flt);
+ void unregisterFilter();
private:
Ui::UICFilterControls ui;
- void loadSettings();
void save();
-
- /** helper **/
- bool settingsDirty;
-
- IFilter* pFilter; // If the filter was active when the dialog was opened, this will hold a pointer to the Filter instance
+ settings s;
+ FTNoIR_Filter* pFilter;
private slots:
void doOK();
void doCancel();
- void settingChanged() { settingsDirty = true; };
- void settingChanged( int ) { settingsDirty = true; };
};
//*******************************************************************************************************
@@ -100,8 +94,6 @@ private slots: class FTNoIR_FilterDll : public Metadata
{
public:
- FTNoIR_FilterDll();
- ~FTNoIR_FilterDll();
void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("EWMA Filter Mk2"); }
void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("EWMA"); }
void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Exponentially Weighted Moving Average filter with dynamic smoothing parameter"); }
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp index eb259572..395d1058 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp @@ -1,191 +1,73 @@ -/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
-* This program is free software; you can redistribute it and/or modify it *
-* under the terms of the GNU General Public License as published by the *
-* Free Software Foundation; either version 3 of the License, or (at your *
-* option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, but *
-* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
-* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
-* more details. *
-* *
-* You should have received a copy of the GNU General Public License along *
-* with this program; if not, see <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
-#include "ftnoir_filter_ewma2.h"
-#include "math.h"
-#include <QDebug>
-#include "facetracknoir/global-settings.h"
-#include "ui_ftnoir_ewma_filtercontrols.h"
-
-//*******************************************************************************************************
-// FaceTrackNoIR Filter Settings-dialog.
-//*******************************************************************************************************
-//
-// Constructor for server-settings-dialog
-//
-FilterControls::FilterControls() :
-QWidget()
-{
- ui.setupUi( this );
-
- QPoint offsetpos(100, 100);
- //if (parent) {
- // this->move(parent->pos() + offsetpos);
- //}
-
- // Connect Qt signals to member-functions
- connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK()));
- connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel()));
-
- // Connect sliders for reduction factor
- connect(ui.minSmooth, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.maxSmooth, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int)));
- connect(ui.powCurve, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int)));
-
- qDebug() << "FilterControls() says: started";
-
- // Load the settings from the current .INI-file
- loadSettings();
-}
-
-//
-// Destructor for server-dialog
-//
-FilterControls::~FilterControls() {
- qDebug() << "~FilterControls() says: started";
-}
-
-//
-// Initialize tracker-client-dialog
-//
-void FilterControls::Initialize(QWidget *parent, IFilter* ptr) {
-
- //
- // The dialog can be opened, while the Tracker is running.
- // In that case, ptr will point to the active Filter-instance.
- // This can be used to update settings, while Tracking and may also be handy to display logging-data and such...
- //
- pFilter = ptr;
-
- //
- //
- //
- QPoint offsetpos(100, 100);
- if (parent) {
- this->move(parent->pos() + offsetpos);
- }
- show();
-}
-
-//
-// OK clicked on server-dialog
-//
-void FilterControls::doOK() {
- save();
- this->close();
-}
-
-// override show event
-void FilterControls::showEvent ( QShowEvent * event ) {
- loadSettings();
-}
-
-//
-// Cancel clicked on server-dialog
-//
-void FilterControls::doCancel() {
- //
- // Ask if changed Settings should be saved
- //
- if (settingsDirty) {
- int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard );
-
- qDebug() << "doCancel says: answer =" << ret;
-
- switch (ret) {
- case QMessageBox::Save:
- save();
- this->close();
- break;
- case QMessageBox::Discard:
- this->close();
- break;
- case QMessageBox::Cancel:
- // Cancel was clicked
- break;
- default:
- // should never be reached
- break;
- }
- }
- else {
- this->close();
- }
-}
-
-//
-// Load the current Settings from the currently 'active' INI-file.
-//
-void FilterControls::loadSettings() {
- qDebug() << "FilterControls::loadSettings says: Starting ";
- QSettings settings("opentrack"); // Registry settings (in HK_USER)
-
- QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString();
- QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file)
-
- qDebug() << "FilterControls::loadSettings says: iniFile = " << currentFile;
-
- //
- // The EWMA2-filter-settings are in the Tracking group: this is because they used to be on the Main Form of FaceTrackNoIR
- //
- iniFile.beginGroup ( "Tracking" );
- ui.minSmooth->setValue (iniFile.value ( "minSmooth", 15 ).toInt());
- ui.maxSmooth->setValue (iniFile.value ( "maxSmooth", 50 ).toInt());
- ui.powCurve->setValue (iniFile.value ( "powCurve", 10 ).toInt());
- iniFile.endGroup ();
-
- settingsDirty = false;
-}
-
-//
-// Save the current Settings to the currently 'active' INI-file.
-//
-void FilterControls::save() {
- QSettings settings("opentrack"); // Registry settings (in HK_USER)
-
- QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString();
- QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file)
-
- iniFile.beginGroup ( "Tracking" );
- iniFile.setValue ( "minSmooth", ui.minSmooth->value() );
- iniFile.setValue ( "powCurve", ui.powCurve->value() );
- iniFile.setValue ( "maxSmooth", ui.maxSmooth->value() );
- iniFile.endGroup ();
-
- settingsDirty = false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Factory function that creates instances if the Filter-settings dialog object.
-
-// Export both decorated and undecorated names.
-// GetFilterDialog - Undecorated name, which can be easily used with GetProcAddress
-// Win32 API function.
-// _GetFilterDialog@0 - Common name decoration for __stdcall functions in C language.
-//#pragma comment(linker, "/export:GetFilterDialog=_GetFilterDialog@0")
-
-extern "C" FTNOIR_FILTER_BASE_EXPORT IFilterDialog* CALLING_CONVENTION GetDialog( )
-{
- return new FilterControls;
-}
+/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +********************************************************************************/ +#include "ftnoir_filter_ewma2.h" +#include "math.h" +#include <QDebug> +#include "facetracknoir/global-settings.h" +#include "ui_ftnoir_ewma_filtercontrols.h" + +FilterControls::FilterControls() : + QWidget(), pFilter(NULL) +{ + ui.setupUi( this ); + + connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); + connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + + tie_setting(s.kMaxSmoothing, ui.maxSmooth); + tie_setting(s.kMinSmoothing, ui.minSmooth); + tie_setting(s.kSmoothingScaleCurve, ui.powCurve); +} + +void FilterControls::registerFilter(IFilter* flt) +{ + pFilter = (FTNoIR_Filter*) flt; +} + +void FilterControls::unregisterFilter() +{ + pFilter = NULL; +} + +void FilterControls::doOK() { + save(); + this->close(); +} + +void FilterControls::doCancel() { + s.b->revert(); + this->close(); +} + +void FilterControls::save() { + s.b->save(); + if (pFilter) + pFilter->receiveSettings(); +} + +extern "C" FTNOIR_FILTER_BASE_EXPORT IFilterDialog* CALLING_CONVENTION GetDialog( ) +{ + return new FilterControls; +} diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp index a01b0661..6ef7768e 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp @@ -1,57 +1,31 @@ -/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
-* This program is free software; you can redistribute it and/or modify it *
-* under the terms of the GNU General Public License as published by the *
-* Free Software Foundation; either version 3 of the License, or (at your *
-* option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, but *
-* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
-* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
-* more details. *
-* *
-* You should have received a copy of the GNU General Public License along *
-* with this program; if not, see <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
-/*
- Modifications (last one on top):
- 20120830 - WVR: The Dialog class was used to get general info on the DLL. This
- had a big disadvantage: the complete dialog was loaded, just to get
- some data and then it was deleted again (without ever showing the dialog).
- The FilterDll class solves this.
- The functions to get the name(s) and icon were removed from the two other classes.
-*/
-#include "ftnoir_filter_ewma2.h"
-#include <QDebug>
-#include "facetracknoir/global-settings.h"
-
-FTNoIR_FilterDll::FTNoIR_FilterDll() {
-}
-
-FTNoIR_FilterDll::~FTNoIR_FilterDll()
-{
-
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Factory function that creates instances if the Filter object.
-
-// Export both decorated and undecorated names.
-// GetFilterDll - Undecorated name, which can be easily used with GetProcAddress
-// Win32 API function.
-// _GetFilterDll@0 - Common name decoration for __stdcall functions in C language.
-//#pragma comment(linker, "/export:GetFilterDll=_GetFilterDll@0")
-
-extern "C" FTNOIR_FILTER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata()
-{
- return new FTNoIR_FilterDll;
-}
+/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see <http://www.gnu.org/licenses/>. * +* * +********************************************************************************/ +#include "ftnoir_filter_ewma2.h" +#include "facetracknoir/global-settings.h" + +extern "C" FTNOIR_FILTER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() +{ + return new FTNoIR_FilterDll; +} |