From 56cb704c208f0fcc29bd50368e61ecf9aa07b151 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sun, 8 Jan 2012 16:26:15 +0000 Subject: Implementing Filter-settings-dialog inside DLL git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@96 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Filter_EWMA2/FTNoIR_FilterControls.ui | 469 +++++++++++++++++++++ FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h | 126 ++++++ FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj | 104 ++++- FTNoIR_Filter_EWMA2/ftnoir_filter_base.h | 47 --- FTNoIR_Filter_EWMA2/ftnoir_filter_base_global.h | 12 - FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp | 75 ++-- FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp | 204 +++++++++ 7 files changed, 924 insertions(+), 113 deletions(-) create mode 100644 FTNoIR_Filter_EWMA2/FTNoIR_FilterControls.ui create mode 100644 FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h delete mode 100644 FTNoIR_Filter_EWMA2/ftnoir_filter_base.h delete mode 100644 FTNoIR_Filter_EWMA2/ftnoir_filter_base_global.h create mode 100644 FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp diff --git a/FTNoIR_Filter_EWMA2/FTNoIR_FilterControls.ui b/FTNoIR_Filter_EWMA2/FTNoIR_FilterControls.ui new file mode 100644 index 00000000..fbc56447 --- /dev/null +++ b/FTNoIR_Filter_EWMA2/FTNoIR_FilterControls.ui @@ -0,0 +1,469 @@ + + + UICFilterControls + + + + 0 + 0 + 411 + 225 + + + + EWMA2 Filter settings FaceTrackNoIR + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + Min. + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + Max. + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + Curve + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 2 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 2 + + + + + + + + 35 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + frames + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 10 + + + + + + + + 35 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + frames + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 10 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 40 + 22 + + + + background:none; + + + 100 + + + 5 + + + 10 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + color:#ccc; +background:none; + + + pow + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + The filter-settings may need some explanation... + + + + + + + ... + + + true + + + + + + + ... + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + btnOK + btnCancel + + + + + 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..398f5e75 --- /dev/null +++ b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h @@ -0,0 +1,126 @@ +/******************************************************************************** +* 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_EWMA2_H +#define INCLUDED_FTN_FILTER_EWMA2_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_EWMA2 : public IFilter +{ +public: + FTNoIR_Filter_EWMA2(); + ~FTNoIR_Filter_EWMA2(); + + void Release(); + void Initialize(); + void StartFilter(); + void FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget); + + void getFilterFullName(QString *strToBeFilled); + void getFilterShortName(QString *strToBeFilled); + void getFilterDescription(QString *strToBeFilled); + + bool setParameterValue(const int index, const float newvalue); + +private: + 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]; + + //parameter list for the filter-function(s) + enum + { + kMinSmoothing=0, + kMaxSmoothing, + kSmoothingScaleCurve, + kNumFilterParameters // Indicate number of parameters used + }; + + QString filterFullName; // Filters' name and description + QString filterShortName; + QString filterDescription; + + QList parameterValueAsFloat; + QList> parameterRange; + QList parameterSteps; + QList parameterNameAsString; + QList parameterValueAsString; + QList parameterUnitsAsString; +}; + +//******************************************************************************************************* +// 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); + void getFilterFullName(QString *strToBeFilled); + void getFilterShortName(QString *strToBeFilled); + void getFilterDescription(QString *strToBeFilled); + +private: + Ui::UICFilterControls ui; + void loadSettings(); + void save(); + + /** helper **/ + bool settingsDirty; + + QString filterFullName; // Filters' name and description + QString filterShortName; + QString filterDescription; + +private slots: + void doOK(); + void doCancel(); + void settingChanged() { settingsDirty = true; }; + void settingChanged( int ) { settingsDirty = true; }; +}; + +#endif //INCLUDED_FTN_FILTER_EWMA2_H +//END + diff --git a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj index ebea3e36..3f501218 100644 --- a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj +++ b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj @@ -37,7 +37,7 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_base.h b/FTNoIR_Filter_EWMA2/ftnoir_filter_base.h deleted file mode 100644 index 87c5c14f..00000000 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_base.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef FTNOIR_FILTER_BASE_H -#define FTNOIR_FILTER_BASE_H - -#include "ftnoir_filter_base_global.h" -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" -#include -#include - -// COM-Like abstract interface. -// This interface doesn't require __declspec(dllexport/dllimport) specifier. -// Method calls are dispatched via virtual table. -// Any C++ compiler can use it. -// Instances are obtained via factory function. -struct IFilter -{ - virtual void Release() = 0; - virtual void Initialize() = 0; - virtual void FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget) = 0; - - virtual void getFilterFullName(QString *strToBeFilled) = 0; - virtual void getFilterShortName(QString *strToBeFilled) = 0; - virtual void getFilterDescription(QString *strToBeFilled) = 0; - - //parameter value get/set - returns true if successful, false if not - virtual bool setParameterValue(const int index, const float newvalue) = 0; -}; - -// Handle type. In C++ language the iterface type is used. -typedef IFilter* FILTERHANDLE; - -//////////////////////////////////////////////////////////////////////////////// -// -#ifdef __cplusplus -# define EXTERN_C extern "C" -#else -# define EXTERN_C -#endif // __cplusplus - -// Factory function that creates instances of the Filter object. -EXTERN_C -FTNOIR_FILTER_BASE_EXPORT -FILTERHANDLE -__stdcall -GetFilter( - void); - -#endif // FTNOIR_FILTER_BASE_H diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_base_global.h b/FTNoIR_Filter_EWMA2/ftnoir_filter_base_global.h deleted file mode 100644 index aac4048e..00000000 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_base_global.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef FTNOIR_FILTER_BASE_GLOBAL_H -#define FTNOIR_FILTER_BASE_GLOBAL_H - -#include - -#ifdef FTNOIR_FILTER_BASE_LIB -# define FTNOIR_FILTER_BASE_EXPORT Q_DECL_EXPORT -#else -# define FTNOIR_FILTER_BASE_EXPORT Q_DECL_IMPORT -#endif - -#endif // FTNOIR_FILTER_BASE_GLOBAL_H diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp index 7bdac328..b119df27 100644 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp +++ b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp @@ -1,8 +1,30 @@ -#include "ftnoir_filter_base.h" +/******************************************************************************** +* 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 -#include -#include //#define LOG_OUTPUT @@ -11,53 +33,6 @@ // EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class FTNoIR_Filter_EWMA2 : public IFilter -{ -public: - FTNoIR_Filter_EWMA2(); - ~FTNoIR_Filter_EWMA2(); - - void Release(); - void Initialize(); - void StartFilter(); - void FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget); - - void getFilterFullName(QString *strToBeFilled); - void getFilterShortName(QString *strToBeFilled); - void getFilterDescription(QString *strToBeFilled); - - bool setParameterValue(const int index, const float newvalue); - -private: - 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]; - - //parameter list for the filter-function(s) - enum - { - kMinSmoothing=0, - kMaxSmoothing, - kSmoothingScaleCurve, - kNumFilterParameters // Indicate number of parameters used - }; - - QString filterFullName; // Filters' name and description - QString filterShortName; - QString filterDescription; - - QList parameterValueAsFloat; - QList> parameterRange; - QList parameterSteps; - QList parameterNameAsString; - QList parameterValueAsString; - QList parameterUnitsAsString; -}; FTNoIR_Filter_EWMA2::FTNoIR_Filter_EWMA2() { 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..130bf47b --- /dev/null +++ b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp @@ -0,0 +1,204 @@ +/******************************************************************************** +* 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 ); + + //populate the description strings + filterFullName = "EWMA Filter Mk2"; + filterShortName = "EWMA"; + filterDescription = "Exponentially Weighted Moving Average filter with dynamic smoothing parameter"; + + 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))); + + // 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) { + + 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() << "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() << "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; +} + +void FilterControls::getFilterFullName(QString *strToBeFilled) +{ + *strToBeFilled = filterFullName; +}; + + +void FilterControls::getFilterShortName(QString *strToBeFilled) +{ + *strToBeFilled = filterShortName; +}; + + +void FilterControls::getFilterDescription(QString *strToBeFilled) +{ + *strToBeFilled = filterDescription; +}; + +//////////////////////////////////////////////////////////////////////////////// +// 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 FILTERDIALOGHANDLE __stdcall GetFilterDialog( ) +{ + return new FilterControls; +} -- cgit v1.2.3