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_Base/ftnoir_filter_base.h | 4 +- FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui | 772 +++++++++++++++++++++ FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.h | 147 ++++ FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.vcproj | 377 ++++++++++ FTNoIR_Filter_DZ1/Filter.qrc | 5 + FTNoIR_Filter_DZ1/ftnoir_filter_dz1.cpp | 251 +++++++ FTNoIR_Filter_DZ1/ftnoir_filter_dz1_dialog.cpp | 228 ++++++ FTNoIR_Filter_DZ1/images/filter-16.png | Bin 0 -> 642 bytes 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 + FaceTrackNoIR/FaceTrackNoIR.cpp | 69 +- FaceTrackNoIR/FaceTrackNoIR.h | 2 - FaceTrackNoIR/tracker.cpp | 15 +- 15 files changed, 1910 insertions(+), 136 deletions(-) create mode 100644 FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui create mode 100644 FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.h create mode 100644 FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.vcproj create mode 100644 FTNoIR_Filter_DZ1/Filter.qrc create mode 100644 FTNoIR_Filter_DZ1/ftnoir_filter_dz1.cpp create mode 100644 FTNoIR_Filter_DZ1/ftnoir_filter_dz1_dialog.cpp create mode 100644 FTNoIR_Filter_DZ1/images/filter-16.png diff --git a/FTNoIR_Filter_Base/ftnoir_filter_base.h b/FTNoIR_Filter_Base/ftnoir_filter_base.h index 8e949553..e7dcd6bc 100644 --- a/FTNoIR_Filter_Base/ftnoir_filter_base.h +++ b/FTNoIR_Filter_Base/ftnoir_filter_base.h @@ -26,9 +26,6 @@ struct IFilter 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 interface type is used. @@ -65,6 +62,7 @@ struct IFilterDialog virtual void getFilterFullName(QString *strToBeFilled) = 0; virtual void getFilterShortName(QString *strToBeFilled) = 0; virtual void getFilterDescription(QString *strToBeFilled) = 0; + virtual void getIcon(QIcon *icon) = 0; }; // Handle type. In C++ language the interface type is used. diff --git a/FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui b/FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui new file mode 100644 index 00000000..7de21537 --- /dev/null +++ b/FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui @@ -0,0 +1,772 @@ + + + UICFilterControls + + + + 0 + 0 + 411 + 366 + + + + DZ1 Filter settings FaceTrackNoIR + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + + + + + + + + 0 + 45 + + + + General Settings + + + + + 10 + 10 + 371 + 31 + + + + + + + + 123 + 0 + + + + + 120 + 16777215 + + + + + + + Camera frequency + + + + + + + + 45 + 15 + + + + 5 + + + 200 + + + 5 + + + 10 + + + 30 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + + + + + + 50 + 22 + + + + background:none; + + + 5 + + + 200 + + + 5 + + + 30 + + + + + + + + 35 + 0 + + + + + 30 + 16777215 + + + + + + + Hz + + + + + + + + + + + + 0 + 90 + + + + High sensitivity settings + + + + + 10 + 10 + 371 + 61 + + + + + + + + 90 + 0 + + + + + 110 + 16777215 + + + + + + + Deadzone + + + + + + + + 35 + 0 + + + + + 100 + 16777215 + + + + + + + degrees + + + + + + + + 110 + 0 + + + + + 130 + 16777215 + + + + + + + Move toward last position + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 5 + + + 10 + + + 24 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 24 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + % + + + + + + + + 50 + 0 + + + + 10.000000000000000 + + + 0.100000000000000 + + + 0.240000000000000 + + + + + + + + + + + + 0 + 90 + + + + Low sensitivity settings + + + + + 10 + 10 + 371 + 61 + + + + + + + + 90 + 0 + + + + + 110 + 16777215 + + + + + + + Maximum difference + + + + + + + + 35 + 0 + + + + + 100 + 16777215 + + + + + + + degrees + + + + + + + + 123 + 0 + + + + + 130 + 16777215 + + + + + + + Move toward saved pos. + + + + + + + + 45 + 15 + + + + 1 + + + 100 + + + 5 + + + 10 + + + 35 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + + + + + + 40 + 22 + + + + background:none; + + + 1 + + + 100 + + + 5 + + + 35 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + % + + + + + + + + 50 + 0 + + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.750000000000000 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + The filter-settings may need some explanation... + + + + + + + Maybe Stanislaw can make one in laymans terms? + + + true + + + + + + + ... + + + + + + + + + + + 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 + + + + + slideHz + valueChanged(int) + spinHz + setValue(int) + + + 291 + 45 + + + 347 + 44 + + + + + spinHz + valueChanged(int) + slideHz + setValue(int) + + + 347 + 44 + + + 291 + 45 + + + + + slideMoveLast + valueChanged(int) + spinMoveLast + setValue(int) + + + 287 + 126 + + + 343 + 125 + + + + + spinMoveLast + valueChanged(int) + slideMoveLast + setValue(int) + + + 343 + 125 + + + 287 + 126 + + + + + slideMoveSaved + valueChanged(int) + spinMoveSaved + setValue(int) + + + 202 + 213 + + + 312 + 212 + + + + + spinMoveSaved + valueChanged(int) + slideMoveSaved + setValue(int) + + + 309 + 203 + + + 260 + 203 + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.h b/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.h new file mode 100644 index 00000000..35a5fcb6 --- /dev/null +++ b/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.h @@ -0,0 +1,147 @@ +/******************************************************************************** +* 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" + +static int compare_double(const void *one, const void *two) { + double foo = (*((double*) one) - *((double*) two)); + if (foo > 0) + return 1; + if (foo < 0) + return -1; + return 0; +} + +//#define HZ 30 + +//#define DEADZONE 0.1 +//#define MOVE_LAST 0.24 +//#define MOVE_SAVED (0.35 / HZ) +#define SLOW_SPEED 0.1 + +//#define MAXDIFF 1.75 +#define INITIAL_SMOOTH_SPEED 0.00834 +#define SMOOTH_FACTOR 2.5 +#define REMEMBER_SMOOTHNESS 5 // Changed from HZ/5 + +#define MULT_Y_POS 1.7 +#define MULT_Y_NEG 0.8 +#define MULT_X 1.5 + +#define COCKPIT_PITCH 8.7 + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// DZ1 Filter: Stanislaw wrote a new filter, which makes the view more stable, when not moving your face. +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +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); + + void getFilterFullName(QString *strToBeFilled); + void getFilterShortName(QString *strToBeFilled); + void getFilterDescription(QString *strToBeFilled); + +private: + void loadSettings(); // Load the settings from the INI-file + THeadPoseData newHeadPose; // Structure with new headpose + + bool first_run; + double last_positions[6]; + double saved_positions[6]; + double prev_positions[6]; + bool smoothing[6]; + double smooth_start[6]; + double smooth_speed[6]; + int smooth_remember[6]; + + float kCameraHz; // Hz + float kDeadZone; // degrees + float kMoveLast; // % + float kMaxDiff; // degrees + float kMoveSaved; // % + + QString filterFullName; // Filters' name and description + QString filterShortName; + QString filterDescription; +}; + +//******************************************************************************************************* +// 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); + void getFilterFullName(QString *strToBeFilled); + void getFilterShortName(QString *strToBeFilled); + void getFilterDescription(QString *strToBeFilled); + void getIcon(QIcon *icon); + +private: + Ui::UICFilterControls ui; + void loadSettings(); + void save(); + + /** helper **/ + bool settingsDirty; + + QString filterFullName; // Filters' name and description + QString filterShortName; + QString filterDescription; + 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; }; + void settingChanged( double ) { settingsDirty = true; }; +}; + +#endif //INCLUDED_FTN_FILTER_H +//END + diff --git a/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.vcproj b/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.vcproj new file mode 100644 index 00000000..a09aa9bd --- /dev/null +++ b/FTNoIR_Filter_DZ1/FTNoIR_Filter_DZ1.vcproj @@ -0,0 +1,377 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FTNoIR_Filter_DZ1/Filter.qrc b/FTNoIR_Filter_DZ1/Filter.qrc new file mode 100644 index 00000000..e64ec35a --- /dev/null +++ b/FTNoIR_Filter_DZ1/Filter.qrc @@ -0,0 +1,5 @@ + + + images/filter-16.png + + diff --git a/FTNoIR_Filter_DZ1/ftnoir_filter_dz1.cpp b/FTNoIR_Filter_DZ1/ftnoir_filter_dz1.cpp new file mode 100644 index 00000000..ce1b4063 --- /dev/null +++ b/FTNoIR_Filter_DZ1/ftnoir_filter_dz1.cpp @@ -0,0 +1,251 @@ +/******************************************************************************** +* 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_DZ1.h" +#include "math.h" +#include + +//#define LOG_OUTPUT + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +FTNoIR_Filter::FTNoIR_Filter() +{ + //populate the description strings + filterFullName = "Deadzone Filter Mk1"; + filterShortName = "DZ1"; + filterDescription = "Deadzone Filter"; + + first_run = true; + 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 ( "Filter_DZ1" ); + kCameraHz = iniFile.value ( "cameraHz", 30 ).toInt(); + kDeadZone = iniFile.value ( "DeadZone", 0.1f ).toFloat(); + kMoveLast = (iniFile.value ( "MoveLast", 24 ).toFloat()) / 100; // Convert from int to float percentage + kMaxDiff = iniFile.value ( "MaxDiff", 1.75f ).toFloat(); + kMoveSaved = ((iniFile.value ( "MoveSaved", 35 ).toFloat()) / 100) / kCameraHz; // Convert from int to float percentage and divide by Hz + 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 + double target[6]; + double prev_output[6]; + double scale[]={3.0, 3.0, 3.0, 3.0, 3.0, 3.0}; +// static double deadzones[] = { DEADZONE, DEADZONE, DEADZONE, DEADZONE, DEADZONE, DEADZONE }; + float output[6]; + int i=0, j=0; + + //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) + { + //on the first run, output=target + for (i=0;i<6;i++) + { + last_positions[i] = target[i]; + saved_positions[i] = target[i]; + prev_positions[i] = target[i]; + smooth_remember[i] = 0; + smoothing[i] = false; + smooth_speed[i] = -1.0; + } + + 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; + } else if (!newTarget) { + int i; + for (i = 0; i < 6; i++) { + output[i] = prev_positions[i]; + } + goto end; + } + + for (i=0;i<6;i++) + { + double e2 = target[i]; + bool slowp = fabs(last_positions[i] - e2) < kDeadZone && fabs(e2 - saved_positions[i]) < kMaxDiff; // DeadZone and MAXDIFF from INI-file + if (smoothing[i] || !slowp) { + double start = smooth_start[i]; + double vec = e2 - start; + int sign = vec < 0 ? -1 : 1; + int sign2 = e2 < 0 ? -1 : 1; + if (sign != sign2) + sign2 = -sign2; + double diff = (kCameraHz / REMEMBER_SMOOTHNESS) - smooth_remember[i]; + smooth_speed[i] *= -(diff * diff) / (double) ((kCameraHz / REMEMBER_SMOOTHNESS) * (kCameraHz / REMEMBER_SMOOTHNESS)) + 1.001; + if (smooth_speed[i] < INITIAL_SMOOTH_SPEED) + smooth_speed[i] = INITIAL_SMOOTH_SPEED; + vec = fabs(vec); + double iter = vec * SMOOTH_FACTOR / (double) kCameraHz; + smooth_speed[i] += iter; + double bleh = smooth_speed[i] * sign; + double foo = smooth_start[i] + bleh; + bool done = sign2 > 0 ? foo > e2 : foo < e2; + smooth_remember[i] = (kCameraHz / REMEMBER_SMOOTHNESS); + if (done) { + smoothing[i] = false; + output[i] = e2; + saved_positions[i] = e2; + last_positions[i] = e2; + prev_positions[i] = e2; + } else { + smoothing[i] = true; + prev_positions[i] = output[i] = foo; + } + } else { + if (smooth_remember[i] <= 0) { + smooth_speed[i] = -1.0; + } else { + smooth_remember[i]--; + } + last_positions[i] = last_positions[i] + (e2 - last_positions[i]) * kMoveLast; // MOVE_LAST from INI-file + saved_positions[i] = saved_positions[i] + (e2 - saved_positions[i]) * kMoveSaved; // MOVE_SAVED from INI-file + output[i] = prev_positions[i] = prev_positions[i] + (e2 - prev_positions[i]) * (SLOW_SPEED/kCameraHz); // Get CameraHz from INI + smooth_start[i] = output[i]; + smoothing[i] = false; +#if 0 + if (i == 3) { + FILE* dlog = fopen("debug-log.txt", "a"); + fprintf(dlog, "slowed=%f frames=%d diff=%f\n", output[i], slow_move_count[i], e1 - last_positions[i]); + fclose(dlog); + } +#endif + } + } + +end: + new_camera_position->x=output[0]; + new_camera_position->y=output[1]; + new_camera_position->z=output[2]; + new_camera_position->yaw=output[3] * MULT_X; + new_camera_position->pitch=output[4] * (output[4] < 0 ? MULT_Y_NEG : MULT_Y_POS) - COCKPIT_PITCH; + new_camera_position->roll=output[5]; + +#if 1 + // + // 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] * MULT_X; + current_camera_position->pitch=output[4] * (output[4] < 0 ? MULT_Y_NEG : MULT_Y_POS) + COCKPIT_PITCH; + current_camera_position->roll=output[5]; +#endif +} + +void FTNoIR_Filter::getFilterFullName(QString *strToBeFilled) +{ + *strToBeFilled = filterFullName; +}; + + +void FTNoIR_Filter::getFilterShortName(QString *strToBeFilled) +{ + *strToBeFilled = filterShortName; +}; + + +void FTNoIR_Filter::getFilterDescription(QString *strToBeFilled) +{ + *strToBeFilled = filterDescription; +}; + +//////////////////////////////////////////////////////////////////////////////// +// 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 FILTERHANDLE __stdcall GetFilter() +{ + return new FTNoIR_Filter; +} diff --git a/FTNoIR_Filter_DZ1/ftnoir_filter_dz1_dialog.cpp b/FTNoIR_Filter_DZ1/ftnoir_filter_dz1_dialog.cpp new file mode 100644 index 00000000..88b4b04b --- /dev/null +++ b/FTNoIR_Filter_DZ1/ftnoir_filter_dz1_dialog.cpp @@ -0,0 +1,228 @@ +/******************************************************************************** +* 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_DZ1.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 = "Deadzone Filter Mk1"; + filterShortName = "DZ1"; + filterDescription = "Deadzone Filter"; + + 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.slideHz, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int))); + connect(ui.spinDeadZone, SIGNAL(valueChanged(double)), this, SLOT(settingChanged(double))); + connect(ui.slideMoveLast, 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 DZ1-filter-settings + // + iniFile.beginGroup ( "Filter_DZ1" ); + ui.slideHz->setValue (iniFile.value ( "cameraHz", 30 ).toInt()); + ui.spinDeadZone->setValue (iniFile.value ( "DeadZone", 0.1f ).toDouble()); + ui.slideMoveLast->setValue (iniFile.value ( "MoveLast", 24 ).toInt()); + ui.spinMaxDiff->setValue (iniFile.value ( "MaxDiff", 1.75f ).toDouble()); + ui.slideMoveSaved->setValue (iniFile.value ( "MoveSaved", 35 ).toFloat()); + 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 ( "Filter_DZ1" ); + iniFile.setValue ( "cameraHz", ui.slideHz->value() ); + iniFile.setValue ( "DeadZone", ui.spinDeadZone->value() ); + iniFile.setValue ( "MoveLast", ui.slideMoveLast->value() ); + iniFile.setValue ( "MaxDiff", ui.spinMaxDiff->value() ); + iniFile.setValue ( "MoveSaved", ui.slideMoveSaved->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; +}; + +void FilterControls::getIcon(QIcon *icon) +{ + *icon = QIcon(":/images/filter-16.png"); +}; + +//////////////////////////////////////////////////////////////////////////////// +// 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; +} diff --git a/FTNoIR_Filter_DZ1/images/filter-16.png b/FTNoIR_Filter_DZ1/images/filter-16.png new file mode 100644 index 00000000..ecde6a10 Binary files /dev/null and b/FTNoIR_Filter_DZ1/images/filter-16.png differ 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. diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index 73d201c3..7e7800bf 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -153,6 +153,7 @@ void FaceTrackNoIR::setupFaceTrackNoIR() { connect(ui.iconcomboProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(profileSelected(int))); connect(ui.iconcomboTrackerSource, SIGNAL(currentIndexChanged(int)), this, SLOT(trackingSourceSelected(int))); connect(ui.iconcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setIcon(int))); + connect(ui.iconcomboFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(filterSelected(int))); //Setup the timer for automatically minimizing after StartTracker. timMinimizeFTN = new QTimer(this); @@ -332,9 +333,6 @@ void FaceTrackNoIR::save() { iniFile.setValue ( "invertY", ui.chkInvertY->isChecked() ); iniFile.setValue ( "invertZ", ui.chkInvertZ->isChecked() ); iniFile.setValue ( "useEWMA", ui.chkUseEWMA->isChecked() ); - //iniFile.setValue ( "minSmooth", ui.minSmooth->value() ); - //iniFile.setValue ( "powCurve", ui.powCurve->value() ); - //iniFile.setValue ( "maxSmooth", ui.maxSmooth->value() ); iniFile.endGroup (); iniFile.beginGroup ( "GameProtocol" ); @@ -453,9 +451,6 @@ void FaceTrackNoIR::loadSettings() { ui.chkInvertZ->setChecked (iniFile.value ( "invertZ", 0 ).toBool()); ui.chkUseEWMA->setChecked (iniFile.value ( "useEWMA", 1 ).toBool()); - //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 (); iniFile.beginGroup ( "GameProtocol" ); @@ -468,6 +463,22 @@ void FaceTrackNoIR::loadSettings() { trackingSourceSelected( ui.iconcomboTrackerSource->currentIndex() ); iniFile.endGroup (); + // + // Read the currently selected Filter from the INI-file. + // + iniFile.beginGroup ( "Filter" ); + QString selectedFilterName = iniFile.value ( "Selection", "FTNoIR_Filter_EWMA2.dll" ).toString(); + qDebug() << "createIconGroupBox says: selectedFilterName = " << selectedFilterName; + iniFile.endGroup (); + + disconnect(ui.iconcomboFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(filterSelected(int))); + for ( int i = 0; i < filterFileList.size(); i++) { + if (filterFileList.at(i) == selectedFilterName) { + ui.iconcomboFilter->setCurrentIndex( i ); + } + } + connect(ui.iconcomboFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(filterSelected(int))); + settingsDirty = false; } @@ -1005,6 +1016,7 @@ void FaceTrackNoIR::createIconGroupBox() importGetFilterDialog getIT; QLibrary *filterLib; QString *filterName; +QIcon *filterIcon; QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) @@ -1028,14 +1040,6 @@ QString *filterName; # endif - // - // Read the currently selected Filter from the INI-file. - // - iniFile.beginGroup ( "Filter" ); - QString selectedFilterName = iniFile.value ( "Selection", "FTNoIR_Filter_EWMA2.dll" ).toString(); - qDebug() << "createIconGroupBox says: selectedFilterName = " << selectedFilterName; - iniFile.endGroup (); - // // Get a List of all the Filter-DLL-files in the Program-folder. // @@ -1064,6 +1068,7 @@ QString *filterName; // Show the appropriate Protocol-server Settings filterLib = new QLibrary(filterFileList.at(i)); filterName = new QString(""); + filterIcon = new QIcon(); getIT = (importGetFilterDialog) filterLib->resolve("GetFilterDialog"); if (getIT) { @@ -1072,6 +1077,7 @@ QString *filterName; { pFilterDialog = ptrXyz; pFilterDialog->getFilterFullName( filterName ); + pFilterDialog->getIcon( filterIcon ); qDebug() << "FaceTrackNoIR::showServerControls GetFilterDialog Function Resolved!"; } else { @@ -1082,16 +1088,10 @@ QString *filterName; QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); } - ui.iconcomboFilter->addItem(QIcon(":/images/Settings16.png"), *filterName ); - if (filterFileList.at(i) == selectedFilterName) { - ui.iconcomboFilter->setItemIcon(i, QIcon(":/images/SettingsOpen16.png")); - ui.iconcomboFilter->setCurrentIndex( i ); - } + ui.iconcomboFilter->addItem(*filterIcon, *filterName ); } connect(ui.iconcomboFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(filterSelected(int))); -// qDebug() << "loadSettings says: iniFile = " << currentFile; - } // @@ -1222,7 +1222,7 @@ void FaceTrackNoIR::profileSelected(int index) QFileInfo pathInfo ( currentFile ); // - // Get a List of all the INI-files in the (currently active) Settings-folder. + // Save the name of the INI-file in the Registry. // settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + iniFileList.at(ui.iconcomboProfile->currentIndex())); loadSettings(); @@ -1233,18 +1233,19 @@ void FaceTrackNoIR::profileSelected(int index) // void FaceTrackNoIR::filterSelected(int index) { - //// - //// Read the current INI-file setting, to get the folder in which it's located... - //// - //QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) - //QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); - // QFileInfo pathInfo ( currentFile ); - - //// - //// Get a List of all the INI-files in the (currently active) Settings-folder. - //// - //settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + iniFileList.at(ui.iconcomboProfile->currentIndex())); - //loadSettings(); + 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) + + // + // Save the name of the filter in the INI-file. Do this immediately, so the Tracker can just read it from the INI-file to load the filter. + // + iniFile.beginGroup ( "Filter" ); + iniFile.setValue ( "Selection", filterFileList.at(ui.iconcomboFilter->currentIndex()) ); + iniFile.endGroup (); + + ui.btnShowFilterControls->setEnabled ( true ); } // diff --git a/FaceTrackNoIR/FaceTrackNoIR.h b/FaceTrackNoIR/FaceTrackNoIR.h index 93403be7..f39062bc 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.h +++ b/FaceTrackNoIR/FaceTrackNoIR.h @@ -93,8 +93,6 @@ private: /** Widget variables **/ QVBoxLayout *l; -// QWidget *_engine_controls; -// QWidget *_server_controls; QWidget *_preferences; QWidget *_keyboard_shortcuts; QWidget *_curve_config; diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 70754a1c..cb3a5b79 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -255,8 +255,19 @@ QFrame *video_frame; // // Load the DLL with the filter-logic and retrieve a pointer to the Filter-class. - // - filterLib = new QLibrary("FTNoIR_Filter_EWMA2.dll"); + // The name of the filter can be found in the INI-file... + libName.clear(); + 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 ( "Filter" ); + libName = iniFile.value ( "Selection", "FTNoIR_Filter_EWMA2.dll" ).toString(); + qDebug() << "Tracker::Tracker() says: selectedFilterName = " << libName; + iniFile.endGroup (); + + filterLib = new QLibrary(libName); getFilter = (importGetFilter) filterLib->resolve("GetFilter"); if (getFilter) { -- cgit v1.2.3