-
Notifications
You must be signed in to change notification settings - Fork 2
/
openglwidget.h
193 lines (148 loc) · 4.37 KB
/
openglwidget.h
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
#pragma once
#include "camera.h"
#include "coordinates.h"
#include "mesh.h"
#include "pvl/Box.hpp"
#include "pvl/Optional.hpp"
#include "quaternion.h"
#include "renderer.h"
#include <GL/glu.h>
#include <QFileInfo>
#include <QImageWriter>
#include <QMouseEvent>
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QWheelEvent>
class OpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions {
Q_OBJECT
struct MeshData {
Mpcv::TexturedMesh mesh;
std::string basename;
Pvl::Box3f box;
bool enabled = true;
struct {
std::vector<float> vertices;
std::vector<float> normals;
std::vector<float> uv;
std::vector<uint8_t> vertexColors;
std::vector<uint8_t> classColors;
} vis;
GLuint texture;
GLuint vbo;
bool pointCloud() const {
return mesh.faces.empty();
}
bool hasNormals() const {
// mesh always has (face) normals
return !pointCloud() || !mesh.normals.empty();
}
bool hasColors() const {
return !mesh.colors.empty();
}
bool hasAo() const {
return !mesh.ao.empty();
}
bool hasClasses() const {
return !mesh.classes.empty();
}
bool hasTexture() const {
// point cloud cannot have texture
return !pointCloud() && !mesh.uv.empty();
}
};
// Pvl::Optional<Triangle> selected;
Mpcv::Camera camera_;
float fov_ = M_PI / 4.f;
float pointSize_ = 2.f;
float pointStride_ = 1.f;
float grid_ = 1.f;
bool showGrid_ = false;
bool enableAo_ = false;
bool enableTextures_ = true;
bool enableClasses_ = false;
std::map<const void*, MeshData> meshes_;
bool wireframe_ = false;
bool dots_ = false;
bool bboxes_ = false;
bool vbos_ = true;
struct {
QPoint pos0;
Mpcv::ArcBall ab;
Mpcv::Camera state;
} mouse_;
Mpcv::RenderSettings renderSettings_;
public:
std::function<void(const QString& text)> mouseMotionCallback;
OpenGLWidget(QWidget* parent)
: QOpenGLWidget(parent) {
setMouseTracking(true);
}
virtual void initializeGL() override;
virtual void resizeGL(const int width, const int height) override;
virtual void paintGL() override;
void view(const void* handle, std::string basename, Mpcv::TexturedMesh&& mesh);
void toggle(const void* handle, bool on) {
meshes_[handle].enabled = on;
update();
}
void wireframe(const bool on) {
wireframe_ = on;
update();
}
void dots(const bool on) {
dots_ = on;
update();
}
void windows(const bool on) {
bboxes_ = on;
update();
}
void classes(const bool on) {
enableClasses_ = on;
update();
}
void deleteMesh(const void* handle);
void laplacianSmooth();
void simplify();
void repair();
void estimateNormals(std::function<bool(std::string, float)> progress);
void estimateNormals(const QString& trajectory, std::function<bool(std::string, float)> progress);
void computeAmbientOcclusion(std::function<bool(float)> progress);
void enableAo(bool on) {
enableAo_ = on;
if (on) {
enableTextures_ = false;
}
update();
}
void enableTextures(bool on) {
enableTextures_ = on;
if (on) {
enableAo_ = false;
}
update();
}
void grid(bool on) {
showGrid_ = on;
update();
}
void resetCamera();
void resetCamera(const Mpcv::Srs& srs);
void cameraUp();
void screenshot(const QString& file);
void saveAsMesh(const QString& file,
const std::vector<const void*>& handles,
std::function<bool(float)> progress);
void setRenderSettings(const Mpcv::RenderSettings& settings) {
renderSettings_ = settings;
}
bool renderView();
virtual void wheelEvent(QWheelEvent* event) override;
virtual void mousePressEvent(QMouseEvent* event) override;
virtual void mouseDoubleClickEvent(QMouseEvent* event) override;
virtual void mouseMoveEvent(QMouseEvent* ev) override;
private:
void updateCamera();
template <typename MeshFunc>
void meshOperation(const MeshFunc& meshFunc);
};