ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
UndistortionWidget.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "UndistortionWidget.h"
9 
10 #include "base/reconstruction.h"
11 #include "util/misc.h"
12 #include "util/option_manager.h"
13 
14 namespace cloudViewer {
15 
16 using namespace colmap;
17 
19  const OptionManager* options)
20  : OptionsWidget(parent),
21  options_(options),
22  reconstruction_(nullptr),
23  thread_control_widget_(new ThreadControlWidget(this)) {
24  setWindowFlags(Qt::Dialog);
25  setWindowModality(Qt::ApplicationModal);
26  setWindowTitle("Undistortion");
27 
28  output_format_ = new QComboBox(this);
29  output_format_->addItem("COLMAP");
30  output_format_->addItem("PMVS");
31  output_format_->addItem("CMP-MVS");
32  output_format_->setFont(font());
33  AddWidgetRow("format", output_format_);
34 
35  AddOptionDouble(&undistortion_options_.min_scale, "min_scale", 0);
36  AddOptionDouble(&undistortion_options_.max_scale, "max_scale", 0);
37  AddOptionInt(&undistortion_options_.max_image_size, "max_image_size", -1);
38  AddOptionDouble(&undistortion_options_.blank_pixels, "blank_pixels", 0);
39  AddOptionDouble(&undistortion_options_.roi_min_x, "roi_min_x", 0.0, 1.0);
40  AddOptionDouble(&undistortion_options_.roi_min_y, "roi_min_y", 0.0, 1.0);
41  AddOptionDouble(&undistortion_options_.roi_max_x, "roi_max_x", 0.0, 1.0);
42  AddOptionDouble(&undistortion_options_.roi_max_y, "roi_max_y", 0.0, 1.0);
43  AddOptionDirPath(&output_path_, "output_path");
44 
45  AddSpacer();
46 
47  QPushButton* undistort_button = new QPushButton(tr("Undistort"), this);
48  connect(undistort_button, &QPushButton::released, this,
49  &UndistortionWidget::Undistort);
50  grid_layout_->addWidget(undistort_button, grid_layout_->rowCount(), 1);
51 }
52 
53 void UndistortionWidget::Show(const Reconstruction& reconstruction) {
54  reconstruction_ = &reconstruction;
55  show();
56  raise();
57 }
58 
59 bool UndistortionWidget::IsValid() const { return ExistsDir(output_path_); }
60 
61 void UndistortionWidget::Undistort() {
62  CHECK_NOTNULL(reconstruction_);
63 
64  WriteOptions();
65 
66  if (IsValid()) {
67  Thread* undistorter = nullptr;
68 
69  if (output_format_->currentIndex() == 0) {
70  undistorter = new COLMAPUndistorter(
71  undistortion_options_,
72  const_cast<colmap::Reconstruction*>(reconstruction_),
73  *options_->image_path, output_path_);
74  } else if (output_format_->currentIndex() == 1) {
75  undistorter = new PMVSUndistorter(
76  undistortion_options_,
77  const_cast<colmap::Reconstruction*>(reconstruction_),
78  *options_->image_path, output_path_);
79  } else if (output_format_->currentIndex() == 2) {
80  undistorter = new CMPMVSUndistorter(
81  undistortion_options_,
82  const_cast<colmap::Reconstruction*>(reconstruction_),
83  *options_->image_path, output_path_);
84  } else {
85  QMessageBox::critical(this, "", tr("Invalid output format"));
86  return;
87  }
88 
89  thread_control_widget_->StartThread("Undistorting...", true,
90  undistorter);
91  } else {
92  QMessageBox::critical(this, "", tr("Invalid output path"));
93  }
94 }
95 
96 } // namespace cloudViewer
void StartThread(const QString &progress_text, const bool stoppable, colmap::Thread *thread)
UndistortionWidget(QWidget *parent, const OptionManager *options)
void Show(const colmap::Reconstruction &reconstruction)
Generic file read and write utility for python interface.
colmap::OptionManager OptionManager