26 namespace visualization {
34 auto slider = std::make_shared<gui::Slider>(
type);
35 slider->SetLimits(
min,
max);
36 slider->SetValue(value);
42 const std::string &resource_path,
43 std::function<
void(
const char *)> on_load_ibl)
44 : model_(model), on_load_ibl_(on_load_ibl) {
45 const auto em =
theme.font_size;
47 const int grid_spacing = int(
std::ceil(0.25 * em));
49 const int separation_height = int(
std::ceil(0.75 * em));
57 std::make_shared<gui::CollapsableVert>(
"Scene controls", 0, indent);
60 show_skybox_ = std::make_shared<gui::Checkbox>(
"Show skymap");
61 show_skybox_->SetOnChecked(
64 bg_color_ = std::make_shared<gui::ColorEdit>();
65 bg_color_->SetOnValueChanged([
this](
const gui::Color &newColor) {
70 auto bg_layout = std::make_shared<gui::VGrid>(2, grid_spacing);
71 bg_layout->AddChild(std::make_shared<gui::Label>(
"BG Color"));
72 bg_layout->AddChild(bg_color_);
74 view_ctrls->AddChild(show_skybox_);
75 view_ctrls->AddFixed(
int(
std::ceil(0.25 * em)));
76 view_ctrls->AddChild(bg_layout);
79 show_axes_ = std::make_shared<gui::Checkbox>(
"Show axes");
80 show_axes_->SetOnChecked(
81 [
this](
bool is_checked) { model_.
SetShowAxes(is_checked); });
82 view_ctrls->AddFixed(separation_height);
83 view_ctrls->AddChild(show_axes_);
86 show_ground_ = std::make_shared<gui::Checkbox>(
"Show ground");
87 show_ground_->SetOnChecked(
88 [
this](
bool is_checked) { model_.
SetShowGround(is_checked); });
89 view_ctrls->AddFixed(separation_height);
90 view_ctrls->AddChild(show_ground_);
93 lighting_profile_ = std::make_shared<gui::Combobox>();
95 lighting_profile_->AddItem(lp.name.c_str());
98 lighting_profile_->SetOnValueChanged([
this](
const char *,
int index) {
100 sun_dir_->SetEnabled(
true);
110 auto profile_layout = std::make_shared<gui::Vert>();
111 profile_layout->AddChild(std::make_shared<gui::Label>(
"Lighting profiles"));
112 profile_layout->AddChild(lighting_profile_);
113 view_ctrls->AddFixed(separation_height);
114 view_ctrls->AddChild(profile_layout);
120 advanced_ = std::make_shared<gui::CollapsableVert>(
"Advanced lighting", 0,
122 advanced_->SetIsOpen(
false);
126 advanced_->AddChild(std::make_shared<gui::Label>(
"Light sources"));
127 auto checkboxes = std::make_shared<gui::Horiz>();
128 ibl_enabled_ = std::make_shared<gui::Checkbox>(
"HDR map");
129 ibl_enabled_->SetOnChecked([
this](
bool checked) {
134 checkboxes->AddChild(ibl_enabled_);
136 sun_enabled_ = std::make_shared<gui::Checkbox>(
"Sun");
137 sun_enabled_->SetOnChecked([
this](
bool checked) {
142 checkboxes->AddChild(sun_enabled_);
143 advanced_->AddChild(checkboxes);
145 advanced_->AddFixed(separation_height);
148 ibls_ = std::make_shared<gui::Combobox>();
149 std::vector<std::string> resource_files;
151 std::sort(resource_files.begin(), resource_files.end());
153 for (
auto &f : resource_files) {
154 if (f.find(
"_ibl.ktx") == f.size() - 8) {
157 ibls_->AddItem(
name.c_str());
159 ibls_->SetSelectedIndex(n);
165 ibls_->SetOnValueChanged(
166 [
this](
const char *
name,
int) { on_load_ibl_(
name); });
170 ibl_intensity_->SetOnValueChanged([
this](
double new_value) {
176 auto ambient_layout = std::make_shared<gui::VGrid>(2, grid_spacing);
177 ambient_layout->AddChild(std::make_shared<gui::Label>(
"HDR map"));
178 ambient_layout->AddChild(ibls_);
179 ambient_layout->AddChild(std::make_shared<gui::Label>(
"Intensity"));
180 ambient_layout->AddChild(ibl_intensity_);
182 advanced_->AddChild(std::make_shared<gui::Label>(
"Environment"));
183 advanced_->AddChild(ambient_layout);
184 advanced_->AddFixed(separation_height);
189 sun_intensity_->SetOnValueChanged([
this](
double new_value) {
194 sun_dir_ = std::make_shared<gui::VectorEdit>();
195 sun_dir_->SetOnValueChanged([
this](
const Eigen::Vector3f &dir) {
197 lighting.
sun_dir = dir.normalized();
201 sun_follows_camera_ = std::make_shared<gui::Checkbox>(
" ");
202 sun_follows_camera_->SetChecked(
true);
203 sun_follows_camera_->SetOnChecked([
this](
bool checked) {
204 sun_dir_->SetEnabled(!checked);
208 sun_color_ = std::make_shared<gui::ColorEdit>();
209 sun_color_->SetOnValueChanged([
this](
const gui::Color &new_color) {
216 auto sun_layout = std::make_shared<gui::VGrid>(2, grid_spacing);
217 sun_layout->AddChild(std::make_shared<gui::Label>(
"Intensity"));
218 sun_layout->AddChild(sun_intensity_);
219 sun_layout->AddChild(std::make_shared<gui::Label>(
"Direction"));
220 sun_layout->AddChild(sun_dir_);
221 sun_layout->AddChild(sun_follows_camera_);
222 sun_layout->AddChild(std::make_shared<gui::Label>(
"Sun Follows Camera"));
223 sun_layout->AddChild(std::make_shared<gui::Label>(
"Color"));
224 sun_layout->AddChild(sun_color_);
227 std::make_shared<gui::Label>(
"Sun (Directional light)"));
228 advanced_->AddChild(sun_layout);
231 auto materials = std::make_shared<gui::CollapsableVert>(
"Material settings",
234 auto mat_grid = std::make_shared<gui::VGrid>(2, grid_spacing);
235 mat_grid->AddChild(std::make_shared<gui::Label>(
"Type"));
237 material_type_.reset(
239 material_type_->SetOnValueChanged([
this](
const char *,
int selected_idx) {
240 switch (selected_idx) {
250 GuiSettingsModel::MaterialType::NORMAL_MAP);
257 mat_grid->AddChild(material_type_);
259 prefab_material_ = std::make_shared<gui::Combobox>();
261 prefab_material_->AddItem(prefab.first.c_str());
263 prefab_material_->SetOnValueChanged([
this](
const char *
name,
int) {
273 mat_grid->AddChild(std::make_shared<gui::Label>(
"Material"));
274 mat_grid->AddChild(prefab_material_);
276 material_color_ = std::make_shared<gui::ColorEdit>();
281 reset_material_color_ = std::make_shared<SmallButton>(
"Reset");
282 reset_material_color_->SetOnClicked([
this]() { model_.
ResetColors(); });
284 mat_grid->AddChild(std::make_shared<gui::Label>(
"Color"));
285 auto color_layout = std::make_shared<gui::Horiz>();
286 color_layout->AddChild(material_color_);
287 color_layout->AddFixed(
int(
std::ceil(0.25 * em)));
288 color_layout->AddChild(reset_material_color_);
289 mat_grid->AddChild(color_layout);
291 mat_grid->AddChild(std::make_shared<gui::Label>(
"Point size"));
293 point_size_->SetOnValueChanged([
this](
double value) {
296 mat_grid->AddChild(point_size_);
298 mat_grid->AddChild(std::make_shared<gui::Label>(
""));
299 generate_normals_ = std::make_shared<SmallButton>(
"Estimate PCD Normals");
300 generate_normals_->SetOnClicked(
302 generate_normals_->SetEnabled(
false);
303 mat_grid->AddChild(generate_normals_);
304 mat_grid->AddChild(std::make_shared<gui::Label>(
"Raw Mode"));
305 basic_mode_ = std::make_shared<gui::Checkbox>(
"");
306 basic_mode_->SetOnChecked([
this](
bool checked) {
307 UpdateUIForBasicMode(checked);
310 mat_grid->AddChild(basic_mode_);
311 mat_grid->AddChild(std::make_shared<gui::Label>(
"Wireframe"));
312 wireframe_mode_ = std::make_shared<gui::Checkbox>(
"");
313 wireframe_mode_->SetOnChecked(
315 mat_grid->AddChild(wireframe_mode_);
317 materials->AddChild(mat_grid);
328 prefab_material_->ChangeItem(
335 prefab_material_->ChangeItem(
344 generate_normals_->SetEnabled(enable);
357 if (!lighting_profile_->SetSelectedValue(lighting.name.c_str())) {
359 "Internal Error: lighting profile '{}' is not in combobox",
360 lighting.name.c_str());
364 ibl_enabled_->SetChecked(lighting.ibl_enabled);
365 sun_enabled_->SetChecked(lighting.sun_enabled);
366 ibl_intensity_->SetValue(lighting.ibl_intensity);
367 sun_intensity_->SetValue(lighting.sun_intensity);
368 sun_dir_->SetValue(lighting.sun_dir);
369 sun_color_->SetValue({lighting.sun_color.x(), lighting.sun_color.y(),
370 lighting.sun_color.z()});
372 if (!prefab_material_->SetSelectedValue(materials.lit_name.c_str())) {
377 for (
int i = 0; i < prefab_material_->GetNumberOfItems(); ++i) {
378 if (materials.lit_name.find(prefab_material_->GetItem(i)) ==
380 prefab_material_->SetSelectedIndex(i);
387 prefab_material_->SetSelectedValue(
392 case GuiSettingsModel::MaterialType::LIT:
393 material_type_->SetSelectedIndex(0);
394 prefab_material_->SetEnabled(
true);
395 material_color_->SetEnabled(
true);
396 material_color_->SetValue({materials.lit.base_color.x(),
397 materials.lit.base_color.y(),
398 materials.lit.base_color.z()});
399 point_size_->SetValue(materials.point_size);
401 case GuiSettingsModel::MaterialType::UNLIT:
402 material_type_->SetSelectedIndex(1);
403 prefab_material_->SetEnabled(
false);
404 material_color_->SetEnabled(
true);
405 material_color_->SetValue({materials.unlit.base_color.x(),
406 materials.unlit.base_color.y(),
407 materials.unlit.base_color.z()});
408 point_size_->SetValue(materials.point_size);
410 case GuiSettingsModel::MaterialType::NORMAL_MAP:
411 material_type_->SetSelectedIndex(2);
412 prefab_material_->SetEnabled(
false);
413 material_color_->SetEnabled(
false);
414 material_color_->SetValue({1.0f, 1.0f, 1.0f});
416 case GuiSettingsModel::MaterialType::DEPTH:
417 material_type_->SetSelectedIndex(3);
418 prefab_material_->SetEnabled(
false);
419 material_color_->SetEnabled(
false);
420 material_color_->SetValue({1.0f, 1.0f, 1.0f});
423 reset_material_color_->SetEnabled(
427 GuiSettingsModel::MaterialType::UNLIT));
431 void GuiSettingsView::UpdateUIForBasicMode(
bool enable) {
433 show_skybox_->SetEnabled(!enable);
434 lighting_profile_->SetEnabled(!enable);
435 ibls_->SetEnabled(!enable);
436 ibl_enabled_->SetEnabled(!enable);
437 ibl_intensity_->SetEnabled(!enable);
438 sun_enabled_->SetEnabled(!enable);
439 sun_dir_->SetEnabled(!enable);
440 sun_color_->SetEnabled(!enable);
441 sun_follows_camera_->SetEnabled(!enable);
442 material_color_->SetEnabled(!enable);
443 prefab_material_->SetEnabled(!enable);
444 wireframe_mode_->SetEnabled(!enable);
449 sun_follows_cam_was_on_ = sun_follows_camera_->IsChecked();
450 lighting.ibl_enabled = !enable;
451 lighting.sun_enabled = enable;
452 lighting.sun_intensity = 160000.f;
453 sun_enabled_->SetChecked(
true);
454 ibl_enabled_->SetChecked(
false);
455 sun_intensity_->SetValue(160000.0);
458 sun_follows_camera_->SetChecked(
true);
459 wireframe_mode_->SetChecked(
false);
463 if (!sun_follows_cam_was_on_) {
464 sun_follows_camera_->SetChecked(
false);
bool GetUserHasCustomizedLighting() const
const Eigen::Vector3f & GetBackgroundColor() const
static constexpr const char * DEFAULT_IBL
bool GetUserHasChangedColor() const
static constexpr const char * MATERIAL_FROM_FILE_NAME
void EstimateNormalsClicked()
void SetCustomLighting(const LightingProfile &profile)
bool GetShowSkybox() const
void SetLitMaterial(const LitMaterial &material, const std::string &name)
void SetShowSkybox(bool show)
void SetBackgroundColor(const Eigen::Vector3f &color)
void SetCurrentMaterialColor(const Eigen::Vector3f &color)
const Materials & GetCurrentMaterials() const
static constexpr const char * CUSTOM_IBL
void SetBasicMode(bool enable)
void SetMaterialType(MaterialType type)
static constexpr const char * DEFAULT_MATERIAL_NAME
void SetLightingProfile(const LightingProfile &profile)
void SetWireframeMode(bool enable)
static const std::map< std::string, const LitMaterial > prefab_materials_
void SetShowAxes(bool show)
void SetPointSize(int size)
bool GetDisplayingPointClouds() const
static const std::vector< LightingProfile > lighting_profiles_
void SetShowGround(bool show)
const LightingProfile & GetLighting() const
void SetSunFollowsCamera(bool follow)
MaterialType GetMaterialType() const
void ShowFileMaterialEntry(bool show)
void EnableEstimateNormals(bool enable)
GuiSettingsView(GuiSettingsModel &model, const gui::Theme &theme, const std::string &resource_path, std::function< void(const char *)> on_load_ibl)
void AddFixed(int size)
Adds a fixed number of pixels after the previously added widget.
void SetMargins(const Margins &margins)
bool ListFilesInDirectory(const std::string &directory, std::vector< std::string > &filenames)
std::string GetFileNameWithoutDirectory(const std::string &filename)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
std::shared_ptr< gui::Slider > MakeSlider(const gui::Slider::Type type, const double min, const double max, const double value)
static const char * CUSTOM_LIGHTING
Generic file read and write utility for python interface.
Eigen::Vector3f sun_color