forked from nmwsharp/polyscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurface_color_quantity.cpp
More file actions
202 lines (159 loc) · 6.58 KB
/
surface_color_quantity.cpp
File metadata and controls
202 lines (159 loc) · 6.58 KB
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
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/surface_color_quantity.h"
#include "polyscope/polyscope.h"
#include "imgui.h"
namespace polyscope {
SurfaceColorQuantity::SurfaceColorQuantity(std::string name, SurfaceMesh& mesh_, std::string definedOn_,
const std::vector<glm::vec3>& colorValues_)
: SurfaceMeshQuantity(name, mesh_, true), ColorQuantity(*this, colorValues_), definedOn(definedOn_) {}
void SurfaceColorQuantity::draw() {
if (!isEnabled()) return;
if (program == nullptr) {
createProgram();
}
// Set uniforms
parent.setStructureUniforms(*program);
parent.setSurfaceMeshUniforms(*program);
render::engine->setMaterialUniforms(*program, parent.getMaterial());
program->draw();
}
void SurfaceColorQuantity::buildCustomUI() {
ImGui::SameLine();
// == Options popup
if (ImGui::Button("Options")) {
ImGui::OpenPopup("OptionsPopup");
}
if (ImGui::BeginPopup("OptionsPopup")) {
buildColorOptionsUI();
ImGui::EndPopup();
}
buildColorUI();
}
// ========================================================
// ========== Vertex Color ==========
// ========================================================
SurfaceVertexColorQuantity::SurfaceVertexColorQuantity(std::string name, SurfaceMesh& mesh_,
std::vector<glm::vec3> colorValues_)
: SurfaceColorQuantity(name, mesh_, "vertex", colorValues_)
{}
void SurfaceVertexColorQuantity::createProgram() {
// Create the program to draw this quantity
// clang-format off
program = render::engine->requestShader("MESH",
render::engine->addMaterialRules(parent.getMaterial(),
addColorRules(
parent.addSurfaceMeshRules(
{"MESH_PROPAGATE_COLOR", "SHADE_COLOR"}
)
)
)
);
// clang-format on
parent.setMeshGeometryAttributes(*program);
program->setAttribute("a_color", colors.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
render::engine->setMaterial(*program, parent.getMaterial());
}
void SurfaceVertexColorQuantity::buildColorOptionsUI() {
ColorQuantity::buildColorOptionsUI();
ImGui::TextUnformatted("(no options available)"); // remove once there is something in this menu
}
void SurfaceVertexColorQuantity::buildVertexInfoGUI(size_t vInd) {
ImGui::TextUnformatted(name.c_str());
ImGui::NextColumn();
glm::vec3 tempColor = colors.getValue(vInd);
ImGui::ColorEdit3("", &tempColor[0], ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker);
ImGui::SameLine();
std::string colorStr = to_string_short(tempColor);
ImGui::TextUnformatted(colorStr.c_str());
ImGui::NextColumn();
}
std::string SurfaceColorQuantity::niceName() { return name + " (" + definedOn + " color)"; }
void SurfaceColorQuantity::refresh() {
program.reset();
Quantity::refresh();
}
// ========================================================
// ========== Face Color ==========
// ========================================================
SurfaceFaceColorQuantity::SurfaceFaceColorQuantity(std::string name, SurfaceMesh& mesh_,
std::vector<glm::vec3> colorValues_)
: SurfaceColorQuantity(name, mesh_, "face", colorValues_)
{}
void SurfaceFaceColorQuantity::createProgram() {
// Create the program to draw this quantity
// clang-format off
program = render::engine->requestShader("MESH",
render::engine->addMaterialRules(parent.getMaterial(),
addColorRules(
parent.addSurfaceMeshRules(
{"MESH_PROPAGATE_COLOR", "SHADE_COLOR"}
)
)
)
);
// clang-format on
parent.setMeshGeometryAttributes(*program);
program->setAttribute("a_color", colors.getIndexedRenderAttributeBuffer(parent.triangleFaceInds));
render::engine->setMaterial(*program, parent.getMaterial());
}
void SurfaceFaceColorQuantity::buildColorOptionsUI() {
ColorQuantity::buildColorOptionsUI();
ImGui::TextUnformatted("(no options available)"); // remove once there is something in this menu
}
void SurfaceFaceColorQuantity::buildFaceInfoGUI(size_t fInd) {
ImGui::TextUnformatted(name.c_str());
ImGui::NextColumn();
glm::vec3 tempColor = colors.getValue(fInd);
ImGui::ColorEdit3("", &tempColor[0], ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker);
ImGui::SameLine();
std::stringstream buffer;
buffer << tempColor;
ImGui::TextUnformatted(buffer.str().c_str());
ImGui::NextColumn();
}
// ========================================================
// ========== Texture Color ==========
// ========================================================
SurfaceTextureColorQuantity::SurfaceTextureColorQuantity(std::string name, SurfaceMesh& mesh_,
SurfaceParameterizationQuantity& param_, size_t dimX_,
size_t dimY_, std::vector<glm::vec3> colorValues_,
ImageOrigin origin_)
: SurfaceColorQuantity(name, mesh_, "texture", colorValues_), TextureMapQuantity(*this, dimX_, dimY_, origin_),
param(param_) {
colors.setTextureSize(dimX, dimY);
}
void SurfaceTextureColorQuantity::createProgram() {
// Create the program to draw this quantity
// clang-format off
program = render::engine->requestShader("MESH",
render::engine->addMaterialRules(parent.getMaterial(),
addColorRules(
parent.addSurfaceMeshRules(
{"MESH_PROPAGATE_TCOORD", getImageOriginRule(imageOrigin), "TEXTURE_PROPAGATE_COLOR", "SHADE_COLOR"}
)
)
)
);
// clang-format on
parent.setMeshGeometryAttributes(*program);
// the indexing into the parameterization varies based on whether it is a corner or vertex quantity
switch (param.definedOn) {
case MeshElement::VERTEX:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
break;
case MeshElement::CORNER:
program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));
break;
default:
// nothing
break;
}
program->setTextureFromBuffer("t_color", colors.getRenderTextureBuffer().get());
render::engine->setMaterial(*program, parent.getMaterial());
colors.getRenderTextureBuffer()->setFilterMode(filterMode.get());
}
void SurfaceTextureColorQuantity::buildColorOptionsUI() {
ColorQuantity::buildColorOptionsUI();
buildTextureMapOptionsUI();
}
} // namespace polyscope