ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RenderOptionsWidget.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 "RenderOptionsWidget.h"
9 
10 #include "ui/colormaps.h"
11 
12 namespace cloudViewer {
13 
14 using namespace colmap;
15 
17  OptionManager* options,
18  ModelViewerWidget* model_viewer_widget)
19  : OptionsWidget(parent),
20  counter(0),
21  automatic_update(true),
22  options_(options),
23  model_viewer_widget_(model_viewer_widget),
24  background_color_(1.0f, 1.0f, 1.0f, 1.0f),
25  point3D_colormap_scale_(1),
26  point3D_colormap_min_q_(0.02),
27  point3D_colormap_max_q_(0.98),
28  image_plane_color_(ImageColormapUniform::kDefaultPlaneColor),
29  image_frame_color_(ImageColormapUniform::kDefaultFrameColor) {
30  setWindowFlags(Qt::Widget | Qt::WindowStaysOnTopHint | Qt::Tool);
31  setWindowModality(Qt::NonModal);
32  setWindowTitle("Render options");
33 
34  QHBoxLayout* point_size_layout = new QHBoxLayout();
35  QPushButton* decrease_point_size = new QPushButton("-", this);
36  connect(decrease_point_size, &QPushButton::released, this,
37  &RenderOptionsWidget::DecreasePointSize);
38  QPushButton* increase_point_size = new QPushButton("+", this);
39  connect(increase_point_size, &QPushButton::released, this,
40  &RenderOptionsWidget::IncreasePointSize);
41  point_size_layout->addWidget(decrease_point_size);
42  point_size_layout->addWidget(increase_point_size);
43  AddLayoutRow("Point size", point_size_layout);
44 
45  QHBoxLayout* camera_size_layout = new QHBoxLayout();
46  QPushButton* decrease_camera_size = new QPushButton("-", this);
47  connect(decrease_camera_size, &QPushButton::released, this,
48  &RenderOptionsWidget::DecreaseCameraSize);
49  QPushButton* increase_camera_size = new QPushButton("+", this);
50  connect(increase_camera_size, &QPushButton::released, this,
51  &RenderOptionsWidget::IncreaseCameraSize);
52  camera_size_layout->addWidget(decrease_camera_size);
53  camera_size_layout->addWidget(increase_camera_size);
54  AddLayoutRow("Camera size", camera_size_layout);
55 
56  AddSpacer();
57 
58  projection_cb_ = new QComboBox(this);
59  projection_cb_->addItem("Perspective");
60  projection_cb_->addItem("Orthographic");
61  AddWidgetRow("Projection", projection_cb_);
62 
63  AddSpacer();
64 
65  QPushButton* select_background_color =
66  new QPushButton(tr("Select color"), this);
67  grid_layout_->addWidget(select_background_color,
68  grid_layout_->rowCount() - 1, 1);
69  connect(select_background_color, &QPushButton::released, this,
70  [&]() { SelectColor("Background color", &background_color_); });
71  AddWidgetRow("Background", select_background_color);
72 
73  AddSpacer();
74 
75  AddOptionDouble(&options->render->max_error, "Point max. error [px]");
76  AddOptionInt(&options->render->min_track_len, "Point min. track length", 0);
77 
78  AddSpacer();
79 
80  point3D_colormap_cb_ = new QComboBox(this);
81  point3D_colormap_cb_->addItem("Photometric");
82  point3D_colormap_cb_->addItem("Error");
83  point3D_colormap_cb_->addItem("Track-Length");
84  point3D_colormap_cb_->addItem("Ground-Resolution");
85  AddWidgetRow("Point colormap", point3D_colormap_cb_);
86 
87  AddOptionDouble(&point3D_colormap_min_q_, "Point colormap minq", 0, 1,
88  0.001, 3);
89  AddOptionDouble(&point3D_colormap_max_q_, "Point colormap maxq", 0, 1,
90  0.001, 3);
91  AddOptionDouble(&point3D_colormap_scale_, "Point colormap scale", -1e7,
92  1e7);
93 
94  // Show the above items only for other colormaps than the photometric one.
95  HideOption(&point3D_colormap_min_q_);
96  HideOption(&point3D_colormap_max_q_);
97  HideOption(&point3D_colormap_scale_);
98  connect(point3D_colormap_cb_,
99  (void(QComboBox::*)(int)) & QComboBox::currentIndexChanged, this,
100  &RenderOptionsWidget::SelectPointColormap);
101 
102  AddSpacer();
103 
104  image_colormap_cb_ = new QComboBox(this);
105  image_colormap_cb_->addItem("Uniform color");
106  image_colormap_cb_->addItem("Images with words in name");
107  AddWidgetRow("Image colormap", image_colormap_cb_);
108 
109  select_image_plane_color_ = new QPushButton(tr("Select color"), this);
110  connect(select_image_plane_color_, &QPushButton::released, this,
111  [&]() { SelectColor("Image plane color", &image_plane_color_); });
112  AddWidgetRow("Image plane", select_image_plane_color_);
113 
114  select_image_frame_color_ = new QPushButton(tr("Select color"), this);
115  connect(select_image_frame_color_, &QPushButton::released, this,
116  [&]() { SelectColor("Image frame color", &image_frame_color_); });
117  AddWidgetRow("Image frame", select_image_frame_color_);
118 
119  image_colormap_name_filter_layout_ = new QHBoxLayout();
120  QPushButton* image_colormap_add_word = new QPushButton("Add", this);
121  connect(image_colormap_add_word, &QPushButton::released, this,
122  &RenderOptionsWidget::ImageColormapNameFilterAddWord);
123  QPushButton* image_colormap_clear_words = new QPushButton("Clear", this);
124  connect(image_colormap_clear_words, &QPushButton::released, this,
125  &RenderOptionsWidget::ImageColormapNameFilterClearWords);
126  image_colormap_name_filter_layout_->addWidget(image_colormap_add_word);
127  image_colormap_name_filter_layout_->addWidget(image_colormap_clear_words);
128  AddLayoutRow("Words", image_colormap_name_filter_layout_);
129 
130  HideLayout(image_colormap_name_filter_layout_);
131  connect(image_colormap_cb_,
132  (void(QComboBox::*)(int)) & QComboBox::currentIndexChanged, this,
133  &RenderOptionsWidget::SelectImageColormap);
134 
135  AddSpacer();
136 
137  AddOptionBool(&options->render->adapt_refresh_rate,
138  "Adaptive refresh rate");
139  AddOptionInt(&options->render->refresh_rate, "Refresh rate [frames]", 1);
140 
141  AddSpacer();
142 
143  AddOptionBool(&options->render->image_connections, "Image connections");
144 
145  AddSpacer();
146 
147  QPushButton* apply = new QPushButton(tr("Apply"), this);
148  grid_layout_->addWidget(apply, grid_layout_->rowCount(), 1);
149  connect(apply, &QPushButton::released, this, &RenderOptionsWidget::Apply);
150 }
151 
152 void RenderOptionsWidget::closeEvent(QCloseEvent* event) {
153  // Just overwrite parent closeEvent to prevent automatic write of options
154 }
155 
156 void RenderOptionsWidget::Apply() {
157  WriteOptions();
158 
159  counter = 0;
160 
161  ApplyProjection();
162  ApplyPointColormap();
163  ApplyImageColormap();
164  ApplyBackgroundColor();
165 
166  model_viewer_widget_->ReloadReconstruction();
167 }
168 
169 void RenderOptionsWidget::ApplyProjection() {
170  switch (projection_cb_->currentIndex()) {
171  case 0:
172  options_->render->projection_type =
173  colmap::RenderOptions::ProjectionType::PERSPECTIVE;
174  break;
175  case 1:
176  options_->render->projection_type =
177  colmap::RenderOptions::ProjectionType::ORTHOGRAPHIC;
178  break;
179  default:
180  options_->render->projection_type =
181  colmap::RenderOptions::ProjectionType::PERSPECTIVE;
182  break;
183  }
184  if (options_->render->projection_type ==
185  colmap::RenderOptions::ProjectionType::PERSPECTIVE) {
186  model_viewer_widget_->SetPerspectiveProjection();
187  }
188  if (options_->render->projection_type ==
189  colmap::RenderOptions::ProjectionType::ORTHOGRAPHIC) {
190  model_viewer_widget_->SetOrthogonalProjection();
191  }
192 }
193 
194 void RenderOptionsWidget::ApplyPointColormap() {
195  PointColormapBase* point3D_color_map;
196 
197  switch (point3D_colormap_cb_->currentIndex()) {
198  case 0:
199  point3D_color_map = new PointColormapPhotometric();
200  break;
201  case 1:
202  point3D_color_map = new PointColormapError();
203  break;
204  case 2:
205  point3D_color_map = new PointColormapTrackLen();
206  break;
207  case 3:
208  point3D_color_map = new PointColormapGroundResolution();
209  break;
210  default:
211  point3D_color_map = new PointColormapPhotometric();
212  break;
213  }
214 
215  point3D_color_map->scale = static_cast<float>(point3D_colormap_scale_);
216  point3D_color_map->min_q = static_cast<float>(point3D_colormap_min_q_);
217  point3D_color_map->max_q = static_cast<float>(point3D_colormap_max_q_);
218 
219  model_viewer_widget_->SetPointColormap(point3D_color_map);
220 }
221 
222 void RenderOptionsWidget::ApplyImageColormap() {
223  ImageColormapBase* image_color_map;
224 
225  switch (image_colormap_cb_->currentIndex()) {
226  case 0:
227  image_color_map = new ImageColormapUniform();
228  reinterpret_cast<ImageColormapUniform*>(image_color_map)
229  ->uniform_plane_color = image_plane_color_;
230  reinterpret_cast<ImageColormapUniform*>(image_color_map)
231  ->uniform_frame_color = image_frame_color_;
232  break;
233  case 1:
234  image_color_map =
235  new ImageColormapNameFilter(image_colormap_name_filter_);
236  break;
237  default:
238  image_color_map = new ImageColormapUniform();
239  break;
240  }
241 
242  model_viewer_widget_->SetImageColormap(image_color_map);
243 }
244 
245 void RenderOptionsWidget::ApplyBackgroundColor() {
246  model_viewer_widget_->SetBackgroundColor(
247  background_color_(0), background_color_(1), background_color_(2));
248 }
249 
250 void RenderOptionsWidget::SelectColor(const std::string& title,
251  Eigen::Vector4f* color) {
252  const QColor initial_color(static_cast<int>(255 * (*color)(0)),
253  static_cast<int>(255 * (*color)(1)),
254  static_cast<int>(255 * (*color)(2)),
255  static_cast<int>(255 * (*color)(3)));
256  const QColor selected_color =
257  QColorDialog::getColor(initial_color, this, title.c_str());
258  (*color)(0) = selected_color.red() / 255.0;
259  (*color)(1) = selected_color.green() / 255.0;
260  (*color)(2) = selected_color.blue() / 255.0;
261  (*color)(3) = selected_color.alpha() / 255.0;
262 }
263 
264 void RenderOptionsWidget::SelectPointColormap(const int idx) {
265  if (idx == 0) {
266  HideOption(&point3D_colormap_scale_);
267  HideOption(&point3D_colormap_min_q_);
268  HideOption(&point3D_colormap_max_q_);
269  } else {
270  ShowOption(&point3D_colormap_scale_);
271  ShowOption(&point3D_colormap_min_q_);
272  ShowOption(&point3D_colormap_max_q_);
273  }
274 }
275 
276 void RenderOptionsWidget::SelectImageColormap(const int idx) {
277  if (idx == 0) {
278  ShowWidget(select_image_plane_color_);
279  ShowWidget(select_image_frame_color_);
280  HideLayout(image_colormap_name_filter_layout_);
281  } else {
282  HideWidget(select_image_plane_color_);
283  HideWidget(select_image_frame_color_);
284  ShowLayout(image_colormap_name_filter_layout_);
285  }
286 }
287 
288 void RenderOptionsWidget::IncreasePointSize() {
289  const float kDelta = 100;
290  model_viewer_widget_->ChangePointSize(kDelta);
291 }
292 
293 void RenderOptionsWidget::DecreasePointSize() {
294  const float kDelta = -100;
295  model_viewer_widget_->ChangePointSize(kDelta);
296 }
297 
298 void RenderOptionsWidget::IncreaseCameraSize() {
299  const float kDelta = 100;
300  model_viewer_widget_->ChangeCameraSize(kDelta);
301 }
302 
303 void RenderOptionsWidget::DecreaseCameraSize() {
304  const float kDelta = -100;
305  model_viewer_widget_->ChangeCameraSize(kDelta);
306 }
307 
308 void RenderOptionsWidget::ImageColormapNameFilterAddWord() {
309  bool word_ok;
310  const QString word = QInputDialog::getText(
311  this, "", "Word:", QLineEdit::Normal, "", &word_ok);
312  if (!word_ok || word == "") {
313  return;
314  }
315 
316  Eigen::Vector4f plane_color(ImageColormapBase::kDefaultPlaneColor);
317  SelectColor("Image plane color", &plane_color);
318 
319  Eigen::Vector4f frame_color(ImageColormapBase::kDefaultFrameColor);
320  SelectColor("Image frame color", &frame_color);
321 
322  image_colormap_name_filter_.AddColorForWord(word.toUtf8().constData(),
323  plane_color, frame_color);
324 }
325 
326 void RenderOptionsWidget::ImageColormapNameFilterClearWords() {
327  image_colormap_name_filter_ = ImageColormapNameFilter();
328 }
329 
330 } // namespace cloudViewer
MouseEvent event
math::float4 color
void SetPointColormap(PointColormapBase *colormap)
void ChangeCameraSize(const float delta)
void SetImageColormap(ImageColormapBase *colormap)
void SetBackgroundColor(const float r, const float g, const float b)
void ChangePointSize(const float delta)
RenderOptionsWidget(QWidget *parent, OptionManager *options, ModelViewerWidget *model_viewer_widget)
Generic file read and write utility for python interface.
colmap::ImageColormapNameFilter ImageColormapNameFilter
colmap::ImageColormapBase ImageColormapBase
colmap::OptionManager OptionManager
colmap::PointColormapBase PointColormapBase