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