Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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-2021 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  bool GetShowGround() const;
106  void SetShowGround(bool show);
107 
108  bool GetSunFollowsCamera() const;
109  void SetSunFollowsCamera(bool follow);
110 
111  const Eigen::Vector3f& GetBackgroundColor() const;
112  void SetBackgroundColor(const Eigen::Vector3f& color);
113 
114  const LightingProfile& GetLighting() const;
115  // Should be from lighting_profiles_
118 
121 
122  // TODO: Get/SetMaterial
123  const Materials& GetCurrentMaterials() const;
125  void SetLitMaterial(const LitMaterial& material, const std::string& name);
126  void SetCurrentMaterials(const Materials& materials,
127  const std::string& name);
128  void SetCurrentMaterials(const std::string& name);
129  void SetMaterialsToDefault();
130 
131  const Eigen::Vector3f& GetCurrentMaterialColor() const;
132  void SetCurrentMaterialColor(const Eigen::Vector3f& color);
133  void ResetColors();
134  void SetCustomDefaultColor(const Eigen::Vector3f color);
136 
137  int GetPointSize() const;
138  void SetPointSize(int size);
139 
140  bool GetBasicMode() const;
141  void SetBasicMode(bool enable);
142 
143  bool GetWireframeMode() const;
144  void SetWireframeMode(bool enable);
145 
147  void EstimateNormalsClicked();
148 
149  bool GetDisplayingPointClouds() const;
151  void SetDisplayingPointClouds(bool displaying);
152 
154  bool GetUserHasCustomizedLighting() const;
155 
156  bool GetUserHasChangedColor() const;
157 
158  void SetOnChanged(std::function<void(bool)> on_changed);
159 
160 private:
161  Eigen::Vector3f bg_color_ = {1.0f, 1.0f, 1.0f};
162  bool show_skybox_ = false;
163  bool show_axes_ = false;
164  bool show_ground_ = false;
165  bool sun_follows_cam_ = true;
166  LightingProfile lighting_;
167  MaterialType current_type_ = LIT;
168  Materials current_materials_;
169  Eigen::Vector3f custom_default_color = {-1.0f, -1.0f, 1.0f};
170  bool user_has_changed_color_ = false;
171  bool user_has_changed_lighting_profile_ = false;
172  bool user_has_customized_lighting_ = false;
173  bool displaying_point_clouds_ = false;
174  bool user_wants_estimate_normals_ = false;
175  bool basic_mode_enabled_ = false;
176  bool wireframe_mode_enabled_ = false;
177 
178  std::function<void(bool)> on_changed_;
179 
180  void NotifyChanged(bool material_changed = false);
181 };
182 
183 } // namespace visualization
184 } // namespace open3d
bool GetWireframeMode() const
Definition: GuiSettingsModel.cpp:230
static const LightingProfile & GetDefaultPointCloudLightingProfile()
Definition: GuiSettingsModel.cpp:176
Eigen::Vector3f sun_color
Definition: GuiSettingsModel.h:51
std::string name
Definition: GuiSettingsModel.h:47
static constexpr const char * DEFAULT_MATERIAL_NAME
Definition: GuiSettingsModel.h:40
MaterialType
Definition: GuiSettingsModel.h:59
bool GetDisplayingPointClouds() const
Definition: GuiSettingsModel.cpp:387
rendering::Scene::Transform ibl_rotation
Definition: GuiSettingsModel.h:52
const Eigen::Vector3f & GetBackgroundColor() const
Definition: GuiSettingsModel.cpp:238
static const std::map< std::string, const LitMaterial > prefab_materials_
Definition: GuiSettingsModel.h:92
void SetCustomLighting(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:256
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:68
double sun_intensity
Definition: GuiSettingsModel.h:49
GuiSettingsModel()
Definition: GuiSettingsModel.cpp:194
void SetCurrentMaterialColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:329
const Eigen::Vector3f & GetCurrentMaterialColor() const
Definition: GuiSettingsModel.cpp:314
void SetOnChanged(std::function< void(bool)> on_changed)
Definition: GuiSettingsModel.cpp:407
bool GetUserHasCustomizedLighting() const
Definition: GuiSettingsModel.cpp:399
void SetMaterialType(MaterialType type)
Definition: GuiSettingsModel.cpp:265
static const LightingProfile & GetDefaultLightingProfile()
Definition: GuiSettingsModel.cpp:171
int GetPointSize() const
Definition: GuiSettingsModel.cpp:364
Definition: GuiSettingsModel.h:36
void SetBackgroundColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:241
static const std::vector< LightingProfile > lighting_profiles_
Definition: GuiSettingsModel.h:91
void SetShowGround(bool show)
Definition: GuiSettingsModel.cpp:213
void EstimateNormalsClicked()
Definition: GuiSettingsModel.cpp:382
LitMaterial lit
Definition: GuiSettingsModel.h:83
void SetSunFollowsCamera(bool follow)
Definition: GuiSettingsModel.cpp:219
math::float4 color
Definition: LineSetBuffers.cpp:64
bool GetShowGround() const
Definition: GuiSettingsModel.cpp:212
Eigen::Vector3f sun_dir
Definition: GuiSettingsModel.h:50
void SetMaterialsToDefault()
Definition: GuiSettingsModel.cpp:302
static const LitMaterial & GetDefaultLitMaterial()
Definition: GuiSettingsModel.cpp:181
void SetCurrentMaterials(const Materials &materials, const std::string &name)
Definition: GuiSettingsModel.cpp:290
std::string lit_name
Definition: GuiSettingsModel.h:88
char type
Definition: FilePCD.cpp:60
bool GetUserHasChangedLightingProfile() const
Definition: GuiSettingsModel.cpp:395
Definition: GuiSettingsModel.h:63
void SetWireframeMode(bool enable)
Definition: GuiSettingsModel.cpp:233
const LightingProfile & GetLighting() const
Definition: GuiSettingsModel.cpp:246
bool GetUserWantsEstimateNormals()
Definition: GuiSettingsModel.cpp:373
bool GetShowSkybox() const
Definition: GuiSettingsModel.cpp:200
bool GetBasicMode() const
Definition: GuiSettingsModel.cpp:224
bool GetUserHasChangedColor() const
Definition: GuiSettingsModel.cpp:403
bool sun_enabled
Definition: GuiSettingsModel.h:56
void SetCustomDefaultColor(const Eigen::Vector3f color)
Definition: GuiSettingsModel.cpp:356
void SetLitMaterial(const LitMaterial &material, const std::string &name)
Definition: GuiSettingsModel.cpp:279
static constexpr const char * DEFAULT_IBL
Definition: GuiSettingsModel.h:38
void SetShowAxes(bool show)
Definition: GuiSettingsModel.cpp:207
Definition: PinholeCameraIntrinsic.cpp:35
Definition: GuiSettingsModel.h:60
bool GetShowAxes() const
Definition: GuiSettingsModel.cpp:206
double ibl_intensity
Definition: GuiSettingsModel.h:48
bool GetSunFollowsCamera() const
Definition: GuiSettingsModel.cpp:218
void ResetColors()
Definition: GuiSettingsModel.cpp:343
void SetShowSkybox(bool show)
Definition: GuiSettingsModel.cpp:201
void SetBasicMode(bool enable)
Definition: GuiSettingsModel.cpp:225
bool use_default_ibl
Definition: GuiSettingsModel.h:55
void SetPointSize(int size)
Definition: GuiSettingsModel.cpp:368
MaterialType GetMaterialType() const
Definition: GuiSettingsModel.cpp:262
void SetDisplayingPointClouds(bool displaying)
If true, enables point size.
Definition: GuiSettingsModel.cpp:390
void SetLightingProfile(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:250
int size
Definition: FilePCD.cpp:59
UnlitMaterial unlit
Definition: GuiSettingsModel.h:84
static constexpr const char * CUSTOM_IBL
Definition: GuiSettingsModel.h:39
static constexpr const char * POINT_CLOUD_PROFILE_NAME
Definition: GuiSettingsModel.h:43
Definition: GuiSettingsModel.h:61
void UnsetCustomDefaultColor()
Definition: GuiSettingsModel.cpp:360
bool ibl_enabled
Definition: GuiSettingsModel.h:54
static constexpr const char * MATERIAL_FROM_FILE_NAME
Definition: GuiSettingsModel.h:41
Open3DScene::LightingProfile profile
Definition: O3DVisualizer.cpp:288
const Materials & GetCurrentMaterials() const
Definition: GuiSettingsModel.cpp:270