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
|
class GUI : public QMainWindow, private Ui::KinectThresholdingCppClass
{
Q_OBJECT
public:
GUI(QWidget *parent = 0, Qt::WFlags flags = 0);
~GUI();
/* Windows */
QHalconWindow *qWindow;
QVTKWidget *vtkWidget;
/* Objects */
Kinect *kinect;
/* Visualisation stuff */
PointCloud<PointXYZRGB>::ConstPtr cloud;
/* Timers */
QTimer *updateLogBrowserTimer;
/* Threads */
RGBViewerThread *rgbViewer;
private:
/* Imported GUI elements from the UI file */
Ui::KinectThresholdingCppClass ui;
/* Windows */
GUIRobotConfig *robotConfig;
GUIKinectAccelerometer *kinectAccelerometer;
/* Log file */
PJLib::Log *log;
private slots:
void startPressed(void);
void UpdateSpanValues(void);
void UpdateThresholdingChecked(void);
void StartRobotConfig(void);
void StartKinectAccelerometer(void);
void ActionViewRGB(void);
void ActionViewPoint_Cloud(void);
void UpdateLogBrowser(void);
void TestButtonPressed(void);
};
/* Constructor: make GUI */
GUI::GUI(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
setupUi(this);
this->setWindowIcon(QIcon(QString("Images/robovisionIcon.png")));
//this->setFixedSize(this->sizeHint());
qWindow = new QHalconWindow(qWindowHub);
qWindow->setMinimumSize(640, 480);
/* Setup the log browser */
this->log = new PJLib::Log("Logs\\", "Log.txt");
logBrowser->setSearchPaths(QStringList("Logs\\"));
logBrowser->setSource(QUrl::fromLocalFile("Log.txt"));
this->updateLogBrowserTimer = new QTimer(this);
this->updateLogBrowserTimer->start(500);
/* Connect the GUI to the program action */
QObject::connect(QButtonStart, SIGNAL(clicked()), this, SLOT(startPressed()));
QObject::connect(qxtSpanSliderX, SIGNAL(spanChanged(int, int)), this, SLOT(UpdateSpanValues()));
QObject::connect(qxtSpanSliderY, SIGNAL(spanChanged(int, int)), this, SLOT(UpdateSpanValues()));
QObject::connect(qxtSpanSliderZ, SIGNAL(spanChanged(int, int)), this, SLOT(UpdateSpanValues()));
QObject::connect(actionRobotConfig, SIGNAL(triggered()), this, SLOT(StartRobotConfig()));
QObject::connect(actionAccelerometer, SIGNAL(triggered()), this, SLOT(StartKinectAccelerometer()));
QObject::connect(actionViewRGB, SIGNAL(triggered()), this, SLOT(ActionViewRGB()));
QObject::connect(actionViewPoint_Cloud, SIGNAL(triggered()), this, SLOT(ActionViewPoint_Cloud()));
QObject::connect(testButton, SIGNAL(clicked()), this, SLOT(TestButtonPressed()));
QObject::connect(this->updateLogBrowserTimer, SIGNAL(timeout()), this, SLOT(UpdateLogBrowser()));
QObject::connect(this->thresholdingGroupBox, SIGNAL(toggled(bool)), this, SLOT(UpdateThresholdingChecked()));
/* Set the globals */
testWindow = qWindow->halconWindow;
lowX = qxtSpanSliderX->lowerValue();
highX = qxtSpanSliderX->upperValue();
lowY = qxtSpanSliderY->lowerValue();
highY= qxtSpanSliderY->upperValue();
lowZ = qxtSpanSliderZ->lowerValue();
highZ = qxtSpanSliderZ->upperValue();
isThresholdingChecked = thresholdingGroupBox->isChecked();
/* Initialise the kinect and create new 3D model */
bool isKinectConnected = false;
while(!isKinectConnected)
{
try
{
this->kinect = new Kinect(this->log);
isKinectConnected = true;
}
catch (exception& ex)
{
QString *error = new QString();
error->append("The kinect could not be initialised. Make sure it is connected properly (USB and Power).");
error->append("\n\nThe error message: \n");
error->append(ex.what());
QMessageBox kinectErrorBox;
kinectErrorBox.setWindowTitle("Kinect not initialised!");
kinectErrorBox.setIcon(QMessageBox::Critical);
kinectErrorBox.setText(*error);
kinectErrorBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Abort);
QIcon kinectIcon = QIcon("Images/kinectIcon.png");
kinectErrorBox.setWindowIcon(kinectIcon);
/* Set the stylesheet */
QFile file("PJStyleSheet.css"); // TO DO
file.open(QFile::ReadOnly);
QString StyleSheet = QLatin1String(file.readAll());
kinectErrorBox.setStyleSheet(StyleSheet);
kinectErrorBox.show();
switch (kinectErrorBox.exec()) {
case QMessageBox::Retry:
break;
case QMessageBox::Abort:
exit(0);
break;
default:
break;
}
}
}
model3D = new Model3D(kinect);
/* Initialise threads */
this->rgbViewer = new RGBViewerThread();
}
GUI::~GUI()
{
rgbViewer->terminate();
this->close();
exit(0);
}
void GUI::startPressed(void)
{
//boost::thread workerThread(&GUI::ViewerThread);
//workerThread.start_thread();
/*
QThread* viewerThread = new QThread();
// Move ViewerThread void to new viewerThread ???
connect(viewerThread, SIGNAL(started()), this, SLOT(ViewerThread(void)));
viewerThread->start();
*/
if(actionViewRGB->isChecked() && !rgbViewer->isRunning())
{
this->rgbViewer->start();
}
else if(actionViewPoint_Cloud->isChecked())
{
this->cloud.reset(new pcl::PointCloud<pcl::PointXYZRGB>);
this->cloud = model3D->GrabPointCloud();
/*vtkWidget = new QVTKWidget(this->qWindowHub);
boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
viewer->addPointCloud<pcl::PointXYZRGB>(cloud);*/
//pviz->addPointCloud<pcl::PointXYZRGB>(cloud);
//pviz.setBackgroundColor(0, 0, 0);
//vtkWidget->show();
/* Visualise the point cloud */
visualization::CloudViewer viewer("Point Cloud");
viewer.showCloud(cloud);
while (!viewer.wasStopped ());
}
else
{
// Should never end up here ...
}
}
void GUI::UpdateSpanValues(void)
{
lowX = qxtSpanSliderX->lowerValue();
highX = qxtSpanSliderX->upperValue();
lowY = qxtSpanSliderY->lowerValue();
highY= qxtSpanSliderY->upperValue();
lowZ = qxtSpanSliderZ->lowerValue();
highZ = qxtSpanSliderZ->upperValue();
}
void GUI::UpdateThresholdingChecked(void)
{
isThresholdingChecked = thresholdingGroupBox->isChecked();
}
/* View actions */
void GUI::ActionViewRGB(void)
{
/* Disable the other option */
actionViewPoint_Cloud->setChecked(false);
}
void GUI::ActionViewPoint_Cloud(void)
{
/* Disable the other option */
actionViewRGB->setChecked(false);
/* If the rgbViewer was running, stop it and clear the testWindow */
if(rgbViewer->isRunning())
{
rgbViewer->terminate();
// Clear the testWindow -> TO DO
}
/* Put the pointcloud window in the windowHub */
// TO DO
}
void GUI::UpdateLogBrowser(void)
{
this->logBrowser->reload();
}
/* Configuration screens */
void GUI::StartRobotConfig(void)
{
robotConfig = new GUIRobotConfig(this, this->kinect, testWindow);
robotConfig->show();
}
void GUI::StartKinectAccelerometer(void)
{
kinectAccelerometer = new GUIKinectAccelerometer(this->kinect, this);
kinectAccelerometer->show();
}
/* Test buttons */
void GUI::TestButtonPressed(void)
{
PointCloud<PointXYZRGB>::ConstPtr cloud;
try
{
cloud = model3D->PointCloudFromMultipleImagesWithRobot();
/* Visualise the point cloud */
visualization::CloudViewer viewer("Point Cloud"); // TO DO: learn to use the PCLVisualiser
viewer.showCloud(cloud);
while (!viewer.wasStopped ());
/*boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
viewer->addPointCloud(cloud, "Point Cloud");
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();*/
}
catch (exception& ex)
{
QString errorMessage;
errorMessage.append("ERROR: ");
errorMessage.append(ex.what());
QMessageBox::critical(0, "Error", errorMessage);
}
}
|