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_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 7 files changed, 1780 insertions(+) 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 (limited to 'FTNoIR_Filter_DZ1') diff --git a/FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui b/FTNoIR_Filter_DZ1/FTNoIR_FilterControls.ui new file mode 100644 index 000000000..7de215373 --- /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 000000000..35a5fcb6f --- /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 000000000..a09aa9bde --- /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 000000000..e64ec35a5 --- /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 000000000..ce1b4063d --- /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 000000000..88b4b04be --- /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 000000000..ecde6a108 Binary files /dev/null and b/FTNoIR_Filter_DZ1/images/filter-16.png differ -- cgit v1.2.3