ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
GuiSettingsModel.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <map>
11 
13 
14 namespace cloudViewer {
15 namespace visualization {
16 
18 public:
19  static constexpr const char* DEFAULT_IBL = "default";
20  static constexpr const char* CUSTOM_IBL = "Custom KTX file...";
21  static constexpr const char* DEFAULT_MATERIAL_NAME = "Polished ceramic";
22  static constexpr const char* MATERIAL_FROM_FILE_NAME =
23  "Material from file [default]";
24  static constexpr const char* POINT_CLOUD_PROFILE_NAME =
25  "Cloudy day (no direct sun)";
26 
27  struct LightingProfile {
28  std::string name;
29  double ibl_intensity;
30  double sun_intensity;
31  Eigen::Vector3f sun_dir;
32  Eigen::Vector3f sun_color = {1.0f, 1.0f, 1.0f};
34  rendering::Scene::Transform::Identity();
35  bool ibl_enabled = true;
36  bool use_default_ibl = false;
37  bool sun_enabled = true;
38  };
39 
40  enum MaterialType {
41  LIT = 0,
45  };
46 
47  struct LitMaterial {
48  Eigen::Vector3f base_color = {0.9f, 0.9f, 0.9f};
49  float metallic = 0.f;
50  float roughness = 0.7f;
51  float reflectance = 0.5f;
52  float clear_coat = 0.2f;
53  float clear_coat_roughness = 0.2f;
54  float anisotropy = 0.f;
55  };
56 
57  struct UnlitMaterial {
58  // The base color should NOT be {1, 1, 1}, because then the
59  // model will be invisible against the default white background.
60  Eigen::Vector3f base_color = {0.9f, 0.9f, 0.9f};
61  };
62 
63  struct Materials {
66  float point_size = 3.0f;
67  // 'name' is only used to keep the UI in sync. It is set by
68  // Set...Material[s]() and should not be set manually.
69  std::string lit_name;
70  };
71 
72  static const std::vector<LightingProfile> lighting_profiles_;
73  static const std::map<std::string, const LitMaterial> prefab_materials_;
76  static const LitMaterial& GetDefaultLitMaterial();
77 
79 
80  bool GetShowSkybox() const;
81  void SetShowSkybox(bool show);
82 
83  bool GetShowAxes() const;
84  void SetShowAxes(bool show);
85 
86  bool GetShowGround() const;
87  void SetShowGround(bool show);
88 
89  bool GetSunFollowsCamera() const;
90  void SetSunFollowsCamera(bool follow);
91 
92  const Eigen::Vector3f& GetBackgroundColor() const;
93  void SetBackgroundColor(const Eigen::Vector3f& color);
94 
95  const LightingProfile& GetLighting() const;
96  // Should be from lighting_profiles_
99 
102 
103  // TODO: Get/SetMaterial
104  const Materials& GetCurrentMaterials() const;
106  void SetLitMaterial(const LitMaterial& material, const std::string& name);
107  void SetCurrentMaterials(const Materials& materials,
108  const std::string& name);
109  void SetCurrentMaterials(const std::string& name);
110  void SetMaterialsToDefault();
111 
112  const Eigen::Vector3f& GetCurrentMaterialColor() const;
113  void SetCurrentMaterialColor(const Eigen::Vector3f& color);
114  void ResetColors();
115  void SetCustomDefaultColor(const Eigen::Vector3f color);
117 
118  int GetPointSize() const;
119  void SetPointSize(int size);
120 
121  bool GetBasicMode() const;
122  void SetBasicMode(bool enable);
123 
124  bool GetWireframeMode() const;
125  void SetWireframeMode(bool enable);
126 
128  void EstimateNormalsClicked();
129 
130  bool GetDisplayingPointClouds() const;
132  void SetDisplayingPointClouds(bool displaying);
133 
135  bool GetUserHasCustomizedLighting() const;
136 
137  bool GetUserHasChangedColor() const;
138 
139  void SetOnChanged(std::function<void(bool)> on_changed);
140 
141 private:
142  Eigen::Vector3f bg_color_ = {1.0f, 1.0f, 1.0f};
143  bool show_skybox_ = false;
144  bool show_axes_ = false;
145  bool show_ground_ = false;
146  bool sun_follows_cam_ = true;
147  LightingProfile lighting_;
148  MaterialType current_type_ = LIT;
149  Materials current_materials_;
150  Eigen::Vector3f custom_default_color = {-1.0f, -1.0f, 1.0f};
151  bool user_has_changed_color_ = false;
152  bool user_has_changed_lighting_profile_ = false;
153  bool user_has_customized_lighting_ = false;
154  bool displaying_point_clouds_ = false;
155  bool user_wants_estimate_normals_ = false;
156  bool basic_mode_enabled_ = false;
157  bool wireframe_mode_enabled_ = false;
158 
159  std::function<void(bool)> on_changed_;
160 
161  void NotifyChanged(bool material_changed = false);
162 };
163 
164 } // namespace visualization
165 } // namespace cloudViewer
int size
std::string name
char type
math::float4 color
CloudViewerScene::LightingProfile profile
const Eigen::Vector3f & GetBackgroundColor() const
static constexpr const char * DEFAULT_IBL
static constexpr const char * MATERIAL_FROM_FILE_NAME
void SetCustomLighting(const LightingProfile &profile)
void SetCurrentMaterials(const Materials &materials, const std::string &name)
void SetLitMaterial(const LitMaterial &material, const std::string &name)
static const LitMaterial & GetDefaultLitMaterial()
void SetBackgroundColor(const Eigen::Vector3f &color)
void SetCustomDefaultColor(const Eigen::Vector3f color)
void SetCurrentMaterialColor(const Eigen::Vector3f &color)
static constexpr const char * CUSTOM_IBL
void SetDisplayingPointClouds(bool displaying)
If true, enables point size.
static const LightingProfile & GetDefaultLightingProfile()
static constexpr const char * DEFAULT_MATERIAL_NAME
void SetLightingProfile(const LightingProfile &profile)
const Eigen::Vector3f & GetCurrentMaterialColor() const
static const std::map< std::string, const LitMaterial > prefab_materials_
static const LightingProfile & GetDefaultPointCloudLightingProfile()
void SetOnChanged(std::function< void(bool)> on_changed)
static const std::vector< LightingProfile > lighting_profiles_
static constexpr const char * POINT_CLOUD_PROFILE_NAME
const LightingProfile & GetLighting() const
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Scene.h:55
Generic file read and write utility for python interface.