ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
BundleAdjustmentWidget.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 
9 
10 #include "ReconstructionWidget.h"
11 #include "ThreadControlWidget.h"
12 #include "controllers/bundle_adjustment.h"
13 #include "util/option_manager.h"
14 
15 namespace cloudViewer {
16 
18 
19 using namespace colmap;
21  ReconstructionWidget* main_window, OptionManager* options)
22  : OptionsWidget(main_window),
23  main_window_(main_window),
24  options_(options),
25  reconstruction_(nullptr),
26  thread_control_widget_(new ThreadControlWidget(this)) {
27  setWindowTitle("Bundle adjustment");
28 
29  AddOptionInt(&options->bundle_adjustment->solver_options.max_num_iterations,
30  "max_num_iterations");
31  AddOptionInt(&options->bundle_adjustment->solver_options
32  .max_linear_solver_iterations,
33  "max_linear_solver_iterations");
34 
35  AddOptionDoubleLog(
36  &options->bundle_adjustment->solver_options.function_tolerance,
37  "function_tolerance [10eX]", -1000, 1000);
38  AddOptionDoubleLog(
39  &options->bundle_adjustment->solver_options.gradient_tolerance,
40  "gradient_tolerance [10eX]", -1000, 1000);
41  AddOptionDoubleLog(
42  &options->bundle_adjustment->solver_options.parameter_tolerance,
43  "parameter_tolerance [10eX]", -1000, 1000);
44 
45  AddOptionBool(&options->bundle_adjustment->refine_focal_length,
46  "refine_focal_length");
47  AddOptionBool(&options->bundle_adjustment->refine_principal_point,
48  "refine_principal_point");
49  AddOptionBool(&options->bundle_adjustment->refine_extra_params,
50  "refine_extra_params");
51  AddOptionBool(&options->bundle_adjustment->refine_extrinsics,
52  "refine_extrinsics");
53 
54  QPushButton* run_button = new QPushButton(tr("Run"), this);
55  grid_layout_->addWidget(run_button, grid_layout_->rowCount(), 1);
56  connect(run_button, &QPushButton::released, this,
57  &BundleAdjustmentWidget::Run);
58 
59  render_action_ = new QAction(this);
60  connect(render_action_, &QAction::triggered, this,
61  &BundleAdjustmentWidget::Render, Qt::QueuedConnection);
62 }
63 
64 void BundleAdjustmentWidget::Show(Reconstruction* reconstruction) {
65  reconstruction_ = reconstruction;
66  show();
67  raise();
68 }
69 
70 void BundleAdjustmentWidget::Run() {
71  CHECK_NOTNULL(reconstruction_);
72 
73  WriteOptions();
74 
75  Thread* thread = new BundleAdjustmentController(*options_, reconstruction_);
76  thread->AddCallback(Thread::FINISHED_CALLBACK,
77  [this]() { render_action_->trigger(); });
78 
79  // Normalize scene for numerical stability and
80  // to avoid large scale changes in viewer.
81  reconstruction_->Normalize();
82 
83  thread_control_widget_->StartThread("Bundle adjusting...", true, thread);
84 }
85 
86 void BundleAdjustmentWidget::Render() { main_window_->RenderNow(); }
87 
88 } // namespace cloudViewer
void Show(colmap::Reconstruction *reconstruction)
BundleAdjustmentWidget(ReconstructionWidget *main_window, OptionManager *options)
void StartThread(const QString &progress_text, const bool stoppable, colmap::Thread *thread)
Generic file read and write utility for python interface.
colmap::BundleAdjustmentController BundleAdjustmentController
colmap::OptionManager OptionManager