From 61a58641089b07b23910c94c677e262388039fb9 Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Fri, 12 Feb 2016 10:46:39 +0100 Subject: tracker/rs: cleaned up preview widget setup and deletetion. --- tracker-rs/ftnoir_tracker_rs.cpp | 14 ++++++++++---- tracker-rs/ftnoir_tracker_rs_worker.cpp | 4 ++-- tracker-rs/imagewidget.cpp | 9 ++++++--- tracker-rs/imagewidget.h | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) (limited to 'tracker-rs') 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 #include +#include class ImageWidget : public QWidget { Q_OBJECT @@ -18,7 +19,7 @@ public: private: QImage mImage; - uchar* mRawData; + QMutex mMutex; protected: void paintEvent(QPaintEvent* event); -- cgit v1.2.3