summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--facetracknoir/facetracknoir.cpp20
-rw-r--r--facetracknoir/facetracknoir.h10
-rw-r--r--facetracknoir/tracker.cpp32
-rw-r--r--facetracknoir/tracker.h115
-rw-r--r--qfunctionconfigurator/functionconfig.cpp44
-rw-r--r--qfunctionconfigurator/functionconfig.h5
6 files changed, 98 insertions, 128 deletions
diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp
index 8937ae91..42ce06a3 100644
--- a/facetracknoir/facetracknoir.cpp
+++ b/facetracknoir/facetracknoir.cpp
@@ -194,7 +194,7 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent, Qt::WFlags flags) :
looping(false),
timUpdateHeadPose(this)
{
- GlobalPose = new HeadPoseData();
+ ui.setupUi(this);
cameraDetected = false;
//
@@ -227,8 +227,6 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent, Qt::WFlags flags) :
/** sets up all objects and connections to buttons */
void FaceTrackNoIR::setupFaceTrackNoIR() {
- ui.setupUi(this);
-
// if we simply place a global variable with THeadPoseData,
// it gets initialized and pulls in QSettings before
// main() starts. program can and will crash.
@@ -650,8 +648,8 @@ void FaceTrackNoIR::startTracker( ) {
for (int i = 0; i < 6; i++)
{
- GlobalPose->axes[i].curvePtr->loadSettings(iniFile);
- GlobalPose->axes[i].curvePtrAlt->loadSettings(iniFile);
+ axis(i).curve.loadSettings(iniFile);
+ axis(i).curveAlt.loadSettings(iniFile);
}
static const char* names[] = {
@@ -675,8 +673,8 @@ void FaceTrackNoIR::startTracker( ) {
iniFile.beginGroup("Tracking");
for (int i = 0; i < 6; i++) {
- GlobalPose->axes[i].altp = iniFile.value(names[i], false).toBool();
- GlobalPose->axes[i].invert = iniFile.value(invert_names[i], false).toBool() ? 1 : -1;
+ axis(i).altp = iniFile.value(names[i], false).toBool();
+ axis(i).invert = iniFile.value(invert_names[i], false).toBool() ? 1 : -1;
}
iniFile.endGroup();
@@ -1483,8 +1481,8 @@ QWidget( parent , f)
for (int i = 0; i < 6; i++)
{
- configs[i]->setConfig(GlobalPose->axes[i].curvePtr, currentFile);
- alt_configs[i]->setConfig(GlobalPose->axes[i].curvePtrAlt, currentFile);
+ configs[i]->setConfig(&mainApp->axis(i).curve, currentFile);
+ alt_configs[i]->setConfig(&mainApp->axis(i).curveAlt, currentFile);
connect(configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)));
connect(alt_configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)));
connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(curveChanged(int)));
@@ -1575,7 +1573,7 @@ void CurveConfigurationDialog::loadSettings() {
iniFile.beginGroup("Tracking");
for (int i = 0; i < 6; i++)
- GlobalPose->axes[i].altp = iniFile.value(names[i], false).toBool();
+ mainApp->axis(i).altp = iniFile.value(names[i], false).toBool();
QCheckBox* widgets[] = {
ui.tx_altp,
@@ -1587,7 +1585,7 @@ void CurveConfigurationDialog::loadSettings() {
};
for (int i = 0; i < 6; i++)
- widgets[i]->setChecked(GlobalPose->axes[i].altp);
+ widgets[i]->setChecked(mainApp->axis(i).altp);
QDoubleSpinBox* widgets2[] = {
ui.pos_tx,
diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h
index b2f1ea27..aa657c0e 100644
--- a/facetracknoir/facetracknoir.h
+++ b/facetracknoir/facetracknoir.h
@@ -63,6 +63,7 @@
#include "ftnoir_filter_base/ftnoir_filter_base.h"
#include "global-settings.h"
+#include "tracker.h"
class Tracker; // pre-define class to avoid circular includes
class FaceTrackNoIR;
@@ -116,6 +117,10 @@ public:
DynamicLibrary* current_filter() {
return dlopen_filters.value(ui.iconcomboFilter->currentIndex(), (DynamicLibrary*) NULL);
}
+ THeadPoseDOF& axis(int idx) {
+ return *pose.axes[idx];
+ }
+
#if defined(_WIN32) || defined(__WIN32)
Key keyCenter, keyZero, keyStartStop, keyInhibit;
KeybindingWorker* keybindingWorker;
@@ -129,6 +134,7 @@ public slots:
void shortcutRecentered();
private:
+ HeadPoseData pose;
Ui::FaceTrackNoIRClass ui;
QTimer timUpdateHeadPose; // Timer to display headpose
QStringList iniFileList; // List of INI-files, that are present in the Settings folder
@@ -207,7 +213,7 @@ private:
};
-class KeyboardShortcutDialog: public QWidget, public Ui::UICKeyboardShortcutDialog
+class KeyboardShortcutDialog: public QWidget
{
Q_OBJECT
public:
@@ -233,7 +239,7 @@ private slots:
};
// Widget that has controls for Keyboard shortcuts.
-class CurveConfigurationDialog: public QWidget, public Ui::UICCurveConfigurationDialog
+class CurveConfigurationDialog: public QWidget
{
Q_OBJECT
public:
diff --git a/facetracknoir/tracker.cpp b/facetracknoir/tracker.cpp
index c42cfa22..3f826f3f 100644
--- a/facetracknoir/tracker.cpp
+++ b/facetracknoir/tracker.cpp
@@ -68,8 +68,6 @@
#include "tracker.h"
#include "facetracknoir.h"
-HeadPoseData* GlobalPose = NULL;
-
/** constructor **/
Tracker::Tracker( FaceTrackNoIR *parent ) :
confid(false),
@@ -89,14 +87,14 @@ Tracker::~Tracker()
static void get_curve(double pos, double& out, THeadPoseDOF& axis) {
bool altp = (pos < 0) && axis.altp;
if (altp) {
- out = axis.invert * axis.curvePtrAlt->getValue(pos);
- axis.curvePtr->setTrackingActive( false );
- axis.curvePtrAlt->setTrackingActive( true );
+ out = axis.invert * axis.curveAlt.getValue(pos);
+ axis.curve.setTrackingActive( false );
+ axis.curveAlt.setTrackingActive( true );
}
else {
- out = axis.invert * axis.curvePtr->getValue(pos);
- axis.curvePtr->setTrackingActive( true );
- axis.curvePtrAlt->setTrackingActive( false );
+ out = axis.invert * axis.curve.getValue(pos);
+ axis.curve.setTrackingActive( true );
+ axis.curveAlt.setTrackingActive( false );
}
out += axis.zero;
}
@@ -141,7 +139,7 @@ void Tracker::run() {
if ( confid ) {
for (int i = 0; i < 6; i++)
- GlobalPose->axes[i].headPos = newpose[i];
+ mainApp->axis(i).headPos = newpose[i];
}
//
@@ -153,7 +151,7 @@ void Tracker::run() {
//
if (confid) {
for (int i = 0; i < 6; i++)
- offset_camera.axes[i] = GlobalPose->axes[i].headPos;
+ offset_camera.axes[i] = mainApp->axis(i).headPos;
}
Tracker::do_center = false;
@@ -166,7 +164,7 @@ void Tracker::run() {
if (getTrackingActive()) {
// get values
for (int i = 0; i < 6; i++)
- target_camera.axes[i] = GlobalPose->axes[i].headPos;
+ target_camera.axes[i] = mainApp->axis(i).headPos;
// do the centering
target_camera = target_camera - offset_camera;
@@ -184,7 +182,7 @@ void Tracker::run() {
}
for (int i = 0; i < 6; i++) {
- get_curve(new_camera.axes[i], output_camera.axes[i], GlobalPose->axes[i]);
+ get_curve(new_camera.axes[i], output_camera.axes[i], mainApp->axis(i));
}
//
@@ -202,8 +200,8 @@ void Tracker::run() {
for (int i = 0; i < 6; i++)
{
- GlobalPose->axes[i].curvePtr->setTrackingActive(false);
- GlobalPose->axes[i].curvePtrAlt->setTrackingActive(false);
+ mainApp->axis(i).curve.setTrackingActive(false);
+ mainApp->axis(i).curveAlt.setTrackingActive(false);
}
}
@@ -213,7 +211,7 @@ void Tracker::run() {
void Tracker::getHeadPose( double *data ) {
for (int i = 0; i < 6; i++)
{
- data[i] = GlobalPose->axes[i].headPos;
+ data[i] = mainApp->axis(i).headPos;
}
}
@@ -249,9 +247,9 @@ void Tracker::loadSettings() {
};
for (int i = 0; i < 6; i++)
- GlobalPose->axes[i].zero = iniFile.value(names2[i], 0).toDouble();
+ mainApp->axis(i).zero = iniFile.value(names2[i], 0).toDouble();
iniFile.endGroup();
}
-void Tracker::setInvertAxis(Axis axis, bool invert) { GlobalPose->axes[axis].invert = invert?-1.0f:1.0f; }
+void Tracker::setInvertAxis(Axis axis, bool invert) { mainApp->axis(axis).invert = invert?-1.0f:1.0f; }
diff --git a/facetracknoir/tracker.h b/facetracknoir/tracker.h
index be39e14f..1b5baf3d 100644
--- a/facetracknoir/tracker.h
+++ b/facetracknoir/tracker.h
@@ -57,88 +57,51 @@
#include "ftnoir_filter_base/ftnoir_filter_base.h"
#include "tracker_types.h"
-// include the DirectX Library files
-//#pragma comment (lib, "dinput8.lib")
-//#pragma comment (lib, "dxguid.lib")
-
-enum AngleName {
- PITCH = 0,
- YAW = 1,
- ROLL = 2,
- X = 3,
- Y = 4,
- Z = 5
-};
-
-enum FTNoIR_Client {
- FREE_TRACK = 0,
- FLIGHTGEAR = 1,
- FTNOIR = 2,
- PPJOY = 3,
- TRACKIR = 4,
- SIMCONNECT = 5,
- FSUIPC = 6,
- MOUSE = 7
-};
-
-//enum FTNoIR_Face_Tracker {
-// FT_SM_FACEAPI = 0,
-// FT_FTNOIR = 1,
-// FT_VISAGE = 2
-//};
-
-enum FTNoIR_Tracker_Status {
- TRACKER_OFF = 0,
- TRACKER_ON = 1
-};
-
class FaceTrackNoIR; // pre-define parent-class to avoid circular includes
-struct HeadPoseData;
-extern HeadPoseData* GlobalPose;
-
//
// Structure to hold all variables concerning one of 6 DOF's
//
class THeadPoseDOF {
+private:
+ THeadPoseDOF(const THeadPoseDOF &) {}
public:
- THeadPoseDOF(QString primary = "", QString secondary= "", int maxInput1 = 50, int maxOutput1 = 180, int maxInput2 = 50, int maxOutput2 = 90) {
- curvePtr = NULL;
- curvePtrAlt = NULL;
+ THeadPoseDOF() :
+ headPos(0),
+ invert(0),
+ altp(false),
+ zero(0)
+ {
+ }
+
+ THeadPoseDOF(QString primary,
+ QString secondary,
+ int maxInput1,
+ int maxOutput1,
+ int maxInput2,
+ int maxOutput2) :
+ curve(primary, maxInput1, maxOutput1),
+ curveAlt(secondary, maxInput2, maxOutput2),
+ headPos(0),
+ invert(1),
+ zero(0)
+ {
QSettings settings("opentrack"); // 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)
-
- if (primary != "")
- {
- curvePtr = new FunctionConfig(primary, maxInput1, maxOutput1); // Create the Function-config for input-output translation
- curvePtr->loadSettings(iniFile); // Load the settings from the INI-file
- }
-
- if (secondary != "")
- {
- curvePtrAlt = new FunctionConfig(secondary, maxInput2, maxOutput2);
- curvePtrAlt->loadSettings(iniFile);
- iniFile.beginGroup("Tracking");
- altp = iniFile.value(secondary).toBool();
- iniFile.endGroup();
- }
- headPos = 0.0f;
- invert = 1;
- zero = 0;
+ QSettings iniFile( currentFile, QSettings::IniFormat );
+ curve.loadSettings(iniFile);
+ curveAlt.loadSettings(iniFile);
+
+ iniFile.beginGroup("Tracking");
+ altp = iniFile.value(secondary).toBool();
+ iniFile.endGroup();
}
float headPos; // Current position (from faceTracker, radials or meters)
float invert; // Invert measured value (= 1.0f or -1.0f)
- FunctionConfig* curvePtr; // Function to translate input -> output
- FunctionConfig* curvePtrAlt;
+ FunctionConfig curve; // Function to translate input -> output
+ FunctionConfig curveAlt;
bool altp;
float zero;
- ~THeadPoseDOF() {
- if (curvePtr)
- delete curvePtr;
- if (curvePtrAlt)
- delete curvePtrAlt;
- }
};
class Tracker : public QThread {
@@ -171,17 +134,17 @@ public:
T6DOF output_camera;
};
-struct HeadPoseData {
+class HeadPoseData {
public:
- THeadPoseDOF axes[6];
+ THeadPoseDOF* axes[6];
HeadPoseData()
{
- axes[TX] = THeadPoseDOF("tx","tx_alt", 100, 100, 100, 100);
- axes[TY] = THeadPoseDOF("ty","ty_alt", 100, 100, 100, 100);
- axes[TZ] = THeadPoseDOF("tz","tz_alt", 100, 100, 100, 100);
- axes[RX] = THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180);
- axes[RY] = THeadPoseDOF("ry", "ry_alt", 180, 180, 180, 180);
- axes[RZ] = THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180);
+ axes[TX] = new THeadPoseDOF("tx","tx_alt", 100, 100, 100, 100);
+ axes[TY] = new THeadPoseDOF("ty","ty_alt", 100, 100, 100, 100);
+ axes[TZ] = new THeadPoseDOF("tz","tz_alt", 100, 100, 100, 100);
+ axes[RX] = new THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180);
+ axes[RY] = new THeadPoseDOF("ry", "ry_alt", 180, 180, 180, 180);
+ axes[RZ] = new THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180);
}
};
diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp
index 511f3c93..1b06bdc2 100644
--- a/qfunctionconfigurator/functionconfig.cpp
+++ b/qfunctionconfigurator/functionconfig.cpp
@@ -6,6 +6,7 @@
* notice appear in all copies.
*/
+#include <QMutexLocker>
#include <QCoreApplication>
#include <QPointF>
#include <QList>
@@ -20,9 +21,9 @@
//
// Constructor with List of Points in argument.
//
-FunctionConfig::FunctionConfig(QString title, int intMaxInput, int intMaxOutput) :
- _mutex(QMutex::Recursive)
+FunctionConfig::FunctionConfig(QString title, int intMaxInput, int intMaxOutput)
{
+ _mutex = new QMutex(QMutex::Recursive);
_title = title;
_points = QList<QPointF>();
_data = 0;
@@ -38,18 +39,28 @@ FunctionConfig::FunctionConfig(QString title, int intMaxInput, int intMaxOutput)
reload();
}
+FunctionConfig::FunctionConfig() :
+ _tracking_active(false),
+ _max_Input(0),
+ _max_Output(0),
+ _data(0),
+ _mutex(0),
+ _size(0)
+{
+ _mutex = new QMutex();
+}
+
//
// Calculate the value of the function, given the input 'x'.
// Used to draw the curve and, most importantly, to translate input to output.
// The return-value is also stored internally, so the Widget can show the current value, when the Tracker is running.
//
float FunctionConfig::getValue(float x) {
+ QMutexLocker foo(_mutex);
int x2 = (int) (std::min<float>(std::max<float>(x, -360), 360) * MEMOIZE_PRECISION);
- _mutex.lock();
float ret = getValueInternal(x2);
lastValueTracked.setX(x);
lastValueTracked.setY(ret);
- _mutex.unlock();
return ret;
}
@@ -57,11 +68,8 @@ float FunctionConfig::getValue(float x) {
// The return-value is also stored internally, so the Widget can show the current value, when the Tracker is running.
//
bool FunctionConfig::getLastPoint(QPointF& point ) {
-
- _mutex.lock();
+ QMutexLocker foo(_mutex);
point = lastValueTracked;
- _mutex.unlock();
-
return _tracking_active;
}
@@ -159,6 +167,8 @@ void FunctionConfig::reload() {
FunctionConfig::~FunctionConfig() {
if (_data)
delete[] _data;
+ if (_mutex)
+ delete _mutex;
}
//
@@ -166,13 +176,12 @@ FunctionConfig::~FunctionConfig() {
// Used by the Widget.
//
void FunctionConfig::removePoint(int i) {
- _mutex.lock();
+ QMutexLocker foo(_mutex);
if (i >= 0 && i < _points.size())
{
_points.removeAt(i);
reload();
}
- _mutex.unlock();
}
//
@@ -180,10 +189,9 @@ void FunctionConfig::removePoint(int i) {
// Used by the Widget and by loadSettings.
//
void FunctionConfig::addPoint(QPointF pt) {
- _mutex.lock();
+ QMutexLocker foo(_mutex);
_points.append(pt);
reload();
- _mutex.unlock();
}
//
@@ -191,13 +199,12 @@ void FunctionConfig::addPoint(QPointF pt) {
// Used by the Widget.
//
void FunctionConfig::movePoint(int idx, QPointF pt) {
- _mutex.lock();
+ QMutexLocker foo(_mutex);
if (idx >= 0 && idx < _points.size())
{
_points[idx] = pt;
reload();
}
- _mutex.unlock();
}
//
@@ -206,11 +213,10 @@ void FunctionConfig::movePoint(int idx, QPointF pt) {
//
QList<QPointF> FunctionConfig::getPoints() {
QList<QPointF> ret;
- _mutex.lock();
+ QMutexLocker foo(_mutex);
for (int i = 0; i < _points.size(); i++) {
ret.append(_points[i]);
}
- _mutex.unlock();
return ret;
}
@@ -219,6 +225,7 @@ QList<QPointF> FunctionConfig::getPoints() {
// Settings for a specific Curve are loaded from their own Group in the INI-file.
//
void FunctionConfig::loadSettings(QSettings& settings) {
+ QMutexLocker foo(_mutex);
QPointF newPoint;
QList<QPointF> points;
@@ -244,10 +251,8 @@ void FunctionConfig::loadSettings(QSettings& settings) {
points.append(newPoint);
}
settings.endGroup();
- _mutex.lock();
_points = points;
reload();
- _mutex.unlock();
}
//
@@ -256,7 +261,7 @@ void FunctionConfig::loadSettings(QSettings& settings) {
// The number of Points is also saved, to make loading more convenient.
//
void FunctionConfig::saveSettings(QSettings& settings) {
- _mutex.lock();
+ QMutexLocker foo(_mutex);
settings.beginGroup(QString("Curves-%1").arg(_title));
int max = _points.size();
settings.setValue("point-count", max);
@@ -274,5 +279,4 @@ void FunctionConfig::saveSettings(QSettings& settings) {
settings.remove(QString("point-%1-y").arg(i));
}
settings.endGroup();
- _mutex.unlock();
}
diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h
index e96d7ffc..0e87c4c8 100644
--- a/qfunctionconfigurator/functionconfig.h
+++ b/qfunctionconfigurator/functionconfig.h
@@ -20,7 +20,7 @@
class FTNOIR_TRACKER_BASE_EXPORT FunctionConfig {
private:
- QMutex _mutex;
+ QMutex* _mutex;
QList<QPointF> _points;
void reload();
float* _data;
@@ -31,11 +31,12 @@ private:
volatile bool _tracking_active;
int _max_Input;
int _max_Output;
-
+ FunctionConfig(const FunctionConfig&) {}
public:
//
// Contructor(s) and destructor
//
+ FunctionConfig();
FunctionConfig(QString title, int intMaxInput, int intMaxOutput);
virtual ~FunctionConfig();