summaryrefslogtreecommitdiffhomepage
path: root/tracker-rs/ftnoir_tracker_rs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-rs/ftnoir_tracker_rs.cpp')
-rw-r--r--tracker-rs/ftnoir_tracker_rs.cpp145
1 files changed, 83 insertions, 62 deletions
diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp
index e073fa3f..99c5e9d0 100644
--- a/tracker-rs/ftnoir_tracker_rs.cpp
+++ b/tracker-rs/ftnoir_tracker_rs.cpp
@@ -7,97 +7,118 @@
#include "ftnoir_tracker_rs.h"
#include "ftnoir_tracker_rs_controls.h"
-
+#include "imagewidget.h"
#include "opentrack/plugin-api.hpp"
#include <QMessageBox>
+#include <QProcess>
+#include <QStackedLayout>
+
+RSTracker::RSTracker() {
+ connect(&mTrackerWorkerThread, &RSTrackerWorkerThread::trackingHasFinished,
+ this, &RSTracker::handleTrackingEnded);
-RSTracker::RSTracker() : mPose{ 0,0,0, 0,0,0 } {
- mThread.setObjectName("RSTrackerWorkerThread");
+ connect(&mPreviewUpdateTimer, &QTimer::timeout,
+ this, &RSTracker::updatePreview);
+}
- mRealSenseImplProcess.moveToThread(&mThread);
- mSocket.moveToThread(&mThread);
+void RSTracker::configurePreviewFrame()
+{
+ if(mImageWidget!=nullptr || mPreviewFrame==nullptr)
+ return;
- connect(&mRealSenseImplProcess, SIGNAL(finished(int)),
- this, SLOT(rsImplProcessFinished(int)), Qt::QueuedConnection);
+ mPreviewFrame->show();
- qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
- connect(&mRealSenseImplProcess, SIGNAL(error(QProcess::ProcessError)),
- this, SLOT(rsImplProcessError(QProcess::ProcessError)), Qt::QueuedConnection);
+ mImageWidget = new ImageWidget(mPreviewFrame);
+ mImageWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- connect(&mSocket, SIGNAL(readyRead()),
- this, SLOT(readPendingUdpPoseData()), Qt::DirectConnection);
+ if(mPreviewFrame->layout() != nullptr){
+ delete mPreviewFrame->layout();
+ }
- connect(&mThread, &QThread::started,
- &mThread, [this]{
- mSocket.bind(QHostAddress::LocalHost, 4242, QUdpSocket::DontShareAddress);
- mRealSenseImplProcess.start("opentrack-tracker-rs-impl.exe", QProcess::NotOpen);
- }, Qt::DirectConnection);
+ QLayout* layout = new QStackedLayout();
+ mPreviewFrame->setLayout(layout);
+ layout->addWidget(mImageWidget);
- connect(&mThread, &QThread::finished,
- &mThread, [this]{
- mRealSenseImplProcess.kill();
- mRealSenseImplProcess.waitForFinished();
- }, Qt::DirectConnection);
+ mImageWidget->show();
}
-void RSTracker::start_tracker(QFrame*)
+void RSTracker::start_tracker(QFrame* previewFrame)
{
- mThread.start();
+ mPreviewFrame = previewFrame;
+
+ configurePreviewFrame();
+
+ startPreview();
+
+ mTrackerWorkerThread.start(QThread::HighPriority);
+}
+
+void RSTracker::startPreview(){
+ mPreviewUpdateTimer.start(kPreviewUpdateInterval);
}
-void RSTracker::readPendingUdpPoseData(){
- double pose[6];
+void RSTracker::updatePreview(){
+ if(mImageWidget!=nullptr && mImageWidget->isEnabled())
+ mImageWidget->setImage(mTrackerWorkerThread.getPreview());
+}
- while(mSocket.hasPendingDatagrams()) {
- mSocket.readDatagram((char*)pose, sizeof(pose));
- QMutexLocker foo(&mMutex);
- memcpy(mPose, pose, sizeof(pose));
+void RSTracker::stopPreview(){
+ mPreviewUpdateTimer.stop();
+}
+
+void RSTracker::handleTrackingEnded(int exitCode){
+ stopPreview();
+
+ if(exitCode!=0)
+ showRealSenseErrorMessageBox(exitCode);
+}
+
+bool RSTracker::startSdkInstallationProcess()
+{
+ bool pStarted = QProcess::startDetached("contrib\\intel_rs_sdk_runtime_websetup_8.0.24.6528.exe --finstall=core,face3d --fnone=all");
+ if(!pStarted){
+ QMessageBox::warning(0, "Intel® RealSense™ Runtime Installation", "Installation process failed to start.", QMessageBox::Ok);
}
+ return pStarted;
}
-void RSTracker::rsImplProcessError(QProcess::ProcessError error){
- if(error == QProcess::FailedToStart){
- QMessageBox::warning(NULL, "RealSense Tracking Error", "Couldn't start the RealSense tracking module.\nMaybe opentrack-tracker-rs-impl.exe is missing.", QMessageBox::Ok);
+void RSTracker::showRealSenseErrorMessageBox(int exitCode)
+{
+ QMessageBox msgBox;
+ msgBox.setIcon(QMessageBox::Critical);
+ msgBox.setText("RealSense Tracking Error");
+ if(exitCode==-101){ //The implementation got an invalid handle from the RealSense SDK session/modules
+ msgBox.setInformativeText("Couldn't initialize RealSense tracking. Please install SDK Runtime R5.");
}
- else if(error == QProcess::Crashed){
- QMessageBox::warning(NULL, "RealSense Tracking Error", "The RealSense tracking module has crashed.", QMessageBox::Ok);
+ else {
+ msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime 2016 R1 to be installed.");
}
-}
+ QPushButton* triggerSdkInstallation = msgBox.addButton("Install Runtime", QMessageBox::ActionRole);
+ msgBox.addButton(QMessageBox::Ok);
+ msgBox.exec();
-void RSTracker::rsImplProcessFinished(int exitCode){
- if(exitCode!=0){
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Critical);
- msgBox.setText("RealSense Tracking Error");
- if(exitCode==-101){ //The implementation got an invalid handle from the RealSense SDK session/modules
- msgBox.setInformativeText("Couldn't initialize RealSense tracking. Please install SDK Runtime R5.");
- }
- else {
- msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime R5 to be installed.");
- }
- QPushButton* triggerSdkInstallation = msgBox.addButton("Install Runtime", QMessageBox::ActionRole);
- msgBox.addButton(QMessageBox::Ok);
- msgBox.exec();
-
- if(msgBox.clickedButton() == triggerSdkInstallation){
- bool pStarted = QProcess::startDetached("contrib\\intel_rs_sdk_runtime_websetup_7.0.23.8048.exe --finstall=core,face3d --fnone=all");
- if(!pStarted){
- QMessageBox::warning(0, "Intel® RealSense™ Runtime Installation", "Installation process failed to start.", QMessageBox::Ok);
- }
- }
- }
+ if(msgBox.clickedButton() == triggerSdkInstallation)
+ startSdkInstallationProcess();
}
void RSTracker::data(double *data)
{
- QMutexLocker foo(&mMutex);
- memcpy(data, mPose, sizeof(mPose));
+ mTrackerWorkerThread.getPose(data);
}
RSTracker::~RSTracker() {
- mThread.quit();
- mThread.wait();
+ stopPreview();
+
+ if(mImageWidget!=nullptr)
+ delete mImageWidget;
+
+ if (mPreviewFrame!=nullptr && mPreviewFrame->layout()!=nullptr)
+ delete mPreviewFrame->layout();
+
+ mTrackerWorkerThread.requestInterruption();
+ mTrackerWorkerThread.quit();
+ mTrackerWorkerThread.wait();
}
QString RSTrackerMetaData::name() {