ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
bundle_adjustment_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 
33 
35 #include "ui/main_window.h"
36 
37 namespace colmap {
38 
40  OptionManager* options)
41  : OptionsWidget(main_window),
42  main_window_(main_window),
43  options_(options),
44  reconstruction_(nullptr),
45  thread_control_widget_(new ThreadControlWidget(this)) {
46  setWindowTitle("Bundle adjustment");
47 
48  AddOptionInt(&options->bundle_adjustment->solver_options.max_num_iterations,
49  "max_num_iterations");
51  &options->bundle_adjustment->solver_options.max_linear_solver_iterations,
52  "max_linear_solver_iterations");
53 
55  &options->bundle_adjustment->solver_options.function_tolerance,
56  "function_tolerance [10eX]", -1000, 1000);
58  &options->bundle_adjustment->solver_options.gradient_tolerance,
59  "gradient_tolerance [10eX]", -1000, 1000);
61  &options->bundle_adjustment->solver_options.parameter_tolerance,
62  "parameter_tolerance [10eX]", -1000, 1000);
63 
64  AddOptionBool(&options->bundle_adjustment->refine_focal_length,
65  "refine_focal_length");
66  AddOptionBool(&options->bundle_adjustment->refine_principal_point,
67  "refine_principal_point");
68  AddOptionBool(&options->bundle_adjustment->refine_extra_params,
69  "refine_extra_params");
70  AddOptionBool(&options->bundle_adjustment->refine_extrinsics,
71  "refine_extrinsics");
72 
73  QPushButton* run_button = new QPushButton(tr("Run"), this);
74  grid_layout_->addWidget(run_button, grid_layout_->rowCount(), 1);
75  connect(run_button, &QPushButton::released, this,
76  &BundleAdjustmentWidget::Run);
77 
78  render_action_ = new QAction(this);
79  connect(render_action_, &QAction::triggered, this,
80  &BundleAdjustmentWidget::Render, Qt::QueuedConnection);
81 }
82 
84  reconstruction_ = reconstruction;
85  show();
86  raise();
87 }
88 
89 void BundleAdjustmentWidget::Run() {
90  CHECK_NOTNULL(reconstruction_);
91 
92  WriteOptions();
93 
94  Thread* thread = new BundleAdjustmentController(*options_, reconstruction_);
96  [this]() { render_action_->trigger(); });
97 
98  // Normalize scene for numerical stability and
99  // to avoid large scale changes in viewer.
100  reconstruction_->Normalize();
101 
102  thread_control_widget_->StartThread("Bundle adjusting...", true, thread);
103 }
104 
105 void BundleAdjustmentWidget::Render() { main_window_->RenderNow(); }
106 
107 } // namespace colmap
BundleAdjustmentWidget(MainWindow *main_window, OptionManager *options)
void Show(Reconstruction *reconstruction)
std::shared_ptr< BundleAdjustmentOptions > bundle_adjustment
QDoubleSpinBox * AddOptionDoubleLog(double *option, const std::string &label_text, const double min=0, const double max=1e7, const double step=0.01, const int decimals=2)
QSpinBox * AddOptionInt(int *option, const std::string &label_text, const int min=0, const int max=static_cast< int >(1e7))
QGridLayout * grid_layout_
QCheckBox * AddOptionBool(bool *option, const std::string &label_text)
void Normalize(const double extent=10.0, const double p0=0.1, const double p1=0.9, const bool use_images=true)
void StartThread(const QString &progress_text, const bool stoppable, Thread *thread)
void AddCallback(const int id, const std::function< void()> &func)
Definition: threading.cc:117
colmap::BundleAdjustmentController BundleAdjustmentController