-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
500 lines (438 loc) · 14.6 KB
/
Copy pathmainwindow.cpp
File metadata and controls
500 lines (438 loc) · 14.6 KB
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#include "mainwindow.h"
#include <QWidget>
#include <QImage>
#include <QFileDialog>
#include <QPixmap>
#include <QAction>
#include <QMessageBox>
#include <QDebug>
#include <QScrollArea>
#include <QGridLayout>
#include <QErrorMessage>
#include <QApplication>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
/* init main window */
initMainWindow();
/* init ui */
initUiComponent();
/* init resource */
initImageResource();
/* create imageViewer */
imageViewer = new QImageViewer();
PCLViewer = new QImageViewer();
}
MainWindow::MainWindow(QWidget* parent,QString x,int y) : QMainWindow(parent),
dir(x),flag(y)
{
/* init main window */
initMainWindow();
if (flag == 0)
{
/* init ui */
initUiComponent();
/* init resource */
initImageResource();
/* create imageViewer */
imageViewer = new QImageViewer(this);
int ret = imageViewer->openImageFile(tr("Select image:"),
dir,
tr("Images (*.jpg *.jpeg *.png *.bmp *.gif)"));
if (ret) {
QMessageBox::information(this, tr("Error"), tr("Open a file failed!"));
return;
}
loadImageResource();
}
else if (flag == 1)//进入pcl处理函数
{
setWindowComponet();
setPCLViewerWidget();
/*QString filename=QFileDialog::getOpenFileName(this, tr("Select point cloud file:"), dir, "*.txt");
if (filename.isEmpty()) {
return;
}
QDir dir1 = QDir(dir);
QFileInfoList infoList = dir1.entryInfoList(QDir::Files);
QFileInfo info;
for (int i = 0; i < infoList.count(); i++) {
info = infoList.at(i);
QString suffix = info.suffix();
if (suffix == "txt") {
fileInfoList.append(info);
}
}
if (ret) {
QMessageBox::information(this, tr("Error"), tr("Open a file failed!"));
return;
}*/
PCLViewer = new QImageViewer(this);
int ret = PCLViewer->openPCLFile(tr("Select PCL:"),
dir,
tr("Point Cloud (*.txt)"));
if (ret) {
QMessageBox::information(this, tr("Error"), tr("Open a file failed!"));
return;
}
loadPCLResource();
}
}
void MainWindow::initImageResource(void)
{
imageLabel->clear();
imageLabel->resize(QSize(200, 100));
setWindowTitle(tr("QImageViewer"));
}
void MainWindow::loadImageResource(void)
{
imageLabel->setPixmap(imageViewer->pixmap);
imageLabel->resize(imageViewer->size);
setWindowTitle(QFileInfo(imageViewer->filename).fileName() + tr(" - QImageViewer"));
}
void MainWindow::loadPCLResource(void)
{
manipulator = new osgGA::TrackballManipulator;
ViewerWindow->setCameraManipulator(manipulator);
ViewerWindow->addEventHandler(new osgViewer::WindowSizeHandler);
ViewerWindow->getCamera()->setClearColor(osg::Vec4f(255.0f, 255.0f, 255.0f, 1.0f));
// 环境光
ViewerWindow->getLight()->setAmbient(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f));
// 漫反射光
ViewerWindow->getLight()->setDiffuse(osg::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
setWindowTitle(QFileInfo(PCLViewer->filename).fileName());
showpointcloud();
}
void MainWindow::showpointcloud()
{
osg::ref_ptr<osg::Group> root = new osg::Group;
std::fstream fs;
std::string file=PCLViewer->filename.toStdString();
fs.open(file);
//新建一个用于存放几何图元的Geode
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
//创建保存几何信息的对象
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::Vec3dArray> vertices = new osg::Vec3dArray();
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
QMessageBox msgBox;
msgBox.setText("wait....");
msgBox.show();
qApp->processEvents();
while (!fs.eof())
{
//从txt读取一行中的坐标和proposal类型
double x, y, z, r,g,b;
int proposal_type;
fs >> x >> y >> z >> r>>g>>b;
//fs>>z>>x>>y;
vertices->push_back(osg::Vec3d(x, y, z));
osg::Vec4 color;
color = osg::Vec4(r/255.0,g/255.0,b/255.0, 1.0);
//color=osg::Vec4(0.7,0.7,0.7,1.0);
colors->push_back(color);
}
geom->setVertexArray(vertices.get());
geom->setColorArray(colors.get());
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vertices->size()));
geode->addDrawable(geom);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
osg::StateSet* stateSet = geode->getOrCreateStateSet();
osg::Point* pointSize = new osg::Point;
//pointSize->setSize(14.0);
pointSize->setSize(7.0);
stateSet->setAttribute(pointSize);
//挂在root下
root->addChild(geode);
ViewerWindow->setSceneData(root.get());
}
void MainWindow::openActionTriggered(void)
{
int ret = imageViewer->openImageFile(tr("Select image:"),
".\\",
tr("Images (*.jpg *.jpeg *.png *.bmp *.gif)"));
if (ret) {
QMessageBox::information(this, tr("Error"), tr("Open a file failed!"));
return ;
}
loadImageResource();
}
void MainWindow::openActionTriggered1(void)
{
int ret = PCLViewer->openPCLFile(tr("Select PCL:"),
".\\",
tr("PCL (*.txt)"));
if (ret) {
QMessageBox::information(this, tr("Error"), tr("Open a file failed!"));
return;
}
loadPCLResource();
}
void MainWindow::closeActionTriggered(void)
{
initImageResource();
imageViewer->closeImageFile();
}
void MainWindow::lastActionTriggered(void)
{
int ret = imageViewer->last();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::lastActionTriggered1(void)
{
int ret = PCLViewer->last(1);
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a PCL, please!"));
return;
}
loadPCLResource();
}
void MainWindow::nextActionTriggered(void)
{
int ret = imageViewer->next();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::nextActionTriggered1(void)
{
int ret = PCLViewer->next(1);
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a PCL, please!"));
return;
}
loadPCLResource();
}
void MainWindow::toLeftActionTriggered(void)
{
int ret = imageViewer->spinToLeft();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::toRightActionTriggered(void)
{
int ret = imageViewer->spinToRight();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::toEnlargeActionTriggered(void)
{
int ret = imageViewer->zoomIn();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::toLessenActionTriggered(void)
{
int ret = imageViewer->zoomOut();
if (ret) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
loadImageResource();
}
void MainWindow::deleteActionTriggered(void)
{
if (!QFile(imageViewer->filename).exists()) {
QMessageBox::information(this,
tr("Error"),
tr("Open a image, please!"));
return ;
}
QMessageBox message(QMessageBox::Warning,
tr("Warning"),
tr("Do you want to delete this image?"),
QMessageBox::Yes|QMessageBox::No,
NULL);
if (message.exec() == QMessageBox::No) {
return ;
}
int ret = imageViewer->delImageFile();
if (ret) {
QMessageBox::warning(this,
tr("Error"),
tr("Delete a image failed!"));
return ;
}
initImageResource();
}
void MainWindow::setQImageViewerWidget(void)
{
/* label show image */
imageLabel = new QLabel();
QScrollArea *imageScrollArea = new QScrollArea();
imageScrollArea->setAlignment(Qt::AlignCenter);
imageScrollArea->setFrameShape(QFrame::NoFrame);
imageScrollArea->setWidget(imageLabel);
QGridLayout *mainLayout = new QGridLayout();
mainLayout->addWidget(imageScrollArea, 0, 0);
centralWidget->setLayout(mainLayout);
}
void MainWindow::setPCLViewerWidget(void)
{
//QGridLayout* mainLayout = new QGridLayout();
//QWidget* tab = new QWidget();
totalLayout=new QHBoxLayout();
totalLayout->addWidget(ViewerWindow);
centralWidget->setLayout(totalLayout);
}
void MainWindow::setWindowComponet(void)
{
openAction = new QAction(tr("Open"), this);
openAction->setShortcut(QKeySequence::Open);
openAction->setStatusTip(tr("Open a image."));
openAction->setIcon(QIcon("./images/open.png"));
closeAction = new QAction(tr("Close"), this);
closeAction->setShortcut(QKeySequence::Close);
closeAction->setStatusTip(tr("Close a image."));
closeAction->setIcon(QIcon("./images/close.png"));
lastAction = new QAction(tr("Last"), this);
lastAction->setStatusTip(tr("Last image."));
lastAction->setIcon(QIcon("./images/left.png"));
nextAction = new QAction(tr("Next"), this);
nextAction->setStatusTip(tr("Next image"));
nextAction->setIcon(QIcon("./images/right.png"));
toLeftAction = new QAction(tr("LeftSpin"), this);
toLeftAction->setStatusTip(tr("To Left."));
toLeftAction->setIcon(QIcon("./images/toLeft.png"));
toRightAction = new QAction(tr("RightSpin"), this);
toRightAction->setStatusTip(tr("To Right."));
toRightAction->setIcon(QIcon("./images/toRight.png"));
toEnlargeAction = new QAction(tr("Enlarge"), this);
toEnlargeAction->setStatusTip(tr("To Enlarge."));
toEnlargeAction->setIcon(QIcon("./images/large.png"));
toLessenAction = new QAction(tr("Lessen"), this);
toLessenAction->setStatusTip(tr("To Lessen."));
toLessenAction->setIcon(QIcon("./images/small.png"));
deleteAction = new QAction(tr("Delete"), this);
deleteAction->setStatusTip(tr("Delete a image"));
deleteAction->setIcon(QIcon("./images/clear.png"));
deleteAction->setShortcut(QKeySequence::Delete);
QAction *exitAction = new QAction(tr("Exit"), this);
exitAction->setStatusTip(tr("Exit"));
exitAction->setIcon(QIcon("./images/quit.png"));
exitAction->setShortcut(QKeySequence::Quit);
QAction *aboutQt = new QAction(tr("About Qt"), this);
aboutQt->setStatusTip(tr("About Qt"));
aboutQt->setIcon(QIcon("./images/Qt.png"));
QAction *about = new QAction(tr("About QImageViewer"), this);
about->setStatusTip(tr("About QImageViewer"));
about->setIcon(QIcon("./images/help.png"));
QMenu *fileMenu = menuBar->addMenu(tr("File"));
fileMenu->addAction(openAction);
fileMenu->addAction(closeAction);
fileMenu->addSeparator();
fileMenu->addAction(deleteAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
QMenu *operationMenu = menuBar->addMenu(tr("Operate"));
operationMenu->addAction(lastAction);
operationMenu->addAction(nextAction);
operationMenu->addSeparator();
operationMenu->addAction(toLeftAction);
operationMenu->addAction(toRightAction);
operationMenu->addSeparator();
operationMenu->addAction(toEnlargeAction);
operationMenu->addAction(toLessenAction);
QMenu *helpMenu = menuBar->addMenu(tr("Help"));
helpMenu->addAction(aboutQt);
helpMenu->addAction(about);
toolBar->addAction(openAction);
toolBar->addAction(closeAction);
toolBar->addAction(lastAction);
toolBar->addAction(nextAction);
toolBar->addAction(toLeftAction);
toolBar->addAction(toRightAction);
toolBar->addAction(toEnlargeAction);
toolBar->addAction(toLessenAction);
toolBar->addAction(deleteAction);
toolBar->addAction(about);
if (flag == 0)
{
connect(openAction, SIGNAL(triggered(bool)), this, SLOT(openActionTriggered()));
connect(closeAction, SIGNAL(triggered(bool)), this, SLOT(closeActionTriggered()));
connect(lastAction, SIGNAL(triggered(bool)), this, SLOT(lastActionTriggered()));
connect(nextAction, SIGNAL(triggered(bool)), this, SLOT(nextActionTriggered()));
connect(toLeftAction, SIGNAL(triggered(bool)), this, SLOT(toLeftActionTriggered()));
connect(toRightAction, SIGNAL(triggered(bool)), this, SLOT(toRightActionTriggered()));
connect(toEnlargeAction, SIGNAL(triggered(bool)), this, SLOT(toEnlargeActionTriggered()));
connect(toLessenAction, SIGNAL(triggered(bool)), this, SLOT(toLessenActionTriggered()));
connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteActionTriggered()));
connect(about, SIGNAL(triggered(bool)), this, SLOT(aboutTriggered()));
connect(aboutQt, SIGNAL(triggered(bool)), this, SLOT(aboutQtTriggered()));
connect(exitAction, SIGNAL(triggered(bool)), this, SLOT(close()));
}
else if (flag == 1)
{
connect(openAction, SIGNAL(triggered(bool)), this, SLOT(openActionTriggered1()));
connect(lastAction, SIGNAL(triggered(bool)), this, SLOT(lastActionTriggered1()));
connect(nextAction, SIGNAL(triggered(bool)), this, SLOT(nextActionTriggered1()));
//connect(toLeftAction, SIGNAL(triggered(bool)), this, SLOT(toLeftActionTriggered()));
//connect(toRightAction, SIGNAL(triggered(bool)), this, SLOT(toRightActionTriggered()));
//connect(toEnlargeAction, SIGNAL(triggered(bool)), this, SLOT(toEnlargeActionTriggered()));
//connect(toLessenAction, SIGNAL(triggered(bool)), this, SLOT(toLessenActionTriggered()));
//connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteActionTriggered()));
connect(about, SIGNAL(triggered(bool)), this, SLOT(aboutTriggered()));
connect(aboutQt, SIGNAL(triggered(bool)), this, SLOT(aboutQtTriggered()));
connect(exitAction, SIGNAL(triggered(bool)), this, SLOT(close()));
}
}
void MainWindow::aboutQtTriggered(void)
{
qApp->aboutQt();
}
void MainWindow::aboutTriggered(void)
{
aboutWidget.setWindowTitle("Help Infomation");
aboutWidget.setWindowIcon(QIcon("./images/help.png"));
aboutWidget.setFixedSize(QABOUT_WIDGET_WIDTH, QABOUT_WIDGET_HEIGHT);
aboutWidget.show();
}
void MainWindow::initUiComponent(void)
{
/* set menu and toolbar */
setWindowComponet();
/* image show widget */
setQImageViewerWidget();
}
void MainWindow::initMainWindow(void)
{
menuBar = new QMenuBar(this);
setMenuBar(menuBar);
toolBar = new QToolBar(this);
addToolBar(toolBar);
centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
statusBar = new QStatusBar(this);
setStatusBar(statusBar);
}