Open3D (C++ API)  0.11.0
GuiSettingsModel.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <map>
30 
32 
33 namespace open3d {
34 namespace visualization {
35 
37 public:
38  static constexpr const char* DEFAULT_IBL = "default";
39  static constexpr const char* CUSTOM_IBL = "Custom KTX file...";
40  static constexpr const char* DEFAULT_MATERIAL_NAME = "Polished ceramic";
41  static constexpr const char* MATERIAL_FROM_FILE_NAME =
42  "Material from file [default]";
43  static constexpr const char* POINT_CLOUD_PROFILE_NAME =
44  "Cloudy day (no direct sun)";
45 
46  struct LightingProfile {
47  std::string name;
48  double ibl_intensity;
49  double sun_intensity;
50  Eigen::Vector3f sun_dir;
51  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
53  rendering::Scene::Transform::Identity();
54  bool ibl_enabled = true;
55  bool use_default_ibl = false;
56  bool sun_enabled = true;
57  };
58 
59  enum MaterialType {
60  LIT = 0,
64  };
65 
66  struct LitMaterial {
67  Eigen::Vector3f base_color = {0.9f, 0.9f, 0.9f};
68  float metallic = 0.f;
69  float roughness = 0.7f;
70  float reflectance = 0.5f;
71  float clear_coat = 0.2f;
72  float clear_coat_roughness = 0.2f;
73  float anisotropy = 0.f;
74  };
75 
76  struct UnlitMaterial {
77  // The base color should NOT be {1, 1, 1}, because then the
78  // model will be invisible against the default white background.
79  Eigen::Vector3f base_color = {0.9f, 0.9f, 0.9f};
80  };
81 
82  struct Materials {
85  float point_size = 3.0f;
86  // 'name' is only used to keep the UI in sync. It is set by
87  // Set...Material[s]() and should not be set manually.
88  std::string lit_name;
89  };
90 
91  static const std::vector<LightingProfile> lighting_profiles_;
92  static const std::map<std::string, const LitMaterial> prefab_materials_;
95  static const LitMaterial& GetDefaultLitMaterial();
96 
98 
99  bool GetShowSkybox() const;
100  void SetShowSkybox(bool show);
101 
102  bool GetShowAxes() const;
103  void SetShowAxes(bool show);
104 
105  const Eigen::Vector3f& GetBackgroundColor() const;
106  void SetBackgroundColor(const Eigen::Vector3f& color);
107 
108  const LightingProfile& GetLighting() const;
109  // Should be from lighting_profiles_
110  void SetLightingProfile(const LightingProfile& profile);
111  void SetCustomLighting(const LightingProfile& profile);
112 
115 
116  // TODO: Get/SetMaterial
117  const Materials& GetCurrentMaterials() const;
119  void SetLitMaterial(const LitMaterial& material, const std::string& name);
120  void SetCurrentMaterials(const Materials& materials,
121  const std::string& name);
122  void SetCurrentMaterials(const std::string& name);
123  void SetMaterialsToDefault();
124 
125  const Eigen::Vector3f& GetCurrentMaterialColor() const;
126  void SetCurrentMaterialColor(const Eigen::Vector3f& color);
127  void ResetColors();
128  void SetCustomDefaultColor(const Eigen::Vector3f color);
130 
131  int GetPointSize() const;
132  void SetPointSize(int size);
133 
134  bool GetDisplayingPointClouds() const;
136  void SetDisplayingPointClouds(bool displaying);
137 
139  bool GetUserHasCustomizedLighting() const;
140 
141  bool GetUserHasChangedColor() const;
142 
143  void SetOnChanged(std::function<void(bool)> on_changed);
144 
145 private:
146  Eigen::Vector3f bg_color_ = {1.0f, 1.0f, 1.0f};
147  bool show_skybox_ = false;
148  bool show_axes_ = false;
149  LightingProfile lighting_;
150  MaterialType current_type_ = LIT;
151  Materials current_materials_;
152  Eigen::Vector3f custom_default_color = {-1.0f, -1.0f, 1.0f};
153  bool user_has_changed_color_ = false;
154  bool user_has_changed_lighting_profile_ = false;
155  bool user_has_customized_lighting_ = false;
156  bool displaying_point_clouds_ = false;
157 
158  std::function<void(bool)> on_changed_;
159 
160  void NotifyChanged(bool material_changed = false);
161 };
162 
163 } // namespace visualization
164 } // namespace open3d
static const LightingProfile & GetDefaultPointCloudLightingProfile()
Definition: GuiSettingsModel.cpp:169
Eigen::Vector3f sun_color
Definition: GuiSettingsModel.h:51
std::string name
Definition: GuiSettingsModel.h:47
MaterialType
Definition: GuiSettingsModel.h:59
bool GetDisplayingPointClouds() const
Definition: GuiSettingsModel.cpp:345
rendering::Scene::Transform ibl_rotation
Definition: GuiSettingsModel.h:52
const Eigen::Vector3f & GetBackgroundColor() const
Definition: GuiSettingsModel.cpp:211
static const std::map< std::string, const LitMaterial > prefab_materials_
Definition: GuiSettingsModel.h:92
void SetCustomLighting(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:228
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:67
double sun_intensity
Definition: GuiSettingsModel.h:49
GuiSettingsModel()
Definition: GuiSettingsModel.cpp:194
void SetCurrentMaterialColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:301
static constexpr const char * DEFAULT_IBL
Definition: GuiSettingsModel.h:38
const Eigen::Vector3f & GetCurrentMaterialColor() const
Definition: GuiSettingsModel.cpp:286
void SetOnChanged(std::function< void(bool)> on_changed)
Definition: GuiSettingsModel.cpp:365
bool GetUserHasCustomizedLighting() const
Definition: GuiSettingsModel.cpp:357
void SetMaterialType(MaterialType type)
Definition: GuiSettingsModel.cpp:237
static const LightingProfile & GetDefaultLightingProfile()
Definition: GuiSettingsModel.cpp:164
int size
Definition: FilePCD.cpp:59
int GetPointSize() const
Definition: GuiSettingsModel.cpp:336
Definition: GuiSettingsModel.h:36
void SetBackgroundColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:214
static const std::vector< LightingProfile > lighting_profiles_
Definition: GuiSettingsModel.h:91
LitMaterial lit
Definition: GuiSettingsModel.h:83
math::float4 color
Definition: LineSetBuffers.cpp:63
Eigen::Vector3f sun_dir
Definition: GuiSettingsModel.h:50
void SetMaterialsToDefault()
Definition: GuiSettingsModel.cpp:274
static const LitMaterial & GetDefaultLitMaterial()
Definition: GuiSettingsModel.cpp:181
void SetCurrentMaterials(const Materials &materials, const std::string &name)
Definition: GuiSettingsModel.cpp:262
std::string lit_name
Definition: GuiSettingsModel.h:88
bool GetUserHasChangedLightingProfile() const
Definition: GuiSettingsModel.cpp:353
Definition: GuiSettingsModel.h:63
static constexpr const char * MATERIAL_FROM_FILE_NAME
Definition: GuiSettingsModel.h:41
const LightingProfile & GetLighting() const
Definition: GuiSettingsModel.cpp:219
bool GetShowSkybox() const
Definition: GuiSettingsModel.cpp:199
char type
Definition: FilePCD.cpp:60
bool GetUserHasChangedColor() const
Definition: GuiSettingsModel.cpp:361
bool sun_enabled
Definition: GuiSettingsModel.h:56
void SetCustomDefaultColor(const Eigen::Vector3f color)
Definition: GuiSettingsModel.cpp:328
void SetLitMaterial(const LitMaterial &material, const std::string &name)
Definition: GuiSettingsModel.cpp:251
void SetShowAxes(bool show)
Definition: GuiSettingsModel.cpp:206
Definition: PinholeCameraIntrinsic.cpp:35
Definition: GuiSettingsModel.h:60
bool GetShowAxes() const
Definition: GuiSettingsModel.cpp:205
double ibl_intensity
Definition: GuiSettingsModel.h:48
static constexpr const char * CUSTOM_IBL
Definition: GuiSettingsModel.h:39
void ResetColors()
Definition: GuiSettingsModel.cpp:315
void SetShowSkybox(bool show)
Definition: GuiSettingsModel.cpp:200
bool use_default_ibl
Definition: GuiSettingsModel.h:55
void SetPointSize(int size)
Definition: GuiSettingsModel.cpp:340
MaterialType GetMaterialType() const
Definition: GuiSettingsModel.cpp:234
void SetDisplayingPointClouds(bool displaying)
If true, enables point size.
Definition: GuiSettingsModel.cpp:348
void SetLightingProfile(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:222
UnlitMaterial unlit
Definition: GuiSettingsModel.h:84
static constexpr const char * DEFAULT_MATERIAL_NAME
Definition: GuiSettingsModel.h:40
Definition: GuiSettingsModel.h:61
static constexpr const char * POINT_CLOUD_PROFILE_NAME
Definition: GuiSettingsModel.h:43
void UnsetCustomDefaultColor()
Definition: GuiSettingsModel.cpp:332
bool ibl_enabled
Definition: GuiSettingsModel.h:54
const Materials & GetCurrentMaterials() const
Definition: GuiSettingsModel.cpp:242