-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathbasics_test.cpp
More file actions
284 lines (202 loc) · 7.43 KB
/
basics_test.cpp
File metadata and controls
284 lines (202 loc) · 7.43 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
282
283
284
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope_test.h"
#include "polyscope/curve_network.h"
#include "polyscope/pick.h"
#include "polyscope/point_cloud.h"
#include "polyscope/polyscope.h"
#include "polyscope/surface_mesh.h"
#include "polyscope/types.h"
#include "polyscope/volume_mesh.h"
#include "gtest/gtest.h"
#include <array>
#include <iostream>
#include <list>
#include <string>
#include <vector>
// ============================================================
// =============== Basic tests
// ============================================================
// Show the gui. Note that the pre-suite script calls Polyscope::init() before
TEST_F(PolyscopeTest, InitializeAndShow) { polyscope::show(3); }
TEST_F(PolyscopeTest, FrameTick) {
for (int i = 0; i < 5; i++) {
polyscope::frameTick();
}
}
TEST_F(PolyscopeTest, FrameTickWithImgui) {
auto showCallback = [&]() { ImGui::Button("do something"); };
polyscope::state::userCallback = showCallback;
for (int i = 0; i < 5; i++) {
polyscope::frameTick();
}
polyscope::state::userCallback = nullptr;
}
// We should be able to nest calls to show() via the callback. ImGUI causes headaches here
TEST_F(PolyscopeTest, NestedShow) {
auto showCallback = [&]() { polyscope::show(3); };
polyscope::state::userCallback = showCallback;
polyscope::show(3);
polyscope::state::userCallback = nullptr;
}
TEST_F(PolyscopeTest, NestedShowWithFrameTick) {
auto showCallback = [&]() { polyscope::show(3); };
polyscope::state::userCallback = showCallback;
for (int i = 0; i < 3; i++) {
polyscope::frameTick();
}
polyscope::state::userCallback = nullptr;
}
TEST_F(PolyscopeTest, Unshow) {
int32_t count = 0;
auto showCallback = [&]() {
if (count > 1) {
polyscope::unshow();
}
count++;
};
polyscope::state::userCallback = showCallback;
polyscope::show(10);
EXPECT_LT(count, 4);
polyscope::state::userCallback = nullptr;
}
TEST_F(PolyscopeTest, ShutdownAndReinitialize) {
polyscope::shutdown();
SetUpTestSuite();
polyscope::show(3);
// do it twice -- we've had some bugs where the first shutdown doesn't clean up properly
polyscope::shutdown();
SetUpTestSuite();
polyscope::show(3);
}
// Make sure that creating an empty buffer does not throw errors
TEST_F(PolyscopeTest, EmptyBuffer) {
std::vector<glm::vec3> empty_points;
polyscope::PointCloud* psPoints = polyscope::registerPointCloud("empty cloud", empty_points);
polyscope::show(3);
std::vector<std::array<uint32_t, 2>> empty_edges;
polyscope::CurveNetwork* psNet = polyscope::registerCurveNetwork("empty curve", empty_points, empty_edges);
polyscope::show(3);
polyscope::removeAllStructures();
}
TEST_F(PolyscopeTest, WindowProperties) {
// set/get window size
int32_t target_w = 500;
int32_t target_h = 300;
polyscope::view::setWindowSize(target_w, target_h);
int32_t w, h;
std::tie(w, h) = polyscope::view::getWindowSize();
EXPECT_EQ(w, target_w);
EXPECT_EQ(h, target_h);
polyscope::show(3);
// get buffer size
// (hard to say what this should be, given hi-dpi etc)
int32_t buffer_w, buffer_h;
std::tie(buffer_w, buffer_h) = polyscope::view::getBufferSize();
float target_aspect = target_w / static_cast<float>(target_h);
float buffer_aspect = buffer_w / static_cast<float>(buffer_h);
EXPECT_NEAR(target_aspect, buffer_aspect, 0.01);
// resizable
polyscope::view::setWindowResizable(false);
EXPECT_FALSE(polyscope::view::getWindowResizable());
polyscope::show(3);
}
TEST_F(PolyscopeTest, Screenshot) {
polyscope::screenshot("test_screeshot.png");
polyscope::screenshot();
polyscope::ScreenshotOptions opts;
opts.includeUI = true;
opts.transparentBackground = false;
polyscope::screenshot(opts);
}
TEST_F(PolyscopeTest, ScreenshotBuffer) {
std::vector<unsigned char> buff = polyscope::screenshotToBuffer();
EXPECT_EQ(buff.size(), polyscope::view::bufferWidth * polyscope::view::bufferHeight * 4);
std::vector<unsigned char> buff2 = polyscope::screenshotToBuffer(false);
EXPECT_EQ(buff2.size(), polyscope::view::bufferWidth * polyscope::view::bufferHeight * 4);
}
TEST_F(PolyscopeTest, ImPlotBasic) {
std::vector<float> xvals = {0., 2., 4., 8.};
auto showCallback = [&]() {
ImGui::Button("do something");
if (ImPlot::BeginPlot("test plot")) {
ImPlot::PlotLine("test line", &xvals.front(), xvals.size());
ImPlot::EndPlot();
}
};
polyscope::state::userCallback = showCallback;
polyscope::show(3);
for (int i = 0; i < 3; i++) {
polyscope::frameTick();
}
polyscope::state::userCallback = nullptr;
}
TEST_F(PolyscopeTest, ImPlotScreenshot) {
// test this because there is some context logic duplicated there
std::vector<float> xvals = {0., 2., 4., 8.};
auto showCallback = [&]() {
ImGui::Button("do something");
if (ImPlot::BeginPlot("test plot")) {
ImPlot::PlotLine("test line", &xvals.front(), xvals.size());
ImPlot::EndPlot();
}
};
polyscope::state::userCallback = showCallback;
polyscope::show(3);
polyscope::ScreenshotOptions opts;
opts.includeUI = true;
opts.transparentBackground = false;
polyscope::screenshot(opts);
polyscope::show(3);
polyscope::state::userCallback = nullptr;
}
// ============================================================
// =============== View and navigation
// ============================================================
TEST_F(PolyscopeTest, NavigationMode) {
// Cycle through the navigation options
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Turntable);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Free);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Planar);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Arcball);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::None);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::FirstPerson);
polyscope::show(3);
polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Turntable); // set back to usual default
}
TEST_F(PolyscopeTest, UIScale) {
// this should trigger a reload of the font atlas
polyscope::options::uiScale = 1.25;
polyscope::show(3);
polyscope::options::uiScale = 1.;
polyscope::show(3);
}
// ============================================================
// =============== Ground plane tests
// ============================================================
TEST_F(PolyscopeTest, GroundPlaneTest) {
// Add a structure and cycle through the ground plane options
auto psMesh = registerTriangleMesh();
polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::None;
polyscope::refresh();
polyscope::show(3);
polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::Tile;
polyscope::refresh();
polyscope::show(3);
polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::TileReflection;
polyscope::refresh();
polyscope::show(3);
polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::ShadowOnly;
polyscope::refresh();
polyscope::show(3);
polyscope::options::groundPlaneHeightMode = polyscope::GroundPlaneHeightMode::Manual;
polyscope::options::groundPlaneHeight = -0.3;
polyscope::show(3);
polyscope::options::groundPlaneHeightMode = polyscope::GroundPlaneHeightMode::Automatic;
polyscope::show(3);
polyscope::removeAllStructures();
}