-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
RenderOption.h
210 lines (186 loc) · 6.66 KB
/
RenderOption.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// Copyright (c) 2018-2023 www.open3d.org
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------
#pragma once
#include <Eigen/Core>
#include "open3d/utility/IJsonConvertible.h"
namespace open3d {
namespace visualization {
/// \class RenderOption
///
/// \brief Defines rendering options for visualizer.
class RenderOption : public utility::IJsonConvertible {
public:
// Global options
enum class TextureInterpolationOption {
Nearest = 0,
Linear = 1,
};
enum class DepthFunc {
Never = 0,
Less = 1,
Equal = 2,
LEqual = 3,
Greater = 4,
NotEqual = 5,
GEqual = 6,
Always = 7
};
/// \enum PointColorOption
///
/// \brief Enum class for point color for PointCloud.
enum class PointColorOption {
Default = 0,
Color = 1,
XCoordinate = 2,
YCoordinate = 3,
ZCoordinate = 4,
Normal = 9,
};
const double POINT_SIZE_MAX = 25.0;
const double POINT_SIZE_MIN = 1.0;
const double POINT_SIZE_STEP = 1.0;
const double POINT_SIZE_DEFAULT = 5.0;
const double LINE_WIDTH_MAX = 10.0;
const double LINE_WIDTH_MIN = 1.0;
const double LINE_WIDTH_STEP = 1.0;
const double LINE_WIDTH_DEFAULT = 1.0;
/// \enum MeshShadeOption
///
/// \brief Enum class for mesh shading for TriangleMesh.
enum class MeshShadeOption {
FlatShade = 0,
SmoothShade = 1,
};
/// \enum MeshColorOption
///
/// \brief Enum class for color for TriangleMesh.
enum class MeshColorOption {
Default = 0,
Color = 1,
XCoordinate = 2,
YCoordinate = 3,
ZCoordinate = 4,
Normal = 9,
};
// Image options
enum class ImageStretchOption {
OriginalSize = 0,
StretchKeepRatio = 1,
StretchWithWindow = 2,
};
public:
/// \brief Default Constructor.
RenderOption() {
// VS2013 does not fully support C++11
// Array initialization has to be done in constructors.
light_position_relative_[0] = Eigen::Vector3d(0, 0, 2);
light_position_relative_[1] = Eigen::Vector3d(0, 0, 2);
light_position_relative_[2] = Eigen::Vector3d(0, 0, -2);
light_position_relative_[3] = Eigen::Vector3d(0, 0, -2);
light_color_[0] = Eigen::Vector3d::Ones();
light_color_[1] = Eigen::Vector3d::Ones();
light_color_[2] = Eigen::Vector3d::Ones();
light_color_[3] = Eigen::Vector3d::Ones();
light_diffuse_power_[0] = 0.66;
light_diffuse_power_[1] = 0.66;
light_diffuse_power_[2] = 0.66;
light_diffuse_power_[3] = 0.66;
light_specular_power_[0] = 0.2;
light_specular_power_[1] = 0.2;
light_specular_power_[2] = 0.2;
light_specular_power_[3] = 0.2;
light_specular_shininess_[0] = 100.0;
light_specular_shininess_[1] = 100.0;
light_specular_shininess_[2] = 100.0;
light_specular_shininess_[3] = 100.0;
}
~RenderOption() override {}
public:
bool ConvertToJsonValue(Json::Value &value) const override;
bool ConvertFromJsonValue(const Json::Value &value) override;
public:
void ToggleLightOn() { light_on_ = !light_on_; }
void ToggleInterpolationOption() {
if (interpolation_option_ == TextureInterpolationOption::Nearest) {
interpolation_option_ = TextureInterpolationOption::Linear;
} else {
interpolation_option_ = TextureInterpolationOption::Nearest;
}
}
void ChangePointSize(double change);
void SetPointSize(double size);
void ChangeLineWidth(double change);
void TogglePointShowNormal() { point_show_normal_ = !point_show_normal_; }
void ToggleShadingOption() {
if (mesh_shade_option_ == MeshShadeOption::FlatShade) {
mesh_shade_option_ = MeshShadeOption::SmoothShade;
} else {
mesh_shade_option_ = MeshShadeOption::FlatShade;
}
}
void ToggleMeshShowBackFace() {
mesh_show_back_face_ = !mesh_show_back_face_;
}
void ToggleMeshShowWireframe() {
mesh_show_wireframe_ = !mesh_show_wireframe_;
}
void ToggleImageStretchOption() {
if (image_stretch_option_ == ImageStretchOption::OriginalSize) {
image_stretch_option_ = ImageStretchOption::StretchKeepRatio;
} else if (image_stretch_option_ ==
ImageStretchOption::StretchKeepRatio) {
image_stretch_option_ = ImageStretchOption::StretchWithWindow;
} else {
image_stretch_option_ = ImageStretchOption::OriginalSize;
}
}
int GetGLDepthFunc() const;
public:
// global options
/// Background RGB color.
Eigen::Vector3d background_color_ = Eigen::Vector3d::Ones();
TextureInterpolationOption interpolation_option_ =
TextureInterpolationOption::Nearest;
DepthFunc depthFunc_ = DepthFunc::Less;
// Phong lighting options
/// Whether to turn on Phong lighting.
bool light_on_ = true;
Eigen::Vector3d light_position_relative_[4];
Eigen::Vector3d light_color_[4];
Eigen::Vector3d light_ambient_color_ = Eigen::Vector3d::Zero();
double light_diffuse_power_[4];
double light_specular_power_[4];
double light_specular_shininess_[4];
// PointCloud options
/// Point size for PointCloud.
double point_size_ = POINT_SIZE_DEFAULT;
/// Point color option for PointCloud.
PointColorOption point_color_option_ = PointColorOption::Default;
/// Whether to show normal for PointCloud.
bool point_show_normal_ = false;
// TriangleMesh options
/// Mesh shading option for TriangleMesh.
MeshShadeOption mesh_shade_option_ = MeshShadeOption::FlatShade;
/// Color option for TriangleMesh.
MeshColorOption mesh_color_option_ = MeshColorOption::Color;
/// Whether to show back faces for TriangleMesh.
bool mesh_show_back_face_ = false;
bool mesh_show_wireframe_ = false;
Eigen::Vector3d default_mesh_color_ = Eigen::Vector3d(0.7, 0.7, 0.7);
// LineSet options
/// Line width for LineSet.
double line_width_ = LINE_WIDTH_DEFAULT;
// Image options
ImageStretchOption image_stretch_option_ =
ImageStretchOption::StretchKeepRatio;
int image_max_depth_ = 3000;
// Coordinate frame
/// Whether to show coordinate frame.
bool show_coordinate_frame_ = false;
};
} // namespace visualization
} // namespace open3d