diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-24 16:34:40 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-24 16:34:40 +0200 |
commit | 92fc39fcfc054effcf1da6017858f3541805f08a (patch) | |
tree | 66b2d2ee9663d3431b60f001a0c64ec899ec58f9 /ftnoir_tracker_sm | |
parent | b9126a18d673dd51bc3bcce8dc97973bddacfc45 (diff) |
faceapi: unbreak build
Diffstat (limited to 'ftnoir_tracker_sm')
-rw-r--r-- | ftnoir_tracker_sm/ftnoir_tracker_faceapi.cpp | 58 | ||||
-rw-r--r-- | ftnoir_tracker_sm/ftnoir_tracker_faceapi_dialog.cpp | 74 | ||||
-rw-r--r-- | ftnoir_tracker_sm/ftnoir_tracker_sm.h | 50 |
3 files changed, 63 insertions, 119 deletions
diff --git a/ftnoir_tracker_sm/ftnoir_tracker_faceapi.cpp b/ftnoir_tracker_sm/ftnoir_tracker_faceapi.cpp index 7fdb8229..b867c60a 100644 --- a/ftnoir_tracker_sm/ftnoir_tracker_faceapi.cpp +++ b/ftnoir_tracker_sm/ftnoir_tracker_faceapi.cpp @@ -26,10 +26,51 @@ #include <QtGui> #include <QMessageBox> #include "facetracknoir/global-settings.h" +#include <QThread> -FTNoIR_Tracker::FTNoIR_Tracker() : lck_shm(SM_MM_DATA, SM_MUTEX, sizeof(SMMemMap)) +FTNoIR_Tracker::FTNoIR_Tracker() : shm(SM_MM_DATA, SM_MUTEX, sizeof(SMMemMap)), started(false) { - pMemData = (SMMemMap*) lck_shm.mem; + pMemData = (SMMemMap*) shm.mem; +} + +static void wait_for_cmd(SMMemMap *pMemData, PortableLockedShm& shm) { + qDebug() << "faceapi: waiting for cmd"; + for (int _ = 0; _ < 3000; _++) + { + bool br = false; + shm.lock(); + if (pMemData->command == 0) + { + br = true; + } + shm.unlock(); + if (br) + break; + QThread::msleep(1); + } + qDebug() << "faceapi: done waiting for cmd"; +} + +// Send a command without parameter-value to the tracking Engine. +// +void FTNoIR_Tracker::doCommand(int command) +{ + shm.lock(); + pMemData->command = command; + shm.unlock(); + wait_for_cmd(pMemData, shm); +} + +// +// Send a command with integer parameter-value to the tracking Engine. +// +void FTNoIR_Tracker::doCommand(int command, int value) +{ + shm.lock(); + pMemData->command = command; // Send command + pMemData->par_val_int = value; + shm.unlock(); + wait_for_cmd(pMemData, shm); } FTNoIR_Tracker::~FTNoIR_Tracker() @@ -47,7 +88,7 @@ FTNoIR_Tracker::~FTNoIR_Tracker() void FTNoIR_Tracker::StartTracker(QFrame *videoframe ) { qDebug() << "FTNoIR_Tracker::Initialize says: Starting "; - QMessageBox::warning(this, + QMessageBox::warning(videoframe, "Tracker deprecation", "Non-free SM FaceAPI is deprecated, hence this annoying message.\n" "It'll be removed for 2.0-final.", @@ -74,12 +115,8 @@ void FTNoIR_Tracker::StartTracker(QFrame *videoframe ) faceAPI->start("\"" + QCoreApplication::applicationDirPath() + "/faceapi/opentrack-faceapi-wrapper" + "\""); // Show the video widget qDebug() << "FTNoIR_Tracker::Initialize says: videoframe = " << videoframe; - if (videoframe != NULL) { videoframe->show(); - } - if ( pMemData != NULL ) { - pMemData->command = FT_SM_START; // Start command } } @@ -100,10 +137,13 @@ void FTNoIR_Tracker::WaitForExit() bool FTNoIR_Tracker::GiveHeadPoseData(double *data) { + if (!started) + doStartEngine(); + started = true; // // Check if the pointer is OK and wait for the Mutex. // - lck_shm.lock(); + shm.lock(); // // Copy the measurements to FaceTrackNoIR. @@ -131,7 +171,7 @@ bool FTNoIR_Tracker::GiveHeadPoseData(double *data) // Reset the handshake, to let faceAPI know we're still here! // pMemData->handshake = 0; - lck_shm.unlock(); + shm.unlock(); return ( pMemData->data.new_pose.confidence > 0 ); } diff --git a/ftnoir_tracker_sm/ftnoir_tracker_faceapi_dialog.cpp b/ftnoir_tracker_sm/ftnoir_tracker_faceapi_dialog.cpp index d8f90e62..1dbdd67f 100644 --- a/ftnoir_tracker_sm/ftnoir_tracker_faceapi_dialog.cpp +++ b/ftnoir_tracker_sm/ftnoir_tracker_faceapi_dialog.cpp @@ -33,17 +33,10 @@ // // Constructor for server-settings-dialog // -TrackerControls::TrackerControls() : - QWidget(), - shm(SM_MM_DATA, SM_MUTEX, sizeof(TFaceData)) +TrackerControls::TrackerControls() : QWidget() { - pMemData = (SMMemMap*) shm.mem; - ui.setupUi( this ); - theTracker = NULL; - prev_state = -1; - //connect(ui.cbxFilterSetting, SIGNAL(currentIndexChanged(int)), this, SLOT(doSetFilter( int ))); //connect(ui.btnCameraSettings, SIGNAL(clicked()), this, SLOT(doShowCam())); @@ -93,7 +86,6 @@ void TrackerControls::doOK() { // override show event void TrackerControls::showEvent ( QShowEvent * event ) { - prev_state = -1; loadSettings(); } @@ -144,8 +136,6 @@ void TrackerControls::loadSettings() { // qDebug() << "loadSettings says: iniFile = " << currentFile; iniFile.beginGroup ( "SMTracker" ); - ui.cbxFilterSetting->setCurrentIndex(iniFile.value ( "FilterLevel", 1 ).toInt()); - ui.chkEnableRoll->setChecked(iniFile.value ( "EnableRoll", 1 ).toBool()); ui.chkEnablePitch->setChecked(iniFile.value ( "EnablePitch", 1 ).toBool()); ui.chkEnableYaw->setChecked(iniFile.value ( "EnableYaw", 1 ).toBool()); @@ -169,8 +159,6 @@ void TrackerControls::save() { QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) iniFile.beginGroup ( "SMTracker" ); - iniFile.setValue ( "FilterLevel", ui.cbxFilterSetting->currentIndex() ); - iniFile.setValue ( "EnableRoll", ui.chkEnableRoll->isChecked() ); iniFile.setValue ( "EnablePitch", ui.chkEnablePitch->isChecked() ); iniFile.setValue ( "EnableYaw", ui.chkEnableYaw->isChecked() ); @@ -180,70 +168,10 @@ void TrackerControls::save() { iniFile.endGroup (); - // - // If the Tracker is active, let it load the new Settings. - // - if (theTracker) { - theTracker->loadSettings(); - } - settingsDirty = false; } -// -// Show the current engine-settings etc. -// -void TrackerControls::showSettings( int newState ) -{ - qDebug() << "TrackerControls::showSettings says: Starting Function"; - switch (newState) - { - case SM_API_ENGINE_STATE_TERMINATED: - ui._engine_state_label->setText("TERMINATED"); - break; - case SM_API_ENGINE_STATE_INVALID: - ui._engine_state_label->setText("INVALID"); - break; - case SM_API_ENGINE_STATE_IDLE: - ui._engine_state_label->setText("IDLE"); - break; - case SM_API_ENGINE_STATE_HT_INITIALIZING: - ui._engine_state_label->setText("INITIALIZING"); - break; - case SM_API_ENGINE_STATE_HT_TRACKING: - ui._engine_state_label->setText("TRACKING"); - break; - case SM_API_ENGINE_STATE_HT_SEARCHING: - ui._engine_state_label->setText("SEARCHING"); - break; - default: - ui._engine_state_label->setText("Unknown State!"); - break; - } - - ui.cbxFilterSetting->setEnabled( (newState == SM_API_ENGINE_STATE_IDLE) ); -} - -// -// Send a command without parameter-value to the tracking Engine. -// -void TrackerControls::doCommand(int command) -{ - shm.lock(); - pMemData->command = command; - shm.unlock(); -} -// -// Send a command with integer parameter-value to the tracking Engine. -// -void TrackerControls::doCommand(int command, int value) -{ - shm.lock(); - pMemData->command = command; // Send command - pMemData->par_val_int = value; - shm.unlock(); -} //////////////////////////////////////////////////////////////////////////////// // Factory function that creates instances if the Tracker-settings dialog object. diff --git a/ftnoir_tracker_sm/ftnoir_tracker_sm.h b/ftnoir_tracker_sm/ftnoir_tracker_sm.h index 615d9d1b..4f38a045 100644 --- a/ftnoir_tracker_sm/ftnoir_tracker_sm.h +++ b/ftnoir_tracker_sm/ftnoir_tracker_sm.h @@ -47,14 +47,20 @@ public: void StopTracker( bool exit ); bool GiveHeadPoseData(double *data); // Returns true if confidence is good void WaitForExit(); - + void doCommand(int foo); + void doCommand(int foo, int bar); + void doStartEngine(){ + doCommand(FT_SM_START); + doCommand(FT_SM_SET_PAR_FILTER, 0); + //doCommand(FT_SM_SHOW_CAM); + } void loadSettings(); private: // // global variables // - PortableLockedShm lck_shm; + PortableLockedShm shm; SMMemMap *pMemData; QProcess *faceAPI; @@ -64,6 +70,7 @@ private: bool bEnableX; bool bEnableY; bool bEnableZ; + bool started; }; // Widget that has controls for SMoIR protocol client-settings. @@ -76,59 +83,28 @@ public: void Initialize(QWidget *parent); void registerTracker(ITracker *tracker) { - theTracker = (FTNoIR_Tracker *) tracker; // Accept the pointer to the Tracker } void unRegisterTracker() { - theTracker = NULL; // Reset the pointer } private: Ui::UICSMClientControls ui; void loadSettings(); - void doCommand( int command ); - void doCommand( int command, int value ); - - /** helper **/ bool settingsDirty; - int prev_state; // Previous engine state - - // - // global variables - // - SMMemMap *pMemData; - - smEngineHandle *engine_handle; - FTNoIR_Tracker *theTracker; - PortableLockedShm shm; private slots: void doOK(); void doCancel(); void save(); void settingChanged() { settingsDirty = true; } - void doTimUpdate(); void showSettings( int newState ); - void doStartEngine(){ - doCommand(FT_SM_START); - } - void doStopEngine(){ - doCommand(FT_SM_STOP); - } - void doShowCam(){ - doCommand(FT_SM_SHOW_CAM); - } - void doSetFilter(int value){ - doCommand(FT_SM_SET_PAR_FILTER, value); - } - void settingChanged(int dummy) { - settingsDirty = true; - } - public slots: - void stateChanged(int newState) { + void stateChanged(int) { settingsDirty = true; } - + void settingChanged(int) { + settingsDirty = true; + } }; //******************************************************************************************************* |