-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathsurface_parameterization_quantity.cpp
More file actions
140 lines (100 loc) · 4.74 KB
/
surface_parameterization_quantity.cpp
File metadata and controls
140 lines (100 loc) · 4.74 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
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/surface_parameterization_quantity.h"
#include "polyscope/file_helpers.h"
#include "polyscope/polyscope.h"
#include "polyscope/render/engine.h"
#include "imgui.h"
namespace polyscope {
// ==============================================================
// ================ Base Parameterization =====================
// ==============================================================
SurfaceParameterizationQuantity::SurfaceParameterizationQuantity(std::string name, SurfaceMesh& mesh_,
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_, ParamVizStyle style_)
: SurfaceMeshQuantity(name, mesh_, true), ParameterizationQuantity(*this, coords_, type_, style_) {}
void SurfaceParameterizationQuantity::draw() {
if (!isEnabled()) return;
if (program == nullptr) {
createProgram();
}
// Set uniforms
setParameterizationUniforms(*program);
parent.setStructureUniforms(*program);
parent.setSurfaceMeshUniforms(*program);
render::engine->setMaterialUniforms(*program, parent.getMaterial());
program->draw();
}
void SurfaceParameterizationQuantity::createProgram() {
// Create the program to draw this quantity
// clang-format off
program = render::engine->requestShader("MESH",
render::engine->addMaterialRules(parent.getMaterial(),
parent.addSurfaceMeshRules(
addParameterizationRules(
{"MESH_PROPAGATE_VALUE2"}
)
)
)
);
//
// Fill buffers
fillCoordBuffers(*program);
fillParameterizationBuffers(*program);
parent.setMeshGeometryAttributes(*program);
render::engine->setMaterial(*program, parent.getMaterial());
}
void SurfaceParameterizationQuantity::buildCustomUI() {
ImGui::SameLine();
// == Options popup
if (ImGui::Button("Options")) {
ImGui::OpenPopup("OptionsPopup");
}
if (ImGui::BeginPopup("OptionsPopup")) {
buildParameterizationOptionsUI();
ImGui::EndPopup();
}
buildParameterizationUI();
}
void SurfaceParameterizationQuantity::refresh() {
program.reset();
Quantity::refresh();
}
// ==============================================================
// =============== Corner Parameterization ====================
// ==============================================================
SurfaceCornerParameterizationQuantity::SurfaceCornerParameterizationQuantity(std::string name, SurfaceMesh& mesh_,
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_,
ParamVizStyle style_)
: SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {}
std::string SurfaceCornerParameterizationQuantity::niceName() { return name + " (corner parameterization)"; }
void SurfaceCornerParameterizationQuantity::fillCoordBuffers(render::ShaderProgram& p) {
p.setAttribute("a_value2", coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));
}
void SurfaceCornerParameterizationQuantity::buildCornerInfoGUI(size_t cInd) {
glm::vec2 coord = coords.getValue(cInd);
ImGui::TextUnformatted(name.c_str());
ImGui::NextColumn();
ImGui::Text("<%g,%g>", coord.x, coord.y);
ImGui::NextColumn();
}
// ==============================================================
// =============== Vertex Parameterization ====================
// ==============================================================
SurfaceVertexParameterizationQuantity::SurfaceVertexParameterizationQuantity(std::string name, SurfaceMesh& mesh_,
const std::vector<glm::vec2>& coords_,
ParamCoordsType type_,
ParamVizStyle style_)
: SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {}
std::string SurfaceVertexParameterizationQuantity::niceName() { return name + " (vertex parameterization)"; }
void SurfaceVertexParameterizationQuantity::fillCoordBuffers(render::ShaderProgram& p) {
p.setAttribute("a_value2", coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
}
void SurfaceVertexParameterizationQuantity::buildVertexInfoGUI(size_t vInd) {
glm::vec2 coord = coords.getValue(vInd);
ImGui::TextUnformatted(name.c_str());
ImGui::NextColumn();
ImGui::Text("<%g,%g>", coord.x, coord.y);
ImGui::NextColumn();
}
} // namespace polyscope