| 287 |
Kevin |
1 |
#include "MainWindow.h"
|
|
|
2 |
#include "ImageWidget.h"
|
|
|
3 |
#include "OpenNI.h"
|
|
|
4 |
#include "DepthProcessor.h"
|
|
|
5 |
#include "RobotControl.h"
|
|
|
6 |
|
|
|
7 |
#include <QtWidgets>
|
|
|
8 |
|
|
|
9 |
MainWindow::MainWindow(QWidget *parent)
|
|
|
10 |
: QWidget(parent) {
|
|
|
11 |
|
|
|
12 |
// Create the widgets that go on the GUI
|
|
|
13 |
statusLabel = new QLabel();
|
|
|
14 |
statusLabel->setFixedHeight(statusLabel->sizeHint().height());
|
|
|
15 |
statusLabel->setText("Initializing OpenNI...");
|
|
|
16 |
|
|
|
17 |
frameLabel = new QLabel();
|
|
|
18 |
frameLabel->setFixedHeight(frameLabel->sizeHint().height());
|
|
|
19 |
frameLabel->setText("Frame: ??");
|
|
|
20 |
|
|
|
21 |
fpsLabel = new QLabel();
|
|
|
22 |
fpsLabel->setFixedHeight(fpsLabel->sizeHint().height());
|
|
|
23 |
fpsLabel->setText("FPS: ??");
|
|
|
24 |
|
|
|
25 |
topLeftImage = new ImageWidget();
|
|
|
26 |
topLeftImage->setSize(X_RES, Y_RES);
|
|
|
27 |
topLeftImage->setText("Initializing OpenNI...");
|
|
|
28 |
topRightImage = new ImageWidget();
|
|
|
29 |
topRightImage->setSize(X_RES, Y_RES);
|
|
|
30 |
topRightImage->setText("Initializing OpenNI...");
|
|
|
31 |
botLeftImage = new ImageWidget();
|
|
|
32 |
botLeftImage->setSize(X_RES, Y_RES);
|
|
|
33 |
botLeftImage->setText("Initializing OpenNI...");
|
|
|
34 |
botRightImage = new ImageWidget();
|
|
|
35 |
botRightImage->setSize(X_RES, Y_RES);
|
|
|
36 |
botRightImage->setText("Initializing OpenNI...");
|
|
|
37 |
|
|
|
38 |
topLeftSelect = new QComboBox();
|
|
|
39 |
topLeftSelect->setFocusPolicy(Qt::NoFocus);
|
|
|
40 |
topRightSelect = new QComboBox();
|
|
|
41 |
topRightSelect->setFocusPolicy(Qt::NoFocus);
|
|
|
42 |
botLeftSelect = new QComboBox();
|
|
|
43 |
botLeftSelect->setFocusPolicy(Qt::NoFocus);
|
|
|
44 |
botRightSelect = new QComboBox();
|
|
|
45 |
botRightSelect->setFocusPolicy(Qt::NoFocus);
|
|
|
46 |
QStringList imageList;
|
|
|
47 |
imageList.append("Raw Depth");
|
|
|
48 |
imageList.append("Last Valid Depth");
|
|
|
49 |
imageList.append("Movement Mask Raw Depth");
|
|
|
50 |
imageList.append("Movement Mask Average Depth");
|
|
|
51 |
imageList.append("Processed Depth");
|
|
|
52 |
imageList.append("Movement Map");
|
|
|
53 |
imageList.append("Raw Depth Horizon");
|
|
|
54 |
imageList.append("Last Valid Horizon");
|
|
|
55 |
imageList.append("Overlay Horizon");
|
|
|
56 |
updateSelectionList(imageList);
|
|
|
57 |
|
|
|
58 |
// Initialize the widgets for controlling the robot
|
|
|
59 |
robot = new RobotControl();
|
|
|
60 |
|
|
|
61 |
// Add all GUI widgets to a layout
|
|
|
62 |
QGridLayout *mainLayout = new QGridLayout();
|
|
|
63 |
mainLayout->addWidget(statusLabel, 0, 0, 1, 3);
|
|
|
64 |
mainLayout->addWidget(frameLabel, 0, 5, 1, 1, Qt::AlignRight);
|
|
|
65 |
mainLayout->addWidget(fpsLabel, 0, 6, 1, 1, Qt::AlignRight);
|
|
|
66 |
|
|
|
67 |
mainLayout->addWidget(topLeftSelect, 1, 0, 1, 3);
|
|
|
68 |
mainLayout->addWidget(topLeftImage, 2, 0, 1, 3);
|
|
|
69 |
|
|
|
70 |
mainLayout->addWidget(topRightSelect, 1, 4, 1, 3);
|
|
|
71 |
mainLayout->addWidget(topRightImage, 2, 4, 1, 3);
|
|
|
72 |
|
|
|
73 |
mainLayout->addWidget(botLeftSelect, 3, 0, 1, 3);
|
|
|
74 |
mainLayout->addWidget(botLeftImage, 4, 0, 1, 3);
|
|
|
75 |
|
|
|
76 |
mainLayout->addWidget(botRightSelect, 3, 4, 1, 3);
|
|
|
77 |
mainLayout->addWidget(botRightImage, 4, 4, 1, 3);
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
mainLayout->addWidget(robot, 5, 0, 1, 7);
|
|
|
81 |
|
|
|
82 |
setLayout(mainLayout);
|
|
|
83 |
|
|
|
84 |
setWindowTitle("RGBD Depth Map");
|
|
|
85 |
|
|
|
86 |
// Initialize the threads for pulling and processing depth data
|
|
|
87 |
openNIThread = new OpenNI();
|
|
|
88 |
openNIProcessor = new DepthProcessor();
|
|
|
89 |
|
|
|
90 |
connect(topLeftSelect, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
|
|
|
91 |
connect(topRightSelect, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
|
|
|
92 |
connect(botLeftSelect, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
|
|
|
93 |
connect(botRightSelect, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
|
|
|
94 |
|
|
|
95 |
connect(openNIThread, SIGNAL(setStatusString(QString)), this, SLOT(updateStatusText(QString)));
|
|
|
96 |
connect(openNIThread, SIGNAL(setFrameString(QString)), this, SLOT(updateFrameText(QString)));
|
|
|
97 |
connect(openNIThread, SIGNAL(setFPSString(QString)), this, SLOT(updateFPSText(QString)));
|
|
|
98 |
connect(openNIThread, SIGNAL(processDepthData(cv::Mat)), openNIProcessor, SLOT(processDepthData(cv::Mat)));
|
|
|
99 |
connect(openNIThread, SIGNAL(sensorConnected()), this, SLOT(sensorConnected()));
|
|
|
100 |
connect(openNIProcessor, SIGNAL(setImageTopLeft(QImage)), topLeftImage, SLOT(updateImage(QImage)));
|
|
|
101 |
connect(openNIProcessor, SIGNAL(setImageTopRight(QImage)), topRightImage, SLOT(updateImage(QImage)));
|
|
|
102 |
connect(openNIProcessor, SIGNAL(setImageBotLeft(QImage)), botLeftImage, SLOT(updateImage(QImage)));
|
|
|
103 |
connect(openNIProcessor, SIGNAL(setImageBotRight(QImage)), botRightImage, SLOT(updateImage(QImage)));
|
|
|
104 |
connect(openNIThread, SIGNAL(setFOV(float, float)), openNIProcessor, SLOT(setFOV(float, float)));
|
|
|
105 |
connect(this, SIGNAL(changeDisplayImage(int, QString)), openNIProcessor, SLOT(setDisplayImage(int, QString)));
|
|
|
106 |
|
|
|
107 |
// Start the thread for processing depth data from the sensor
|
|
|
108 |
openNIProcessor->start(QThread::HighPriority);
|
|
|
109 |
// Start the thread for reading depth data from the sensor
|
|
|
110 |
openNIThread->start();
|
|
|
111 |
|
|
|
112 |
setFixedSize(this->sizeHint());
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
MainWindow::~MainWindow() {
|
|
|
116 |
delete(topLeftImage);
|
|
|
117 |
delete(topRightImage);
|
|
|
118 |
delete(botLeftImage);
|
|
|
119 |
delete(botRightImage);
|
|
|
120 |
|
|
|
121 |
delete(topLeftSelect);
|
|
|
122 |
delete(topRightSelect);
|
|
|
123 |
delete(botLeftSelect);
|
|
|
124 |
delete(botRightSelect);
|
|
|
125 |
|
|
|
126 |
delete(robot);
|
|
|
127 |
|
|
|
128 |
delete(statusLabel);
|
|
|
129 |
delete(frameLabel);
|
|
|
130 |
delete(fpsLabel);
|
|
|
131 |
|
|
|
132 |
openNIThread->terminate();
|
|
|
133 |
openNIProcessor->terminate();
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
void MainWindow::updateStatusText(const QString &string) {
|
|
|
137 |
statusLabel->setText(string);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
void MainWindow::updateFrameText(const QString &string) {
|
|
|
141 |
frameLabel->setText("Frame: " + string);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
void MainWindow::updateFPSText(const QString &string) {
|
|
|
145 |
fpsLabel->setText("FPS: " + string);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
void MainWindow::updateSelectionList(const QStringList &list) {
|
|
|
149 |
topLeftSelect->addItems(list);
|
|
|
150 |
topRightSelect->addItems(list);
|
|
|
151 |
botLeftSelect->addItems(list);
|
|
|
152 |
botRightSelect->addItems(list);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
void MainWindow::imageSelectionChanged(const QString &str) {
|
|
|
156 |
if (sender() == topLeftSelect) {
|
|
|
157 |
emit changeDisplayImage(0, str);
|
|
|
158 |
} else if (sender() == topRightSelect) {
|
|
|
159 |
emit changeDisplayImage(1, str);
|
|
|
160 |
} else if (sender() == botLeftSelect) {
|
|
|
161 |
emit changeDisplayImage(2, str);
|
|
|
162 |
} else if (sender() == botRightSelect) {
|
|
|
163 |
emit changeDisplayImage(3, str);
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
void MainWindow::sensorConnected() {
|
|
|
168 |
emit changeDisplayImage(0, "Raw Depth");
|
|
|
169 |
emit changeDisplayImage(1, "Raw Depth Horizon");
|
|
|
170 |
emit changeDisplayImage(2, "Processed Depth");
|
|
|
171 |
emit changeDisplayImage(3, "Overlay Horizon");
|
|
|
172 |
topLeftSelect->setCurrentIndex(0);
|
|
|
173 |
topRightSelect->setCurrentIndex(6);
|
|
|
174 |
botLeftSelect->setCurrentIndex(4);
|
|
|
175 |
botRightSelect->setCurrentIndex(8);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
void MainWindow::keyPressEvent(QKeyEvent *event) {
|
|
|
179 |
// Send keypress events to the robot handing code
|
|
|
180 |
robot->handleKeyPress(event);
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
void MainWindow::keyReleaseEvent(QKeyEvent *event) {
|
|
|
184 |
// Send keypress events to the robot handing code
|
|
|
185 |
robot->handleKeyRelease(event);
|
|
|
186 |
}
|