-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubwindow.cpp
352 lines (285 loc) · 7.84 KB
/
subwindow.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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include<Qt3DRender/QTexture>
#include "subwindow.h"
#include "ui_subwindow.h"
#include <QMessageBox>
bool isInit = false;
float RA = 0;
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
isCamera = false;
isModel = false;
isvGuide = false;
isCollection = false;
connect(ui->actionRegistration, SIGNAL(triggered()), this, SLOT(Regist()));
connect(ui->actionLoad_Model, SIGNAL(triggered()), this, SLOT(onLoadModel()));
aimooeThread = new QThread();
aimooeOperator::GetInstance().moveToThread(aimooeThread);
connect(ui->actionOpen_NDI, SIGNAL(triggered()), this, SLOT(openNDI()));
connect(aimooeThread, SIGNAL(started()), &aimooeOperator::GetInstance(), SLOT(openAimooe()));
connect(ui->actionOpen_Camera, SIGNAL(triggered()), this, SLOT(on_btnCameraCtrl_clicked()));
connect(ui->actionLoad_vGuide, SIGNAL(triggered()), this, SLOT(vGuide()));
connect(ui->btnLocation, SIGNAL(triggered()), this, SLOT(on_btnLocation_clicked()));
connect(ui->btnProjectCtrl, SIGNAL(triggered()), this, SLOT(on_btnProjectCtrl_clicked()));
connect(&aimooeOperator::GetInstance(), SIGNAL(flage(bool)), this, SLOT(Sampling(bool)));
//thread = new QThread;
//VideoFlow::GetInstance().moveToThread(thread);
//t_Msg = &MyThread::GetInstance();
//thread = new QThread;
//connect(thread, SIGNAL(started()), t_Msg, SLOT(runThread()));
//connect(t_Msg, SIGNAL(MySignal(QString)), this, SLOT(HandleSignal(QString)));
//t_Msg->moveToThread(thread);
/*
backgroundActor = vtkImageActor::New();
backgroundActor->SetScale(1000);
backgroundRenderer = vtkSmartPointer<vtkRenderer>::New();*/
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::HandleSignal(QString msg)
{
}
void MainWindow::Sampling(bool flage) {
}
void MainWindow::Regist() {
//在loadmode中获取了术前模型
}
void MainWindow::DisplayVTKImage(cv::Mat& mat)
{
}
void MainWindow::on_btnProjectCtrl_clicked() {
if ((ui->btnProjectCtrl->text() == "相机模式")) {
VtkVisual::GetInstance().SwitchTrackbll("a");
ui->btnProjectCtrl->setText("模型模式");
}
else {
VtkVisual::GetInstance().SwitchTrackbll("c");
ui->btnProjectCtrl->setText("相机模式");
}
}
void MainWindow::on_btnCameraCtrl_clicked()//摄像头开关控制
{
if (VideoFlow::GetInstance().isStarted) {
vtkAR = std::make_shared<CVTKAR>(ui->qvtkWidget);
ARVisual::GetInstance().Start(*vtkAR.get());
startTimer(0);
isCamera = true;
}
else if (ui->actionOpen_Camera->isChecked())//未开启状态
{
VideoFlow::GetInstance().Start();
//capture.open(0);
if (VideoFlow::GetInstance().isStarted) {
vtkAR = std::make_shared<CVTKAR>(ui->qvtkWidget);
ARVisual::GetInstance().Start(*vtkAR.get());
startTimer(0);
isCamera = true;
}
else {
qDebug() << "error";
isCamera = false;
}
}
else
{
killTimer(0);
isCamera = false;
}
}
void MainWindow::paintEvent(QPaintEvent* e)
{
}
void MainWindow::onLoadModel()
{
//qDebug() << "onBrowseBtnClicked";
QString directory = QFileDialog::getOpenFileName(this, tr("Open file"), "", nullptr);
QFileInfo fileInfo(directory);
if (directory.isEmpty() || !fileInfo.exists()) {
return;
}
qDebug() << directory;
if (directory.isEmpty() || !fileInfo.exists()) {
return;
}
vtkDisplay = std::make_shared<CVTKDisplay>(ui->qvtkWidget_2);
vtkDisplay2 = std::make_shared<CVTKDisplay>(ui->qvtkWidget_3);
VtkVisual::GetInstance().Load(directory.toStdString());
VtkVisual::GetInstance().Start(*vtkDisplay.get(), *vtkDisplay2.get());
qDebug() << "load ready";
isModel = true;
}
void MainWindow::vGuide()
{
qDebug() << "onBrowseBtnClicked";
QString directory = QFileDialog::getOpenFileName(this, tr("Open file"), "", nullptr);
QFileInfo fileInfo(directory);
if (directory.isEmpty() || !fileInfo.exists()) {
return;
}
qDebug() << directory;
if (directory.isEmpty() || !fileInfo.exists()) {
return;
}
isvGuide = true;
}
QImage MainWindow::cvMat2QImage(const cv::Mat& mat) // Mat 改成 QImage
{
if (mat.type() == CV_8UC1) // 单通道
{
QImage image(mat.cols, mat.rows, QImage::Format_Indexed8);
image.setColorCount(256); // 灰度级数256
for (int i = 0; i < 256; i++)
{
image.setColor(i, qRgb(i, i, i));
}
uchar* pSrc = mat.data; // 复制mat数据
for (int row = 0; row < mat.rows; row++)
{
uchar* pDest = image.scanLine(row);
memcpy(pDest, pSrc, mat.cols);
pSrc += mat.step;
}
return image;
}
else if (mat.type() == CV_8UC3) // 3通道
{
const uchar* pSrc = (const uchar*)mat.data; // 复制像素
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888); // R, G, B 对应 0,1,2
return image.rgbSwapped(); // rgbSwapped是为了显示效果色彩好一些。
}
else if (mat.type() == CV_8UC4)
{
const uchar* pSrc = (const uchar*)mat.data; // 复制像素
// Create QImage with same dimensions as input Mat
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_ARGB32); // B,G,R,A 对应 0,1,2,3
return image.copy();
}
else
{
return QImage();
}
}
cv::Mat MainWindow::QImage2cvMat(QImage image)
{
cv::Mat mat;
switch (image.format())
{
case QImage::Format_ARGB32:
case QImage::Format_RGB32:
case QImage::Format_ARGB32_Premultiplied:
mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.bits(), image.bytesPerLine());
break;
case QImage::Format_RGB888:
mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.bits(), image.bytesPerLine());
cv::cvtColor(mat, mat, cv::COLOR_BGR2GRAY);
break;
case QImage::Format_Indexed8:
mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.bits(), image.bytesPerLine());
break;
}
return mat;
}
void MainWindow::timerEvent(QTimerEvent* event)
{
QApplication::processEvents();
if (isCamera) {
VideoFlow::GetInstance().GetImage(orFrame);
VideoFlow::GetInstance().interlaceImage(orFrame,frame);
QImage image = cvMat2QImage(frame);
ui->Camera->setPixmap(QPixmap::fromImage(image)); // 将图片显示到label上
}
}
void MainWindow::openNDI()
{
aimooeThread->start();
}
void MainWindow::mousePressEvent(QMouseEvent* e)
{
//获取点击的下标
qDebug() << e->x() << ":" << e->y();
if (e->button() == Qt::LeftButton)
{
qDebug() << "左键";
}
else if (e->button() == Qt::RightButton)
{
qDebug() << "右键";
}
}
//鼠标 移动
void MainWindow::mouseMoveEvent(QMouseEvent* e)
{
qDebug() << "move" << e->x() << ":" << e->y();
}
//鼠标 松开
void MainWindow::mouseReleaseEvent(QMouseEvent* e)
{
qDebug() << "Release" << e->x() << ":" << e->y();
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
cout << event->key();
cv::Mat R;
switch (event->key())
{
case Qt::Key_Escape:
qDebug() << "ESC";
break;
case Qt::Key_F1:
break;
case Qt::Key_F2:
{
break;
}
case Qt::Key_F3: {
//cameraForm * w = new cameraForm();
//w->show();
}
case Qt::Key_5:
qDebug() << "5";
break;
case Qt::Key_Back:
qDebug() << "Back";
break;
case Qt::Key_Enter:
qDebug() << "Enter";
break;
case Qt::Key_Left:
break;
case Qt::Key_Down:
break;
case Qt::Key_Up:
break;
case Qt::Key_Right:
break;
case Qt::Key_Q:
break;
case Qt::Key_E:
break;
case Qt::Key_P:
break;
case Qt::Key_L:
break;
case Qt::Key_O:
break;
case Qt::Key_K:
break;
case Qt::Key_I:
break;
case Qt::Key_J:
break;
default:
qDebug() << event->key();
break;
}
}
void MainWindow::on_btnLocation_clicked()
{
if (aimooeOperator::GetInstance().isStarted&&VideoFlow::GetInstance().isStarted) {
VtkVisual::GetInstance().DoTransform();//根据定位器校准模型位置
}
}