summaryrefslogtreecommitdiffhomepage
path: root/tracker-rs
diff options
context:
space:
mode:
authorXavier Hallade <xavier.hallade@intel.com>2016-02-12 10:46:39 +0100
committerXavier Hallade <xavier.hallade@intel.com>2016-02-12 10:46:39 +0100
commit61a58641089b07b23910c94c677e262388039fb9 (patch)
tree48fa2bdae749e5cfb831b902924ae46942f5b862 /tracker-rs
parent652bdad279f7769523d3c6faa609448028907256 (diff)
tracker/rs: cleaned up preview widget setup and deletetion.
Diffstat (limited to 'tracker-rs')
-rw-r--r--tracker-rs/ftnoir_tracker_rs.cpp14
-rw-r--r--tracker-rs/ftnoir_tracker_rs_worker.cpp4
-rw-r--r--tracker-rs/imagewidget.cpp9
-rw-r--r--tracker-rs/imagewidget.h3
4 files changed, 20 insertions, 10 deletions
diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp
index d8d12210..99c5e9d0 100644
--- a/tracker-rs/ftnoir_tracker_rs.cpp
+++ b/tracker-rs/ftnoir_tracker_rs.cpp
@@ -26,6 +26,8 @@ void RSTracker::configurePreviewFrame()
if(mImageWidget!=nullptr || mPreviewFrame==nullptr)
return;
+ mPreviewFrame->show();
+
mImageWidget = new ImageWidget(mPreviewFrame);
mImageWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
@@ -35,19 +37,20 @@ void RSTracker::configurePreviewFrame()
QLayout* layout = new QStackedLayout();
mPreviewFrame->setLayout(layout);
-
layout->addWidget(mImageWidget);
+
+ mImageWidget->show();
}
void RSTracker::start_tracker(QFrame* previewFrame)
{
mPreviewFrame = previewFrame;
- mTrackerWorkerThread.start(QThread::HighPriority);
-
configurePreviewFrame();
startPreview();
+
+ mTrackerWorkerThread.start(QThread::HighPriority);
}
void RSTracker::startPreview(){
@@ -55,7 +58,7 @@ void RSTracker::startPreview(){
}
void RSTracker::updatePreview(){
- if(mImageWidget->isEnabled())
+ if(mImageWidget!=nullptr && mImageWidget->isEnabled())
mImageWidget->setImage(mTrackerWorkerThread.getPreview());
}
@@ -107,6 +110,9 @@ void RSTracker::data(double *data)
RSTracker::~RSTracker() {
stopPreview();
+ if(mImageWidget!=nullptr)
+ delete mImageWidget;
+
if (mPreviewFrame!=nullptr && mPreviewFrame->layout()!=nullptr)
delete mPreviewFrame->layout();
diff --git a/tracker-rs/ftnoir_tracker_rs_worker.cpp b/tracker-rs/ftnoir_tracker_rs_worker.cpp
index 213f13ff..c0ea6749 100644
--- a/tracker-rs/ftnoir_tracker_rs_worker.cpp
+++ b/tracker-rs/ftnoir_tracker_rs_worker.cpp
@@ -11,7 +11,7 @@
RSTrackerWorkerThread::RSTrackerWorkerThread(): mPose{0,0,0,0,0,0}{
setObjectName("RSTrackerWorkerThread");
- mPreviewRawData = (uchar*)malloc(kPreviewStreamWidth*kPreviewStreamHeight);
+ mPreviewRawData = (uchar*)malloc(1*kPreviewStreamWidth*kPreviewStreamHeight);
memset(mPreviewRawData, 125, kPreviewStreamWidth*kPreviewStreamHeight); //start with a gray image.
}
@@ -33,7 +33,7 @@ void RSTrackerWorkerThread::run(){
QMutexLocker lock(&mMutex);
memcpy(mPose, pose, sizeof(pose));
}
- else if(retValue != -303){ // pose update failed. -303 is OK as it's only a timeout.
+ else if(retValue != -303){ // pose update failed and not because of a timeout (-303)
emit trackingHasFinished(retValue);
break;
}
diff --git a/tracker-rs/imagewidget.cpp b/tracker-rs/imagewidget.cpp
index 0136c621..63986234 100644
--- a/tracker-rs/imagewidget.cpp
+++ b/tracker-rs/imagewidget.cpp
@@ -16,12 +16,15 @@ ImageWidget::ImageWidget(QWidget *parent) :
void ImageWidget::setImage(const QImage image)
{
- mImage = image;
+ {
+ QMutexLocker lock(&mMutex);
+ mImage = image;
+ }
repaint();
}
void ImageWidget::paintEvent(QPaintEvent*)
{
- QPainter painter(this);
- painter.drawImage(rect(), mImage, mImage.rect());
+ QMutexLocker lock(&mMutex);
+ QPainter(this).drawImage(rect(), mImage, mImage.rect());
}
diff --git a/tracker-rs/imagewidget.h b/tracker-rs/imagewidget.h
index 8f800058..e8b6e61e 100644
--- a/tracker-rs/imagewidget.h
+++ b/tracker-rs/imagewidget.h
@@ -9,6 +9,7 @@
#include <QWidget>
#include <QImage>
+#include <QMutex>
class ImageWidget : public QWidget {
Q_OBJECT
@@ -18,7 +19,7 @@ public:
private:
QImage mImage;
- uchar* mRawData;
+ QMutex mMutex;
protected:
void paintEvent(QPaintEvent* event);