-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.h
More file actions
281 lines (218 loc) · 7.8 KB
/
context.h
File metadata and controls
281 lines (218 loc) · 7.8 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#pragma once
#include <geogram_gfx/gui/application.h> // for set_style()
#include <geogram_gfx/gui/simple_mesh_application.h>
#include <geogram/basic/file_system.h> // for is_file(), extension() in load()
#include <geogram/basic/command_line.h> // for get_arg_bool() in load()
#include <geogram/mesh/mesh_io.h> // for MeshIOFlags, mesh_load() in load()
#include <geogram/basic/command_line.h> // for CmdLine::get_arg() and CmdLine::set_arg()
#include <geogram/basic/string.h> // for String::string_ends_with()
#include "gui_base.h"
#include <ultimaille/all.h>
#include <nicostuff/algo/framework/benjamin_API.h>
#include "geom_ultimaille_binding.h"
#include "mesh_metadata.h"
// std libs
#include <optional>
enum GUIMode {
Camera,
Hover,
Filter,
Painting,
BlocPadding,
PatchPadding,
NewBlocPadding,
Polycubify,
HexCollapse,
Smooth,
Embedit,
PathConstraintPadding,
HexSplit
};
struct ViewBinding {
bool &show_attributes_;
bool &show_vertices_;
bool &show_volume_;
bool &show_surface_;
bool &show_hexes_;
float &cells_shrink_;
enum Mode {
None,
Surface,
Volume
};
const char * modes[3] = { "None", "Surface", "Volume" };
int current_mode = Surface;
index_t ¤t_colormap_index_;
std::vector<unsigned int> colormaps;
std::string &attribute_;
GEO::MeshElementsFlags &attribute_subelements_;
std::string &attribute_name_;
float &attribute_min_;
float &attribute_max_;
bool &lighting_;
void change_mode(Mode mode) {
current_mode = mode;
if (mode == ViewBinding::Mode::Surface) {
show_surface_ = true;
show_volume_ = false;
} else if (mode == ViewBinding::Mode::Volume) {
show_surface_ = false;
show_volume_ = true;
} else {
show_surface_ = false;
show_volume_ = false;
}
}
void change_mode(int i) {
change_mode((ViewBinding::Mode)i);
}
void switch_to_volume() {
change_mode(ViewBinding::Mode::Volume);
attribute_ = "";
attribute_name_ = "";
}
void switch_to_surface() {
change_mode(ViewBinding::Mode::Surface);
attribute_ = "";
attribute_name_ = "";
}
void switch_to_volume_select_mode() {
change_mode(ViewBinding::Mode::Volume);
attribute_subelements_ = GEO::MeshElementsFlags::MESH_CELLS;
attribute_ = "cells.cell_hovered";
attribute_name_ = "cell_hovered";
attribute_min_ = 0;
attribute_max_ = 2;
}
void switch_to_surface_select_mode() {
change_mode(ViewBinding::Mode::Surface);
attribute_subelements_ = GEO::MeshElementsFlags::MESH_FACETS;
attribute_ = "facets.hovered";
attribute_name_ = "hovered";
attribute_min_ = 0;
attribute_max_ = 2;
}
ImVec4 getColorFromTexture1D(GLuint textureID, int x) {
glBindTexture(GL_TEXTURE_2D, textureID);
// Get the width
GLint width;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
unsigned char pixels[width * 4];
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
int i = x * 4;
return ImVec4(pixels[i] / 255.f, pixels[i + 1] / 255.f, pixels[i + 2] / 255.f, pixels[i + 3]);
}
};
struct Context {
Context(Mesh &mesh, MeshGfx &mesh_gfx, ViewBinding view) : mesh_(mesh), mesh_gfx_(mesh_gfx), view(view) {
hex_bound = std::make_unique<MyHexBoundary>(hex);
tet_bound = std::make_unique<TetBoundary>(tet);
}
bool show_last_picked_point_ = false;
bool show_hovered_cell_overlay_ = true;
bool show_hovered_cell_facet_overlay_ = false;
float overlay_thickness = 3.;
bool region_selection_activated = false;
index_t hovered_vertex = NO_VERTEX;
index_t hovered_edge = NO_EDGE;
index_t hovered_facet = NO_FACET;
index_t hovered_cell_facet = NO_FACET;
index_t hovered_cell_lfacet = NO_FACET;
index_t hovered_cell = NO_CELL;
index_t last_hovered_vertex = NO_VERTEX;
index_t last_hovered_edge = NO_EDGE;
index_t last_hovered_facet = NO_FACET;
index_t last_hovered_cell_facet = NO_FACET;
index_t last_hovered_cell_lfacet = NO_FACET;
index_t last_hovered_cell = NO_CELL;
std::set<index_t> hovered_cells;
index_t selected_vertex = NO_VERTEX;
index_t selected_edge = NO_EDGE;
index_t selected_facet = NO_FACET;
index_t selected_cell_facet = NO_FACET;
index_t selected_cell_lfacet = NO_FACET;
index_t selected_cell = NO_CELL;
std::vector<index_t> selected_cells;
int brush_size = 1;
int um_hovered_cell_facet() {
int n_facet_per_cell =mesh_metadata.cell_type == MESH_HEX ? 6 : 4;
return um_bindings::um_facet_index_from_geo_facet_index(hovered_cell_facet, n_facet_per_cell);
}
int hovered_lhe() {
return um_bindings::he_from_cell_e_lf(hovered_edge, hovered_cell_lfacet);
}
Volume::Halfedge hovered_he(Volume &v) {
Volume::Cell c(v, hovered_cell);
return c.halfedge(hovered_lhe());
}
// TODO Please refactor this !
bool is_cell_hovered() { return (hovered_cell != NO_CELL && hovered_cell < mesh_.cells.nb()); }
bool is_facet_hovered() { return (hovered_facet != NO_FACET && hovered_facet < mesh_.facets.nb()); }
bool is_cell_facet_hovered() { return (hovered_cell_facet != NO_FACET && hovered_cell_facet < mesh_.cell_facets.nb()); }
bool is_cell_lfacet_hovered() { return (hovered_cell_lfacet != NO_FACET && hovered_cell_lfacet < 6); }
bool is_cell_edge_hovered() { return (hovered_edge != NO_EDGE && hovered_edge < 12); }
bool is_cell_selected() { return (selected_cell != NO_CELL && selected_cell < mesh_.cells.nb()); }
bool is_facet_selected() { return (selected_facet != NO_FACET && selected_facet < mesh_.facets.nb()); }
bool is_cell_facet_selected() { return (selected_cell_facet != NO_FACET && selected_cell_facet < mesh_.cell_facets.nb()); }
bool is_cell_lfacet_selected() { return (selected_cell_lfacet != NO_FACET && selected_cell_lfacet < 6); }
bool is_cell_edge_selected() { return (selected_edge != NO_EDGE && selected_edge < 12); }
void reset_hovered_selected() {
hovered_vertex = NO_VERTEX;
hovered_edge = NO_EDGE;
hovered_cell_facet = NO_FACET;
hovered_cell_lfacet = NO_FACET;
hovered_cell = NO_CELL;
selected_vertex = NO_VERTEX;
selected_edge = NO_EDGE;
selected_cell_facet = NO_FACET;
selected_cell_lfacet = NO_FACET;
selected_cell = NO_CELL;
hovered_cells.clear();
selected_cells.clear();
brush_size = 1;
}
void recompute_hex() {
// Recompute hex boundary
hex_bound = std::make_unique<MyHexBoundary>(hex);
// Make chart segmentation & init embedding
tri_chart = std::make_unique<FacetAttribute<int>>(tet_bound->tri, -1);
quad_chart = std::make_unique<FacetAttribute<int>>(hex_bound->quad, -1);
BenjaminAPI::embeditinit(tet_bound->tri, *tri_chart, hex_bound->hex, *emb_attr, *quad_chart, false);
// Recompute geo mesh
um_bindings::geo_mesh_from_hexboundary(*hex_bound, mesh_);
// Refresh view
mesh_gfx_.set_mesh(&mesh_);
}
void recompute_hex(CellFacetAttribute<bool> &selected) {
// Recompute hex boundary
hex_bound = std::make_unique<MyHexBoundary>(hex, selected);
// Make chart segmentation & init embedding
tri_chart = std::make_unique<FacetAttribute<int>>(tet_bound->tri, -1);
quad_chart = std::make_unique<FacetAttribute<int>>(hex_bound->quad, -1);
BenjaminAPI::embeditinit(tet_bound->tri, *tri_chart, hex_bound->hex, *emb_attr, *quad_chart, false);
// Recompute geo mesh
um_bindings::geo_mesh_from_hexboundary(*hex_bound, mesh_);
// Refresh view
mesh_gfx_.set_mesh(&mesh_);
}
GEO::vec3 click_pos;
bool left_mouse_pressed = false;
bool right_mouse_pressed = false;
GUIMode gui_mode = Camera;
GUIMode switch_mode = Camera;
GEO::vec3 posA;
GEO::vec3 posB;
Mesh &mesh_;
MeshGfx &mesh_gfx_;
UM::Tetrahedra tet;
UM::Hexahedra hex;
std::unique_ptr<TetBoundary> tet_bound;
std::unique_ptr<MyHexBoundary> hex_bound;
// Embedding
std::unique_ptr<CellFacetAttribute<int>> emb_attr;
std::unique_ptr<FacetAttribute<int>> tri_chart;
std::unique_ptr<FacetAttribute<int>> quad_chart;
std::vector<int> emb;
MeshMetadata mesh_metadata;
ViewBinding view;
};