ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RenderOption.cpp
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 
9 
10 #include <GL/glew.h>
11 #include <Logging.h>
12 #include <json/json.h>
13 
14 #include <algorithm>
15 
16 namespace cloudViewer {
17 namespace visualization {
18 
19 bool RenderOption::ConvertToJsonValue(Json::Value &value) const {
20  value["class_name"] = "RenderOption";
21  value["version_major"] = 1;
22  value["version_minor"] = 0;
23 
25  value["background_color"])) {
26  return false;
27  }
28  value["interpolation_option"] = (int)interpolation_option_;
29 
30  value["light_on"] = light_on_;
32  value["light_ambient_color"])) {
33  return false;
34  }
36  value["light0_position"])) {
37  return false;
38  }
39  if (!EigenVector3dToJsonArray(light_color_[0], value["light0_color"])) {
40  return false;
41  }
42  value["light0_diffuse_power"] = light_diffuse_power_[0];
43  value["light0_specular_power"] = light_specular_power_[0];
44  value["light0_specular_shininess"] = light_specular_shininess_[0];
46  value["light1_position"])) {
47  return false;
48  }
49  if (!EigenVector3dToJsonArray(light_color_[1], value["light1_color"])) {
50  return false;
51  }
52  value["light1_diffuse_power"] = light_diffuse_power_[1];
53  value["light1_specular_power"] = light_specular_power_[1];
54  value["light1_specular_shininess"] = light_specular_shininess_[1];
56  value["light2_position"])) {
57  return false;
58  }
59  if (!EigenVector3dToJsonArray(light_color_[2], value["light2_color"])) {
60  return false;
61  }
62  value["light2_diffuse_power"] = light_diffuse_power_[2];
63  value["light2_specular_power"] = light_specular_power_[2];
64  value["light2_specular_shininess"] = light_specular_shininess_[2];
66  value["light3_position"])) {
67  return false;
68  }
69  if (!EigenVector3dToJsonArray(light_color_[3], value["light3_color"])) {
70  return false;
71  }
72  value["light3_diffuse_power"] = light_diffuse_power_[3];
73  value["light3_specular_power"] = light_specular_power_[3];
74  value["light3_specular_shininess"] = light_specular_shininess_[3];
75 
76  value["point_size"] = point_size_;
77  value["point_color_option"] = (int)point_color_option_;
78  value["point_show_normal"] = point_show_normal_;
79 
80  value["mesh_shade_option"] = (int)mesh_shade_option_;
81  value["mesh_color_option"] = (int)mesh_color_option_;
82  value["mesh_show_back_face"] = mesh_show_back_face_;
83  value["mesh_show_wireframe"] = mesh_show_wireframe_;
85  value["default_mesh_color"])) {
86  return false;
87  }
88 
89  value["line_width"] = line_width_;
90 
91  value["image_stretch_option"] = (int)image_stretch_option_;
92  value["image_max_depth"] = image_max_depth_;
93 
94  value["show_coordinate_frame"] = show_coordinate_frame_;
95  return true;
96 }
97 
98 bool RenderOption::ConvertFromJsonValue(const Json::Value &value) {
99  if (!value.isObject()) {
101  "ViewTrajectory read JSON failed: unsupported json format.");
102  return false;
103  }
104  if (value.get("class_name", "").asString() != "RenderOption" ||
105  value.get("version_major", 1).asInt() != 1 ||
106  value.get("version_minor", 0).asInt() != 0) {
108  "ViewTrajectory read JSON failed: unsupported json format.");
109  return false;
110  }
111 
113  value["background_color"])) {
114  return false;
115  }
118  .get("interpolation_option", (int)interpolation_option_)
119  .asInt();
120 
121  light_on_ = value.get("light_on", light_on_).asBool();
123  value["light_ambient_color"])) {
124  return false;
125  }
127  value["light0_position"])) {
128  return false;
129  }
130  if (!EigenVector3dFromJsonArray(light_color_[0], value["light0_color"])) {
131  return false;
132  }
134  value.get("light0_diffuse_power", light_diffuse_power_[0])
135  .asDouble();
137  value.get("light0_specular_power", light_specular_power_[0])
138  .asDouble();
140  value.get("light0_specular_shininess", light_specular_shininess_[0])
141  .asDouble();
143  value["light1_position"])) {
144  return false;
145  }
146  if (!EigenVector3dFromJsonArray(light_color_[1], value["light1_color"])) {
147  return false;
148  }
150  value.get("light1_diffuse_power", light_diffuse_power_[1])
151  .asDouble();
153  value.get("light1_specular_power", light_specular_power_[1])
154  .asDouble();
156  value.get("light1_specular_shininess", light_specular_shininess_[1])
157  .asDouble();
159  value["light2_position"])) {
160  return false;
161  }
162  if (!EigenVector3dFromJsonArray(light_color_[2], value["light2_color"])) {
163  return false;
164  }
166  value.get("light2_diffuse_power", light_diffuse_power_[2])
167  .asDouble();
169  value.get("light2_specular_power", light_specular_power_[2])
170  .asDouble();
172  value.get("light2_specular_shininess", light_specular_shininess_[2])
173  .asDouble();
175  value["light3_position"])) {
176  return false;
177  }
178  if (!EigenVector3dFromJsonArray(light_color_[3], value["light3_color"])) {
179  return false;
180  }
182  value.get("light3_diffuse_power", light_diffuse_power_[3])
183  .asDouble();
185  value.get("light3_specular_power", light_specular_power_[3])
186  .asDouble();
188  value.get("light3_specular_shininess", light_specular_shininess_[3])
189  .asDouble();
190 
191  point_size_ = value.get("point_size", point_size_).asDouble();
193  (PointColorOption)value
194  .get("point_color_option", (int)point_color_option_)
195  .asInt();
197  value.get("point_show_normal", point_show_normal_).asBool();
198 
200  (MeshShadeOption)value
201  .get("mesh_shade_option", (int)mesh_shade_option_)
202  .asInt();
204  (MeshColorOption)value
205  .get("mesh_color_option", (int)mesh_color_option_)
206  .asInt();
208  value.get("mesh_show_back_face", mesh_show_back_face_).asBool();
210  value.get("mesh_show_wireframe", mesh_show_wireframe_).asBool();
212  value["default_mesh_color"])) {
213  return false;
214  }
215 
216  line_width_ = value.get("line_width", line_width_).asDouble();
217 
219  (ImageStretchOption)value
220  .get("image_stretch_option", (int)image_stretch_option_)
221  .asInt();
222  image_max_depth_ = value.get("image_max_depth", image_max_depth_).asInt();
223 
225  value.get("show_coordinate_frame", show_coordinate_frame_).asBool();
226  return true;
227 }
228 
229 void RenderOption::ChangePointSize(double change) {
233 }
234 
237 }
238 
239 void RenderOption::ChangeLineWidth(double change) {
243 }
244 
246  switch (depthFunc_) {
247  case DepthFunc::Never:
248  return GL_NEVER;
249  case DepthFunc::Less:
250  return GL_LESS;
251  case DepthFunc::Equal:
252  return GL_EQUAL;
253  case DepthFunc::LEqual:
254  return GL_LEQUAL;
255  case DepthFunc::Greater:
256  return GL_GREATER;
257  case DepthFunc::NotEqual:
258  return GL_NOTEQUAL;
259  case DepthFunc::GEqual:
260  return GL_GEQUAL;
261  case DepthFunc::Always:
262  return GL_ALWAYS;
263  }
264  return GL_LESS; // never hit, makes GCC happy
265 }
266 
267 } // namespace visualization
268 } // namespace cloudViewer
int size
static bool EigenVector3dFromJsonArray(Eigen::Vector3d &vec, const Json::Value &value)
static bool EigenVector3dToJsonArray(const Eigen::Vector3d &vec, Json::Value &value)
bool ConvertToJsonValue(Json::Value &value) const override
MeshShadeOption
Enum class for mesh shading for TriangleMesh.
Definition: RenderOption.h:63
bool mesh_show_back_face_
Whether to show back faces for TriangleMesh.
Definition: RenderOption.h:190
TextureInterpolationOption interpolation_option_
Definition: RenderOption.h:162
Eigen::Vector3d background_color_
Background RGB color.
Definition: RenderOption.h:161
PointColorOption
Enum class for point color for PointCloud.
Definition: RenderOption.h:42
MeshColorOption mesh_color_option_
Color option for TriangleMesh.
Definition: RenderOption.h:188
bool point_show_normal_
Whether to show normal for PointCloud.
Definition: RenderOption.h:182
MeshColorOption
Enum class for color for TriangleMesh.
Definition: RenderOption.h:71
bool ConvertFromJsonValue(const Json::Value &value) override
double point_size_
Point size for PointCloud.
Definition: RenderOption.h:178
double line_width_
Line width for LineSet.
Definition: RenderOption.h:197
MeshShadeOption mesh_shade_option_
Mesh shading option for TriangleMesh.
Definition: RenderOption.h:186
bool show_coordinate_frame_
Whether to show coordinate frame.
Definition: RenderOption.h:206
bool light_on_
Whether to turn on Phong lighting.
Definition: RenderOption.h:168
PointColorOption point_color_option_
Point color option for PointCloud.
Definition: RenderOption.h:180
#define LogWarning(...)
Definition: Logging.h:72
int min(int a, int b)
Definition: cutil_math.h:53
int max(int a, int b)
Definition: cutil_math.h:48
Generic file read and write utility for python interface.