ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
undistortion_widget.cc
Go to the documentation of this file.
1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 // its contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #include "ui/undistortion_widget.h"
33 
34 namespace colmap {
35 
37  const OptionManager* options)
38  : OptionsWidget(parent),
39  options_(options),
40  reconstruction_(nullptr),
41  thread_control_widget_(new ThreadControlWidget(this)) {
42  setWindowFlags(Qt::Dialog);
43  setWindowModality(Qt::ApplicationModal);
44  setWindowTitle("Undistortion");
45 
46  output_format_ = new QComboBox(this);
47  output_format_->addItem("COLMAP");
48  output_format_->addItem("PMVS");
49  output_format_->addItem("CMP-MVS");
50  output_format_->setFont(font());
51  AddWidgetRow("format", output_format_);
52 
53  AddOptionDouble(&undistortion_options_.min_scale, "min_scale", 0);
54  AddOptionDouble(&undistortion_options_.max_scale, "max_scale", 0);
55  AddOptionInt(&undistortion_options_.max_image_size, "max_image_size", -1);
56  AddOptionDouble(&undistortion_options_.blank_pixels, "blank_pixels", 0);
57  AddOptionDouble(&undistortion_options_.roi_min_x, "roi_min_x", 0.0, 1.0);
58  AddOptionDouble(&undistortion_options_.roi_min_y, "roi_min_y", 0.0, 1.0);
59  AddOptionDouble(&undistortion_options_.roi_max_x, "roi_max_x", 0.0, 1.0);
60  AddOptionDouble(&undistortion_options_.roi_max_y, "roi_max_y", 0.0, 1.0);
61  AddOptionDirPath(&output_path_, "output_path");
62 
63  AddSpacer();
64 
65  QPushButton* undistort_button = new QPushButton(tr("Undistort"), this);
66  connect(undistort_button, &QPushButton::released, this,
67  &UndistortionWidget::Undistort);
68  grid_layout_->addWidget(undistort_button, grid_layout_->rowCount(), 1);
69 }
70 
71 void UndistortionWidget::Show(const Reconstruction& reconstruction) {
72  reconstruction_ = &reconstruction;
73  show();
74  raise();
75 }
76 
77 bool UndistortionWidget::IsValid() const { return ExistsDir(output_path_); }
78 
79 void UndistortionWidget::Undistort() {
80  CHECK_NOTNULL(reconstruction_);
81 
82  WriteOptions();
83 
84  if (IsValid()) {
85  Thread* undistorter = nullptr;
86 
87  if (output_format_->currentIndex() == 0) {
88  undistorter =
89  new COLMAPUndistorter(undistortion_options_, const_cast<Reconstruction*>(reconstruction_),
90  *options_->image_path, output_path_);
91  } else if (output_format_->currentIndex() == 1) {
92  undistorter = new PMVSUndistorter(undistortion_options_, const_cast<Reconstruction*>(reconstruction_),
93  *options_->image_path, output_path_);
94  } else if (output_format_->currentIndex() == 2) {
95  undistorter =
96  new CMPMVSUndistorter(undistortion_options_, const_cast<Reconstruction*>(reconstruction_),
97  *options_->image_path, output_path_);
98  } else {
99  QMessageBox::critical(this, "", tr("Invalid output format"));
100  return;
101  }
102 
103  thread_control_widget_->StartThread("Undistorting...", true, undistorter);
104  } else {
105  QMessageBox::critical(this, "", tr("Invalid output path"));
106  }
107 }
108 
109 } // namespace colmap
std::shared_ptr< std::string > image_path
QDoubleSpinBox * AddOptionDouble(double *option, const std::string &label_text, const double min=0, const double max=1e7, const double step=0.01, const int decimals=2)
void AddWidgetRow(const std::string &label_text, QWidget *widget)
QSpinBox * AddOptionInt(int *option, const std::string &label_text, const int min=0, const int max=static_cast< int >(1e7))
QLineEdit * AddOptionDirPath(std::string *option, const std::string &label_text)
QGridLayout * grid_layout_
void StartThread(const QString &progress_text, const bool stoppable, Thread *thread)
UndistortionWidget(QWidget *parent, const OptionManager *options)
void Show(const Reconstruction &reconstruction)
bool ExistsDir(const std::string &path)
Definition: misc.cc:104