-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSLPointCloudWidgetOld.cpp
106 lines (88 loc) · 2.64 KB
/
SLPointCloudWidgetOld.cpp
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
#include "SLPointCloudWidget.h"
#include <cmath>
#ifdef __APPLE__
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
void SLPointCloudWidget::updatePointCloud(cv::Mat _pointCloud, cv::Mat _shading){
pointCloud = _pointCloud;
shading = _shading;
this->updateGL();
emit newPointCloudDisplayed();
}
void SLPointCloudWidget::initializeGL() {
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void SLPointCloudWidget::resizeGL(int w, int h) {
//TODO: emulate camera viewpoint
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(26, (float)w/(float)h, 0, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0);
}
void SLPointCloudWidget::paintGL(){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0);
glTranslatef(0.0, 0.0, 250.0);
glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glRotatef(rotationZ, 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.0, -250.0);
glClear(GL_COLOR_BUFFER_BIT);
// Draw coordinate system
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3i(0,0,0);
glVertex3i(100,0,0);
glEnd();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3i(0,0,0);
glVertex3i(0,100,0);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3i(0,0,0);
glVertex3i(0,0,100);
glEnd();
// Draw points
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POINTS);
for (int row = 0; row<pointCloud.rows; row++){
for (int col = 0; col<pointCloud.cols; col++){
const cv::Vec3f pnt = pointCloud.at<cv::Vec3f>(row,col);
const float shade = shading.at<float>(row,col);
glColor3f(shade, shade, shade);
glVertex3f(pnt[0], pnt[1], pnt[2]);
}
}
glEnd();
}
void SLPointCloudWidget::mousePressEvent(QMouseEvent *event){
lastMousePos = event->pos();
}
void SLPointCloudWidget::mouseMoveEvent(QMouseEvent *event){
GLfloat dx = GLfloat(event->x() - lastMousePos.x()) / width();
GLfloat dy = GLfloat(event->y() - lastMousePos.y()) / height();
if (event->buttons() & Qt::LeftButton) {
rotationX += 50 * dy;
rotationY += 50 * dx;
updateGL();
} else if (event->buttons() & Qt::RightButton) {
rotationX += 50 * dy;
rotationZ += 50 * dx;
updateGL();
}
lastMousePos = event->pos();
}
void SLPointCloudWidget::mouseDoubleClickEvent(QMouseEvent*){
rotationX = 0;
rotationY = 0;
rotationZ = 0;
updateGL();
}