From 671a0a2fb81830b364d708a3f6123e44f88042cf Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sun, 15 Jan 2012 16:56:28 +0000 Subject: Finished making the Filter a plug-in and implemented the DZ1 filter. First attempt though... git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@100 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h | 32 +++----- FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj | 46 +++++++++++ FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp | 93 +++++----------------- FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp | 5 ++ 4 files changed, 81 insertions(+), 95 deletions(-) (limited to 'FTNoIR_Filter_EWMA2') diff --git a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h index feec6f1f..f335eb47 100644 --- a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h +++ b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.h @@ -23,8 +23,8 @@ * * ********************************************************************************/ #pragma once -#ifndef INCLUDED_FTN_FILTER_EWMA2_H -#define INCLUDED_FTN_FILTER_EWMA2_H +#ifndef INCLUDED_FTN_FILTER_H +#define INCLUDED_FTN_FILTER_H #include "..\ftnoir_filter_base\ftnoir_filter_base.h" #include "ui_FTNoIR_FilterControls.h" @@ -34,11 +34,11 @@ // EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class FTNoIR_Filter_EWMA2 : public IFilter +class FTNoIR_Filter : public IFilter { public: - FTNoIR_Filter_EWMA2(); - ~FTNoIR_Filter_EWMA2(); + FTNoIR_Filter(); + ~FTNoIR_Filter(); void Release(); void Initialize(); @@ -49,8 +49,6 @@ public: void getFilterShortName(QString *strToBeFilled); void getFilterDescription(QString *strToBeFilled); - bool setParameterValue(const int index, const float newvalue); - private: void loadSettings(); // Load the settings from the INI-file THeadPoseData newHeadPose; // Structure with new headpose @@ -62,25 +60,14 @@ private: 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 - }; + float kMinSmoothing; + float kMaxSmoothing; + float kSmoothingScaleCurve; QString filterFullName; // Filters' name and description QString filterShortName; QString filterDescription; - QList parameterValueAsFloat; - QList> parameterRange; - QList parameterSteps; - QList parameterNameAsString; - QList parameterValueAsString; - QList parameterUnitsAsString; }; //******************************************************************************************************* @@ -102,6 +89,7 @@ public: void getFilterFullName(QString *strToBeFilled); void getFilterShortName(QString *strToBeFilled); void getFilterDescription(QString *strToBeFilled); + void getIcon(QIcon *icon); private: Ui::UICFilterControls ui; @@ -123,6 +111,6 @@ private slots: void settingChanged( int ) { settingsDirty = true; }; }; -#endif //INCLUDED_FTN_FILTER_EWMA2_H +#endif //INCLUDED_FTN_FILTER_H //END diff --git a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj index 3f501218..918f8b28 100644 --- a/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj +++ b/FTNoIR_Filter_EWMA2/FTNoIR_Filter_EWMA2.vcproj @@ -253,6 +253,32 @@ UniqueIdentifier="{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}" ParseFiles="false" > + + + + + + + + + + + + + + + + diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp index 7034a152..179db04c 100644 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp +++ b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2.cpp @@ -22,7 +22,7 @@ * with this program; if not, see . * * * ********************************************************************************/ -#include "ftnoir_filter_EWMA2.h" +#include "ftnoir_filter_ewma2.h" #include "math.h" #include @@ -34,65 +34,32 @@ // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -FTNoIR_Filter_EWMA2::FTNoIR_Filter_EWMA2() +FTNoIR_Filter::FTNoIR_Filter() { //populate the description strings filterFullName = "EWMA Filter Mk2"; filterShortName = "EWMA"; filterDescription = "Exponentially Weighted Moving Average filter with dynamic smoothing parameter"; - //allocate memory for the parameters - parameterValueAsFloat.clear(); - parameterRange.clear(); - parameterSteps.clear(); - parameterNameAsString.clear(); - parameterValueAsString.clear(); - parameterUnitsAsString.clear(); - - //set up parameters - parameterNameAsString.append("MinSmoothing"); - parameterUnitsAsString.append("Frames"); - parameterRange.append(std::pair(1.0f,100.0f)); - parameterSteps.append(1.0f); - parameterValueAsFloat.append(0.0f); - parameterValueAsString.append(""); - setParameterValue(kMinSmoothing,10.0f); - - parameterNameAsString.append("MaxSmoothing"); - parameterUnitsAsString.append("Frames"); - parameterRange.append(std::pair(1.0f,100.0f)); - parameterSteps.append(1.0f); - parameterValueAsFloat.append(0.0f); - parameterValueAsString.append(""); - setParameterValue(kMaxSmoothing,50.0f); - - parameterNameAsString.append("SmoothingScaleCurve"); - parameterUnitsAsString.append("Power"); - parameterRange.append(std::pair(0.25f,10.0f)); - parameterSteps.append(0.0f); - parameterValueAsFloat.append(0.0f); - parameterValueAsString.append(""); - setParameterValue(kSmoothingScaleCurve,10.0f); - first_run = true; alpha_smoothing = 0.02f; // this is a constant for now, might be a parameter later loadSettings(); // Load the Settings } -FTNoIR_Filter_EWMA2::~FTNoIR_Filter_EWMA2() +FTNoIR_Filter::~FTNoIR_Filter() { } -void FTNoIR_Filter_EWMA2::Release() +void FTNoIR_Filter::Release() { delete this; } -void FTNoIR_Filter_EWMA2::Initialize() +void FTNoIR_Filter::Initialize() { - qDebug() << "FTNoIR_Filter_EWMA2::Initialize says: Starting "; + qDebug() << "FTNoIR_Filter::Initialize says: Starting "; loadSettings(); return; } @@ -100,27 +67,27 @@ void FTNoIR_Filter_EWMA2::Initialize() // // Load the current Settings from the currently 'active' INI-file. // -void FTNoIR_Filter_EWMA2::loadSettings() { - qDebug() << "FTNoIR_Filter_EWMA2::loadSettings says: Starting "; +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_EWMA2::loadSettings says: iniFile = " << currentFile; + 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" ); - setParameterValue(0, iniFile.value ( "minSmooth", 15 ).toInt()); - setParameterValue(1, iniFile.value ( "maxSmooth", 50 ).toInt()); - setParameterValue(2, iniFile.value ( "powCurve", 10 ).toInt()); + kMinSmoothing = iniFile.value ( "minSmooth", 15 ).toInt(); + kMaxSmoothing = iniFile.value ( "maxSmooth", 50 ).toInt(); + kSmoothingScaleCurve = iniFile.value ( "powCurve", 10 ).toInt(); iniFile.endGroup (); } -void FTNoIR_Filter_EWMA2::FilterHeadPoseData(THeadPoseData *current_camera_position, THeadPoseData *target_camera_position, THeadPoseData *new_camera_position, bool newTarget) +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]; @@ -195,13 +162,13 @@ void FTNoIR_Filter_EWMA2::FilterHeadPoseData(THeadPoseData *current_camera_posit // if (newTarget) { for (i=0;i<6;i++) { - alpha[i]=1.0f/(parameterValueAsFloat[kMinSmoothing]+((1.0f-pow(norm_output_delta[i],parameterValueAsFloat[kSmoothingScaleCurve]))*smoothing_frames_range)); + 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_EWMA2::FilterHeadPoseData() smoothing frames = " << smoothing_frames_range; - //qDebug() << "FTNoIR_Filter_EWMA2::FilterHeadPoseData() alpha[3] = " << alpha[3]; + //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) @@ -259,43 +226,23 @@ void FTNoIR_Filter_EWMA2::FilterHeadPoseData(THeadPoseData *current_camera_posit return; } -void FTNoIR_Filter_EWMA2::getFilterFullName(QString *strToBeFilled) +void FTNoIR_Filter::getFilterFullName(QString *strToBeFilled) { *strToBeFilled = filterFullName; }; -void FTNoIR_Filter_EWMA2::getFilterShortName(QString *strToBeFilled) +void FTNoIR_Filter::getFilterShortName(QString *strToBeFilled) { *strToBeFilled = filterShortName; }; -void FTNoIR_Filter_EWMA2::getFilterDescription(QString *strToBeFilled) +void FTNoIR_Filter::getFilterDescription(QString *strToBeFilled) { *strToBeFilled = filterDescription; }; -bool FTNoIR_Filter_EWMA2::setParameterValue(const int index, const float newvalue) -{ - if ((index >= 0) && (index < parameterValueAsFloat.size())) - { - parameterValueAsFloat[index]=std::min(std::max(newvalue,parameterRange[index].first),parameterRange[index].second); -// updateParameterString(index); - - if (index==kMinSmoothing || index==kMaxSmoothing) - { - smoothing_frames_range=parameterValueAsFloat[kMaxSmoothing]-parameterValueAsFloat[kMinSmoothing]; - } - return true; - } - else - { - return false; - } -}; - - //////////////////////////////////////////////////////////////////////////////// // Factory function that creates instances if the Filter object. @@ -307,5 +254,5 @@ bool FTNoIR_Filter_EWMA2::setParameterValue(const int index, const float newvalu FTNOIR_FILTER_BASE_EXPORT FILTERHANDLE __stdcall GetFilter() { - return new FTNoIR_Filter_EWMA2; + return new FTNoIR_Filter; } diff --git a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp index f2523145..fd24d552 100644 --- a/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp +++ b/FTNoIR_Filter_EWMA2/ftnoir_filter_ewma2_dialog.cpp @@ -204,6 +204,11 @@ void FilterControls::getFilterDescription(QString *strToBeFilled) *strToBeFilled = filterDescription; }; +void FilterControls::getIcon(QIcon *icon) +{ + *icon = QIcon(":/images/filter-16.png"); +}; + //////////////////////////////////////////////////////////////////////////////// // Factory function that creates instances if the Filter-settings dialog object. -- cgit v1.2.3