forked from nmwsharp/polyscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasics_test.cpp
More file actions
206 lines (146 loc) · 5.66 KB
/
basics_test.cpp
File metadata and controls
206 lines (146 loc) · 5.66 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
// 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
polyscope::view::setWindowSize(300, 400);
int32_t w, h;
std::tie(w, h) = polyscope::view::getWindowSize();
EXPECT_EQ(w, 300);
EXPECT_EQ(h, 400);
// get buffer size
// (hard to say what this should be, given hi-dpi etc)
std::tie(w, h) = polyscope::view::getBufferSize();
// resizable
polyscope::view::setWindowResizable(false);
EXPECT_FALSE(polyscope::view::getWindowResizable());
polyscope::show(3);
}
TEST_F(PolyscopeTest, Screenshot) { polyscope::screenshot("test_screeshot.png"); }
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);
}
// ============================================================
// =============== 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
}
// ============================================================
// =============== 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();
}