From c19611ed33f439efe9bf0ae215507d613da92b4d Mon Sep 17 00:00:00 2001 From: Benjamin Wild Date: Wed, 16 Mar 2016 18:18:11 +0100 Subject: [PATCH 01/31] 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 02/31] 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 03/31] 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 04/31] 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 05/31] 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 06/31] 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 07/31] 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 08/31] 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 09/31] 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 10/31] 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 11/31] #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 12/31] 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 13/31] 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 14/31] 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 15/31] 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 16/31] 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 17/31] 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 18/31] #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 19/31] #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 20/31] 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 21/31] 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 22/31] 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 23/31] 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 24/31] 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 25/31] 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 26/31] 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 27/31] 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 28/31] 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 29/31] 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 30/31] 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 31/31] 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());