From 8b463eb89247952e21de47fc823756efe01fe2b7 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 10 Dec 2015 20:01:29 +0100 Subject: [PATCH 01/46] remove SpinBoxWithSlider after move to core --- biotracker/SpinBoxWithSlider.h | 116 ---------------------- biotracker/src/SpinBoxWithSlider.cpp | 141 --------------------------- 2 files changed, 257 deletions(-) delete mode 100644 biotracker/SpinBoxWithSlider.h delete mode 100644 biotracker/src/SpinBoxWithSlider.cpp diff --git a/biotracker/SpinBoxWithSlider.h b/biotracker/SpinBoxWithSlider.h deleted file mode 100644 index add6b91..0000000 --- a/biotracker/SpinBoxWithSlider.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SpinBoxWithSlider.h - * - * Created on: Nov 14, 2014 - * Author: tobias - */ - -#ifndef SPINBOXWITHSLIDER_H_ -#define SPINBOXWITHSLIDER_H_ - -#include -#include -#include -#include -#include -#include -#include - - -class SteppedSpinBox: public QSpinBox { - Q_OBJECT - public: - SteppedSpinBox(QWidget *p = nullptr); - - protected: - virtual int valueFromText(const QString &text) const override; -}; - - -class SpinBoxWithSlider: public QWidget { - Q_OBJECT - public: - /** - * Integer Spinbox + Slider. - * representable values: {min, min + step_size, min + 2 * step_size, ..., max - step_size, max} - * Default (step_size = 1): {min, min + 1, min + 2, ..., max - 1, max} - * - * @param min lower bound - * @param max upper bound, max >= min && max == min + n * step_size; \f$n \in \mathbb{N}\f$ - * @param start_value min <= start_value <= max && start_value == min + n * step_size; \f$n \in \mathbb{N}\f$ - * @param step_size >= 1 - */ - explicit SpinBoxWithSlider(QWidget *parent, const QString &name, int min, - int max, int start_value, int step_size = 1); - explicit SpinBoxWithSlider(QWidget *parent, QFormLayout *layout, - const QString &name, int min, int max, int start_value, int step_size = 1); - - SpinBoxWithSlider(const SpinBoxWithSlider &) = delete; - SpinBoxWithSlider &operator=(const SpinBoxWithSlider &) = delete; - - int value() const { - return m_spinbox.value(); - } - - void setValue(const int value) { - m_spinbox.setValue(value); - } - - virtual ~SpinBoxWithSlider() override = default; - - private Q_SLOTS: - void SpinBoxValueChanged(int val); - void SliderValueChanged(int value); - - Q_SIGNALS: - void valueChanged(int i); - - private: - int m_step_size; - QHBoxLayout m_layout; - QLabel m_name; - QSlider m_slider; - SteppedSpinBox m_spinbox; -}; - - -class DoubleSpinBoxWithSlider: public QWidget { - Q_OBJECT - public: - /** - * double Spinbox + Slider. - * - * @param precision : decimal places - */ - explicit DoubleSpinBoxWithSlider(QWidget *parent, const QString &name, - double min, double max, double start_value, int precision = 1); - explicit DoubleSpinBoxWithSlider(QWidget *parent, QFormLayout *layout, - const QString &name, double min, double max, double start_value, - int precision = 1); - - DoubleSpinBoxWithSlider(const DoubleSpinBoxWithSlider &) = delete; - DoubleSpinBoxWithSlider &operator=(const DoubleSpinBoxWithSlider &) = delete; - - double value() const { - return m_spinbox.value(); - } - - virtual ~DoubleSpinBoxWithSlider() override = default; - - private Q_SLOTS: - void SpinBoxValueChanged(double val); - void SliderValueChanged(int value); - - Q_SIGNALS: - void valueChanged(double i); - - private: - int m_factor; - QHBoxLayout m_layout; - QLabel m_name; - QSlider m_slider; - QDoubleSpinBox m_spinbox; -}; - - -#endif /* SPINBOXWITHSLIDER_H_ */ diff --git a/biotracker/src/SpinBoxWithSlider.cpp b/biotracker/src/SpinBoxWithSlider.cpp deleted file mode 100644 index 24737e2..0000000 --- a/biotracker/src/SpinBoxWithSlider.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * SpinBoxWithSlider.cpp - * - * Created on: Nov 14, 2014 - * Author: tobias - */ - -#include "../SpinBoxWithSlider.h" -#include // std::invalid_argument - -int pow(int base, unsigned int exp) { - return exp == 0 ? 1 : base * pow(base, exp - 1); -} - - - -SteppedSpinBox::SteppedSpinBox(QWidget *p) - : QSpinBox(p) { -} - -int SteppedSpinBox::valueFromText(const QString &text) const { - int value = text.toInt(); - value = qMax(value, this->minimum()); - value = qMin(value, this->maximum()); - value -= (value - this->minimum()) % this->singleStep(); - return value; -} - -SpinBoxWithSlider::SpinBoxWithSlider(QWidget *parent, const QString &name, - int min, int max, int start_value, int step_size) - : QWidget(parent) - , m_step_size(step_size) - , m_layout(this) - , m_name(name, this) - , m_slider(this) - , m_spinbox(this) { - { - if (m_step_size < 1) { - throw std::invalid_argument("step isn't strictly positive"); - } - if (!(min < max)) { - throw std::invalid_argument("invalid range"); - } - if (!(min <= start_value && start_value <= max)) { - throw std::invalid_argument("start value isn't in range"); - } - if ((max - min) % m_step_size) { - throw std::invalid_argument("range length isn't a multiple of step size"); - } - if ((start_value - min) % m_step_size) { - throw std::invalid_argument("invalid start value"); - } - } - - m_spinbox.setRange(min, max); - m_spinbox.setValue(start_value); - - m_slider.setOrientation(Qt::Horizontal); - m_slider.setRange(0, (max - min) / m_step_size); - m_slider.setValue((start_value - min) / m_step_size); - - - QObject::connect(&m_spinbox, SIGNAL(valueChanged(int)), - this, SLOT(SpinBoxValueChanged(int))); - QObject::connect(&m_slider, SIGNAL(valueChanged(int)), - this, SLOT(SliderValueChanged(int))); - - m_spinbox.setSingleStep(m_step_size); - - m_layout.setMargin(3); - m_layout.setSpacing(3); - - m_layout.addWidget(&m_name); - m_layout.addWidget(&m_slider); - m_layout.addWidget(&m_spinbox); -} - -SpinBoxWithSlider::SpinBoxWithSlider(QWidget *parent, QFormLayout *layout, - const QString &name, int min, int max, int start_value, int step_size) - : SpinBoxWithSlider(parent, name, min, max, start_value, step_size) { - if (layout) { - layout->addRow(this); - } -} - -void SpinBoxWithSlider::SpinBoxValueChanged(int val) { - m_slider.setValue((val - m_spinbox.minimum()) / m_step_size); - Q_EMIT valueChanged(this->value()); -} -void SpinBoxWithSlider::SliderValueChanged(int value) { - m_spinbox.setValue(m_spinbox.minimum() + value * m_step_size); - Q_EMIT valueChanged(this->value()); -} - -DoubleSpinBoxWithSlider::DoubleSpinBoxWithSlider(QWidget *parent, - const QString &name, double min, double max, double start_value, int precision) - : QWidget(parent) - , m_factor(pow(10, precision)) - , m_layout(this) - , m_name(name, this) - , m_slider(this) - , m_spinbox(this) { - m_spinbox.setRange(min, max); - m_spinbox.setValue(start_value); - m_spinbox.setDecimals(precision); - m_spinbox.setSingleStep(1.0 / m_factor); - - m_slider.setOrientation(Qt::Horizontal); - m_slider.setRange(static_cast(m_factor * min), - static_cast(m_factor * max)); - m_slider.setValue(static_cast(m_factor * start_value)); - - - QObject::connect(&m_spinbox, SIGNAL(valueChanged(double)), - this, SLOT(SpinBoxValueChanged(double))); - QObject::connect(&m_slider, SIGNAL(valueChanged(int)), - this, SLOT(SliderValueChanged(int))); - - m_layout.addWidget(&m_name); - m_layout.addWidget(&m_slider); - m_layout.addWidget(&m_spinbox); -} - -DoubleSpinBoxWithSlider::DoubleSpinBoxWithSlider(QWidget *parent, - QFormLayout *layout, const QString &name, double min, double max, - double start_value, int precision) - : DoubleSpinBoxWithSlider(parent, name, min, max, start_value, precision) { - if (layout) { - layout->addRow(this); - } -} - -void DoubleSpinBoxWithSlider::SpinBoxValueChanged(double val) { - m_slider.setValue(static_cast(val * m_factor)); - Q_EMIT valueChanged(this->value()); -} - -void DoubleSpinBoxWithSlider::SliderValueChanged(int value) { - m_spinbox.setValue(static_cast(value) / m_factor); - Q_EMIT valueChanged(this->value()); -} From 1416706bc981029cd52b3bb84ecc94adea2e9e4c Mon Sep 17 00:00:00 2001 From: justayak Date: Thu, 10 Dec 2015 20:33:01 +0000 Subject: [PATCH 02/46] bubble view back to core --- biotracker/VideoControlWidget.h | 2 ++ biotracker/VideoView.h | 6 ++++++ biotracker/src/VideoControlWidget.cpp | 24 ++++++++++++++++++++++++ biotracker/src/VideoView.cpp | 3 ++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/biotracker/VideoControlWidget.h b/biotracker/VideoControlWidget.h index 85482e1..9f3f2ac 100644 --- a/biotracker/VideoControlWidget.h +++ b/biotracker/VideoControlWidget.h @@ -60,6 +60,8 @@ class VideoControlWidget : public QWidget { void videoSliderReleased(); void videoSliderPressed(); void speedSliderValueChanged(int value); + void viewChanged(QString); + void registerViews(const std::vector view); }; } diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 161326b..d3a6135 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -40,6 +40,10 @@ class VideoView : public QOpenGLWidget, protected QOpenGLFunctions { bool isZoomed(); + void setView(TrackingAlgorithm::View v) { + m_view = v; + } + public Q_SLOTS: void setMode(const Mode mode); void fitToWindow(); @@ -97,6 +101,8 @@ private Q_SLOTS: Core::BioTrackerApp &m_biotracker; + TrackingAlgorithm::View m_view; + /** * @brief m_painter */ diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 1581f05..a10cc01 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -124,6 +124,14 @@ void VideoControlWidget::initConnects() { // speed slider QObject::connect(m_ui.sld_speed, &QSlider::valueChanged, this, &VideoControlWidget::speedSliderValueChanged); + + QObject::connect(m_ui.comboBoxSelectedView, static_cast(&QComboBox::currentIndexChanged), + this, &VideoControlWidget::viewChanged); + + QObject::connect(&m_bioTracker, &Core::BioTrackerApp::registerViews, this, + &VideoControlWidget::registerViews); + + } void VideoControlWidget::playPause() { @@ -215,6 +223,22 @@ void VideoControlWidget::speedSliderValueChanged(int speed) { } } +void VideoControlWidget::viewChanged(QString n) { + auto view = TrackingAlgorithm::OriginalView; + if (n != "Original") { + view.name = n.toUtf8().constData(); + } + m_videoView->setView(view); +} + +void VideoControlWidget::registerViews(const std::vector views) { + m_ui.comboBoxSelectedView->clear(); + m_ui.comboBoxSelectedView->addItem("Original"); + for (auto view : views) { + m_ui.comboBoxSelectedView->addItem(QString::fromStdString(view.name)); + } +} + void VideoControlWidget::changeCurrentFrameByEdit() { setFrame(m_ui.sld_video->value()); } diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 5c8d270..d112cc4 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -22,6 +22,7 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_screenPicRatio(0) , m_texture(this) , m_biotracker(biotracker) + , m_view(TrackingAlgorithm::OriginalView) , m_painter() , m_firstAttempt(true) { QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -92,7 +93,7 @@ void VideoView::resizeEvent(QResizeEvent *event) { void VideoView::paintEvent(QPaintEvent *) { directPaint(this->width(), this->height(), false); - m_biotracker.paint(*this, m_painter); + m_biotracker.paint(*this, m_painter, m_view); } void VideoView::firstPaint() { From 27449a148326471e2d219321a38c66605ad264ec Mon Sep 17 00:00:00 2001 From: justayak Date: Thu, 10 Dec 2015 21:22:35 +0000 Subject: [PATCH 03/46] forcepaint from core --- biotracker/VideoControlWidget.h | 1 + biotracker/src/VideoControlWidget.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/biotracker/VideoControlWidget.h b/biotracker/VideoControlWidget.h index 9f3f2ac..29603e1 100644 --- a/biotracker/VideoControlWidget.h +++ b/biotracker/VideoControlWidget.h @@ -61,6 +61,7 @@ class VideoControlWidget : public QWidget { void videoSliderPressed(); void speedSliderValueChanged(int value); void viewChanged(QString); + void onRequestRepaint(); void registerViews(const std::vector view); }; diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index a10cc01..53f10fc 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -231,6 +231,20 @@ void VideoControlWidget::viewChanged(QString n) { m_videoView->setView(view); } +void repaintVideoView(VideoView *videoView) { + if (!videoView->isZoomed()) { + // TODO: fix this ugly hack + //videoView->resize(videoView->width() + 1, videoView->height()); + //videoView->resize(videoView->width() - 1, videoView->height()); + } + videoView->update(); +} + +void VideoControlWidget::onRequestRepaint() +{ + repaintVideoView(m_videoView); +} + void VideoControlWidget::registerViews(const std::vector views) { m_ui.comboBoxSelectedView->clear(); m_ui.comboBoxSelectedView->addItem("Original"); @@ -276,12 +290,7 @@ void VideoControlWidget::frameCalculated(const size_t frameNumber, const bool hasNext = frameNumber < m_bioTracker.getNumFrames() - 1; - if (!m_videoView->isZoomed()) { - // TODO: fix this ugly hack - m_videoView->resize(m_videoView->width() + 1, m_videoView->height()); - m_videoView->resize(m_videoView->width() - 1, m_videoView->height()); - } - m_videoView->update(); + repaintVideoView(m_videoView); m_ui.sld_video->setValue(frameNumber); m_ui.frame_num_edit->setText(QString::number(frameNumber)); From ad539669f41e032aea0a9dd1734d801b82b85efd Mon Sep 17 00:00:00 2001 From: justayak Date: Thu, 10 Dec 2015 21:42:37 +0000 Subject: [PATCH 04/46] resize 'fix' for painting --- biotracker/src/VideoControlWidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 53f10fc..45565d3 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -234,8 +234,8 @@ void VideoControlWidget::viewChanged(QString n) { void repaintVideoView(VideoView *videoView) { if (!videoView->isZoomed()) { // TODO: fix this ugly hack - //videoView->resize(videoView->width() + 1, videoView->height()); - //videoView->resize(videoView->width() - 1, videoView->height()); + videoView->resize(videoView->width() + 1, videoView->height()); + videoView->resize(videoView->width() - 1, videoView->height()); } videoView->update(); } From f46ecb1d943eaf30a18197c970d09f8552df54c0 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Fri, 11 Dec 2015 11:40:52 +0100 Subject: [PATCH 05/46] don't use static libs by default --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b00b56..b0c7c1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ CPM_Finish() biorobotics_config() -set(OpenCV_STATIC ON) +set(OpenCV_STATIC OFF) find_package(OpenCV REQUIRED) find_package(OpenGL REQUIRED) @@ -50,7 +50,7 @@ find_package(Qt5OpenGL REQUIRED) find_package(Threads REQUIRED) find_package(PythonLibs REQUIRED) -set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_LIBS OFF) find_package(Boost COMPONENTS filesystem serialization system REQUIRED) include_directories( From 881c921268a4fce22be3c389109d3cdc6448df42 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Fri, 11 Dec 2015 11:41:03 +0100 Subject: [PATCH 06/46] remove python dependency --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c7c1c..f34148e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ find_package(OpenGL REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5OpenGL REQUIRED) find_package(Threads REQUIRED) -find_package(PythonLibs REQUIRED) set(Boost_USE_STATIC_LIBS OFF) find_package(Boost COMPONENTS filesystem serialization system REQUIRED) @@ -58,7 +57,6 @@ include_directories( SYSTEM ${Qt5Widgets_INCLUDE_DIRS} SYSTEM ${OpenCV_INCLUDE_DIRS} SYSTEM ${Qt5OpenGL_INCLUDE_DIRS} - SYSTEM ${PYTHON_INCLUDE_DIRS} ) set(CMAKE_INCLUDE_CURRENT_DIR ON) From a3e85d639aad61353c5a3b028746d453a77bf10d Mon Sep 17 00:00:00 2001 From: justayak Date: Fri, 11 Dec 2015 14:19:00 +0000 Subject: [PATCH 07/46] #24 connect notification --- biotracker/src/NotificationWidget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biotracker/src/NotificationWidget.cpp b/biotracker/src/NotificationWidget.cpp index 941d161..6d9d0cf 100644 --- a/biotracker/src/NotificationWidget.cpp +++ b/biotracker/src/NotificationWidget.cpp @@ -21,6 +21,9 @@ void NotificationWidget::notify(const std::string &message, case MSGS::FILE_OPEN: m_ui.edit_notification->append(QString(message.c_str())); break; + case MSGS::NOTIFICATION: + m_ui.edit_notification->append(QString(message.c_str())); + break; default: ; } From 555d8b85fd5ef763d361a8b5d352a377c3074828 Mon Sep 17 00:00:00 2001 From: justayak Date: Fri, 11 Dec 2015 14:42:46 +0000 Subject: [PATCH 08/46] connect request for repaint --- biotracker/src/VideoControlWidget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 45565d3..b18767a 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -130,7 +130,8 @@ void VideoControlWidget::initConnects() { QObject::connect(&m_bioTracker, &Core::BioTrackerApp::registerViews, this, &VideoControlWidget::registerViews); - + QObject::connect(&m_bioTracker, &Core::BioTrackerApp::requestPaint, this, + &VideoControlWidget::onRequestRepaint); } From 5e07d545f5b9746c704e96cf383356b1a315e033 Mon Sep 17 00:00:00 2001 From: justayak Date: Wed, 16 Dec 2015 00:24:40 +0000 Subject: [PATCH 09/46] wip- rework opengl calls --- biotracker/VideoView.h | 4 +-- biotracker/src/VideoView.cpp | 48 ++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index d3a6135..1f54185 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -111,9 +111,7 @@ private Q_SLOTS: void initializeGL() override; void resizeGL(int w, int h) override; - void resizeEvent(QResizeEvent *event) override; - void paintEvent(QPaintEvent *event) override; - + void paintGL(); /** * @brief unprojectScreenPos diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index d112cc4..4a64b72 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -27,6 +27,11 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_firstAttempt(true) { QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(sizePolicy); + + QSurfaceFormat format = QSurfaceFormat::defaultFormat(); + format.setSamples(94); + this->setFormat(format); + } void VideoView::setMode(const VideoView::Mode mode) { @@ -67,33 +72,37 @@ void VideoView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { } void VideoView::initializeGL() { - makeCurrent(); - initializeOpenGLFunctions(); - m_openGLLogger.initialize(); // initializes in the current context, i.e. ctx - connect(&m_openGLLogger, &QOpenGLDebugLogger::messageLogged, this, - &VideoView::handleLoggedMessage); - m_openGLLogger.startLogging(); + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - resizeGL(width(), height()); m_biotracker.initializeOpenGL(context(), this->getTexture()); } -void VideoView::resizeGL(int width, int height) { - directPaint(width, height, false); -} +void VideoView::resizeGL(int w, int h) { + + //m_projection.setToIdentity(); + //m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f); + -void VideoView::resizeEvent(QResizeEvent *event) { - QOpenGLWidget::resizeEvent(event); - if (isValid()) { - fitToWindow(); - } } -void VideoView::paintEvent(QPaintEvent *) { - directPaint(this->width(), this->height(), false); - m_biotracker.paint(*this, m_painter, m_view); +void VideoView::paintGL() +{ + QPainter painter(this); + painter.beginNativePainting(); + + // actual opengl stuff + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClear(GL_COLOR_BUFFER_BIT); + + painter.endNativePainting(); + + m_biotracker.paint(*this, painter, m_view); + + painter.setPen(QColor(255, 0, 0)); + painter.drawRect(QRect(10, 20, 50, 60)); + } void VideoView::firstPaint() { @@ -109,6 +118,7 @@ void VideoView::firstPaint() { void VideoView::directPaint(const size_t w, const size_t h, const bool fitToWindow) { + return; makeCurrent(); if (w == 0 || h == 0) { return; From 88cb6be072665af4c80a6399dfa0140d9d0d91bb Mon Sep 17 00:00:00 2001 From: justayak Date: Wed, 30 Dec 2015 21:53:28 +0000 Subject: [PATCH 10/46] rewrite opengl code --- biotracker/Gui.h | 2 - biotracker/MainWindow.h | 1 - biotracker/VideoView.h | 26 +----- biotracker/src/VideoView.cpp | 151 ++++++++++++++--------------------- 4 files changed, 60 insertions(+), 120 deletions(-) diff --git a/biotracker/Gui.h b/biotracker/Gui.h index 3f6849b..cca6455 100644 --- a/biotracker/Gui.h +++ b/biotracker/Gui.h @@ -7,8 +7,6 @@ #include "MainWindow.h" -#include "biotracker/util/QOpenGLContextWrapper.h" - namespace BioTracker { namespace Gui { diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index 927489e..e905573 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -10,7 +10,6 @@ #include "OpenCameraDialog.h" #include "VideoView.h" #include "biotracker/util/QtRaiiWrapper.hpp" -#include "biotracker/util/QOpenGLContextWrapper.h" #include "biotracker/util/stringTools.h" namespace BioTracker { diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 1f54185..2e44518 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -53,28 +53,6 @@ private Q_SLOTS: void handleLoggedMessage(const QOpenGLDebugMessage &debugMessage); private: - /** - * @brief Used to store mouse cursor offsets while panning. - */ - struct CurrentPanState { - QPointF lastPos; - - CurrentPanState(const QPointF lastPos) - : lastPos(lastPos) { - } - }; - - /** - * @brief Stores the current zoom and pan offsets. While panning, panState stores the last mouse cursor position. - */ - struct PanZoomState { - float zoomFactor = 0.f; - float panX = 0.f; - float panY = 0.f; - bool isChanged = false; - - boost::optional panState; - }; QOpenGLDebugLogger m_openGLLogger; @@ -87,7 +65,7 @@ private Q_SLOTS: /** * @brief Pan/Zoom state variables. */ - PanZoomState m_panZoomState; + BioTracker::Core::PanZoomState m_panZoomState; /** * @brief Ratio of widget size and image size @@ -132,8 +110,6 @@ private Q_SLOTS: void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void wheelEvent(QWheelEvent *e) override; - - void directPaint(const size_t w, const size_t h, const bool fitToWindow); private Q_SLOTS: void firstPaint(); }; diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 4a64b72..2c3502a 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -12,6 +12,8 @@ #include #endif +#include + namespace BioTracker { namespace Gui { @@ -25,13 +27,14 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_view(TrackingAlgorithm::OriginalView) , m_painter() , m_firstAttempt(true) { - QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + /*QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(sizePolicy); QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setSamples(94); this->setFormat(format); - + */ } void VideoView::setMode(const VideoView::Mode mode) { @@ -52,8 +55,7 @@ void VideoView::setMode(const VideoView::Mode mode) { void VideoView::fitToWindow() { makeCurrent(); // reset PanZoomState - m_panZoomState = PanZoomState(); - directPaint(width(), height(), true); + m_panZoomState = BioTracker::Core::PanZoomState(); update(); } @@ -72,10 +74,6 @@ void VideoView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { } void VideoView::initializeGL() { - - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - m_biotracker.initializeOpenGL(context(), this->getTexture()); } @@ -89,16 +87,24 @@ void VideoView::resizeGL(int w, int h) { void VideoView::paintGL() { - QPainter painter(this); - painter.beginNativePainting(); + const size_t width = this->width(); + const size_t height = this->height(); - // actual opengl stuff - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glClear(GL_COLOR_BUFFER_BIT); + const int imageCols = m_texture.getImage().cols; + const int imageRows = m_texture.getImage().rows; - painter.endNativePainting(); + // calculate ratio of screen to displayed image + const float imgRatio = static_cast(imageCols) / imageRows; + const float windowRatio = static_cast(width) / height; - m_biotracker.paint(*this, painter, m_view); + if (windowRatio < imgRatio) { + m_screenPicRatio = imageRows / (width / imgRatio); + } else { + m_screenPicRatio = imageCols / (height * imgRatio); + } + + QPainter painter(this); + m_biotracker.paint(width, height, painter, m_panZoomState, m_view); painter.setPen(QColor(255, 0, 0)); painter.drawRect(QRect(10, 20, 50, 60)); @@ -116,64 +122,6 @@ void VideoView::firstPaint() { } } -void VideoView::directPaint(const size_t w, const size_t h, const bool fitToWindow) -{ - return; - makeCurrent(); - if (w == 0 || h == 0) { - return; - } - - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); - - int width = w; - int height = h; - - const int imageCols = m_texture.getImage().cols; - const int imageRows = m_texture.getImage().rows; - - // calculate ratio of screen to displayed image - const float imgRatio = static_cast(imageCols) / imageRows; - const float windowRatio = static_cast(width) / height; - - // create viewport with coordinates matching picture size in pixels - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (fitToWindow) { - if (windowRatio < imgRatio) { - m_panZoomState.panY = -((height - (width / imgRatio)) / 2) * - (m_screenPicRatio + m_panZoomState.zoomFactor); - m_panZoomState.panX = 0; - } else { - m_panZoomState.panX = - ((width - (height * imgRatio)) / 2) * - (m_screenPicRatio + m_panZoomState.zoomFactor); - m_panZoomState.panY = 0; - } - } else { - if (windowRatio < imgRatio) { - m_screenPicRatio = imageRows / (width / imgRatio); - } else { - m_screenPicRatio = imageCols / (height * imgRatio); - } - } - - width = static_cast(width * (m_screenPicRatio + - m_panZoomState.zoomFactor)); - height = static_cast(height *(m_screenPicRatio + - m_panZoomState.zoomFactor)); - - - const float left = m_panZoomState.panX; - const float top = m_panZoomState.panY; - const float right = left + width; - const float bottom = top + height; - - glOrtho(left, right, bottom, top, 0.0, 1.0); - glMatrixMode(GL_MODELVIEW); -} - QPoint VideoView::unprojectScreenPos(QPoint mouseCoords) { // variables required to map window coordinates to picture coordinates GLint viewport[4]; @@ -224,18 +172,24 @@ void VideoView::mouseMoveEvent(QMouseEvent *e) { switch (m_currentMode) { case Mode::PANZOOM: { + + QPoint stuff = Core::ScreenHelper::screenToImageCoords( + m_panZoomState, + m_texture.getImage().cols, + m_texture.getImage().rows, + width(), + height(), + QPoint(0,0)); + if (m_panZoomState.panState) { const QPointF delta = e->localPos() - (*m_panZoomState.panState).lastPos; (*m_panZoomState.panState).lastPos = e->localPos(); m_panZoomState.isChanged = true; - m_panZoomState.panX -= static_cast(delta.x() * (m_screenPicRatio + - m_panZoomState.zoomFactor)); - m_panZoomState.panY -= static_cast(delta.y() * (m_screenPicRatio + - m_panZoomState.zoomFactor)); - - resizeGL(this->width(), this->height()); + m_panZoomState.panX -= static_cast(delta.x()); + m_panZoomState.panY -= static_cast(delta.y()); update(); + } else { } break; } @@ -260,7 +214,7 @@ void VideoView::mousePressEvent(QMouseEvent *e) { case Mode::PANZOOM: { if (QApplication::keyboardModifiers() == Qt::NoModifier) { m_panZoomState.isChanged = true; - m_panZoomState.panState = CurrentPanState(e->localPos()); + m_panZoomState.panState = BioTracker::Core::CurrentPanState(e->localPos()); setCursor(Qt::ClosedHandCursor); } if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonDblClick) { @@ -309,9 +263,10 @@ void VideoView::wheelEvent(QWheelEvent *e) { // The maximum zoom is defined such that one image pixel can never become bigger than the widget size. The zoom // step size is calculated based on the ratio of widget size and image size and decays exponentially when zooming // in. - float step = 0.0005f * m_screenPicRatio; + //float step = 0.0005f * m_screenPicRatio; + float step = 1; if ((m_panZoomState.zoomFactor / m_screenPicRatio) < 0.f) { - step *= 1.f + (m_panZoomState.zoomFactor / m_screenPicRatio); + //step *= 1.f + (m_panZoomState.zoomFactor / m_screenPicRatio); } switch (m_currentMode) { @@ -321,20 +276,32 @@ void VideoView::wheelEvent(QWheelEvent *e) { const int numDegrees = e->delta(); const float deltaZoom = step * numDegrees; - m_panZoomState.zoomFactor -= deltaZoom; + const float oldZoomFactor = 1 + m_panZoomState.zoomFactor; + + QPoint imPos = BioTracker::Core::ScreenHelper::screenToImageCoords( + m_panZoomState, + m_texture.getImage().cols, m_texture.getImage().rows, + this->width(), this->height(), + e->pos() + ); + + m_panZoomState.zoomFactor -= deltaZoom/1200; m_panZoomState.isChanged = true; - // offset of mouse cursor from widget center in proportion to widget size - const float propX = width() / 2.f - static_cast(pos.x()); - const float propY = height() / 2.f - static_cast(pos.y()); + const float delta_zoom = oldZoomFactor - m_panZoomState.zoomFactor; + + + float propX = -30 * delta_zoom; + float propY = 0; + + float zoom = 1 + m_panZoomState.zoomFactor; - // zoom to center - m_panZoomState.panX += (deltaZoom * width()) / 2; - m_panZoomState.panY += (deltaZoom * height()) / 2; + // reset to non-zoomed coordinates + const float oldPanX = m_panZoomState.panX / oldZoomFactor; + const float oldPanY = m_panZoomState.panY / oldZoomFactor; - // adjust for cursor position - m_panZoomState.panX -= (deltaZoom * propX); - m_panZoomState.panY -= (deltaZoom * propY); + m_panZoomState.panX = (oldPanX - propX) * zoom; + m_panZoomState.panY = (oldPanY - propY) * zoom; resizeGL(this->width(), this->height()); update(); From e0d82811accdcafcf862183b28cc2bf22dc063e2 Mon Sep 17 00:00:00 2001 From: justayak Date: Sat, 2 Jan 2016 00:51:58 +0000 Subject: [PATCH 11/46] simplify zoom functions and use of biotracker api --- biotracker/src/VideoView.cpp | 47 ++---------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 2c3502a..330807c 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -172,24 +172,13 @@ void VideoView::mouseMoveEvent(QMouseEvent *e) { switch (m_currentMode) { case Mode::PANZOOM: { - - QPoint stuff = Core::ScreenHelper::screenToImageCoords( - m_panZoomState, - m_texture.getImage().cols, - m_texture.getImage().rows, - width(), - height(), - QPoint(0,0)); - if (m_panZoomState.panState) { const QPointF delta = e->localPos() - (*m_panZoomState.panState).lastPos; (*m_panZoomState.panState).lastPos = e->localPos(); - m_panZoomState.isChanged = true; m_panZoomState.panX -= static_cast(delta.x()); m_panZoomState.panY -= static_cast(delta.y()); update(); - } else { } break; } @@ -260,50 +249,18 @@ void VideoView::mouseReleaseEvent(QMouseEvent *e) { } void VideoView::wheelEvent(QWheelEvent *e) { - // The maximum zoom is defined such that one image pixel can never become bigger than the widget size. The zoom - // step size is calculated based on the ratio of widget size and image size and decays exponentially when zooming - // in. - //float step = 0.0005f * m_screenPicRatio; - float step = 1; - if ((m_panZoomState.zoomFactor / m_screenPicRatio) < 0.f) { - //step *= 1.f + (m_panZoomState.zoomFactor / m_screenPicRatio); - } - switch (m_currentMode) { case Mode::PANZOOM: { if (e->orientation() == Qt::Vertical) { - const QPointF pos = e->posF(); const int numDegrees = e->delta(); const float deltaZoom = step * numDegrees; - - const float oldZoomFactor = 1 + m_panZoomState.zoomFactor; - - QPoint imPos = BioTracker::Core::ScreenHelper::screenToImageCoords( + m_panZoomState = BioTracker::Core::ScreenHelper::zoomTo( m_panZoomState, m_texture.getImage().cols, m_texture.getImage().rows, this->width(), this->height(), + deltaZoom, e->pos() ); - - m_panZoomState.zoomFactor -= deltaZoom/1200; - m_panZoomState.isChanged = true; - - const float delta_zoom = oldZoomFactor - m_panZoomState.zoomFactor; - - - float propX = -30 * delta_zoom; - float propY = 0; - - float zoom = 1 + m_panZoomState.zoomFactor; - - // reset to non-zoomed coordinates - const float oldPanX = m_panZoomState.panX / oldZoomFactor; - const float oldPanY = m_panZoomState.panY / oldZoomFactor; - - m_panZoomState.panX = (oldPanX - propX) * zoom; - m_panZoomState.panY = (oldPanY - propY) * zoom; - - resizeGL(this->width(), this->height()); update(); e->accept(); } From d4a9daa7fc5d5b3e8f5b5da7879ca817f90dda2e Mon Sep 17 00:00:00 2001 From: justayak Date: Sat, 2 Jan 2016 12:28:21 +0000 Subject: [PATCH 12/46] unproject points and cleanup for opengl rewrite --- biotracker/VideoView.h | 8 ----- biotracker/src/VideoView.cpp | 61 +++++------------------------------- 2 files changed, 8 insertions(+), 61 deletions(-) diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 2e44518..2f687a2 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -88,7 +88,6 @@ private Q_SLOTS: bool m_firstAttempt; void initializeGL() override; - void resizeGL(int w, int h) override; void paintGL(); /** @@ -98,13 +97,6 @@ private Q_SLOTS: */ QPoint unprojectScreenPos(QPoint mouseCoords); - /** - * @brief projectPicturePos - * @param imageCoords coordinates relative to image - * @return coordinates relative to window - */ - QPoint projectPicturePos(QPoint imageCoords); - void keyPressEvent(QKeyEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 330807c..fc11185 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -28,13 +28,6 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_painter() , m_firstAttempt(true) { - /*QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - setSizePolicy(sizePolicy); - - QSurfaceFormat format = QSurfaceFormat::defaultFormat(); - format.setSamples(94); - this->setFormat(format); - */ } void VideoView::setMode(const VideoView::Mode mode) { @@ -77,14 +70,6 @@ void VideoView::initializeGL() { m_biotracker.initializeOpenGL(context(), this->getTexture()); } -void VideoView::resizeGL(int w, int h) { - - //m_projection.setToIdentity(); - //m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f); - - -} - void VideoView::paintGL() { const size_t width = this->width(); @@ -124,42 +109,12 @@ void VideoView::firstPaint() { QPoint VideoView::unprojectScreenPos(QPoint mouseCoords) { // variables required to map window coordinates to picture coordinates - GLint viewport[4]; - GLdouble modelview[16]; - GLdouble projection[16]; - GLdouble posX, posY, posZ; - QPoint imageCoord; - - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); - glGetDoublev(GL_PROJECTION_MATRIX, projection); - glGetIntegerv(GL_VIEWPORT, viewport); - gluUnProject(mouseCoords.x(), viewport[3] - mouseCoords.y(), 0, modelview, - projection, viewport, &posX, &posY, &posZ); - imageCoord.setX(static_cast((m_texture.getImage().cols / 2) - posX * - (m_texture.getImage().cols / 2))); - imageCoord.setY(static_cast((m_texture.getImage().rows / 2) - posY * - (m_texture.getImage().rows / 2))); - - return imageCoord; -} - -QPoint VideoView::projectPicturePos(QPoint imageCoords) { - //variables required to map picture coordinates to window coordinates - GLint viewport[4]; - GLdouble modelview[16]; - GLdouble projection[16]; - GLdouble posX, posY, posZ; - QPoint windowCoord; - - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); - glGetDoublev(GL_PROJECTION_MATRIX, projection); - glGetIntegerv(GL_VIEWPORT, viewport); - gluProject(imageCoords.x(), imageCoords.y() , 0, modelview, projection, - viewport, &posX, &posY, &posZ); - windowCoord.setX(static_cast(posX)); - windowCoord.setY(-(static_cast(posY - viewport[3]))); - - return windowCoord; + return BioTracker::Core::ScreenHelper::screenToImageCoords( + m_panZoomState, + m_texture.getImage().cols, m_texture.getImage().rows, + width(), height(), + mouseCoords + ); } void VideoView::keyPressEvent(QKeyEvent *e) { @@ -253,7 +208,7 @@ void VideoView::wheelEvent(QWheelEvent *e) { case Mode::PANZOOM: { if (e->orientation() == Qt::Vertical) { const int numDegrees = e->delta(); - const float deltaZoom = step * numDegrees; + const float deltaZoom = numDegrees; m_panZoomState = BioTracker::Core::ScreenHelper::zoomTo( m_panZoomState, m_texture.getImage().cols, m_texture.getImage().rows, @@ -268,7 +223,7 @@ void VideoView::wheelEvent(QWheelEvent *e) { } case Mode::INTERACTION: { e->accept(); - QPoint p = unprojectScreenPos(e->pos()); + const QPoint p = unprojectScreenPos(e->pos()); const QPointF localPos(p); QWheelEvent modifiedEvent(e->pos(),localPos,e->pixelDelta(),e->angleDelta(),e->delta(),e->orientation(),e->buttons(),e->modifiers()); QCoreApplication::sendEvent(QApplication::activeWindow(), &modifiedEvent); From f2e9d91416da939e6b341a7a27edd278c9de3498 Mon Sep 17 00:00:00 2001 From: justayak Date: Fri, 8 Jan 2016 11:10:20 +0000 Subject: [PATCH 13/46] cleanup --- biotracker/VideoView.h | 3 --- biotracker/src/VideoControlWidget.cpp | 3 --- biotracker/src/VideoView.cpp | 22 ---------------------- 3 files changed, 28 deletions(-) diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 2f687a2..9fe3063 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -47,7 +47,6 @@ class VideoView : public QOpenGLWidget, protected QOpenGLFunctions { public Q_SLOTS: void setMode(const Mode mode); void fitToWindow(); - void initialPaint(); private Q_SLOTS: void handleLoggedMessage(const QOpenGLDebugMessage &debugMessage); @@ -102,8 +101,6 @@ private Q_SLOTS: void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void wheelEvent(QWheelEvent *e) override; -private Q_SLOTS: - void firstPaint(); }; } } diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index b18767a..434d3f3 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -178,9 +178,6 @@ void VideoControlWidget::fileOpened(const std::string filename, m_ui.fps_label->setText(QString::number(targetFps)); const int fpsAsInt = static_cast(targetFps + 0.5); m_ui.sld_speed->setValue(fpsAsInt); - // refresh - m_videoView->initialPaint(); - } void VideoControlWidget::previousFrame() { diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index fc11185..64e9059 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -52,16 +52,6 @@ void VideoView::fitToWindow() { update(); } -/** - This attempts to fix a nasty bug that the very first image is not set - correctly. - TODO: fix this bug CORRECTLY! - * @brief VideoView::initialPaint - */ -void VideoView::initialPaint() { - QTimer::singleShot(20, this, SLOT(firstPaint())); -} - void VideoView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { std::cout << debugMessage.message().toStdString() << std::endl; } @@ -90,23 +80,11 @@ void VideoView::paintGL() QPainter painter(this); m_biotracker.paint(width, height, painter, m_panZoomState, m_view); - painter.setPen(QColor(255, 0, 0)); painter.drawRect(QRect(10, 20, 50, 60)); } -void VideoView::firstPaint() { - - if (m_firstAttempt) { - m_firstAttempt = false; - this->resize(this->width() + 1, this->height()); - QTimer::singleShot(20, this, SLOT(firstPaint())); - } else { - this->resize(this->width() - 1, this->height()); - } -} - QPoint VideoView::unprojectScreenPos(QPoint mouseCoords) { // variables required to map window coordinates to picture coordinates return BioTracker::Core::ScreenHelper::screenToImageCoords( From 7cc779148638173cb4ea0723fc34f87d2dbd4bbb Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Fri, 8 Jan 2016 17:34:32 +0100 Subject: [PATCH 14/46] remove old code --- biotracker/src/VideoControlWidget.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 434d3f3..24c10de 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -230,11 +230,6 @@ void VideoControlWidget::viewChanged(QString n) { } void repaintVideoView(VideoView *videoView) { - if (!videoView->isZoomed()) { - // TODO: fix this ugly hack - videoView->resize(videoView->width() + 1, videoView->height()); - videoView->resize(videoView->width() - 1, videoView->height()); - } videoView->update(); } From 7ee376208ce85572cbcfdf98301273e3692030da Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Fri, 8 Jan 2016 17:34:57 +0100 Subject: [PATCH 15/46] adapt to biotracker core changes --- biotracker/VideoView.h | 11 +---------- biotracker/src/VideoView.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 9fe3063..918c211 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -34,14 +34,11 @@ class VideoView : public QOpenGLWidget, protected QOpenGLFunctions { return m_currentMode; } - Core::TextureObject &getTexture() { - return m_texture; - } - bool isZoomed(); void setView(TrackingAlgorithm::View v) { m_view = v; + update(); } public Q_SLOTS: @@ -71,11 +68,6 @@ private Q_SLOTS: */ float m_screenPicRatio; - /** - * @brief Wrapper for the OpenGL texture. Also contains the original image as opencv matrix. - */ - Core::TextureObject m_texture; - Core::BioTrackerApp &m_biotracker; TrackingAlgorithm::View m_view; @@ -86,7 +78,6 @@ private Q_SLOTS: QPainter m_painter; bool m_firstAttempt; - void initializeGL() override; void paintGL(); /** diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 64e9059..4642688 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -1,8 +1,5 @@ #include "../VideoView.h" -// TODO -// check if m_texture is nullptr - // OS X puts the headers in a different location in the include path than // Windows and Linux, so we need to distinguish between OS X and the other // systems. @@ -22,7 +19,6 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_openGLLogger(this) , m_currentMode(Mode::INTERACTION) , m_screenPicRatio(0) - , m_texture(this) , m_biotracker(biotracker) , m_view(TrackingAlgorithm::OriginalView) , m_painter() @@ -56,17 +52,16 @@ void VideoView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { std::cout << debugMessage.message().toStdString() << std::endl; } -void VideoView::initializeGL() { - m_biotracker.initializeOpenGL(context(), this->getTexture()); -} - void VideoView::paintGL() { + BioTracker::Core::TextureObject const& texture = + m_biotracker.getTrackingThread().getTexture(); + const size_t width = this->width(); const size_t height = this->height(); - const int imageCols = m_texture.getImage().cols; - const int imageRows = m_texture.getImage().rows; + const int imageCols = texture.width(); + const int imageRows = texture.height(); // calculate ratio of screen to displayed image const float imgRatio = static_cast(imageCols) / imageRows; @@ -80,16 +75,16 @@ void VideoView::paintGL() QPainter painter(this); m_biotracker.paint(width, height, painter, m_panZoomState, m_view); - painter.setPen(QColor(255, 0, 0)); - painter.drawRect(QRect(10, 20, 50, 60)); - } QPoint VideoView::unprojectScreenPos(QPoint mouseCoords) { + BioTracker::Core::TextureObject const& texture = + m_biotracker.getTrackingThread().getTexture(); + // variables required to map window coordinates to picture coordinates return BioTracker::Core::ScreenHelper::screenToImageCoords( m_panZoomState, - m_texture.getImage().cols, m_texture.getImage().rows, + texture.width(), texture.height(), width(), height(), mouseCoords ); @@ -182,6 +177,9 @@ void VideoView::mouseReleaseEvent(QMouseEvent *e) { } void VideoView::wheelEvent(QWheelEvent *e) { + BioTracker::Core::TextureObject const& texture = + m_biotracker.getTrackingThread().getTexture(); + switch (m_currentMode) { case Mode::PANZOOM: { if (e->orientation() == Qt::Vertical) { @@ -189,7 +187,7 @@ void VideoView::wheelEvent(QWheelEvent *e) { const float deltaZoom = numDegrees; m_panZoomState = BioTracker::Core::ScreenHelper::zoomTo( m_panZoomState, - m_texture.getImage().cols, m_texture.getImage().rows, + texture.width(), texture.height(), this->width(), this->height(), deltaZoom, e->pos() From c19611ed33f439efe9bf0ae215507d613da92b4d Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Wed, 16 Mar 2016 18:18:11 +0100 Subject: [PATCH 16/46] fix some warnings --- biotracker/src/MainWindow.cpp | 3 +-- biotracker/src/VideoControlWidget.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index e276a7a..7bd7f4d 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -19,8 +19,7 @@ void MainWindow::initalizeVideoView(Core::BioTrackerApp &biotracker) { biotracker, m_videoView.get()); } -void MainWindow::frameCalculated(const size_t frameNumber, - const std::string filename, const double currentFps) { +void MainWindow::frameCalculated(const size_t, const std::string filename, const double) { setWindowTitle("BioTracker [" + QString::fromStdString(stem_filename(filename)) + "]"); } diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 24c10de..39d3f95 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -279,7 +279,7 @@ void VideoControlWidget::switchPanZoomMode() { } void VideoControlWidget::frameCalculated(const size_t frameNumber, - const std::string filename, const double currentFps) { + const std::string, const double currentFps) { const bool hasNext = frameNumber < m_bioTracker.getNumFrames() - 1; From cde7da7e34232ccac8c92b95f1431c9357933be9 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Wed, 16 Mar 2016 18:41:30 +0100 Subject: [PATCH 17/46] Use QPointer to track TrackingAlgorithm widget --- biotracker/MainWindow.h | 7 ------- biotracker/src/MainWindow.cpp | 6 +----- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index e905573..7218a49 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -66,13 +66,6 @@ class MainWindow : public QMainWindow { OpenCameraDialog m_openCameraDialog; QVBoxLayout m_tools; - /** - * @brief lastToolsWidget - * We need to store a reference to the last used widget so we can - * remove it upon selecting a new algorithm - */ - std::shared_ptr m_lastToolsWidget; - void initalizeVideoView(Core::BioTrackerApp &biotracker); }; diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index 7bd7f4d..32304c8 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -24,11 +24,7 @@ void MainWindow::frameCalculated(const size_t, const std::string filename, const } void MainWindow::trackerSelected(std::shared_ptr tracker) { - if (m_lastToolsWidget) { - m_tools.removeWidget(m_lastToolsWidget.get()); - } - m_lastToolsWidget = tracker.get()->getToolsWidget(); - m_tools.addWidget(m_lastToolsWidget.get()); + m_tools.addWidget(tracker->getToolsWidget()); m_ui.groupBox_tools->repaint(); } From 792a4c38103849e0d4d711cc4505d55e11298dc8 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 16:58:09 +0100 Subject: [PATCH 18/46] unify namespaces --- biotracker/MainWindow.h | 2 +- biotracker/NotificationWidget.h | 2 +- biotracker/VideoControlWidget.h | 2 +- biotracker/VideoView.h | 4 ++-- biotracker/src/MainWindow.cpp | 4 ++-- biotracker/src/NotificationWidget.cpp | 6 +++--- biotracker/src/VideoControlWidget.cpp | 12 ++++++------ biotracker/src/VideoView.cpp | 2 +- biotracker/src/main.cpp | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index 7218a49..1d0b15a 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -55,7 +55,7 @@ class MainWindow : public QMainWindow { * gets called whenever a new tracker is selected * @param tracker */ - void trackerSelected(std::shared_ptr tracker); + void trackerSelected(std::shared_ptr tracker); private: MainWindowUi m_ui; diff --git a/biotracker/NotificationWidget.h b/biotracker/NotificationWidget.h index f2d8833..755e6c6 100644 --- a/biotracker/NotificationWidget.h +++ b/biotracker/NotificationWidget.h @@ -25,7 +25,7 @@ class NotificationWidget : public QWidget { * @brief notify * Status messages for the user interface */ - void notify(const std::string &message, const MSGS::MTYPE type); + void notify(const std::string &message, const Core::MessageType type); diff --git a/biotracker/VideoControlWidget.h b/biotracker/VideoControlWidget.h index 29603e1..871634b 100644 --- a/biotracker/VideoControlWidget.h +++ b/biotracker/VideoControlWidget.h @@ -62,7 +62,7 @@ class VideoControlWidget : public QWidget { void speedSliderValueChanged(int value); void viewChanged(QString); void onRequestRepaint(); - void registerViews(const std::vector view); + void registerViews(const std::vector view); }; } diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 918c211..7200810 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -36,7 +36,7 @@ class VideoView : public QOpenGLWidget, protected QOpenGLFunctions { bool isZoomed(); - void setView(TrackingAlgorithm::View v) { + void setView(Core::TrackingAlgorithm::View v) { m_view = v; update(); } @@ -70,7 +70,7 @@ private Q_SLOTS: Core::BioTrackerApp &m_biotracker; - TrackingAlgorithm::View m_view; + Core::TrackingAlgorithm::View m_view; /** * @brief m_painter diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index 32304c8..ec341a1 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -20,10 +20,10 @@ void MainWindow::initalizeVideoView(Core::BioTrackerApp &biotracker) { } void MainWindow::frameCalculated(const size_t, const std::string filename, const double) { - setWindowTitle("BioTracker [" + QString::fromStdString(stem_filename(filename)) + "]"); + setWindowTitle("BioTracker [" + QString::fromStdString(Util::stem_filename(filename)) + "]"); } -void MainWindow::trackerSelected(std::shared_ptr tracker) { +void MainWindow::trackerSelected(std::shared_ptr tracker) { m_tools.addWidget(tracker->getToolsWidget()); m_ui.groupBox_tools->repaint(); } diff --git a/biotracker/src/NotificationWidget.cpp b/biotracker/src/NotificationWidget.cpp index 6d9d0cf..efbfd89 100644 --- a/biotracker/src/NotificationWidget.cpp +++ b/biotracker/src/NotificationWidget.cpp @@ -16,12 +16,12 @@ void NotificationWidget::initConnects() { } void NotificationWidget::notify(const std::string &message, - const MSGS::MTYPE type) { + const Core::MessageType type) { switch (type) { - case MSGS::FILE_OPEN: + case Core::MessageType::FILE_OPEN: m_ui.edit_notification->append(QString(message.c_str())); break; - case MSGS::NOTIFICATION: + case Core::MessageType::NOTIFICATION: m_ui.edit_notification->append(QString(message.c_str())); break; default: diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 39d3f95..6093444 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -68,7 +68,7 @@ void VideoControlWidget::updateWidgets() { void VideoControlWidget::initShortcuts() { const QString shortcutPanKey = QString::fromStdString( m_bioTracker.getSettings().getValueOrDefault - (GUIPARAM::SHORTCUT_ZOOM,"Z")); + (GuiParam::SHORTCUT_ZOOM,"Z")); const QShortcut *shortcutPan = new QShortcut(QKeySequence(shortcutPanKey), this); QObject::connect(shortcutPan, &QShortcut::activated, m_ui.button_panZoom, @@ -76,7 +76,7 @@ void VideoControlWidget::initShortcuts() { const QString shortcutPlayKey = QString::fromStdString( m_bioTracker.getSettings().getValueOrDefault - (GUIPARAM::SHORTCUT_PLAY,"Space")); + (GuiParam::SHORTCUT_PLAY,"Space")); const QShortcut *shortcutPlay = new QShortcut(QKeySequence(shortcutPlayKey), this); QObject::connect(shortcutPlay, &QShortcut::activated, m_ui.button_playPause, @@ -84,7 +84,7 @@ void VideoControlWidget::initShortcuts() { const QString shortcutNextKey = QString::fromStdString( m_bioTracker.getSettings().getValueOrDefault - (GUIPARAM::SHORTCUT_NEXT,"Right")); + (GuiParam::SHORTCUT_NEXT,"Right")); const QShortcut *shortcutNext = new QShortcut(QKeySequence(shortcutNextKey), this); QObject::connect(shortcutNext, &QShortcut::activated, m_ui.button_nextFrame, @@ -92,7 +92,7 @@ void VideoControlWidget::initShortcuts() { const QString shortcutPrevKey = QString::fromStdString( m_bioTracker.getSettings().getValueOrDefault - (GUIPARAM::SHORTCUT_PREV,"Left")); + (GuiParam::SHORTCUT_PREV,"Left")); const QShortcut *shortcutPrev = new QShortcut(QKeySequence(shortcutPrevKey), this); QObject::connect(shortcutPrev, &QShortcut::activated, m_ui.button_previousFrame, @@ -222,7 +222,7 @@ void VideoControlWidget::speedSliderValueChanged(int speed) { } void VideoControlWidget::viewChanged(QString n) { - auto view = TrackingAlgorithm::OriginalView; + auto view = Core::TrackingAlgorithm::OriginalView; if (n != "Original") { view.name = n.toUtf8().constData(); } @@ -238,7 +238,7 @@ void VideoControlWidget::onRequestRepaint() repaintVideoView(m_videoView); } -void VideoControlWidget::registerViews(const std::vector views) { +void VideoControlWidget::registerViews(const std::vector views) { m_ui.comboBoxSelectedView->clear(); m_ui.comboBoxSelectedView->addItem("Original"); for (auto view : views) { diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 4642688..9395bcf 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -20,7 +20,7 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_currentMode(Mode::INTERACTION) , m_screenPicRatio(0) , m_biotracker(biotracker) - , m_view(TrackingAlgorithm::OriginalView) + , m_view(Core::TrackingAlgorithm::OriginalView) , m_painter() , m_firstAttempt(true) { diff --git a/biotracker/src/main.cpp b/biotracker/src/main.cpp index e5d7008..d6e4154 100644 --- a/biotracker/src/main.cpp +++ b/biotracker/src/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { // meta types qRegisterMetaType("cv::Mat"); - qRegisterMetaType("MSGS::MTYPE"); + qRegisterMetaType("BioTracker::Core::Messages::MessageType"); qRegisterMetaType("std::string"); qRegisterMetaType("std::size_t"); qRegisterMetaType("size_t"); @@ -31,8 +31,8 @@ int main(int argc, char *argv[]) { BioTracker::Gui::Gui w; return app.exec(); } else { - static const std::string title = MSGS::SYSTEM::APPLICATION_CANNOT_START; - static const std::string msg = MSGS::SYSTEM::NO_OPENGL; + static const std::string title = BioTracker::Core::Messages::System::APPLICATION_CANNOT_START; + static const std::string msg = BioTracker::Core::Messages::System::NO_OPENGL; QMessageBox::critical(nullptr, QString::fromStdString(title), QString::fromStdString(msg)); From a7be27462850aa3cc9ffda0fd381fd36a2393efd Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 17:54:04 +0100 Subject: [PATCH 19/46] store/restore window state and geometry upon close/exit --- biotracker/MainWindow.h | 3 ++- biotracker/VideoView.h | 2 +- biotracker/src/Gui.cpp | 1 + biotracker/src/MainWindow.cpp | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index 1d0b15a..f7556e2 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -53,7 +53,6 @@ class MainWindow : public QMainWindow { /** * @brief trackerSelected * gets called whenever a new tracker is selected - * @param tracker */ void trackerSelected(std::shared_ptr tracker); @@ -67,6 +66,8 @@ class MainWindow : public QMainWindow { QVBoxLayout m_tools; void initalizeVideoView(Core::BioTrackerApp &biotracker); + + void closeEvent(QCloseEvent* event) override; }; diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index 7200810..bb19c56 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -78,7 +78,7 @@ private Q_SLOTS: QPainter m_painter; bool m_firstAttempt; - void paintGL(); + void paintGL() override; /** * @brief unprojectScreenPos diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 0035892..9a94127 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -20,6 +20,7 @@ Gui::Gui() , m_biotracker() , m_mainWindow(m_biotracker) { initConnects(); + m_mainWindow.show(); } diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index ec341a1..38c92c8 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -10,13 +10,46 @@ MainWindow::MainWindow(Core::BioTrackerApp &biotracker) , m_openCameraDialog(m_ui.centralWidget, biotracker) , m_tools(m_ui.groupBox_tools){ initalizeVideoView(biotracker); + + { + QFile file(QString::fromStdString(ConfigParam::GEOMETRY_FILE.string())); + if (file.open(QIODevice::ReadOnly)) restoreGeometry(file.readAll()); + } + + { + QFile file(QString::fromStdString(ConfigParam::STATE_FILE.string())); + if (file.open(QIODevice::ReadOnly)) restoreState(file.readAll()); + } } void MainWindow::initalizeVideoView(Core::BioTrackerApp &biotracker) { m_videoView = std::make_unique(m_ui.trackingArea, biotracker); m_ui.videoViewLayout->addWidget(m_videoView.get()); m_videoControl = std::make_unique(m_ui.videoControls, - biotracker, m_videoView.get()); + biotracker, m_videoView.get()); +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + const auto dialog = QMessageBox::warning( + this, "Exit", "Do you really want to close the application?", + QMessageBox::Yes | QMessageBox::No); + + if( dialog == QMessageBox::Yes) { + { + QFile file(QString::fromStdString(ConfigParam::GEOMETRY_FILE.string())); + if (file.open(QIODevice::WriteOnly)) file.write(saveGeometry()); + } + + { + QFile file(QString::fromStdString(ConfigParam::STATE_FILE.string())); + if (file.open(QIODevice::WriteOnly)) file.write(saveState()); + } + + QMainWindow::closeEvent(event); + } else { + event->ignore(); + } } void MainWindow::frameCalculated(const size_t, const std::string filename, const double) { From 02b9a562e7378c2958e6c63ed5075ffb9fdbd014 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 18:00:03 +0100 Subject: [PATCH 20/46] Qt >= 5.4 is required --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f34148e..2f078f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,8 @@ set(OpenCV_STATIC OFF) find_package(OpenCV REQUIRED) find_package(OpenGL REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5OpenGL REQUIRED) +find_package(Qt5Widgets 5.4 REQUIRED) +find_package(Qt5OpenGL 5.4 REQUIRED) find_package(Threads REQUIRED) set(Boost_USE_STATIC_LIBS OFF) From c5148417d17b040079c4327022d6ef3751b42288 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 18:31:24 +0100 Subject: [PATCH 21/46] reimplement screenshot functionality --- biotracker/src/VideoControlWidget.cpp | 26 +++++++++++++++----------- biotracker/src/VideoControlWidget.ui | 18 +++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 6093444..0b0f6a0 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -251,17 +251,21 @@ void VideoControlWidget::changeCurrentFrameByEdit() { } void VideoControlWidget::takeScreenshot() { - /* - QString filename = ""; - const std::chrono::system_clock::time_point p = std::chrono::system_clock::now(); - const std::time_t t = std::chrono::system_clock::to_time_t(p); - std::string dateTime = std::ctime(&t); - //ctime adds a newline to the string due to historical reasons - dateTime = dateTime.substr(0, dateTime.size() - 1); - filename.append("/screenshot_").append(QString::fromStdString(dateTime)).append(".png"); - QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), "/home/"+filename , tr("Images (*.png)")); - ui.videoView->takeScreenshot(filepath); - */ + QString filename; + const std::time_t t = std::time(nullptr); + const std::tm tm = *std::localtime(&t); + std::ostringstream ss; + ss << std::put_time(&tm, "%Y-%m-%d_%H-%M-%S"); + std::string dateTime = ss.str(); + filename.append("/Screenshot_").append(QString::fromStdString(dateTime)).append(".png"); + std::cout << QDir::homePath().append(filename).toStdString() << std::endl; + QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), + QDir::homePath().append(filename), + tr("Images (*.png)")); + + if (filepath.count()) { + m_bioTracker.getTrackingThread().getTexture().get().save(filepath); + } } void VideoControlWidget::switchPanZoomMode() { diff --git a/biotracker/src/VideoControlWidget.ui b/biotracker/src/VideoControlWidget.ui index f3b0d80..dd342d1 100644 --- a/biotracker/src/VideoControlWidget.ui +++ b/biotracker/src/VideoControlWidget.ui @@ -6,7 +6,7 @@ 0 0 - 719 + 721 193 @@ -99,7 +99,7 @@ - + :/BioTracker/resources/arrows-skip-back.png:/BioTracker/resources/arrows-skip-back.png @@ -125,7 +125,7 @@ - + :/BioTracker/resources/arrow-forward1.png:/BioTracker/resources/arrow-forward1.png @@ -154,7 +154,7 @@ - + :/BioTracker/resources/stop.png:/BioTracker/resources/stop.png @@ -183,7 +183,7 @@ - + :/BioTracker/resources/arrows-skip-forward.png:/BioTracker/resources/arrows-skip-forward.png @@ -197,7 +197,7 @@ - false + true @@ -217,7 +217,7 @@ - + :/BioTracker/resources/screenshot.png:/BioTracker/resources/screenshot.png @@ -340,7 +340,7 @@ - + :/BioTracker/resources/panZoom.png:/BioTracker/resources/panZoom.png @@ -502,7 +502,7 @@ - + From 798cf7858e143f2d0a9901b75c05828376be6d8d Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 18:42:55 +0100 Subject: [PATCH 22/46] automatically select a newly loaded tracker --- biotracker/src/AlgorithmSelectionWidget.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/biotracker/src/AlgorithmSelectionWidget.cpp b/biotracker/src/AlgorithmSelectionWidget.cpp index ea38c70..db75876 100644 --- a/biotracker/src/AlgorithmSelectionWidget.cpp +++ b/biotracker/src/AlgorithmSelectionWidget.cpp @@ -20,10 +20,12 @@ AlgorithmSelectionWidget::AlgorithmSelectionWidget(QWidget *parent, QComboBox::InsertPolicy::InsertAlphabetically); } -void AlgorithmSelectionWidget::addTrackingAlgorithm(const Core::TrackerType - type) { - m_ui.cb_algorithms->addItem(QString::fromStdString( - m_biotracker.getRegistry().getStringByType().at(type))); +void AlgorithmSelectionWidget::addTrackingAlgorithm(const Core::TrackerType type) { + const QString trackerName = QString::fromStdString( + m_biotracker.getRegistry().getStringByType().at(type)); + m_ui.cb_algorithms->addItem(trackerName); + const int index = m_ui.cb_algorithms->findText(trackerName); + m_ui.cb_algorithms->setCurrentIndex(index); } void AlgorithmSelectionWidget::initAlgorithmList() { From 3000210365eb84dead56f187555b5c73d5a74811 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 18:48:04 +0100 Subject: [PATCH 23/46] reformat code using astyle --- biotracker/AlgorithmSelectionWidget.h | 2 +- biotracker/MainWindow.h | 4 +- biotracker/VideoView.h | 4 +- biotracker/src/Gui.cpp | 2 +- biotracker/src/MainWindow.cpp | 45 +++--- biotracker/src/VideoControlWidget.cpp | 15 +- biotracker/src/VideoView.cpp | 200 +++++++++++++------------- 7 files changed, 139 insertions(+), 133 deletions(-) diff --git a/biotracker/AlgorithmSelectionWidget.h b/biotracker/AlgorithmSelectionWidget.h index da266ee..e5be2f4 100644 --- a/biotracker/AlgorithmSelectionWidget.h +++ b/biotracker/AlgorithmSelectionWidget.h @@ -34,7 +34,7 @@ class AlgorithmSelectionWidget : public QWidget { void initConnects(); private Q_SLOTS: - void trackingAlgorithmSelected(const QString& name); + void trackingAlgorithmSelected(const QString &name); }; } diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index f7556e2..12576c6 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -48,7 +48,7 @@ class MainWindow : public QMainWindow { * handles the showing of filenames in statusbar */ void frameCalculated(const size_t frameNumber, - const std::string filename, const double currentFps); + const std::string filename, const double currentFps); /** * @brief trackerSelected @@ -67,7 +67,7 @@ class MainWindow : public QMainWindow { void initalizeVideoView(Core::BioTrackerApp &biotracker); - void closeEvent(QCloseEvent* event) override; + void closeEvent(QCloseEvent *event) override; }; diff --git a/biotracker/VideoView.h b/biotracker/VideoView.h index bb19c56..16d6dba 100644 --- a/biotracker/VideoView.h +++ b/biotracker/VideoView.h @@ -41,11 +41,11 @@ class VideoView : public QOpenGLWidget, protected QOpenGLFunctions { update(); } -public Q_SLOTS: + public Q_SLOTS: void setMode(const Mode mode); void fitToWindow(); -private Q_SLOTS: + private Q_SLOTS: void handleLoggedMessage(const QOpenGLDebugMessage &debugMessage); private: diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 9a94127..776bb65 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -50,7 +50,7 @@ void Gui::initConnects() { &m_mainWindow, &MainWindow::frameCalculated); QObject::connect(&m_biotracker, &Core::BioTrackerApp::trackerSelected, - &m_mainWindow, &MainWindow::trackerSelected); + &m_mainWindow, &MainWindow::trackerSelected); QObject::connect(&m_biotracker, &Core::BioTrackerApp::notify, &m_mainWindow.getNotification(), &NotificationWidget::notify); diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index 38c92c8..4ac3c98 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -8,17 +8,21 @@ MainWindow::MainWindow(Core::BioTrackerApp &biotracker) , m_algorithmSelection(m_ui.widget_alg, biotracker) , m_notification(m_ui.dockWidgetNotificationContents, biotracker) , m_openCameraDialog(m_ui.centralWidget, biotracker) - , m_tools(m_ui.groupBox_tools){ + , m_tools(m_ui.groupBox_tools) { initalizeVideoView(biotracker); { QFile file(QString::fromStdString(ConfigParam::GEOMETRY_FILE.string())); - if (file.open(QIODevice::ReadOnly)) restoreGeometry(file.readAll()); + if (file.open(QIODevice::ReadOnly)) { + restoreGeometry(file.readAll()); + } } { QFile file(QString::fromStdString(ConfigParam::STATE_FILE.string())); - if (file.open(QIODevice::ReadOnly)) restoreState(file.readAll()); + if (file.open(QIODevice::ReadOnly)) { + restoreState(file.readAll()); + } } } @@ -26,29 +30,32 @@ void MainWindow::initalizeVideoView(Core::BioTrackerApp &biotracker) { m_videoView = std::make_unique(m_ui.trackingArea, biotracker); m_ui.videoViewLayout->addWidget(m_videoView.get()); m_videoControl = std::make_unique(m_ui.videoControls, - biotracker, m_videoView.get()); + biotracker, m_videoView.get()); } -void MainWindow::closeEvent(QCloseEvent *event) -{ +void MainWindow::closeEvent(QCloseEvent *event) { const auto dialog = QMessageBox::warning( - this, "Exit", "Do you really want to close the application?", - QMessageBox::Yes | QMessageBox::No); + this, "Exit", "Do you really want to close the application?", + QMessageBox::Yes | QMessageBox::No); - if( dialog == QMessageBox::Yes) { - { - QFile file(QString::fromStdString(ConfigParam::GEOMETRY_FILE.string())); - if (file.open(QIODevice::WriteOnly)) file.write(saveGeometry()); - } + if (dialog == QMessageBox::Yes) { + { + QFile file(QString::fromStdString(ConfigParam::GEOMETRY_FILE.string())); + if (file.open(QIODevice::WriteOnly)) { + file.write(saveGeometry()); + } + } - { - QFile file(QString::fromStdString(ConfigParam::STATE_FILE.string())); - if (file.open(QIODevice::WriteOnly)) file.write(saveState()); - } + { + QFile file(QString::fromStdString(ConfigParam::STATE_FILE.string())); + if (file.open(QIODevice::WriteOnly)) { + file.write(saveState()); + } + } - QMainWindow::closeEvent(event); + QMainWindow::closeEvent(event); } else { - event->ignore(); + event->ignore(); } } diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 0b0f6a0..f4a1ccb 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -17,8 +17,7 @@ VideoControlWidget::VideoControlWidget(QWidget *parent, , m_ui(parent) , m_bioTracker(facade) , m_videoView(videoView) - , m_isPanZoomMode(false) -{ + , m_isPanZoomMode(false) { m_iconPause.addFile(QStringLiteral(":/BioTracker/resources/pause-sign.png"), QSize(), QIcon::Normal, QIcon::Off); m_iconPlay.addFile(QStringLiteral(":/BioTracker/resources/arrow-forward1.png"), @@ -125,8 +124,9 @@ void VideoControlWidget::initConnects() { QObject::connect(m_ui.sld_speed, &QSlider::valueChanged, this, &VideoControlWidget::speedSliderValueChanged); - QObject::connect(m_ui.comboBoxSelectedView, static_cast(&QComboBox::currentIndexChanged), - this, &VideoControlWidget::viewChanged); + QObject::connect(m_ui.comboBoxSelectedView, + static_cast(&QComboBox::currentIndexChanged), + this, &VideoControlWidget::viewChanged); QObject::connect(&m_bioTracker, &Core::BioTrackerApp::registerViews, this, &VideoControlWidget::registerViews); @@ -233,8 +233,7 @@ void repaintVideoView(VideoView *videoView) { videoView->update(); } -void VideoControlWidget::onRequestRepaint() -{ +void VideoControlWidget::onRequestRepaint() { repaintVideoView(m_videoView); } @@ -260,8 +259,8 @@ void VideoControlWidget::takeScreenshot() { filename.append("/Screenshot_").append(QString::fromStdString(dateTime)).append(".png"); std::cout << QDir::homePath().append(filename).toStdString() << std::endl; QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), - QDir::homePath().append(filename), - tr("Images (*.png)")); + QDir::homePath().append(filename), + tr("Images (*.png)")); if (filepath.count()) { m_bioTracker.getTrackingThread().getTexture().get().save(filepath); diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index 9395bcf..c243d79 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -52,10 +52,9 @@ void VideoView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { std::cout << debugMessage.message().toStdString() << std::endl; } -void VideoView::paintGL() -{ - BioTracker::Core::TextureObject const& texture = - m_biotracker.getTrackingThread().getTexture(); +void VideoView::paintGL() { + BioTracker::Core::TextureObject const &texture = + m_biotracker.getTrackingThread().getTexture(); const size_t width = this->width(); const size_t height = this->height(); @@ -78,16 +77,16 @@ void VideoView::paintGL() } QPoint VideoView::unprojectScreenPos(QPoint mouseCoords) { - BioTracker::Core::TextureObject const& texture = - m_biotracker.getTrackingThread().getTexture(); + BioTracker::Core::TextureObject const &texture = + m_biotracker.getTrackingThread().getTexture(); // variables required to map window coordinates to picture coordinates return BioTracker::Core::ScreenHelper::screenToImageCoords( - m_panZoomState, - texture.width(), texture.height(), - width(), height(), - mouseCoords - ); + m_panZoomState, + texture.width(), texture.height(), + width(), height(), + mouseCoords + ); } void VideoView::keyPressEvent(QKeyEvent *e) { @@ -99,117 +98,118 @@ void VideoView::keyPressEvent(QKeyEvent *e) { void VideoView::mouseMoveEvent(QMouseEvent *e) { switch (m_currentMode) { - case Mode::PANZOOM: { - if (m_panZoomState.panState) { - const QPointF delta = e->localPos() - (*m_panZoomState.panState).lastPos; - (*m_panZoomState.panState).lastPos = e->localPos(); - m_panZoomState.isChanged = true; - m_panZoomState.panX -= static_cast(delta.x()); - m_panZoomState.panY -= static_cast(delta.y()); - update(); - } - break; - } - case Mode::INTERACTION: { - e->accept(); - QPoint p = unprojectScreenPos(e->pos()); - const QPointF localPos(p); - QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); - m_biotracker.mouseEvent(&modifiedEvent); - break; - } - default: { - assert(false); - break; + case Mode::PANZOOM: { + if (m_panZoomState.panState) { + const QPointF delta = e->localPos() - (*m_panZoomState.panState).lastPos; + (*m_panZoomState.panState).lastPos = e->localPos(); + m_panZoomState.isChanged = true; + m_panZoomState.panX -= static_cast(delta.x()); + m_panZoomState.panY -= static_cast(delta.y()); + update(); } + break; + } + case Mode::INTERACTION: { + e->accept(); + QPoint p = unprojectScreenPos(e->pos()); + const QPointF localPos(p); + QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); + m_biotracker.mouseEvent(&modifiedEvent); + break; + } + default: { + assert(false); + break; + } } } void VideoView::mousePressEvent(QMouseEvent *e) { switch (m_currentMode) { - case Mode::PANZOOM: { - if (QApplication::keyboardModifiers() == Qt::NoModifier) { - m_panZoomState.isChanged = true; - m_panZoomState.panState = BioTracker::Core::CurrentPanState(e->localPos()); - setCursor(Qt::ClosedHandCursor); - } - if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonDblClick) { - fitToWindow(); - } - break; + case Mode::PANZOOM: { + if (QApplication::keyboardModifiers() == Qt::NoModifier) { + m_panZoomState.isChanged = true; + m_panZoomState.panState = BioTracker::Core::CurrentPanState(e->localPos()); + setCursor(Qt::ClosedHandCursor); } - case Mode::INTERACTION: { - e->accept(); - QPoint p = unprojectScreenPos(e->pos()); - const QPointF localPos(p); - QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); - m_biotracker.mouseEvent(&modifiedEvent); - break; - } - default: { - assert(false); - break; + if (e->button() == Qt::LeftButton && e->type() == QEvent::MouseButtonDblClick) { + fitToWindow(); } + break; + } + case Mode::INTERACTION: { + e->accept(); + QPoint p = unprojectScreenPos(e->pos()); + const QPointF localPos(p); + QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); + m_biotracker.mouseEvent(&modifiedEvent); + break; + } + default: { + assert(false); + break; + } } } void VideoView::mouseReleaseEvent(QMouseEvent *e) { switch (m_currentMode) { - case Mode::PANZOOM: { - setCursor(Qt::OpenHandCursor); - m_panZoomState.panState.reset(); - break; - } - case Mode::INTERACTION: { - e->accept(); - QPoint p = unprojectScreenPos(e->pos()); - const QPointF localPos(p); - QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); - m_biotracker.mouseEvent(&modifiedEvent); - break; - } - default: { - assert(false); - break; - } + case Mode::PANZOOM: { + setCursor(Qt::OpenHandCursor); + m_panZoomState.panState.reset(); + break; + } + case Mode::INTERACTION: { + e->accept(); + QPoint p = unprojectScreenPos(e->pos()); + const QPointF localPos(p); + QMouseEvent modifiedEvent(e->type(),localPos,e->screenPos(),e->button(),e->buttons(),e->modifiers()); + m_biotracker.mouseEvent(&modifiedEvent); + break; + } + default: { + assert(false); + break; + } } } void VideoView::wheelEvent(QWheelEvent *e) { - BioTracker::Core::TextureObject const& texture = - m_biotracker.getTrackingThread().getTexture(); + BioTracker::Core::TextureObject const &texture = + m_biotracker.getTrackingThread().getTexture(); switch (m_currentMode) { - case Mode::PANZOOM: { - if (e->orientation() == Qt::Vertical) { - const int numDegrees = e->delta(); - const float deltaZoom = numDegrees; - m_panZoomState = BioTracker::Core::ScreenHelper::zoomTo( - m_panZoomState, - texture.width(), texture.height(), - this->width(), this->height(), - deltaZoom, - e->pos() - ); - update(); - e->accept(); - } - break; - } - case Mode::INTERACTION: { + case Mode::PANZOOM: { + if (e->orientation() == Qt::Vertical) { + const int numDegrees = e->delta(); + const float deltaZoom = numDegrees; + m_panZoomState = BioTracker::Core::ScreenHelper::zoomTo( + m_panZoomState, + texture.width(), texture.height(), + this->width(), this->height(), + deltaZoom, + e->pos() + ); + update(); e->accept(); - const QPoint p = unprojectScreenPos(e->pos()); - const QPointF localPos(p); - QWheelEvent modifiedEvent(e->pos(),localPos,e->pixelDelta(),e->angleDelta(),e->delta(),e->orientation(),e->buttons(),e->modifiers()); - QCoreApplication::sendEvent(QApplication::activeWindow(), &modifiedEvent); - m_biotracker.mouseWheelEvent(&modifiedEvent); - break; - } - default: { - assert(false); - break; } + break; + } + case Mode::INTERACTION: { + e->accept(); + const QPoint p = unprojectScreenPos(e->pos()); + const QPointF localPos(p); + QWheelEvent modifiedEvent(e->pos(),localPos,e->pixelDelta(),e->angleDelta(),e->delta(),e->orientation(),e->buttons(), + e->modifiers()); + QCoreApplication::sendEvent(QApplication::activeWindow(), &modifiedEvent); + m_biotracker.mouseWheelEvent(&modifiedEvent); + break; + } + default: { + assert(false); + break; + } } } From 17f67732070685979e820e88f0aeae16fecf99fa Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Thu, 17 Mar 2016 19:01:13 +0100 Subject: [PATCH 24/46] make more room for image --- biotracker/src/MainWindow.ui | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/biotracker/src/MainWindow.ui b/biotracker/src/MainWindow.ui index 8b760c2..806665c 100644 --- a/biotracker/src/MainWindow.ui +++ b/biotracker/src/MainWindow.ui @@ -85,7 +85,7 @@ 3 - + 0 @@ -98,16 +98,22 @@ 150 - - Tracking Area - - - false - - - false - + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -144,7 +150,7 @@ 0 0 982 - 20 + 27 @@ -290,7 +296,7 @@ - Load Tracker... + L&oad Tracker... From 7bb1866775a61c99a5cf542c9ff62b7053904371 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Fri, 18 Mar 2016 17:18:19 +0100 Subject: [PATCH 25/46] fix build for gcc<4.8 --- biotracker/src/VideoControlWidget.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index f4a1ccb..35b8696 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -251,17 +251,15 @@ void VideoControlWidget::changeCurrentFrameByEdit() { void VideoControlWidget::takeScreenshot() { QString filename; - const std::time_t t = std::time(nullptr); - const std::tm tm = *std::localtime(&t); - std::ostringstream ss; - ss << std::put_time(&tm, "%Y-%m-%d_%H-%M-%S"); - std::string dateTime = ss.str(); - filename.append("/Screenshot_").append(QString::fromStdString(dateTime)).append(".png"); - std::cout << QDir::homePath().append(filename).toStdString() << std::endl; + char buffer[80]; + time_t rawtime; + std::time(&rawtime); + struct tm *timeinfo = localtime(&rawtime); + strftime(buffer, 80, "%d-%m-%Y_%I-%M-%S", timeinfo); + filename.append("/Screenshot_").append(buffer).append(".png"); QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath().append(filename), tr("Images (*.png)")); - if (filepath.count()) { m_bioTracker.getTrackingThread().getTexture().get().save(filepath); } From 6e28fdc315ae559b9070e57d19f766458eb6f6ed Mon Sep 17 00:00:00 2001 From: justayak Date: Thu, 24 Mar 2016 17:18:19 +0000 Subject: [PATCH 26/46] #27 make text messages visible --- biotracker/src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/biotracker/src/main.cpp b/biotracker/src/main.cpp index d6e4154..b1ceab6 100644 --- a/biotracker/src/main.cpp +++ b/biotracker/src/main.cpp @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) { // meta types qRegisterMetaType("cv::Mat"); qRegisterMetaType("BioTracker::Core::Messages::MessageType"); + qRegisterMetaType("MessageType"); qRegisterMetaType("std::string"); qRegisterMetaType("std::size_t"); qRegisterMetaType("size_t"); From 0031e6e48232bf82bd79bc38c268383c41114ba8 Mon Sep 17 00:00:00 2001 From: justayak Date: Fri, 25 Mar 2016 21:27:49 +0000 Subject: [PATCH 27/46] enable keyboard events for gui --- biotracker/src/VideoView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biotracker/src/VideoView.cpp b/biotracker/src/VideoView.cpp index c243d79..c1ba162 100644 --- a/biotracker/src/VideoView.cpp +++ b/biotracker/src/VideoView.cpp @@ -23,7 +23,7 @@ VideoView::VideoView(QWidget *parent, Core::BioTrackerApp &biotracker) , m_view(Core::TrackingAlgorithm::OriginalView) , m_painter() , m_firstAttempt(true) { - + setFocusPolicy(Qt::FocusPolicy::ClickFocus); } void VideoView::setMode(const VideoView::Mode mode) { From bc3a8a00846965314e23b7a9c3859ce28e558e0e Mon Sep 17 00:00:00 2001 From: justayak Date: Tue, 29 Mar 2016 17:53:06 +0000 Subject: [PATCH 28/46] allow *.mov video files to load --- biotracker/src/Gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 776bb65..39f18a9 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -60,7 +60,7 @@ void Gui::initConnects() { } void Gui::browseVideo() { - static const QString videoFilter("Video files (*.avi *.wmv *.mp4 *.mkv)"); + static const QString videoFilter("Video files (*.avi *.wmv *.mp4 *.mkv *.mov)"); std::vector files; const QString filename = QFileDialog::getOpenFileName(&m_mainWindow, From 49435372611768763cfc6b6492d7c0d273e2f9ac Mon Sep 17 00:00:00 2001 From: justayak Date: Tue, 5 Apr 2016 10:43:23 +0000 Subject: [PATCH 29/46] different colors are used for representing different types of messages in the message box --- biotracker/src/NotificationWidget.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/biotracker/src/NotificationWidget.cpp b/biotracker/src/NotificationWidget.cpp index efbfd89..f289557 100644 --- a/biotracker/src/NotificationWidget.cpp +++ b/biotracker/src/NotificationWidget.cpp @@ -17,16 +17,22 @@ void NotificationWidget::initConnects() { void NotificationWidget::notify(const std::string &message, const Core::MessageType type) { + std::stringstream ss; switch (type) { case Core::MessageType::FILE_OPEN: - m_ui.edit_notification->append(QString(message.c_str())); + ss << "" << message << ""; break; case Core::MessageType::NOTIFICATION: - m_ui.edit_notification->append(QString(message.c_str())); + ss << "" << message << ""; + break; + case Core::MessageType::FAIL: + ss << "" << message << ""; break; default: - ; + assert(false); } + ss << "
"; + m_ui.edit_notification->insertHtml(QString(ss.str().c_str())); } From 166ac5f155ec7335dddf3f0edab52c5cf97fef38 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Wed, 6 Apr 2016 16:24:28 +0200 Subject: [PATCH 30/46] Embed TrackingAlgorithm Tool Widget in QScrollArea --- biotracker/MainWindow.h | 1 + biotracker/src/AlgorithmSelectionWidget.ui | 15 +++++ biotracker/src/MainWindow.cpp | 2 +- biotracker/src/MainWindow.ui | 75 ++++++++++++++++++++-- biotracker/src/VideoControlWidget.ui | 3 + 5 files changed, 88 insertions(+), 8 deletions(-) diff --git a/biotracker/MainWindow.h b/biotracker/MainWindow.h index 12576c6..f94577e 100644 --- a/biotracker/MainWindow.h +++ b/biotracker/MainWindow.h @@ -9,6 +9,7 @@ #include "VideoControlWidget.h" #include "OpenCameraDialog.h" #include "VideoView.h" + #include "biotracker/util/QtRaiiWrapper.hpp" #include "biotracker/util/stringTools.h" diff --git a/biotracker/src/AlgorithmSelectionWidget.ui b/biotracker/src/AlgorithmSelectionWidget.ui index 8ef92d0..9cf319c 100644 --- a/biotracker/src/AlgorithmSelectionWidget.ui +++ b/biotracker/src/AlgorithmSelectionWidget.ui @@ -20,6 +20,21 @@ Form + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + diff --git a/biotracker/src/MainWindow.cpp b/biotracker/src/MainWindow.cpp index 4ac3c98..5e88b75 100644 --- a/biotracker/src/MainWindow.cpp +++ b/biotracker/src/MainWindow.cpp @@ -8,7 +8,7 @@ MainWindow::MainWindow(Core::BioTrackerApp &biotracker) , m_algorithmSelection(m_ui.widget_alg, biotracker) , m_notification(m_ui.dockWidgetNotificationContents, biotracker) , m_openCameraDialog(m_ui.centralWidget, biotracker) - , m_tools(m_ui.groupBox_tools) { + , m_tools(m_ui.groupBoxContents) { initalizeVideoView(biotracker); { diff --git a/biotracker/src/MainWindow.ui b/biotracker/src/MainWindow.ui index 806665c..f135193 100644 --- a/biotracker/src/MainWindow.ui +++ b/biotracker/src/MainWindow.ui @@ -180,7 +180,7 @@ 200 - 172 + 207 @@ -210,19 +210,19 @@ - 3 + 2 - 8 + 3 - 8 + 3 - 8 + 3 - 8 + 3 @@ -237,7 +237,7 @@ - + 0 0 @@ -245,6 +245,67 @@ Tools + + false + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + QFrame::Plain + + + 0 + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 176 + 525 + + + + + 0 + 0 + + + + + + diff --git a/biotracker/src/VideoControlWidget.ui b/biotracker/src/VideoControlWidget.ui index dd342d1..5cc564c 100644 --- a/biotracker/src/VideoControlWidget.ui +++ b/biotracker/src/VideoControlWidget.ui @@ -68,6 +68,9 @@ Video Controls + + false + 3 From c89aab72aff7bd4feedfd92c6ced040d92e2ba26 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Fri, 15 Apr 2016 08:05:53 +0200 Subject: [PATCH 31/46] added explicit casts to silence conversion warnings --- biotracker/src/VideoControlWidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/biotracker/src/VideoControlWidget.cpp b/biotracker/src/VideoControlWidget.cpp index 35b8696..821ca15 100644 --- a/biotracker/src/VideoControlWidget.cpp +++ b/biotracker/src/VideoControlWidget.cpp @@ -174,7 +174,8 @@ void VideoControlWidget::fileOpened(const std::string filename, const double targetFps) { (void)filename; // "un-use" filename. FileOpen is a generic event, but we dont // need the filename at this place - m_ui.sld_video->setMaximum(totalFrames - 1); + assert(totalFrames > 0); + m_ui.sld_video->setMaximum(static_cast(totalFrames - 1)); m_ui.fps_label->setText(QString::number(targetFps)); const int fpsAsInt = static_cast(targetFps + 0.5); m_ui.sld_speed->setValue(fpsAsInt); @@ -286,7 +287,7 @@ void VideoControlWidget::frameCalculated(const size_t frameNumber, repaintVideoView(m_videoView); - m_ui.sld_video->setValue(frameNumber); + m_ui.sld_video->setValue(static_cast(frameNumber)); m_ui.frame_num_edit->setText(QString::number(frameNumber)); if (currentFps >= 0) { From af91d6ae68d012cfc8541e8d02d472592ac41be2 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Fri, 15 Apr 2016 08:07:07 +0200 Subject: [PATCH 32/46] removed obsolete forward declaration of "Facade" class ..which has now been renamed to "BioTrackerApp" and apparently works without a forward declaration, because the header is included. --- biotracker/AlgorithmSelectionWidget.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/biotracker/AlgorithmSelectionWidget.h b/biotracker/AlgorithmSelectionWidget.h index e5be2f4..873b013 100644 --- a/biotracker/AlgorithmSelectionWidget.h +++ b/biotracker/AlgorithmSelectionWidget.h @@ -6,8 +6,6 @@ #include "ui_AlgorithmSelectionWidget.h" #include "biotracker/util/QtRaiiWrapper.hpp" -class Facade; - namespace BioTracker { namespace Gui { From 70e03c54c72372d94700b412bda42abecdc8ed69 Mon Sep 17 00:00:00 2001 From: justayak Date: Sat, 16 Apr 2016 21:25:51 +0000 Subject: [PATCH 33/46] #32 checkbox to enable/disable tracking --- biotracker/AlgorithmSelectionWidget.h | 1 + biotracker/src/AlgorithmSelectionWidget.cpp | 19 +++++++++++++++++++ biotracker/src/AlgorithmSelectionWidget.ui | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/biotracker/AlgorithmSelectionWidget.h b/biotracker/AlgorithmSelectionWidget.h index 873b013..90e6bf3 100644 --- a/biotracker/AlgorithmSelectionWidget.h +++ b/biotracker/AlgorithmSelectionWidget.h @@ -33,6 +33,7 @@ class AlgorithmSelectionWidget : public QWidget { private Q_SLOTS: void trackingAlgorithmSelected(const QString &name); + void enableDisableTracking(bool state); }; } diff --git a/biotracker/src/AlgorithmSelectionWidget.cpp b/biotracker/src/AlgorithmSelectionWidget.cpp index db75876..c153700 100644 --- a/biotracker/src/AlgorithmSelectionWidget.cpp +++ b/biotracker/src/AlgorithmSelectionWidget.cpp @@ -46,10 +46,29 @@ void AlgorithmSelectionWidget::initConnects() { this, &AlgorithmSelectionWidget::addTrackingAlgorithm); QObject::connect(m_ui.cb_algorithms, static_cast(&QComboBox::currentIndexChanged), this, &AlgorithmSelectionWidget::trackingAlgorithmSelected); + QObject::connect(m_ui.chk_enableTracking, &QCheckBox::toggled, + this, &AlgorithmSelectionWidget::enableDisableTracking); } void AlgorithmSelectionWidget::trackingAlgorithmSelected(const QString &name) { m_biotracker.setTrackingAlgorithm(name.toStdString()); + + // check if we have "any" tracking or not + auto noTrackingStr = QString::fromStdString(m_biotracker.getRegistry().getStringByType().at(Core::NoTracking)); + if (name.compare(noTrackingStr) == 0) { + m_ui.chk_enableTracking->setChecked(true); + m_ui.chk_enableTracking->setEnabled(false); + } else { + m_ui.chk_enableTracking->setEnabled(true); + } +} + +void AlgorithmSelectionWidget::enableDisableTracking(bool checked) { + if (checked) { + m_biotracker.enableTracking(); + } else { + m_biotracker.disableTracking(); + } } } diff --git a/biotracker/src/AlgorithmSelectionWidget.ui b/biotracker/src/AlgorithmSelectionWidget.ui index 9cf319c..23a6319 100644 --- a/biotracker/src/AlgorithmSelectionWidget.ui +++ b/biotracker/src/AlgorithmSelectionWidget.ui @@ -84,6 +84,19 @@ + + + + false + + + Tracking enabled + + + true + + +
From 83fd661249f00dba6bfd0efa0763480e844f789a Mon Sep 17 00:00:00 2001 From: justayak Date: Sat, 16 Apr 2016 21:49:12 +0000 Subject: [PATCH 34/46] #32 add shortcut for the checkbox enable/disabe tracking --- biotracker/src/AlgorithmSelectionWidget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/biotracker/src/AlgorithmSelectionWidget.cpp b/biotracker/src/AlgorithmSelectionWidget.cpp index c153700..b6461fa 100644 --- a/biotracker/src/AlgorithmSelectionWidget.cpp +++ b/biotracker/src/AlgorithmSelectionWidget.cpp @@ -48,6 +48,13 @@ void AlgorithmSelectionWidget::initConnects() { this, &AlgorithmSelectionWidget::trackingAlgorithmSelected); QObject::connect(m_ui.chk_enableTracking, &QCheckBox::toggled, this, &AlgorithmSelectionWidget::enableDisableTracking); + + const QString shortcutTrackingKey = QString::fromStdString( + m_biotracker.getSettings().getValueOrDefault + (GuiParam::SHORTCUT_TRACKING, "T")); + auto *shortcutTracking = new QShortcut(QKeySequence(shortcutTrackingKey), this); + QObject::connect(shortcutTracking, &QShortcut::activated, m_ui.chk_enableTracking, + &QCheckBox::click); } void AlgorithmSelectionWidget::trackingAlgorithmSelected(const QString &name) { From d1f6825916d26d43b119dafdca2717aeb4494b6d Mon Sep 17 00:00:00 2001 From: Amjad Saadeh Date: Mon, 18 Apr 2016 19:42:40 +0000 Subject: [PATCH 35/46] fix camera listing --- biotracker/src/Gui.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 39f18a9..291858b 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -94,16 +94,27 @@ void Gui::browseCameras() { QListWidget *cameraListWidget = cameraDialog.getUi().cameraList; cameraListWidget->clear(); + BioTracker::Core::Settings settings = m_biotracker.getSettings(); + BioTracker::Core::TrackerStatus trackerStatus = m_biotracker.getTrackingThread().getStatus(); // Add Item for each camera cv::VideoCapture vcap; - for (uint8_t i = 0; i <= 254; i++) { - vcap = cv::VideoCapture(i); - if (!vcap.isOpened()) { - break; + boost::optional mediaTypeOpt = settings.maybeGetValueOfParam(GuiParam::MEDIA_TYPE); + GuiParam::MediaType mediaType = mediaTypeOpt ? static_cast(*mediaTypeOpt) : GuiParam::MediaType::NoMedia; + boost::optional camIdOpt = settings.maybeGetValueOfParam(CaptureParam::CAP_CAMERA_ID); + int camId = camIdOpt ? *camIdOpt : -1; + for (int i = 0; i <= 254; i++) { + QListWidgetItem* item = new QListWidgetItem(QString("Camera ") + QString::number(static_cast(i))); + if (mediaType == GuiParam::MediaType::Camera && camId == i && trackerStatus != BioTracker::Core::TrackerStatus::NothingLoaded) { + item->setText(item->text() + QString(" (in use)")); + item->setFlags(Qt::NoItemFlags); + } else { + vcap = cv::VideoCapture(i); + if (!vcap.isOpened()) { + break; + } + vcap.release(); } - vcap.release(); - cameraListWidget->addItem(QString("Camera ") + QString::number(static_cast - (i))); + cameraListWidget->addItem(item); } if (cameraDialog.exec() == QDialog::Accepted) { From 4cb4462621e4d0ededbfb2f5f47ec7d31aa44600 Mon Sep 17 00:00:00 2001 From: Amjad Saadeh Date: Tue, 19 Apr 2016 10:18:00 +0000 Subject: [PATCH 36/46] add comment to justify the iteration over the camera devices --- biotracker/src/Gui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 291858b..f39c9cc 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -102,6 +102,7 @@ void Gui::browseCameras() { GuiParam::MediaType mediaType = mediaTypeOpt ? static_cast(*mediaTypeOpt) : GuiParam::MediaType::NoMedia; boost::optional camIdOpt = settings.maybeGetValueOfParam(CaptureParam::CAP_CAMERA_ID); int camId = camIdOpt ? *camIdOpt : -1; + // OpenCV does not have an API to list camera devices https://github.com/Itseez/opencv/issues/4269 for (int i = 0; i <= 254; i++) { QListWidgetItem* item = new QListWidgetItem(QString("Camera ") + QString::number(static_cast(i))); if (mediaType == GuiParam::MediaType::Camera && camId == i && trackerStatus != BioTracker::Core::TrackerStatus::NothingLoaded) { From 48f5108ce15ecb8a9c66366954fc27746dda402e Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Wed, 20 Apr 2016 18:14:54 +0200 Subject: [PATCH 37/46] Gui.h: removed superfluous header inclusion ..which then makes the whole project depend on ZMQ. That fails on windows. --- biotracker/Gui.h | 1 - 1 file changed, 1 deletion(-) diff --git a/biotracker/Gui.h b/biotracker/Gui.h index cca6455..e85d1f0 100644 --- a/biotracker/Gui.h +++ b/biotracker/Gui.h @@ -3,7 +3,6 @@ #include #include "biotracker/BioTrackerApp.h" -#include "biotracker/ZmqTrackingAlgorithm.h" #include "MainWindow.h" From 99b18a8e94c35341562472f5ad41b5a878c1e8db Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Wed, 20 Apr 2016 18:15:27 +0200 Subject: [PATCH 38/46] cmake: add boost directories to include paths ..otherwise it fails on windows (not on unix, because boost lies in the default directories there). --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f078f1..b3c342e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ include_directories( SYSTEM ${Qt5Widgets_INCLUDE_DIRS} SYSTEM ${OpenCV_INCLUDE_DIRS} SYSTEM ${Qt5OpenGL_INCLUDE_DIRS} + SYSTEM ${Boost_INCLUDE_DIRS} ) set(CMAKE_INCLUDE_CURRENT_DIR ON) From 048ea89dbe731de3c527d3597ef81deea0edea32 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Thu, 21 Apr 2016 15:39:09 +0200 Subject: [PATCH 39/46] added boost library directories to linker paths Otherwise it'll fail on windows. It worked on unix, because the paths are standard (and known) there. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3c342e..62930b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ include_directories( SYSTEM ${Boost_INCLUDE_DIRS} ) +link_directories( + ${Boost_LIBRARY_DIRS} +) + set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) add_definitions(${Qt5Widgets_DEFINITIONS}) From b42c920c2f76858032c0b4a5a67fa4cd1554223a Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Thu, 21 Apr 2016 15:40:34 +0200 Subject: [PATCH 40/46] MSVC: made "BioTracker" project the start-up project Which means that just hitting CTRL+F5 will run that project. Instead of trying to run ALL_BUILD, which obviously fails. The property should just have no effect on non-MSVC targets. I hope. --- biotracker/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biotracker/CMakeLists.txt b/biotracker/CMakeLists.txt index c5e0f6d..f459809 100644 --- a/biotracker/CMakeLists.txt +++ b/biotracker/CMakeLists.txt @@ -11,6 +11,9 @@ qt5_wrap_ui(UI_HEADERS ${ui}) add_executable(BioTracker ${src} ${hdr} ${UI_RESOURCES} ${UI_HEADERS} ) +# Make this target the default target for the solution. +set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "BioTracker") + include_directories( SYSTEM ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(BioTracker Qt5::Widgets From 3f47dfe2e46b37a3a5ffd80b56b7a3920cc4a610 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Fri, 22 Apr 2016 16:01:34 +0200 Subject: [PATCH 41/46] cmake: build GUI and core on windows into same directory This avoids some issues with having to copy the core DLL to the GUI output directory to be able to run it. --- CMakeLists.txt | 14 ++++++++++++++ biotracker/CMakeLists.txt | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62930b0..0a6bc6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,3 +70,17 @@ add_definitions(${Qt5Widgets_DEFINITIONS}) add_definitions(-DQT_NO_KEYWORDS) add_subdirectory(biotracker) + +# Make all targets (core and GUI) build to a common output directory on windows to work around copying DLLs. +# Note that this must come before including the other projects. +if(MSVC) + set(common_output_directory ${CMAKE_BINARY_DIR}/bin) + foreach(SUBTARGET BioTracker ${CPM_LIBRARIES}) + foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG) + set_target_properties(${SUBTARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${common_output_directory}) + set_target_properties(${SUBTARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${common_output_directory}) + set_target_properties(${SUBTARGET} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${common_output_directory}) + endforeach() + endforeach() +endif() diff --git a/biotracker/CMakeLists.txt b/biotracker/CMakeLists.txt index f459809..7ce3bda 100644 --- a/biotracker/CMakeLists.txt +++ b/biotracker/CMakeLists.txt @@ -13,7 +13,11 @@ add_executable(BioTracker ) # Make this target the default target for the solution. set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "BioTracker") - +# Give the debug executable a different name on windows as they are build +# into the same directory. +if(MSVC) + set_target_properties(BioTracker PROPERTIES OUTPUT_NAME_DEBUG BioTracker-Debug) +endif() include_directories( SYSTEM ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(BioTracker Qt5::Widgets From 9d9048997888ddd8faea688956421aa28f91c95e Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Mon, 9 May 2016 10:10:16 +0200 Subject: [PATCH 42/46] dummy commit for triggering jenkins From 720cf284e3e0ae54946f084ee1a1e072dec2323a Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Mon, 9 May 2016 10:30:22 +0200 Subject: [PATCH 43/46] fix link to dependencies --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89f8493..6baecea 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This repository contains the GUI frontend for the [BioTracker](https://github.co ## Dependencies ### Unix -You can find an up-to-date list of [dependencies](https://github.com/BioroboticsLab/DockerFiles/blob/master/biotracker/dependencies.sh) +You can find an up-to-date list of [dependencies](https://github.com/BioroboticsLab/DockerFiles/blob/master/ubuntu-15.10-biotracker/dependencies.sh) needed to build the BioTracker in our docker repository. ### OSX From b90dc90ca8e51875866825bd089a2b41a3190c35 Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Tue, 31 May 2016 14:08:18 +0200 Subject: [PATCH 44/46] dummy trigger commit From 76bca6883a8771b0070f1070dbd492d6c7e40537 Mon Sep 17 00:00:00 2001 From: Patrick Winterstein Date: Tue, 19 Jul 2016 13:07:54 +0200 Subject: [PATCH 45/46] added load/save of trackingdata --- biotracker/Gui.h | 4 + biotracker/src/Gui.cpp | 161 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/biotracker/Gui.h b/biotracker/Gui.h index e85d1f0..0db7c7e 100644 --- a/biotracker/Gui.h +++ b/biotracker/Gui.h @@ -20,6 +20,10 @@ class Gui : public QObject { void initConnects(); QStringList browse(const QString &title, const QString &filter); + boost::optional> getOpenFiles(); + boost::optional getFileHash(std::string const& filename, const size_t numFiles) const; + std::vector getFilenamesFromPaths(std::vector const& paths) const; + private Q_SLOTS: void browseVideo(); void browsePictures(); diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index f39c9cc..42723cd 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -12,6 +12,12 @@ #include #include "opencv2/highgui/highgui.hpp" +#include "biotracker/serialization/SerializationData.h" + +#include +#include +#include + namespace BioTracker { namespace Gui { @@ -141,11 +147,166 @@ void Gui::loadTracker() { } void Gui::loadTrackingData() { + static const QString trackingdataFilter("Trackingdata Files (*.tdat)"); + + const QString path = QFileDialog::getOpenFileName(&m_mainWindow, "Load trackingdata", "", trackingdataFilter); + if (!path.isEmpty()) { +// printGuiMessage("Restoring tracking data from " + filename, MSGS::NOTIFICATION); + std::ifstream is(path.toStdString()); + cereal::JSONInputArchive ar(is); + + Core::Serialization::Data sdata; + ar(sdata); + + if (m_biotracker.getTrackingThread().getTrackerType()){ + assert(m_biotracker.getTrackingThread().getTrackerType()); + const std::string trackerType = + Core::Registry::getInstance().getStringByType().at(m_biotracker.getTrackingThread().getTrackerType().get()); + + if (sdata.getType() != trackerType) { + QMessageBox::warning(&m_mainWindow, "Unable to load tracking data", + "Tracker type does not match."); + return; + } + } else { + // try to automatically select the required tracking algorithm + const auto& typeByString = Core::Registry::getInstance().getTypeByString(); + const auto it = typeByString.find(sdata.getType()); + if (it != typeByString.end()) { + m_biotracker.getTrackingThread().setTrackingAlgorithm( + Core::Registry::getInstance().makeNewTracker( + Core::Registry::getInstance().getTypeByString().at(sdata.getType()), m_biotracker.getSettings() + ) + ); + } else { + QMessageBox::warning(&m_mainWindow, "Unable to load tracking data", + "Unknown tracker type."); + return; + } + } + + const boost::optional> currentFiles = getOpenFiles(); + + if (!currentFiles) { + QMessageBox::warning(&m_mainWindow, "Unable to load tracking data", + "No file opened."); + return; + } + const boost::optional hash = getFileHash(currentFiles.get().front(), currentFiles.get().size()); + + if (!hash) { + QMessageBox::warning(&m_mainWindow, "Unable to load tracking data", + "Could not calculate file hash."); + return; + } + + if (sdata.getFileSha1Hash() != hash.get()) { + auto buttonClicked = QMessageBox::warning(&m_mainWindow, "Unable to load tracking data", + "File hash does not match", QMessageBox::Ok | QMessageBox::Ignore); + if (buttonClicked == QMessageBox::Ok) + return; + } + + m_biotracker.getTrackingThread().loadTrackedObjects(sdata.getTrackedObjects()); + } } void Gui::storeTrackingData() { + if (!m_biotracker.getTrackingThread().getTrackerType()) { + QMessageBox::warning(&m_mainWindow, "Unable to store tracking data", + "No tracker selected."); + return; + } + + QFileDialog dialog(&m_mainWindow, "Save tracking data"); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setDefaultSuffix("tdat"); + dialog.setNameFilter("Data Files (*.tdat)"); + // set displayed file as default filename: +// if (_filename.lastIndexOf(".") > 0) +// dialog.selectFile(_filename.left(_filename.lastIndexOf("."))); + if (dialog.exec()) { + const QStringList filenames = dialog.selectedFiles(); + if (!filenames.empty()) { + assert(m_biotracker.getTrackingThread().getTrackerType()); +// printGuiMessage("Storing tracking data in " + path.toStdString(), MSGS::NOTIFICATION); + + const std::string trackerType = + Core::Registry::getInstance().getStringByType().at(m_biotracker.getTrackingThread().getTrackerType().get()); + const boost::optional> currentFiles = getOpenFiles(); + + if (!currentFiles) { + QMessageBox::warning(&m_mainWindow, "Unable to store tracking data", + "No file opened."); + return; + } + + const boost::optional hash = getFileHash(currentFiles.get().front(), currentFiles.get().size()); + if (!hash) { + QMessageBox::warning(&m_mainWindow, "Unable to store tracking data", + "Could not calculate file hash."); + return; + } + + Core::Serialization::Data sdata(trackerType, hash.get(), getFilenamesFromPaths(currentFiles.get()), + m_biotracker.getTrackingThread().getTrackedObjects().get()); + + std::ofstream ostream(filenames.first().toStdString(), std::ios::binary); + cereal::JSONOutputArchive archive(ostream); + archive(std::move(sdata)); + } + } +} + +boost::optional> Gui::getOpenFiles() { + Core::Settings settings = m_biotracker.getSettings(); + boost::optional mediaTypeOpt = settings.maybeGetValueOfParam(GuiParam::MEDIA_TYPE); + GuiParam::MediaType mediaType = mediaTypeOpt ? static_cast(*mediaTypeOpt) : GuiParam::MediaType::NoMedia; + + boost::optional> filename; + switch (mediaType) { + case GuiParam::MediaType::Images: + filename = settings.getValueOfParam>(PictureParam::PICTURE_FILES); + break; + case GuiParam::MediaType::Video: + filename = std::vector(); + filename.get().push_back(settings.getValueOfParam(CaptureParam::CAP_VIDEO_FILE)); + break; + default: + return boost::optional>(); + } + + // cap_video_file and picture_file can be set, but empty. therefore, we + // need to check if the parameter actually contains a file name. + if (filename && !filename.get().empty()) return filename; + + return boost::optional>(); +} + +boost::optional Gui::getFileHash(const std::string &filename, const size_t numFiles) const { + QCryptographicHash sha1Generator(QCryptographicHash::Sha1); + QFile file(QString::fromStdString(filename)); + if (file.open(QIODevice::ReadOnly)) { + // calculate hash from first 4096 bytes of file + sha1Generator.addData(file.peek(4096)); + sha1Generator.addData(QByteArray::number(static_cast(numFiles))); + return QString(sha1Generator.result().toHex()).toStdString(); + } + + return boost::optional(); +} + +std::vector Gui::getFilenamesFromPaths(const std::vector &paths) const { + std::vector filenames; + filenames.reserve(paths.size()); + for (std::string const& path : paths) { + const QFileInfo fi(QString::fromStdString(path)); + filenames.push_back(fi.baseName().toStdString()); + } + return filenames; } void Gui::exit() { From 2134d642987baf589fd6621d61bef357abfa56a5 Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Tue, 20 Sep 2016 16:30:43 +0200 Subject: [PATCH 46/46] Remove code comments --- biotracker/src/Gui.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/biotracker/src/Gui.cpp b/biotracker/src/Gui.cpp index 42723cd..9665445 100644 --- a/biotracker/src/Gui.cpp +++ b/biotracker/src/Gui.cpp @@ -31,7 +31,7 @@ Gui::Gui() } void Gui::initConnects() { - //File -> Open Video + // File -> Open Video QObject::connect(m_mainWindow.getUi().actionOpen_Video, &QAction::triggered, this, &Gui::browseVideo); QObject::connect(m_mainWindow.getUi().actionOpen_Picture, &QAction::triggered, @@ -151,7 +151,6 @@ void Gui::loadTrackingData() { const QString path = QFileDialog::getOpenFileName(&m_mainWindow, "Load trackingdata", "", trackingdataFilter); if (!path.isEmpty()) { -// printGuiMessage("Restoring tracking data from " + filename, MSGS::NOTIFICATION); std::ifstream is(path.toStdString()); cereal::JSONInputArchive ar(is); @@ -224,14 +223,10 @@ void Gui::storeTrackingData() { dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setDefaultSuffix("tdat"); dialog.setNameFilter("Data Files (*.tdat)"); - // set displayed file as default filename: -// if (_filename.lastIndexOf(".") > 0) -// dialog.selectFile(_filename.left(_filename.lastIndexOf("."))); if (dialog.exec()) { const QStringList filenames = dialog.selectedFiles(); if (!filenames.empty()) { assert(m_biotracker.getTrackingThread().getTrackerType()); -// printGuiMessage("Storing tracking data in " + path.toStdString(), MSGS::NOTIFICATION); const std::string trackerType = Core::Registry::getInstance().getStringByType().at(m_biotracker.getTrackingThread().getTrackerType().get());