Open3D (C++ API)  0.12.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_
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: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:352
rendering::Scene::Transform ibl_rotation
Definition: GuiSettingsModel.h:52
const Eigen::Vector3f & GetBackgroundColor() const
Definition: GuiSettingsModel.cpp:218
static const std::map< std::string, const LitMaterial > prefab_materials_
Definition: GuiSettingsModel.h:92
void SetCustomLighting(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:235
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:67
double sun_intensity
Definition: GuiSettingsModel.h:49
GuiSettingsModel()
Definition: GuiSettingsModel.cpp:201
void SetCurrentMaterialColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:308
const Eigen::Vector3f & GetCurrentMaterialColor() const
Definition: GuiSettingsModel.cpp:293
void SetOnChanged(std::function< void(bool)> on_changed)
Definition: GuiSettingsModel.cpp:372
bool GetUserHasCustomizedLighting() const
Definition: GuiSettingsModel.cpp:364
void SetMaterialType(MaterialType type)
Definition: GuiSettingsModel.cpp:244
static const LightingProfile & GetDefaultLightingProfile()
Definition: GuiSettingsModel.cpp:171
int size
Definition: FilePCD.cpp:59
int GetPointSize() const
Definition: GuiSettingsModel.cpp:343
Definition: GuiSettingsModel.h:36
void SetBackgroundColor(const Eigen::Vector3f &color)
Definition: GuiSettingsModel.cpp:221
static const std::vector< LightingProfile > lighting_profiles_
Definition: GuiSettingsModel.h:91
LitMaterial lit
Definition: GuiSettingsModel.h:83
math::float4 color
Definition: LineSetBuffers.cpp:64
Eigen::Vector3f sun_dir
Definition: GuiSettingsModel.h:50
void SetMaterialsToDefault()
Definition: GuiSettingsModel.cpp:281
static const LitMaterial & GetDefaultLitMaterial()
Definition: GuiSettingsModel.cpp:188
void SetCurrentMaterials(const Materials &materials, const std::string &name)
Definition: GuiSettingsModel.cpp:269
std::string lit_name
Definition: GuiSettingsModel.h:88
bool GetUserHasChangedLightingProfile() const
Definition: GuiSettingsModel.cpp:360
Definition: GuiSettingsModel.h:63
const LightingProfile & GetLighting() const
Definition: GuiSettingsModel.cpp:226
bool GetShowSkybox() const
Definition: GuiSettingsModel.cpp:206
char type
Definition: FilePCD.cpp:60
bool GetUserHasChangedColor() const
Definition: GuiSettingsModel.cpp:368
bool sun_enabled
Definition: GuiSettingsModel.h:56
void SetCustomDefaultColor(const Eigen::Vector3f color)
Definition: GuiSettingsModel.cpp:335
void SetLitMaterial(const LitMaterial &material, const std::string &name)
Definition: GuiSettingsModel.cpp:258
static constexpr const char * DEFAULT_IBL
Definition: GuiSettingsModel.h:38
void SetShowAxes(bool show)
Definition: GuiSettingsModel.cpp:213
Definition: PinholeCameraIntrinsic.cpp:35
Definition: GuiSettingsModel.h:60
bool GetShowAxes() const
Definition: GuiSettingsModel.cpp:212
double ibl_intensity
Definition: GuiSettingsModel.h:48
void ResetColors()
Definition: GuiSettingsModel.cpp:322
void SetShowSkybox(bool show)
Definition: GuiSettingsModel.cpp:207
bool use_default_ibl
Definition: GuiSettingsModel.h:55
void SetPointSize(int size)
Definition: GuiSettingsModel.cpp:347
MaterialType GetMaterialType() const
Definition: GuiSettingsModel.cpp:241
void SetDisplayingPointClouds(bool displaying)
If true, enables point size.
Definition: GuiSettingsModel.cpp:355
void SetLightingProfile(const LightingProfile &profile)
Definition: GuiSettingsModel.cpp:229
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:339
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:278
const Materials & GetCurrentMaterials() const
Definition: GuiSettingsModel.cpp:249