From 3089c4bbc10e98d18f43e8a70e7a3d0c0eaf0900 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 22 Mar 2013 20:48:17 +0100 Subject: Downcase. PLEASE TURN OFF IGNORING CASE IN GIT CONFIG!!! .git/config: [core] ignorecase = false --- ftnoir_filter_ewma2/FTNoIR_FilterControls.ui | 586 +++++++++++++++++++++ ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2.h | 119 +++++ ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc8.vcproj | 388 ++++++++++++++ ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc9.vcproj | 380 +++++++++++++ ftnoir_filter_ewma2/Filter.qrc | 5 + ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp | 236 +++++++++ ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp | 197 +++++++ ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp | 56 ++ ftnoir_filter_ewma2/images/filter-16.png | Bin 0 -> 642 bytes ftnoir_filter_ewma2/images/filter-32.png | Bin 0 -> 1904 bytes 10 files changed, 1967 insertions(+) create mode 100644 ftnoir_filter_ewma2/FTNoIR_FilterControls.ui create mode 100644 ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2.h create mode 100644 ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc8.vcproj create mode 100644 ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc9.vcproj create mode 100644 ftnoir_filter_ewma2/Filter.qrc create mode 100644 ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp create mode 100644 ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp create mode 100644 ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp create mode 100644 ftnoir_filter_ewma2/images/filter-16.png create mode 100644 ftnoir_filter_ewma2/images/filter-32.png (limited to 'ftnoir_filter_ewma2') diff --git a/ftnoir_filter_ewma2/FTNoIR_FilterControls.ui b/ftnoir_filter_ewma2/FTNoIR_FilterControls.ui new file mode 100644 index 00000000..e9419a73 --- /dev/null +++ b/ftnoir_filter_ewma2/FTNoIR_FilterControls.ui @@ -0,0 +1,586 @@ + + + UICFilterControls + + + + 0 + 0 + 371 + 380 + + + + + 0 + 380 + + + + EWMA2 Filter settings FaceTrackNoIR + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + + + + + + + QLayout::SetMinimumSize + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + Max. + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + Curve + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 2 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 2 + + + + + + + + 35 + 0 + + + + + 30 + 16777215 + + + + + + + frames + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 10 + + + + + + + + 35 + 0 + + + + + 30 + 16777215 + + + + + + + frames + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 100 + + + 5 + + + 10 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + pow + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + Min. + + + + + + + + + + 0 + 204 + + + + background-color: rgb(214, 214, 214); +border-color: rgb(0, 0, 0); + + + QFrame::Box + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min. frames:</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Higher value: slower response;</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Max. frames:</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to slow movements;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Higher value: slower response;</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Pow:</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the filters 'readiness' to respond to speed changes;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Higher value = </span><span style=" font-size:10pt; font-weight:600;">higher</span><span style=" font-size:10pt;"> response;</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"></p></body></html> + + + 5 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 52 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 52 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + btnOK + btnCancel + + + + + minSmooth + valueChanged(int) + spinMinSmooth + setValue(int) + + + 199 + 22 + + + 337 + 23 + + + + + spinMinSmooth + valueChanged(int) + minSmooth + setValue(int) + + + 330 + 12 + + + 185 + 17 + + + + + maxSmooth + valueChanged(int) + spinMaxSmooth + setValue(int) + + + 181 + 48 + + + 335 + 54 + + + + + spinMaxSmooth + valueChanged(int) + maxSmooth + setValue(int) + + + 324 + 42 + + + 259 + 43 + + + + + powCurve + valueChanged(int) + spinPowCurve + setValue(int) + + + 145 + 74 + + + 339 + 78 + + + + + spinPowCurve + valueChanged(int) + powCurve + setValue(int) + + + 330 + 69 + + + 176 + 76 + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2.h b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2.h new file mode 100644 index 00000000..18afe3bd --- /dev/null +++ b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2.h @@ -0,0 +1,119 @@ +/******************************************************************************** +* 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 . * +* * +********************************************************************************/ +#pragma once +#ifndef INCLUDED_FTN_FILTER_H +#define INCLUDED_FTN_FILTER_H + +#include "..\ftnoir_filter_base\ftnoir_filter_base.h" +#include "ui_FTNoIR_FilterControls.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class FTNoIR_Filter : public IFilter +{ +public: + FTNoIR_Filter(); + ~FTNoIR_Filter(); + + void Release(); + void Initialize(); + void StartFilter(); + void FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget); + +private: + void loadSettings(); // Load the settings from the INI-file + THeadPoseData newHeadPose; // Structure with new headpose + + bool first_run; + float smoothing_frames_range; + float alpha_smoothing; + float prev_alpha[6]; + float alpha[6]; + float smoothed_alpha[6]; + + float kMinSmoothing; + float kMaxSmoothing; + float kSmoothingScaleCurve; +}; + +//******************************************************************************************************* +// FaceTrackNoIR Filter Settings-dialog. +//******************************************************************************************************* + +// Widget that has controls for FTNoIR protocol filter-settings. +class FilterControls: public QWidget, Ui::UICFilterControls, public IFilterDialog +{ + Q_OBJECT +public: + + explicit FilterControls(); + virtual ~FilterControls(); + void showEvent ( QShowEvent * event ); + + void Release(); // Member functions which are accessible from outside the DLL + void Initialize(QWidget *parent, IFilterPtr ptr); + +private: + Ui::UICFilterControls ui; + void loadSettings(); + void save(); + + /** helper **/ + bool settingsDirty; + + IFilterPtr pFilter; // If the filter was active when the dialog was opened, this will hold a pointer to the Filter instance + +private slots: + void doOK(); + void doCancel(); + void settingChanged() { settingsDirty = true; }; + void settingChanged( int ) { settingsDirty = true; }; +}; + +//******************************************************************************************************* +// FaceTrackNoIR Filter DLL. Functions used to get general info on the Filter +//******************************************************************************************************* +class FTNoIR_FilterDll : public IFilterDll +{ +public: + FTNoIR_FilterDll(); + ~FTNoIR_FilterDll(); + + void Release(); + void Initialize(); + + 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"); }; + + void getIcon(QIcon *icon){ *icon = QIcon(":/images/filter-16.png"); }; +}; + +#endif //INCLUDED_FTN_FILTER_H +//END + diff --git a/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc8.vcproj b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc8.vcproj new file mode 100644 index 00000000..3a185272 --- /dev/null +++ b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc8.vcproj @@ -0,0 +1,388 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc9.vcproj b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc9.vcproj new file mode 100644 index 00000000..d692d8cd --- /dev/null +++ b/ftnoir_filter_ewma2/FTNoIR_Filter_EWMA2_vc9.vcproj @@ -0,0 +1,380 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ftnoir_filter_ewma2/Filter.qrc b/ftnoir_filter_ewma2/Filter.qrc new file mode 100644 index 00000000..e64ec35a --- /dev/null +++ b/ftnoir_filter_ewma2/Filter.qrc @@ -0,0 +1,5 @@ + + + images/filter-16.png + + diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp new file mode 100644 index 00000000..fac0e13c --- /dev/null +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp @@ -0,0 +1,236 @@ +/******************************************************************************** +* 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 . * +* * +********************************************************************************/ +#include "ftnoir_filter_ewma2.h" +#include "math.h" +#include + +//#define LOG_OUTPUT + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +FTNoIR_Filter::FTNoIR_Filter() +{ + first_run = true; + alpha_smoothing = 0.02f; // this is a constant for now, might be a parameter later + loadSettings(); // Load the Settings + +} + +FTNoIR_Filter::~FTNoIR_Filter() +{ + +} + +void FTNoIR_Filter::Release() +{ + delete this; +} + +void FTNoIR_Filter::Initialize() +{ + qDebug() << "FTNoIR_Filter::Initialize says: Starting "; + loadSettings(); + return; +} + +// +// Load the current Settings from the currently 'active' INI-file. +// +void FTNoIR_Filter::loadSettings() { + qDebug() << "FTNoIR_Filter::loadSettings says: Starting "; + QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // 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" ); + kMinSmoothing = iniFile.value ( "minSmooth", 15 ).toInt(); + kMaxSmoothing = iniFile.value ( "maxSmooth", 50 ).toInt(); + kSmoothingScaleCurve = iniFile.value ( "powCurve", 10 ).toInt(); + iniFile.endGroup (); + +} + +void FTNoIR_Filter::FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget) +{ + //non-optimised version for clarity + float prev_output[6]; + float target[6]; + float output_delta[6]; + float scale[]={0.025f,0.025f,0.025f,6.0f,6.0f,6.0f}; + float norm_output_delta[6]; + float output[6]; + int i=0; + + #if PRE_FILTER_SCALING + //compensate for any prefilter scaling + scale[0]*=X_POS_SCALE; + scale[1]*=Y_POS_SCALE; + scale[2]*=Z_POS_SCALE; + scale[3]*=X_ROT_SCALE; + scale[4]*=Y_ROT_SCALE; + scale[5]*=Z_ROT_SCALE; + #endif + + //find out how far the head has moved + prev_output[0]=current_camera_position->x; + prev_output[1]=current_camera_position->y; + prev_output[2]=current_camera_position->z; + prev_output[3]=current_camera_position->yaw; + prev_output[4]=current_camera_position->pitch; + prev_output[5]=current_camera_position->roll; + + target[0]=target_camera_position->x; + target[1]=target_camera_position->y; + target[2]=target_camera_position->z; + target[3]=target_camera_position->yaw; + target[4]=target_camera_position->pitch; + target[5]=target_camera_position->roll; + + if (first_run==true) + { + //on the first run, output=target + for (i=0;i<6;i++) + { + output[i]=target[i]; + prev_alpha[i] = 0.0f; + } + + new_camera_position->x=target[0]; + new_camera_position->y=target[1]; + new_camera_position->z=target[2]; + new_camera_position->yaw=target[3]; + new_camera_position->pitch=target[4]; + new_camera_position->roll=target[5]; + + first_run=false; + + //we can bail + return; + } + + //how far does the camera need to move to catch up? + for (i=0;i<6;i++) + { + output_delta[i]=(target[i]-prev_output[i]); + } + + //normalise the deltas + for (i=0;i<6;i++) + { + norm_output_delta[i]=std::min(std::max(fabs(output_delta[i])/scale[i],0.0f),1.0f); + } + + //calculate the alphas + //work out the dynamic smoothing factors +// if (newTarget) { + for (i=0;i<6;i++) + { + alpha[i]=1.0f/(kMinSmoothing+((1.0f-pow(norm_output_delta[i],kSmoothingScaleCurve))*smoothing_frames_range)); + smoothed_alpha[i]=(alpha_smoothing*alpha[i])+((1.0f-alpha_smoothing)*prev_alpha[i]); + } +// } + + //qDebug() << "FTNoIR_Filter::FilterHeadPoseData() smoothing frames = " << smoothing_frames_range; + //qDebug() << "FTNoIR_Filter::FilterHeadPoseData() alpha[3] = " << alpha[3]; + + //use the same (largest) smoothed alpha for each channel + //NB: larger alpha = *less* lag (opposite to what you'd expect) + float largest_alpha=0.0f; + for (i=0;i<6;i++) + { + if (smoothed_alpha[i]>=largest_alpha) + { + largest_alpha=smoothed_alpha[i]; + } + } + + //move the camera + for (i=0;i<6;i++) + { + output[i]=(largest_alpha*target[i])+((1.0f-largest_alpha)*prev_output[i]); +// output[i]=(smoothed_alpha[i]*target[i])+((1.0f-smoothed_alpha[i])*prev_output[i]); + } + + + #ifdef LOG_OUTPUT + // Use this for some debug-output to file... + QFile data(QCoreApplication::applicationDirPath() + "\\EWMA_output.txt"); + if (data.open(QFile::WriteOnly | QFile::Append)) { + QTextStream out(&data); + out << "output:\t" << output[0] << "\t" << output[1] << "\t" << output[2] << "\t" << output[3] << "\t" << output[4] << "\t" << output[5] << '\n'; + out << "target:\t" << target[0] << "\t" << target[1] << "\t" << target[2] << "\t" << target[3] << "\t" << target[4] << "\t" << target[5] << '\n'; + out << "prev_output:\t" << prev_output[0] << "\t" << prev_output[1] << "\t" << prev_output[2] << "\t" << prev_output[3] << "\t" << prev_output[4] << "\t" << prev_output[5] << '\n'; + out << "largest_alpha:\t" << largest_alpha << '\n'; + } + #endif + + new_camera_position->x=output[0]; + new_camera_position->y=output[1]; + new_camera_position->z=output[2]; + new_camera_position->yaw=output[3]; + new_camera_position->pitch=output[4]; + new_camera_position->roll=output[5]; + + // + // Also update the 'current' position, for the next iteration. + // + current_camera_position->x=output[0]; + current_camera_position->y=output[1]; + current_camera_position->z=output[2]; + current_camera_position->yaw=output[3]; + current_camera_position->pitch=output[4]; + current_camera_position->roll=output[5]; + + //update filter memories ready for next sample + for (i=0;i<6;i++) + { + prev_alpha[i]=smoothed_alpha[i]; + } + return; +} + +//////////////////////////////////////////////////////////////////////////////// +// 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. +#pragma comment(linker, "/export:GetFilter=_GetFilter@0") + +FTNOIR_FILTER_BASE_EXPORT IFilterPtr __stdcall GetFilter() +{ + return new FTNoIR_Filter; +} diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp new file mode 100644 index 00000000..c7798ac0 --- /dev/null +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp @@ -0,0 +1,197 @@ +/******************************************************************************** +* 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 . * +* * +********************************************************************************/ +#include "ftnoir_filter_EWMA2.h" +#include "math.h" +#include + +//******************************************************************************************************* +// 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"; +} + +void FilterControls::Release() +{ + delete this; +} + +// +// Initialize tracker-client-dialog +// +void FilterControls::Initialize(QWidget *parent, IFilterPtr 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(); + if (pFilter) { + pFilter->Initialize(); + } + 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("Abbequerque Inc.", "FaceTrackNoIR"); // 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("Abbequerque Inc.", "FaceTrackNoIR"); // 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") + +FTNOIR_FILTER_BASE_EXPORT IFilterDialogPtr __stdcall GetFilterDialog( ) +{ + return new FilterControls; +} diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp new file mode 100644 index 00000000..4e644446 --- /dev/null +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp @@ -0,0 +1,56 @@ +/******************************************************************************** +* 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 . * +* * +********************************************************************************/ +/* + 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 + +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") + +FTNOIR_FILTER_BASE_EXPORT IFilterDllPtr __stdcall GetFilterDll() +{ + return new FTNoIR_FilterDll; +} diff --git a/ftnoir_filter_ewma2/images/filter-16.png b/ftnoir_filter_ewma2/images/filter-16.png new file mode 100644 index 00000000..ecde6a10 Binary files /dev/null and b/ftnoir_filter_ewma2/images/filter-16.png differ diff --git a/ftnoir_filter_ewma2/images/filter-32.png b/ftnoir_filter_ewma2/images/filter-32.png new file mode 100644 index 00000000..12b02caf Binary files /dev/null and b/ftnoir_filter_ewma2/images/filter-32.png differ -- cgit v1.2.3