1 |
#include "SMScanner.h"
|
1 |
#include "SMScanner.h"
|
2 |
#include "ui_SMScanner.h"
|
2 |
#include "ui_SMScanner.h"
|
3 |
|
3 |
|
4 |
#include <QMetaObject>
|
4 |
#include <QMetaObject>
|
5 |
#include <QFileDialog>
|
5 |
#include <QFileDialog>
|
6 |
|
6 |
|
7 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
7 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
8 |
calibrationReviewMode(false), captureReviewMode(false){
|
8 |
calibrationReviewMode(false), captureReviewMode(false){
|
9 |
|
9 |
|
10 |
// Register metatypes
|
10 |
// Register metatypes
|
11 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
11 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
12 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
12 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
13 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
13 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
14 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
14 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
15 |
qRegisterMetaType<SMCalibrationParameters>("SMCalibrationParameters");
|
15 |
qRegisterMetaType<SMCalibrationParameters>("SMCalibrationParameters");
|
16 |
qRegisterMetaTypeStreamOperators<SMCalibrationParameters>("SMCalibrationParameters");
|
16 |
qRegisterMetaTypeStreamOperators<SMCalibrationParameters>("SMCalibrationParameters");
|
17 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
17 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
18 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
18 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
19 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
19 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
20 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
20 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
21 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
21 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
22 |
|
22 |
|
23 |
// Setup ui (requires stream operators registered)
|
23 |
// Setup ui (requires stream operators registered)
|
24 |
ui->setupUi(this);
|
24 |
ui->setupUi(this);
|
25 |
|
25 |
|
26 |
// Restore geometry
|
26 |
// Restore geometry
|
27 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
27 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
28 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
28 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
29 |
|
29 |
|
30 |
// Set up threads
|
30 |
// Set up threads
|
31 |
captureWorker = new SMCaptureWorker;
|
31 |
captureWorker = new SMCaptureWorker;
|
32 |
captureWorkerThread = new QThread(this);
|
32 |
captureWorkerThread = new QThread(this);
|
33 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
33 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
34 |
captureWorker->moveToThread(captureWorkerThread);
|
34 |
captureWorker->moveToThread(captureWorkerThread);
|
35 |
captureWorkerThread->start();
|
35 |
captureWorkerThread->start();
|
36 |
|
36 |
|
37 |
// Connections
|
37 |
// Connections
|
38 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
38 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
39 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
39 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
40 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
40 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
41 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
41 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
42 |
|
42 |
|
43 |
// Start capturing
|
43 |
// Start capturing
|
44 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
44 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
45 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
45 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
46 |
|
46 |
|
47 |
}
|
47 |
}
|
48 |
|
48 |
|
49 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
49 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
50 |
|
50 |
|
51 |
if(camId == 0){
|
51 |
if(camId == 0){
|
52 |
if(!calibrationReviewMode)
|
52 |
if(!calibrationReviewMode)
|
53 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
53 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
54 |
if(!captureReviewMode)
|
54 |
if(!captureReviewMode)
|
55 |
ui->captureCamera0Widget->showImageCV(frame);
|
55 |
ui->captureCamera0Widget->showImageCV(frame);
|
56 |
} else if(camId == 1){
|
56 |
} else if(camId == 1){
|
57 |
if(!calibrationReviewMode)
|
57 |
if(!calibrationReviewMode)
|
58 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
58 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
59 |
if(!captureReviewMode)
|
59 |
if(!captureReviewMode)
|
60 |
ui->captureCamera1Widget->showImageCV(frame);
|
60 |
ui->captureCamera1Widget->showImageCV(frame);
|
61 |
}
|
61 |
}
|
62 |
}
|
62 |
}
|
63 |
|
63 |
|
64 |
void SMScanner::on_actionPreferences_triggered(){
|
64 |
void SMScanner::on_actionPreferences_triggered(){
|
65 |
|
65 |
|
66 |
preferenceDialog.show();
|
66 |
preferenceDialog.show();
|
67 |
}
|
67 |
}
|
68 |
|
68 |
|
69 |
void SMScanner::closeEvent(QCloseEvent *event){
|
69 |
void SMScanner::closeEvent(QCloseEvent *event){
|
70 |
|
70 |
|
71 |
// Stop capturing thread
|
71 |
// Stop capturing thread
|
72 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
72 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
73 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
73 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
74 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
74 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
75 |
captureWorkerThread->quit();
|
75 |
captureWorkerThread->quit();
|
76 |
captureWorkerThread->wait();
|
76 |
captureWorkerThread->wait();
|
77 |
|
77 |
|
78 |
// Save window geometry
|
78 |
// Save window geometry
|
79 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
79 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
80 |
settings.setValue("state/mainwindow", this->saveState());
|
80 |
settings.setValue("state/mainwindow", this->saveState());
|
81 |
|
81 |
|
82 |
event->accept();
|
82 |
event->accept();
|
83 |
|
83 |
|
84 |
}
|
84 |
}
|
85 |
|
85 |
|
86 |
SMScanner::~SMScanner(){
|
86 |
SMScanner::~SMScanner(){
|
87 |
delete ui;
|
87 |
delete ui;
|
88 |
}
|
88 |
}
|
89 |
|
89 |
|
90 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
90 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
91 |
|
91 |
|
92 |
// If in review mode, go back to aquisition mode
|
92 |
// If in review mode, go back to aquisition mode
|
93 |
if(calibrationReviewMode){
|
93 |
if(calibrationReviewMode){
|
94 |
ui->calibrationListWidget->clearSelection();
|
94 |
ui->calibrationListWidget->clearSelection();
|
95 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
95 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
96 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
96 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
97 |
calibrationReviewMode = false;
|
97 |
calibrationReviewMode = false;
|
98 |
return;
|
98 |
return;
|
99 |
}
|
99 |
}
|
100 |
|
100 |
|
101 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
101 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
102 |
|
102 |
|
103 |
}
|
103 |
}
|
104 |
|
104 |
|
105 |
|
105 |
|
106 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
106 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
107 |
|
107 |
|
108 |
// If in review mode, go back to aquisition mode
|
108 |
// If in review mode, go back to aquisition mode
|
109 |
if(calibrationReviewMode){
|
109 |
if(calibrationReviewMode){
|
110 |
ui->calibrationListWidget->clearSelection();
|
110 |
ui->calibrationListWidget->clearSelection();
|
111 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
111 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
112 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
112 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
113 |
calibrationReviewMode = false;
|
113 |
calibrationReviewMode = false;
|
114 |
return;
|
114 |
return;
|
115 |
}
|
115 |
}
|
116 |
|
116 |
|
117 |
// Construct vector of angles
|
117 |
// Construct vector of angles
|
118 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
118 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
119 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
119 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
120 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
120 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
121 |
|
121 |
|
122 |
if(angleStart > angleEnd)
|
122 |
if(angleStart > angleEnd)
|
123 |
angleEnd += 360;
|
123 |
angleEnd += 360;
|
124 |
|
124 |
|
125 |
std::vector<float> angles;
|
125 |
std::vector<float> angles;
|
126 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
126 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
127 |
angles.push_back(i % 360);
|
127 |
angles.push_back(i % 360);
|
128 |
|
128 |
|
129 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
129 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
130 |
|
130 |
|
131 |
std::cout << "Aquiring sets at ";
|
131 |
std::cout << "Aquiring sets at ";
|
132 |
for(int i=0; i<angles.size(); i++)
|
132 |
for(int i=0; i<angles.size(); i++)
|
133 |
std::cout << angles[i] << " ";
|
133 |
std::cout << angles[i] << " ";
|
134 |
std::cout << " degrees" <<std::endl;
|
134 |
std::cout << " degrees" <<std::endl;
|
135 |
}
|
135 |
}
|
136 |
|
136 |
|
137 |
|
137 |
|
138 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
138 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
139 |
|
139 |
|
140 |
float angle = ui->calibrationRotationDial->value();
|
140 |
float angle = ui->calibrationRotationDial->value();
|
141 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
141 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
142 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
142 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
143 |
|
143 |
|
144 |
ui->captureRotationDial->setValue(ui->calibrationRotationDial->value());
|
144 |
ui->captureRotationDial->setValue(ui->calibrationRotationDial->value());
|
145 |
}
|
145 |
}
|
146 |
|
146 |
|
147 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
147 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
148 |
calibrationData.push_back(calibrationSet);
|
148 |
calibrationData.push_back(calibrationSet);
|
149 |
|
149 |
|
150 |
// Add identifier to list
|
150 |
// Add identifier to list
|
151 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(ui->calibrationListWidget->count()).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
151 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(ui->calibrationListWidget->count()).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
152 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
152 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
153 |
item->setCheckState(Qt::Checked);
|
153 |
item->setCheckState(Qt::Checked);
|
154 |
ui->calibrationListWidget->addItem(item);
|
154 |
ui->calibrationListWidget->addItem(item);
|
155 |
|
155 |
|
156 |
// Set enabled checkmark
|
156 |
// Set enabled checkmark
|
157 |
if(calibrationData.size() >= 2)
|
157 |
if(calibrationData.size() >= 2)
|
158 |
ui->calibrateButton->setEnabled(true);
|
158 |
ui->calibrateButton->setEnabled(true);
|
159 |
}
|
159 |
}
|
160 |
|
160 |
|
161 |
void SMScanner::on_calibrateButton_clicked(){
|
161 |
void SMScanner::on_calibrateButton_clicked(){
|
162 |
|
162 |
|
163 |
// disable ui elements
|
163 |
// disable ui elements
|
164 |
ui->calibrateButton->setEnabled(false);
|
164 |
ui->calibrateButton->setEnabled(false);
|
165 |
ui->calibrationFrame->setEnabled(false);
|
165 |
ui->calibrationFrame->setEnabled(false);
|
166 |
|
166 |
|
167 |
// set checked flags
|
167 |
// set checked flags
|
168 |
for(int i=0; i<calibrationData.size(); i++){
|
168 |
for(int i=0; i<calibrationData.size(); i++){
|
169 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
169 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
170 |
}
|
170 |
}
|
171 |
|
171 |
|
172 |
// SMCalibrationWorker calibrationWorker;
|
172 |
// SMCalibrationWorker calibrationWorker;
|
173 |
// calibrationWorker.performCalibration(calibrationData);
|
173 |
// calibrationWorker.performCalibration(calibrationData);
|
174 |
|
174 |
|
175 |
// Set up calibration thread
|
175 |
// Set up calibration thread
|
176 |
calibrationWorker = new SMCalibrationWorker;
|
176 |
calibrationWorker = new SMCalibrationWorker;
|
177 |
calibrationWorkerThread = new QThread(this);
|
177 |
calibrationWorkerThread = new QThread(this);
|
178 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
178 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
179 |
calibrationWorker->moveToThread(captureWorkerThread);
|
179 |
calibrationWorker->moveToThread(captureWorkerThread);
|
180 |
calibrationWorkerThread->start();
|
180 |
calibrationWorkerThread->start();
|
181 |
|
181 |
|
182 |
// Connections
|
182 |
// Connections
|
183 |
connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
|
183 |
connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
|
184 |
connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
|
184 |
connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
|
185 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
|
185 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
|
186 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
186 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
187 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
187 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
188 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
188 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
189 |
|
189 |
|
190 |
// Start calibration
|
190 |
// Start calibration
|
191 |
QMetaObject::invokeMethod(calibrationWorker, "performCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
191 |
QMetaObject::invokeMethod(calibrationWorker, "performCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
192 |
|
192 |
|
193 |
}
|
193 |
}
|
194 |
|
194 |
|
195 |
|
195 |
|
196 |
|
196 |
|
197 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
197 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
198 |
|
198 |
|
199 |
ui->calibrationListWidget->setCurrentRow(idx);
|
199 |
ui->calibrationListWidget->setCurrentRow(idx);
|
200 |
}
|
200 |
}
|
201 |
|
201 |
|
202 |
void SMScanner::onCalibrationDone(){
|
202 |
void SMScanner::onCalibrationDone(){
|
203 |
|
203 |
|
204 |
std::cout << "Calibration done!" << std::endl;
|
204 |
std::cout << "Calibration done!" << std::endl;
|
205 |
ui->calibrateButton->setEnabled(true);
|
205 |
ui->calibrateButton->setEnabled(true);
|
206 |
ui->calibrationFrame->setEnabled(true);
|
206 |
ui->calibrationFrame->setEnabled(true);
|
207 |
|
207 |
|
208 |
}
|
208 |
}
|
209 |
|
209 |
|
210 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
210 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
211 |
|
211 |
|
212 |
// if selection is just cleared
|
212 |
// if selection is just cleared
|
213 |
if(ui->calibrationListWidget->selectedItems().empty())
|
213 |
if(ui->calibrationListWidget->selectedItems().empty())
|
214 |
return;
|
214 |
return;
|
215 |
|
215 |
|
216 |
int currentRow = ui->calibrationListWidget->currentRow();
|
216 |
int currentRow = ui->calibrationListWidget->currentRow();
|
217 |
|
217 |
|
218 |
calibrationReviewMode = true;
|
218 |
calibrationReviewMode = true;
|
219 |
ui->singleCalibrationButton->setText("Live View");
|
219 |
ui->singleCalibrationButton->setText("Live View");
|
220 |
ui->batchCalibrationButton->setText("Live View");
|
220 |
ui->batchCalibrationButton->setText("Live View");
|
221 |
|
221 |
|
222 |
if(!calibrationData[currentRow].frame0Result.empty())
|
222 |
if(!calibrationData[currentRow].frame0Result.empty())
|
223 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
223 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
224 |
else
|
224 |
else
|
225 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
225 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
226 |
|
226 |
|
227 |
if(!calibrationData[currentRow].frame1Result.empty())
|
227 |
if(!calibrationData[currentRow].frame1Result.empty())
|
228 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
228 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
229 |
else
|
229 |
else
|
230 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
230 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
231 |
|
231 |
|
232 |
// std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
|
232 |
// std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
|
233 |
}
|
233 |
}
|
234 |
|
234 |
|
235 |
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
|
235 |
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
|
236 |
|
236 |
|
237 |
// std::cout << "onCalibrationFrameResult " << idx << camID << std::endl;
|
237 |
// std::cout << "onCalibrationFrameResult " << idx << camID << std::endl;
|
238 |
|
238 |
|
239 |
if(!success)
|
239 |
if(!success)
|
240 |
ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
|
240 |
ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
|
241 |
else {
|
241 |
else {
|
242 |
if(camID == 0)
|
242 |
if(camID == 0)
|
243 |
calibrationData[idx].frame0Result = result;
|
243 |
calibrationData[idx].frame0Result = result;
|
244 |
else if(camID == 1)
|
244 |
else if(camID == 1)
|
245 |
calibrationData[idx].frame1Result = result;
|
245 |
calibrationData[idx].frame1Result = result;
|
246 |
}
|
246 |
}
|
247 |
|
247 |
|
248 |
}
|
248 |
}
|
249 |
|
249 |
|
250 |
void SMScanner::on_singleCaptureButton_clicked(){
|
250 |
void SMScanner::on_singleCaptureButton_clicked(){
|
251 |
|
251 |
|
252 |
// If in review mode, go back to aquisition mode
|
252 |
// If in review mode, go back to aquisition mode
|
253 |
if(captureReviewMode){
|
253 |
if(captureReviewMode){
|
254 |
ui->captureTreeWidget->clearSelection();
|
254 |
ui->captureTreeWidget->clearSelection();
|
255 |
ui->singleCaptureButton->setText("Single Aquisition");
|
255 |
ui->singleCaptureButton->setText("Single Aquisition");
|
256 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
256 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
257 |
captureReviewMode = false;
|
257 |
captureReviewMode = false;
|
258 |
return;
|
258 |
return;
|
259 |
}
|
259 |
}
|
260 |
|
260 |
|
261 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
261 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
262 |
|
262 |
|
263 |
}
|
263 |
}
|
264 |
|
264 |
|
265 |
|
265 |
|
266 |
void SMScanner::on_batchCaptureButton_clicked(){
|
266 |
void SMScanner::on_batchCaptureButton_clicked(){
|
267 |
|
267 |
|
268 |
// If in review mode, go back to aquisition mode
|
268 |
// If in review mode, go back to aquisition mode
|
269 |
if(captureReviewMode){
|
269 |
if(captureReviewMode){
|
270 |
ui->captureTreeWidget->clearSelection();
|
270 |
ui->captureTreeWidget->clearSelection();
|
271 |
ui->singleCaptureButton->setText("Single Aquisition");
|
271 |
ui->singleCaptureButton->setText("Single Aquisition");
|
272 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
272 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
273 |
captureReviewMode = false;
|
273 |
captureReviewMode = false;
|
274 |
return;
|
274 |
return;
|
275 |
}
|
275 |
}
|
276 |
|
276 |
|
277 |
// Construct vector of angles
|
277 |
// Construct vector of angles
|
278 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
278 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
279 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
279 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
280 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
280 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
281 |
|
281 |
|
282 |
if(angleStart > angleEnd)
|
282 |
if(angleStart > angleEnd)
|
283 |
angleEnd += 360;
|
283 |
angleEnd += 360;
|
284 |
|
284 |
|
285 |
std::vector<float> angles;
|
285 |
std::vector<float> angles;
|
286 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
286 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
287 |
angles.push_back(i % 360);
|
287 |
angles.push_back(i % 360);
|
288 |
|
288 |
|
289 |
std::cout << "Aquiring sequences at ";
|
289 |
std::cout << "Aquiring sequences at ";
|
290 |
for(int i=0; i<angles.size(); i++)
|
290 |
for(int i=0; i<angles.size(); i++)
|
291 |
std::cout << angles[i] << " ";
|
291 |
std::cout << angles[i] << " ";
|
292 |
std::cout << " degrees" <<std::endl;
|
292 |
std::cout << " degrees" <<std::endl;
|
293 |
|
293 |
|
294 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
294 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
295 |
}
|
295 |
}
|
296 |
|
296 |
|
297 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
297 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
298 |
|
298 |
|
299 |
float angle = ui->captureRotationDial->value();
|
299 |
float angle = ui->captureRotationDial->value();
|
300 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
300 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
301 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
301 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
302 |
|
302 |
|
303 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
303 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
304 |
}
|
304 |
}
|
305 |
|
305 |
|
306 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
306 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
307 |
|
307 |
|
308 |
captureData.push_back(frameSequence);
|
308 |
captureData.push_back(frameSequence);
|
309 |
|
309 |
|
310 |
int idx = captureData.size()-1;
|
310 |
int idx = captureData.size()-1;
|
311 |
|
311 |
|
312 |
// Add identifier to list
|
312 |
// Add identifier to list
|
313 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
313 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
314 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(idx).arg(frameSequence.rotationAngle));
|
314 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(idx).arg(frameSequence.rotationAngle));
|
315 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
315 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
316 |
item->setData(0, Qt::UserRole, QPoint(idx, -1));
|
316 |
item->setData(0, Qt::UserRole, QPoint(idx, -1));
|
317 |
item->setCheckState(0, Qt::Checked);
|
317 |
item->setCheckState(0, Qt::Checked);
|
318 |
//ui->captureTreeWidget->addItem(item);
|
318 |
//ui->captureTreeWidget->addItem(item);
|
319 |
|
319 |
|
320 |
for(int i=0; i<frameSequence.frames0.size(); i++){
|
320 |
for(int i=0; i<frameSequence.frames0.size(); i++){
|
321 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
321 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
322 |
subItem->setText(0, QString("frames %1").arg(i));
|
322 |
subItem->setText(0, QString("frames %1").arg(i));
|
323 |
subItem->setData(0, Qt::UserRole, QPoint(idx, i));
|
323 |
subItem->setData(0, Qt::UserRole, QPoint(idx, i));
|
324 |
}
|
324 |
}
|
325 |
|
325 |
|
326 |
ui->reconstructButton->setEnabled(true);
|
326 |
ui->reconstructButton->setEnabled(true);
|
327 |
}
|
327 |
}
|
328 |
|
328 |
|
329 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
329 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
330 |
|
330 |
|
331 |
// if selection is just cleared
|
331 |
// if selection is just cleared
|
332 |
if(ui->captureTreeWidget->selectedItems().empty())
|
332 |
if(ui->captureTreeWidget->selectedItems().empty())
|
333 |
return;
|
333 |
return;
|
334 |
|
334 |
|
335 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
335 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
336 |
|
336 |
|
337 |
captureReviewMode = true;
|
337 |
captureReviewMode = true;
|
338 |
|
338 |
|
339 |
ui->singleCaptureButton->setText("Live View");
|
339 |
ui->singleCaptureButton->setText("Live View");
|
340 |
ui->batchCaptureButton->setText("Live View");
|
340 |
ui->batchCaptureButton->setText("Live View");
|
341 |
|
341 |
|
342 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
342 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
343 |
|
343 |
|
344 |
if(idx.y() != -1){
|
344 |
if(idx.y() != -1){
|
345 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
345 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
346 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
346 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
347 |
}
|
347 |
}
|
348 |
|
348 |
|
349 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
349 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
350 |
}
|
350 |
}
|
351 |
|
351 |
|
352 |
|
352 |
|
353 |
void SMScanner::onReceiveRotatedTo(float angle){
|
353 |
void SMScanner::onReceiveRotatedTo(float angle){
|
354 |
|
354 |
|
355 |
// update ui with new position
|
355 |
// update ui with new position
|
356 |
ui->calibrationRotationDial->setValue(angle);
|
356 |
ui->calibrationRotationDial->setValue(angle);
|
357 |
ui->captureRotationDial->setValue(angle);
|
357 |
ui->captureRotationDial->setValue(angle);
|
358 |
|
358 |
|
359 |
}
|
359 |
}
|
360 |
|
360 |
|
361 |
void SMScanner::on_actionExport_Sets_triggered(){
|
361 |
void SMScanner::on_actionExport_Sets_triggered(){
|
362 |
|
362 |
|
363 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
363 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
364 |
for(int i=0; i<calibrationData.size(); i++){
|
364 |
for(int i=0; i<calibrationData.size(); i++){
|
365 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
365 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
366 |
cv::Mat frameBGR;
|
366 |
cv::Mat frameBGR;
|
367 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_RGB2BGR);
|
367 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_RGB2BGR);
|
368 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
368 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
369 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
369 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
370 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
370 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
371 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
371 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
372 |
}
|
372 |
}
|
373 |
|
373 |
|
374 |
}
|
374 |
}
|
375 |
|
375 |
|
376 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
376 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
377 |
|
377 |
|
378 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
378 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
379 |
|
379 |
|
380 |
for(int i=0; i<captureData.size(); i++){
|
380 |
for(int i=0; i<captureData.size(); i++){
|
381 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
381 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
382 |
if(!QDir().mkdir(seqDirName))
|
382 |
if(!QDir().mkdir(seqDirName))
|
383 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
383 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
384 |
for(int j=0; j<captureData[i].frames0.size(); j++){
|
384 |
for(int j=0; j<captureData[i].frames0.size(); j++){
|
385 |
QString fileName = QString("%1/frames0_%2.png").arg(seqDirName).arg(j);
|
385 |
QString fileName = QString("%1/frames0_%2.png").arg(seqDirName).arg(j);
|
386 |
cv::Mat frameBGR;
|
386 |
cv::Mat frameBGR;
|
387 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_RGB2BGR);
|
387 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_RGB2BGR);
|
388 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
388 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
389 |
}
|
389 |
}
|
390 |
for(int j=0; j<captureData[i].frames1.size(); j++){
|
390 |
for(int j=0; j<captureData[i].frames1.size(); j++){
|
391 |
QString fileName = QString("%1/frames1_%2.png").arg(seqDirName).arg(j);
|
391 |
QString fileName = QString("%1/frames1_%2.png").arg(seqDirName).arg(j);
|
392 |
cv::Mat frameBGR;
|
392 |
cv::Mat frameBGR;
|
393 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_RGB2BGR);
|
393 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_RGB2BGR);
|
394 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
394 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
395 |
}
|
395 |
}
|
396 |
}
|
396 |
}
|
397 |
}
|
397 |
}
|
398 |
|
398 |
|
399 |
void SMScanner::on_reconstructButton_clicked(){
|
399 |
void SMScanner::on_reconstructButton_clicked(){
|
400 |
|
400 |
|
401 |
// // set checked flags
|
401 |
// // set checked flags
|
402 |
// for(int i=0; i<captureData.size(); i++){
|
402 |
// for(int i=0; i<captureData.size(); i++){
|
403 |
// captureData[i].checked = (ui->captureTreeWidget->item(i)->checkState() == Qt::Checked);
|
403 |
// captureData[i].checked = (ui->captureTreeWidget->item(i)->checkState() == Qt::Checked);
|
404 |
// }
|
404 |
// }
|
405 |
|
405 |
|
406 |
|
406 |
|
407 |
// Set up reconstruction thread
|
407 |
// Set up reconstruction thread
|
408 |
reconstructionWorker = new SMReconstructionWorker;
|
408 |
reconstructionWorker = new SMReconstructionWorker;
|
409 |
reconstructionWorkerThread = new QThread(this);
|
409 |
reconstructionWorkerThread = new QThread(this);
|
410 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
410 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
411 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
411 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
412 |
reconstructionWorkerThread->start();
|
412 |
reconstructionWorkerThread->start();
|
413 |
|
413 |
|
414 |
// Connections
|
414 |
// Connections
|
415 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onNewPointCloud(SMPointCloud)));
|
415 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onNewPointCloud(SMPointCloud)));
|
416 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
416 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
417 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
417 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
418 |
|
418 |
|
419 |
// Start reconstructing
|
419 |
// Start reconstructing
|
420 |
QMetaObject::invokeMethod(reconstructionWorker, "setup");
|
420 |
QMetaObject::invokeMethod(reconstructionWorker, "setup");
|
421 |
QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointClouds", Q_ARG(std::vector<SMFrameSequence>, captureData));
|
421 |
QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointClouds", Q_ARG(std::vector<SMFrameSequence>, captureData));
|
422 |
|
422 |
|
423 |
}
|
423 |
}
|
424 |
|
424 |
|
425 |
void SMScanner::onNewPointCloud(SMPointCloud smCloud){
|
425 |
void SMScanner::onNewPointCloud(SMPointCloud smCloud){
|
426 |
|
426 |
|
427 |
pointCloudData.push_back(smCloud);
|
427 |
pointCloudData.push_back(smCloud);
|
- |
|
428 |
int id = pointCloudData.size()-1;
|
428 |
|
429 |
|
429 |
// Add identifier to list
|
430 |
// Add identifier to list
|
430 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(ui->pointCloudsListWidget->count()).arg(smCloud.rotationAngle), ui->pointCloudsListWidget);
|
431 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(id).arg(smCloud.rotationAngle), ui->pointCloudsListWidget);
|
431 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
432 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
432 |
item->setCheckState(Qt::Checked);
|
433 |
item->setCheckState(Qt::Checked);
|
433 |
ui->pointCloudsListWidget->addItem(item);
|
434 |
ui->pointCloudsListWidget->addItem(item);
|
434 |
|
435 |
|
435 |
ui->pointCloudWidget->addPointCloud(smCloud.pointCloud);
|
436 |
ui->pointCloudWidget->addPointCloud(smCloud.pointCloud, id);
|
436 |
}
|
437 |
}
|
437 |
|
438 |
|
438 |
void SMScanner::on_actionExport_Calibration_triggered(){
|
439 |
void SMScanner::on_actionExport_Calibration_triggered(){
|
439 |
|
440 |
|
440 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
441 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
441 |
QFileInfo info(fileName);
|
442 |
QFileInfo info(fileName);
|
442 |
QString type = info.suffix();
|
443 |
QString type = info.suffix();
|
443 |
if(type == ""){
|
444 |
if(type == ""){
|
444 |
fileName.append(".xml");
|
445 |
fileName.append(".xml");
|
445 |
}
|
446 |
}
|
446 |
|
447 |
|
447 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
448 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
448 |
calibration.exportToXML(fileName);
|
449 |
calibration.exportToXML(fileName);
|
449 |
}
|
450 |
}
|
450 |
|
451 |
|