Skip to content

Commit

Permalink
Upgrade to new QOpenGLWidget to fix several Qt bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojnnes committed Jan 10, 2018
1 parent 75263ff commit feeab87
Show file tree
Hide file tree
Showing 17 changed files with 238 additions and 317 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if(CUDA_ENABLED)
find_package(CUDA ${CUDA_MIN_VERSION} QUIET)
endif()

find_package(Qt5 REQUIRED)
find_package(Qt5 5.4 REQUIRED)


################################################################################
Expand Down
7 changes: 6 additions & 1 deletion cmake/FindQt5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ if(Qt5Core_FOUND AND Qt5OpenGL_FOUND)
endif()

if(Qt5_FOUND)
message(STATUS "Found Qt ${Qt5Core_VERSION_STRING}")
if(Qt5Core_VERSION VERSION_LESS Qt5_FIND_VERSION)
message(FATAL_ERROR "Qt5 version ${Qt5_FIND_VERSION} or newer needed, "
"but only found ${Qt5Core_VERSION}")
else()
message(STATUS "Found Qt ${Qt5Core_VERSION_STRING}")
endif()
else()
if(Qt5_FIND_REQUIRED)
set(Qt5_ERROR_MESSAGE "Could not find Qt5:")
Expand Down
3 changes: 0 additions & 3 deletions scripts/shell/colmap.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ if "%COMMAND%"=="-h" goto show_help
if "%COMMAND%"=="--help" goto show_help
if not exist "%SCRIPT_PATH%\bin\%COMMAND%" goto show_help

@echo on

"%SCRIPT_PATH%\bin\%COMMAND%" %ARGUMENTS%

@echo off
goto :eof

:show_help
Expand Down
2 changes: 1 addition & 1 deletion src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ COLMAP_ADD_LIBRARY(ui
log_widget.h log_widget.cc
main_window.h main_window.cc
match_matrix_widget.h match_matrix_widget.cc
model_viewer_widget.h model_viewer_widget.cc
movie_grabber_widget.h movie_grabber_widget.cc
opengl_window.h opengl_window.cc
options_widget.h options_widget.cc
point_painter.h point_painter.cc
point_viewer_widget.h point_viewer_widget.cc
Expand Down
19 changes: 10 additions & 9 deletions src/ui/image_viewer_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "ui/image_viewer_widget.h"

#include "ui/opengl_window.h"
#include "ui/model_viewer_widget.h"
#include "util/misc.h"

namespace colmap {
Expand Down Expand Up @@ -233,9 +233,10 @@ void FeatureImageViewerWidget::ShowOrHide() {
}

DatabaseImageViewerWidget::DatabaseImageViewerWidget(
QWidget* parent, OpenGLWindow* opengl_window, OptionManager* options)
QWidget* parent, ModelViewerWidget* model_viewer_widget,
OptionManager* options)
: FeatureImageViewerWidget(parent, "keypoints"),
opengl_window_(opengl_window),
model_viewer_widget_(model_viewer_widget),
options_(options) {
setWindowTitle("Image information");

Expand Down Expand Up @@ -328,14 +329,14 @@ DatabaseImageViewerWidget::DatabaseImageViewerWidget(
}

void DatabaseImageViewerWidget::ShowImageWithId(const image_t image_id) {
if (opengl_window_->images.count(image_id) == 0) {
if (model_viewer_widget_->images.count(image_id) == 0) {
return;
}

image_id_ = image_id;

const Image& image = opengl_window_->images.at(image_id);
const Camera& camera = opengl_window_->cameras.at(image.CameraId());
const Image& image = model_viewer_widget_->images.at(image_id);
const Camera& camera = model_viewer_widget_->cameras.at(image.CameraId());

image_id_item_->setText(QString::number(image_id));
camera_id_item_->setText(QString::number(image.CameraId()));
Expand Down Expand Up @@ -389,10 +390,10 @@ void DatabaseImageViewerWidget::DeleteImage() {
this, "", tr("Do you really want to delete this image?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
if (opengl_window_->reconstruction->ExistsImage(image_id_)) {
opengl_window_->reconstruction->DeRegisterImage(image_id_);
if (model_viewer_widget_->reconstruction->ExistsImage(image_id_)) {
model_viewer_widget_->reconstruction->DeRegisterImage(image_id_);
}
opengl_window_->Update();
model_viewer_widget_->ReloadReconstruction();
}
hide();
}
Expand Down
7 changes: 4 additions & 3 deletions src/ui/image_viewer_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace colmap {

class OpenGLWindow;
class ModelViewerWidget;

class ImageViewerWidget : public QWidget {
public:
Expand Down Expand Up @@ -81,7 +81,8 @@ class FeatureImageViewerWidget : public ImageViewerWidget {

class DatabaseImageViewerWidget : public FeatureImageViewerWidget {
public:
DatabaseImageViewerWidget(QWidget* parent, OpenGLWindow* opengl_window,
DatabaseImageViewerWidget(QWidget* parent,
ModelViewerWidget* model_viewer_widget,
OptionManager* options);

void ShowImageWithId(const image_t image_id);
Expand All @@ -90,7 +91,7 @@ class DatabaseImageViewerWidget : public FeatureImageViewerWidget {
void ResizeTable();
void DeleteImage();

OpenGLWindow* opengl_window_;
ModelViewerWidget* model_viewer_widget_;

OptionManager* options_;

Expand Down
47 changes: 15 additions & 32 deletions src/ui/main_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ const ReconstructionManager& MainWindow::GetReconstructionManager() const {
return reconstruction_manager_;
}

void MainWindow::showEvent(QShowEvent* event) {
after_show_event_->trigger();
event->accept();
}

void MainWindow::afterShowEvent() { opengl_window_->PaintGL(); }

void MainWindow::closeEvent(QCloseEvent* event) {
if (window_closed_) {
event->accept();
Expand Down Expand Up @@ -87,14 +80,8 @@ void MainWindow::closeEvent(QCloseEvent* event) {
}

void MainWindow::CreateWidgets() {
opengl_window_ = new OpenGLWindow(this, &options_);

#ifdef _MSC_VER
setCentralWidget(
QWidget::createWindowContainer(opengl_window_, this, Qt::MSWindowsOwnDC));
#else
setCentralWidget(QWidget::createWindowContainer(opengl_window_, this));
#endif
model_viewer_widget_ = new ModelViewerWidget(this, &options_);
setCentralWidget(model_viewer_widget_);

project_widget_ = new ProjectWidget(this, &options_);
project_widget_->SetDatabasePath(*options_.database_path);
Expand All @@ -109,7 +96,7 @@ void MainWindow::CreateWidgets() {
bundle_adjustment_widget_ = new BundleAdjustmentWidget(this, &options_);
dense_reconstruction_widget_ = new DenseReconstructionWidget(this, &options_);
render_options_widget_ =
new RenderOptionsWidget(this, &options_, opengl_window_);
new RenderOptionsWidget(this, &options_, model_viewer_widget_);
log_widget_ = new LogWidget(this);
undistortion_widget_ = new UndistortionWidget(this, &options_);
reconstruction_manager_widget_ =
Expand All @@ -124,10 +111,6 @@ void MainWindow::CreateWidgets() {
}

void MainWindow::CreateActions() {
after_show_event_ = new QAction(tr("After show event"), this);
connect(after_show_event_, &QAction::triggered, this,
&MainWindow::afterShowEvent, Qt::QueuedConnection);

//////////////////////////////////////////////////////////////////////////////
// File actions
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -296,8 +279,8 @@ void MainWindow::CreateActions() {

action_render_reset_view_ = new QAction(
QIcon(":/media/render-reset-view.png"), tr("Reset view"), this);
connect(action_render_reset_view_, &QAction::triggered, opengl_window_,
&OpenGLWindow::ResetView);
connect(action_render_reset_view_, &QAction::triggered, model_viewer_widget_,
&ModelViewerWidget::ResetView);

action_render_options_ = new QAction(QIcon(":/media/render-options.png"),
tr("Render options"), this);
Expand Down Expand Up @@ -335,8 +318,8 @@ void MainWindow::CreateActions() {

action_grab_movie_ =
new QAction(QIcon(":/media/grab-movie.png"), tr("Grab movie"), this);
connect(action_grab_movie_, &QAction::triggered, opengl_window_,
&OpenGLWindow::GrabMovie);
connect(action_grab_movie_, &QAction::triggered, model_viewer_widget_,
&ModelViewerWidget::GrabMovie);

action_undistort_ =
new QAction(QIcon(":/media/undistort.png"), tr("Undistortion"), this);
Expand Down Expand Up @@ -514,11 +497,11 @@ void MainWindow::CreateStatusbar() {
connect(statusbar_timer_, &QTimer::timeout, this, &MainWindow::UpdateTimer);
statusbar_timer_->start(1000);

opengl_window_->statusbar_status_label =
model_viewer_widget_->statusbar_status_label =
new QLabel("0 Images - 0 Points", this);
opengl_window_->statusbar_status_label->setFont(font);
opengl_window_->statusbar_status_label->setAlignment(Qt::AlignCenter);
statusBar()->addWidget(opengl_window_->statusbar_status_label, 1);
model_viewer_widget_->statusbar_status_label->setFont(font);
model_viewer_widget_->statusbar_status_label->setAlignment(Qt::AlignCenter);
statusBar()->addWidget(model_viewer_widget_->statusbar_status_label, 1);
}

void MainWindow::CreateControllers() {
Expand Down Expand Up @@ -1081,15 +1064,15 @@ void MainWindow::RenderSelectedReconstruction() {
}

const size_t reconstruction_idx = SelectedReconstructionIdx();
opengl_window_->reconstruction =
model_viewer_widget_->reconstruction =
&reconstruction_manager_.Get(reconstruction_idx);
opengl_window_->Update();
model_viewer_widget_->ReloadReconstruction();
}

void MainWindow::RenderClear() {
reconstruction_manager_widget_->SelectReconstruction(
ReconstructionManagerWidget::kNewestReconstructionIdx);
opengl_window_->Clear();
model_viewer_widget_->ClearReconstruction();
}

void MainWindow::RenderOptions() {
Expand Down Expand Up @@ -1141,7 +1124,7 @@ void MainWindow::GrabImage() {
!HasFileExtension(file_name.toUtf8().constData(), ".jpg")) {
file_name += ".png";
}
QImage image = opengl_window_->GrabImage();
QImage image = model_viewer_widget_->GrabImage();
image.save(file_name);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/ui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "ui/license_widget.h"
#include "ui/log_widget.h"
#include "ui/match_matrix_widget.h"
#include "ui/opengl_window.h"
#include "ui/model_viewer_widget.h"
#include "ui/project_widget.h"
#include "ui/reconstruction_manager_widget.h"
#include "ui/reconstruction_options_widget.h"
Expand All @@ -50,8 +50,6 @@ class MainWindow : public QMainWindow {
const ReconstructionManager& GetReconstructionManager() const;

protected:
void showEvent(QShowEvent* event);
void afterShowEvent();
void closeEvent(QCloseEvent* event);

private:
Expand Down Expand Up @@ -138,7 +136,7 @@ class MainWindow : public QMainWindow {

Timer timer_;

OpenGLWindow* opengl_window_;
ModelViewerWidget* model_viewer_widget_;
ProjectWidget* project_widget_;
FeatureExtractionWidget* feature_extraction_widget_;
FeatureMatchingWidget* feature_matching_widget_;
Expand Down Expand Up @@ -167,8 +165,6 @@ class MainWindow : public QMainWindow {
QTimer* statusbar_timer_;
QLabel* statusbar_timer_label_;

QAction* after_show_event_;

QAction* action_project_new_;
QAction* action_project_open_;
QAction* action_project_edit_;
Expand Down
Loading

0 comments on commit feeab87

Please sign in to comment.