-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainwindow.cpp
1452 lines (1201 loc) · 47.7 KB
/
mainwindow.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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
//qCC includes
#include "ccCommon.h"
#include "ccConsole.h"
//qCC io
#include "BinFilter.h"
//qCC_db
#include <ccGenericPointCloud.h>
#include <ccCameraSensor.h>
//db_tree
#include<ccDBRoot.h>
//dialogs
#include "ccCamSensorProjectionDlg.h"
#include "PointCloudGenDlg.h"
#include "ccCameraParamEditDlg.h"
#include "ccOverlayDialog.h"
//Qt Includes
#include <QtGui>
#include <QMdiArea>
#include <QSignalMapper>
#include <QMdiSubWindow>
#include <QLCDNumber>
#include <QFileDialog>
#include <QActionGroup>
#include <QSettings>
#include <QMessageBox>
#include <QElapsedTimer>
#include <QInputDialog>
#include <QTextStream>
#include <QColorDialog>
//System
#include <string.h>
#include <math.h>
#include <assert.h>
#include <cfloat>
#include <iostream>
//==========================global variables===================================//
//global static pointer (as there shoule only be one instance of MainWidow)
static MainWindow * s_instance=0;
//default 'All files' file filter
static const QString s_allFilesFilter("All (*.*)");
//default file filter separator
static const QString s_fileFilterSeparator(";;");
//=======================================MainWindow===========================================//
MainWindow::MainWindow()
:m_ccRoot(0)
,m_viewModePopupButton(0)
,m_pivotVisibilityPopupButton(0)
,m_cpeDlg(0){
setupUi(this);
QSettings settings;
restoreGeometry(settings.value(ccPS::MainWinGeom()).toByteArray());
//setWindowTitle(QString("IGITLandscapeViewer v") + ccCommon::GetCCVersion(false));
setWindowTitle(QString("IGIT地形地物可视化 版本") + ccCommon::GetCCVersion(false));
// console // gloabal variables
ccConsole::Init(consoleWidget, this, this);
// db-tree link
m_ccRoot = new ccDBRoot(dbTreeView, propertiesTreeView, this);
connect(m_ccRoot, SIGNAL(selectionChanged()), this, SLOT(updateUIWithSelection()));
//MDI Area
m_mdiArea = new QMdiArea(this);
// 设置成中心部件
setCentralWidget(m_mdiArea);
// 一旦有窗口被激活,更新该激活窗口的菜单 // 一旦有窗口被激活,同时激活该窗口三维视角的
connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus()));
connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(on3DViewActivated(QMdiSubWindow*)));
// QSignalMapper
m_windowMapper = new QSignalMapper(this);
connect(m_windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
//advanced widgets not handled by QDesigner
{
//view mode pop-up menu
{
// create menu
m_viewModePopupButton = new QToolButton();
QMenu *menu = new QMenu(m_viewModePopupButton);
menu->addAction(actionSetOrthoView);
menu->addAction(actionSetCenteredPerspectiveView);
menu->addAction(actionSetViewerPerspectiveView);
// create Popup Button
m_viewModePopupButton->setMenu(menu);
m_viewModePopupButton->setPopupMode(QToolButton::InstantPopup);
m_viewModePopupButton->setToolTip("Set current Veiw Mode");
m_viewModePopupButton->setStatusTip(m_viewModePopupButton->toolTip());
// insert m_viewModePopButton before actionSetViewTop
toolBarView->insertWidget(actionSetViewTop, m_viewModePopupButton);
m_viewModePopupButton->setEnabled(false);
}
//pivot center pop-up menu
{
// create menu
m_pivotVisibilityPopupButton = new QToolButton();
QMenu * menu = new QMenu(m_pivotVisibilityPopupButton);
menu->addAction(actionSetPivotAlwaysOn);
menu->addAction(actionSetPivotRotationOnly);
menu->addAction(actionSetPivotOff);
m_pivotVisibilityPopupButton->setMenu(menu);
m_pivotVisibilityPopupButton->setPopupMode(QToolButton::InstantPopup);
m_pivotVisibilityPopupButton->setToolTip("Set Pivot Visibility");
m_pivotVisibilityPopupButton->setStatusTip(m_pivotVisibilityPopupButton->toolTip());
toolBarView->insertWidget(actionSetViewTop, m_pivotVisibilityPopupButton);
m_pivotVisibilityPopupButton->setEnabled(false);
}
}
connectActions();
// create new 3D view
new3DView();
// freeze all widgets
freezeUI(false);
updateMenus();
updateUIWithSelection();
//maximize
showMaximized();
//QMainWindow::statusBar()->showMessage(QString("Ready"));
//ccConsole::Print("IGITLandscapeVeiwer started!");
QMainWindow::statusBar()->showMessage(QString("准备完毕!"));
ccConsole::Print("IGITLandscapeViewer 启动!");
}
//! Connects all QT actions to slots
void MainWindow::connectActions(){
assert(m_ccRoot);
assert(m_mdiArea);
//"File" menu
connect(actionOpen, SIGNAL(triggered()), this, SLOT(doActionLoadFile()));
connect(actionSave, SIGNAL(triggered()), this, SLOT(doActionSaveFile()));
//"Edit" menu
connect(actionCreateCameraSensor, SIGNAL(triggered()), this, SLOT(doActionCreateCameraSensor()));
connect(actionCreateCameraSensorFromFile, SIGNAL(triggered()), this, SLOT(doActionCreateCameraSensorFromFile()));
connect(actionTextureGeneration, SIGNAL(triggered()), this, SLOT(doActionTextureGeneration()));
//"Display" menu
connect(actionLockRotationVertAxis, SIGNAL(triggered()), this, SLOT(toggleRotationAboutVertAxis()));
connect(actionEditCamera, SIGNAL(triggered()), this, SLOT(doActionEditCamera()));
//"3D Views"
connect(menu3DViews, SIGNAL(aboutToShow()), this, SLOT(update3DViewsMenu()));
connect(actionNew3DView, SIGNAL(triggered()), this, SLOT(new3DView()));
connect(actionClose3DView, SIGNAL(triggered()), m_mdiArea, SLOT(closeActiveSubWindow()));
connect(actionCloseAll3DViews, SIGNAL(triggered()), m_mdiArea, SLOT(closeAllSubWindows()));
connect(actionTile3DViews, SIGNAL(triggered()), m_mdiArea, SLOT(tileSubWindows()));
connect(actionCascade3DViews, SIGNAL(triggered()), m_mdiArea, SLOT(cascadeSubWindows()));
connect(actionNext3DView, SIGNAL(triggered()), m_mdiArea, SLOT(activateNextSubWindow()));
connect(actionPrevious3DView, SIGNAL(triggered()), m_mdiArea, SLOT(activatePreviousSubWindow()));
// View Tool bar
connect(actionSetPivotAlwaysOn, SIGNAL(triggered()), this, SLOT(setPivotAlwaysOn()));
connect(actionSetPivotRotationOnly, SIGNAL(triggered()), this, SLOT(setPivotRotationOnly()));
connect(actionSetPivotOff, SIGNAL(triggered()), this, SLOT(setPivotOff()));
connect(actionSetOrthoView, SIGNAL(triggered()), this, SLOT(setOrthoView()));
connect(actionSetCenteredPerspectiveView, SIGNAL(triggered()), this, SLOT(setCenteredPerspectiveView()));
connect(actionSetViewerPerspectiveView, SIGNAL(triggered()), this, SLOT(setViewerPerspectiveView()));
connect(actionSetViewTop, SIGNAL(triggered()), this, SLOT(setTopView()));
connect(actionSetViewBottom, SIGNAL(triggered()), this, SLOT(setBottomView()));
connect(actionSetViewFront, SIGNAL(triggered()), this, SLOT(setFrontView()));
connect(actionSetViewBack, SIGNAL(triggered()), this, SLOT(setBackView()));
connect(actionSetViewLeft, SIGNAL(triggered()), this, SLOT(setLeftView()));
connect(actionSetViewRight, SIGNAL(triggered()), this, SLOT(setRightView()));
connect(actionSetViewIso1, SIGNAL(triggered()), this, SLOT(setIsoView1()));
connect(actionSetViewIso2, SIGNAL(triggered()), this, SLOT(setIsoView2()));
}
//=======================================setActiveSubWindow====================================//
void MainWindow::setActiveSubWindow(QWidget* window){
if(!window|| !m_mdiArea)return;
m_mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow*>(window));
}
//========================================TheInstance=========================================//
MainWindow* MainWindow::TheInstance(){
if(!s_instance){
s_instance = new MainWindow();
}
return s_instance;
}
//==========================================GetActiveGLWindow====================================//
ccGLWindow * MainWindow::GetActiveGLWindow(){
return TheInstance()->getActiveGLWindow();
}
//==========================================getActiveGLWindow=====================================//
ccGLWindow * MainWindow:: getActiveGLWindow(){
if(!m_mdiArea){
return 0;
}
// if active sub window existed
QMdiSubWindow * activeSubWindow = m_mdiArea->activeSubWindow();
if(activeSubWindow){
return static_cast<ccGLWindow*>(activeSubWindow->widget());
}
// if active sub window does not existed, return the first sub window
else{
QList<QMdiSubWindow*> subWindowList = m_mdiArea->subWindowList();
if(!subWindowList.empty()){
return static_cast<ccGLWindow*>(subWindowList[0]->widget());
}
}
return 0;
}
//========================================GetGLWindow============================================//
ccGLWindow* MainWindow:: GetGLWindow(const QString & title){
// collect the pointers of all sub windows
QList<QMdiSubWindow*> windows = TheInstance()->m_mdiArea->subWindowList();
int winNum = windows.size();
if(winNum ==0){
return 0;
}
// find the sub window with the given title
for(int i=0; i< winNum; i++){
ccGLWindow * win = static_cast<ccGLWindow*> (windows.at(i)->widget());
if(win->windowTitle()== title){
return win;
}
}
return 0;
}
//==========================================GetGLWindow============================================//
void MainWindow::GetGLWindows(std::vector<ccGLWindow*> & glWindows){
QList<QMdiSubWindow*> windows = TheInstance()->m_mdiArea->subWindowList();
int winNum = windows.size();
if(winNum==0) return;
glWindows.clear();
glWindows.reserve(winNum);
for(int i=0; i<winNum; i++){
glWindows.push_back(static_cast<ccGLWindow*>(windows.at(i)->widget()));
}
}
//============================================RefreshAllGLWindow=======================================//
void MainWindow::RefreshAllGLWindow(bool only2D /*false*/){
TheInstance()->refreshAll(only2D);
}
//=============================================refreshAll===============================================//
void MainWindow::refreshAll(bool only2D ){
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i<windows.size(); i++){
static_cast<ccGLWindow*>(windows.at(i)->widget())->refresh(only2D);
}
}
//=============================================DestroyInstance===========================================//
void MainWindow:: DestroyInstance(){
if(s_instance){
delete s_instance;
}
s_instance = 0;
}
//==============================================UpdateUI==============================//
void MainWindow::UpdateUI(){
TheInstance()->updateUI();
}
//==============================================updateUI==============================//
void MainWindow::updateUI(){
updateUIWithSelection();
updateMenus();
if(m_ccRoot){
m_ccRoot->updatePropertiesView();
}
}
//=====================================updateUIWithSelection===========================//
void MainWindow::updateUIWithSelection(){
dbTreeSelectionInfo selInfo;
m_selectedEntities.clear();
if (m_ccRoot)
m_ccRoot->getSelectedEntities(m_selectedEntities,CC_TYPES::OBJECT,&selInfo);
//expandDBTreeWithSelection(m_selectedEntities);
enableUIItems(selInfo);
}
//====================================a bit complex ===================================//
void MainWindow::enableUIItems(dbTreeSelectionInfo& selInfo){
bool atLeastOneEntity = (selInfo.selCount > 0);
bool atLeastOneCloud = (selInfo.cloudCount > 0);
bool atLeastOneMesh = (selInfo.meshCount > 0);
//bool atLeastOneOctree = (selInfo.octreeCount > 0);
bool atLeastOneNormal = (selInfo.normalsCount > 0);
bool atLeastOneColor = (selInfo.colorCount > 0);
bool atLeastOneSF = (selInfo.sfCount > 0);
//bool atLeastOneSensor = (selInfo.sensorCount > 0);
bool atLeastOneCameraSensor = (selInfo.cameraSensorCount > 0);
bool atLeastOnePolyline = (selInfo.polylineCount > 0);
bool activeWindow = (getActiveGLWindow() != 0);
actionSave->setEnabled(atLeastOneEntity);
// == 1
bool exactlyOneEntity = (selInfo.selCount == 1);
bool exactlyOneGroup = (selInfo.groupCount == 1);
bool exactlyOneCloud = (selInfo.cloudCount == 1);
bool exactlyOneMesh = (selInfo.meshCount == 1);
bool exactlyOneSF = (selInfo.sfCount == 1);
bool exactlyOneSensor = (selInfo.sensorCount == 1);
bool exactlyOneCameraSensor = (selInfo.cameraSensorCount == 1);
actionCreateCameraSensor->setEnabled(atLeastOneCloud);
actionCheckPointsInsideFrustrum->setEnabled(exactlyOneCameraSensor);
}
//===================================ApplyCCLibAlgorthim===============================//
//! Applies a standard CCLib algorithm (see CC_LIB_ALGORITHM) on a set of entities
bool MainWindow::ApplyCCLibAlgorithm(CC_LIB_ALGORITHM algo,
ccHObject::Container& entities,
QWidget* parent,
void** additionalParameters){
return true;
}
//===================================AddToDB========================================//
void MainWindow::addToDB(const QStringList& filenames,
QString fileFilter,
ccGLWindow* destWin){
//to handle same 'shift on load' for multiple files
CCVector3d loadCoordinatesShift(0,0,0);
bool loadCoordinatesTransEnabled = false;
FileIOFilter::LoadParameters parameters;
parameters.alwaysDisplayLoadDialog = false; //显示对话框
parameters.shiftHandlingMode = ccGlobalShiftManager::DIALOG_IF_NECESSARY;
parameters.coordinatesShift = &loadCoordinatesShift;
parameters.coordinatesShiftEnabled = &loadCoordinatesTransEnabled;
//the same for 'addToDB' (if the first one is not supported, or if the scale remains too big)
CCVector3d addCoordinatesShift(0,0,0);
for (int i=0; i<filenames.size(); ++i){
ccHObject* newGroup = FileIOFilter::LoadFromFile(filenames[i],parameters,fileFilter);
if (newGroup){
if (destWin)
newGroup->setDisplay_recursive(destWin);
addToDB(newGroup,true,true,false);
}
}
//QMainWindow::statusBar()->showMessage(QString("%1 file(s) loaded").arg(filenames.size()),2000);
QMainWindow::statusBar()->showMessage(QString("%1 file(s) 加载完成").arg(filenames.size()),2000);
}
//==================================addToDB===========================================//
void MainWindow::addToDB(ccHObject* obj, bool updateZoom,
bool autoExpandDBTree,
bool checkDimensions){
//let's check that the new entity is not too big nor too far from scene center!
if (checkDimensions){
//get entity bounding box
ccBBox bBox = obj->getBB_recursive();
CCVector3 center = bBox.getCenter();
PointCoordinateType diag = bBox.getDiagNorm();
CCVector3d P = CCVector3d::fromArray(center.u);
CCVector3d Pshift(0,0,0);
double scale = 1.0;
//here we must test that coordinates are not too big whatever the case because OpenGL
//really doesn't like big ones (even if we work with GLdoubles :( ).
if (ccGlobalShiftManager::Handle(P,diag,ccGlobalShiftManager::DIALOG_IF_NECESSARY,false,Pshift,&scale)) {
bool needRescale = (scale != 1.0);
bool needShift = (Pshift.norm2() > 0);
if (needRescale || needShift){
ccGLMatrix mat;
mat.toIdentity();
mat.data()[0] = mat.data()[5] = mat.data()[10] = static_cast<float>(scale);
mat.setTranslation(Pshift);
obj->applyGLTransformation_recursive(&mat);
//ccConsole::Warning(QString("Entity '%1' has been translated: (%2,%3,%4) and rescaled of a factor %5 [original position will be restored when saving]").arg(obj->getName()).arg(Pshift.x,0,'f',2).arg(Pshift.y,0,'f',2).arg(Pshift.z,0,'f',2).arg(scale,0,'f',6));
ccConsole::Warning(QString("物体 '%1' 被平移: (%2,%3,%4) 被缩放: %5 [存储时将会恢复原始坐标]").arg(obj->getName()).arg(Pshift.x,0,'f',2).arg(Pshift.y,0,'f',2).arg(Pshift.z,0,'f',2).arg(scale,0,'f',6));
}
//update 'global shift' and 'global scale' for ALL clouds recursively
//FIXME: why don't we do that all the time by the way?!
ccHObject::Container children;
children.push_back(obj);
while (!children.empty()){
ccHObject* child = children.back();
children.pop_back();
if (child->isKindOf(CC_TYPES::POINT_CLOUD)) {
ccGenericPointCloud* pc = ccHObjectCaster::ToGenericPointCloud(child);
pc->setGlobalShift(pc->getGlobalShift() + Pshift);
pc->setGlobalScale(pc->getGlobalScale() * scale);
}
for (unsigned i=0; i<child->getChildrenNumber(); ++i)
children.push_back(child->getChild(i));
}
}
}
//add object to DB root
if (m_ccRoot){
//force a 'global zoom' if the DB was emtpy!
if (!m_ccRoot->getRootEntity() || m_ccRoot->getRootEntity()->getChildrenNumber() == 0)
updateZoom = true;
m_ccRoot->addElement(obj,autoExpandDBTree);
}
else{
//ccLog::Warning("[MainWindow::addToDB] Internal error: no associated db?!");
ccLog::Warning("[MainWindow::addToDB] 内部错误: 没有相关的 db?!");
assert(false);
}
//we can now set destination display (if none already)
if (!obj->getDisplay()){
ccGLWindow* activeWin = getActiveGLWindow();
if (!activeWin){
//no active GL window?!
return;
}
obj->setDisplay_recursive(activeWin);
}
//eventually we update the corresponding display
assert(obj->getDisplay());
if (updateZoom){
static_cast<ccGLWindow*>(obj->getDisplay())->zoomGlobal(); //automatically calls ccGLWindow::redraw
}
else{
obj->prepareDisplayForRefresh();
refreshAll();
}
}
//=================================loadTexturedResults================================//
void MainWindow::loadTexturedResults(QString ResultsDir){
QDir dir(ResultsDir);
if(!dir.exists()){
return;
}
dir.setFilter(QDir::Files | QDir::NoSymLinks);
QStringList filters;
filters<<QString("*.OBJ")<<QString("*.obj");
dir.setNameFilters(filters);
QFileInfoList nameList = dir.entryInfoList();
if(nameList.size()==0) return;
//to handle same 'shift on load' for multiple files
CCVector3d loadCoordinatesShift(0,0,0);
bool loadCoordinatesTransEnabled = false;
FileIOFilter::LoadParameters parameters;
parameters.alwaysDisplayLoadDialog = false; //显示对话框
parameters.shiftHandlingMode = ccGlobalShiftManager::DIALOG_IF_NECESSARY;
parameters.coordinatesShift = &loadCoordinatesShift;
parameters.coordinatesShiftEnabled = &loadCoordinatesTransEnabled;
QString currentOpenDlgFilter;
currentOpenDlgFilter.clear();
for (int i = 0; i < nameList.size(); ++i) {
QFileInfo fileInfo = nameList.at(i);
QString fileDir = fileInfo.absoluteFilePath();
ccHObject* group = FileIOFilter::LoadFromFile(fileDir,parameters, currentOpenDlgFilter);
if(!group|| group->getChildrenNumber()==0) return;
ccHObject * Mesh = group->getFirstChild();
if(!Mesh)return;
ccHObject * MeshGroup = m_ccRoot->getRootEntity()->find("MeshList");
if(!MeshGroup){
MeshGroup = new ccHObject();
addToDB(MeshGroup);
MeshGroup->setName("MeshList");
}
MeshGroup->addChild(Mesh);
ccGLWindow* win = getActiveGLWindow();
if (win){
//setDisplay(win);
//Mesh->setVisible(true);
Mesh->setDisplay_recursive(win);
addToDB(Mesh,true,true,false);
}
//addToDB(Mesh);
}
QMainWindow::statusBar()->showMessage(QString("%1 file(s) loaded").arg(nameList.size()),2000);
}
//=================================loadPMVSCameras====================================//
void MainWindow::loadPMVSCameras(QString ResultsDir){
QDir dir(ResultsDir);
if(!dir.exists()){
return;
}
dir.setFilter(QDir::Files | QDir::NoSymLinks);
QStringList filters;
filters<<QString("*.TXT")<<QString("*.txt");
dir.setNameFilters(filters);
QFileInfoList nameList = dir.entryInfoList();
if(nameList.size()==0) return;
CCVector3d loadCoordinatesShift(0,0,0);
bool loadCoordinatesTransEnabled = false;
FileIOFilter::LoadParameters parameters;
parameters.alwaysDisplayLoadDialog = false; //显示对话框
parameters.shiftHandlingMode = ccGlobalShiftManager::DIALOG_IF_NECESSARY;
parameters.coordinatesShift = &loadCoordinatesShift;
parameters.coordinatesShiftEnabled = &loadCoordinatesTransEnabled;
QString currentOpenDlgFilter;
currentOpenDlgFilter.clear();
for (int i=0; i<nameList.size(); ++i){
QFileInfo fileInfo = nameList.at(i);
QString fileDir = fileInfo.absoluteFilePath();
ccHObject* group = FileIOFilter::LoadFromFile(fileDir,parameters, currentOpenDlgFilter);
if(!group|| group->getChildrenNumber()==0) return;
ccHObject * sensor = group->getFirstChild();
if(!sensor)return;
ccHObject * CameraGroup = m_ccRoot->getRootEntity()->find("CameraLists");
if(!CameraGroup){
CameraGroup = new ccHObject();
addToDB(CameraGroup);
CameraGroup->setName("CameraLists");
}
CameraGroup->addChild(sensor);
ccGLWindow* win = getActiveGLWindow();
if (win){
sensor->setDisplay(win);
sensor->setVisible(true);
}
addToDB(sensor);
}
//QMainWindow::statusBar()->showMessage(QString("%1 file(s) loaded").arg(filenames.size()),2000);
QMainWindow::statusBar()->showMessage(QString("%1 file(s) 加载完成").arg(nameList.size()),2000);
}
//===================================echoMouseWheelRotate============================//
void MainWindow::echoMouseWheelRotate(float angle){
if(checkBoxCameraLink->checkState()!= Qt::Checked) return;
// find which window sends the signal // dynamic_cast 会进行安全检察
ccGLWindow* sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow) return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i< windows.size(); i++){
ccGLWindow *child = static_cast<ccGLWindow*>(windows.at(i)->widget());
//find the other ccGLwindows, the rotations are performed on them// the sending windows has been
// rotated, so it should not be processed agained
if(child!=sendingWindow){
// can not receive other signals
child->blockSignals(true);
//对窗口进行尺度变化
child->onWheelEvent(angle);
child->blockSignals(true);
child->redraw();
}
}
}
//===================================echoCameraDisplay==============================//
void MainWindow::echoCameraDisplaced(float ddx, float ddy){
if(checkBoxCameraLink->checkState()!= Qt::Checked)return;
// find the window that sends the signal
ccGLWindow* sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow)return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i<windows.size(); i++){
ccGLWindow * child = static_cast<ccGLWindow*>(windows.at(i)->widget());
if(child!= sendingWindow){
child->blockSignals(true);
child->moveCamera(ddx,ddy, 0.0f);
child->blockSignals(false);
child->redraw();
}
}
}
//===================================echoBaseViewMatRotation=========================//
void MainWindow::echoBaseViewMatRotation(const ccGLMatrixd& rotMat){
if(checkBoxCameraLink->checkState()!= Qt::Checked) return;
ccGLWindow *sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow)return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i< windows.size(); i++){
ccGLWindow * child = static_cast<ccGLWindow*>(windows.at(i)->widget());
if(child!=sendingWindow){
child->blockSignals(true);
// 对窗口进行旋转
child->rotateBaseViewMat(rotMat);
child->blockSignals(false);
child->redraw();
}
}
}
//===================================echoCameraPosChanged===========================//
void MainWindow::echoCameraPosChanged(const CCVector3d& P){
if(checkBoxCameraLink->checkState() != Qt::Checked) return;
ccGLWindow * sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow) return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i< windows.size(); i++){
ccGLWindow * child = static_cast<ccGLWindow*>(windows.at(i)->widget());
if(child!=sendingWindow){
child->blockSignals(true);
child->setCameraPos(P);
child->blockSignals(false);
child->redraw();
}
}
}
//===================================echoPivotPointChanged==========================//
void MainWindow::echoPivotPointChanged(const CCVector3d&P){
if(checkBoxCameraLink->checkState() != Qt::Checked) return;
ccGLWindow * sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow) return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i< windows.size(); i++){
ccGLWindow * child = static_cast<ccGLWindow*>(windows.at(i)->widget());
if(child!= sendingWindow){
child->blockSignals(true);
child->setPivotPoint(P);
child->blockSignals(false);
child->redraw();
}
}
}
//===================================echoPixelSizeChanged===========================//
void MainWindow::echoPixelSizeChanged(float size){
if(checkBoxCameraLink->state()!= Qt::Checked) return;
ccGLWindow* sendingWindow = dynamic_cast<ccGLWindow*>(sender());
if(!sendingWindow)return;
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
for(int i=0; i<windows.size(); i++){
ccGLWindow* child = static_cast<ccGLWindow*>(windows.at(i)->widget());
if(child!=sendingWindow){
child->blockSignals(true);
// 设置点的大小
child->setPixelSize(size);
child->blockSignals(false);
child->redraw();
}
}
}
//===================================prepareWindowDeletion==========================//
void MainWindow::prepareWindowDeletion(QObject* glWindow){
}
//===================================addToDBAuto====================================//
void MainWindow::addToDBAuto(const QStringList& filenames){
}
//====================================handleNewLabel================================//
void MainWindow::handleNewLabel(ccHObject*){
}
//====================================doActionLoadFile=============================//
//QApplication::applicationDirPath()//当前编译exe文件的路径
void MainWindow::doActionLoadFile(){
//persistent settings
QSettings settings;
settings.beginGroup(ccPS::LoadFile());
QString currentPath = settings.value(ccPS::CurrentPath(),QApplication::applicationDirPath()).toString();
QString currentOpenDlgFilter = settings.value(ccPS::SelectedInputFilter(), BinFilter::GetFileFilter()).toString();
// Add all available file I/O filters (with import capabilities)
QStringList fileFilters;
fileFilters.append(s_allFilesFilter);
bool defaultFilterFound = false;
{
const FileIOFilter::FilterContainer& filters = FileIOFilter::GetFilters();
for (size_t i=0; i<filters.size(); ++i){
if (filters[i]->importSupported()){
QStringList ff = filters[i]->getFileFilters(true);
for (int j=0; j<ff.size(); ++j){
fileFilters.append(ff[j]);
//is it the (last) default filter?
if (!defaultFilterFound && currentOpenDlgFilter == ff[j]){
defaultFilterFound = true;
}
}
}
}
}
//default filter is still valid?
if (!defaultFilterFound)
currentOpenDlgFilter = s_allFilesFilter;
//file choosing dialog
QStringList selectedFiles = QFileDialog::getOpenFileNames( this,
"Open file(s)",
currentPath,
fileFilters.join(s_fileFilterSeparator),
¤tOpenDlgFilter
#ifdef _DEBUG
,QFileDialog::DontUseNativeDialog
#endif
);
if (selectedFiles.isEmpty())
return;
//save last loading parameters
currentPath = QFileInfo(selectedFiles[0]).absolutePath();
settings.setValue(ccPS::CurrentPath(),currentPath);
settings.setValue(ccPS::SelectedInputFilter(),currentOpenDlgFilter);
settings.endGroup();
if (currentOpenDlgFilter == s_allFilesFilter)
currentOpenDlgFilter.clear(); //this way FileIOFilter will try to guess the file type automatically!
//load files
addToDB(selectedFiles,currentOpenDlgFilter);
}
//====================================doActionSaveFile=============================//
void MainWindow::doActionSaveFile(){
}
//====================================doActionCreateCameraSensors===================//
void MainWindow::doActionCreateCameraSensor(){
ccCamSensorProjectionDlg spDlg(this); // 设置相机参数
if (!spDlg.exec())
return;
//We create the corresponding sensor for each input cloud
ccHObject::Container selectedEntities = m_selectedEntities; //选择到的物体
size_t selNum = selectedEntities.size(); //选择到的物体的个数
for (size_t i=0; i<selNum; ++i){
ccHObject* ent = selectedEntities[i];
if (ent->isKindOf(CC_TYPES::POINT_CLOUD)){
//如果是点云 //将ccHobject 指针转化成 ccGenericPointCloud 指针
ccGenericPointCloud* cloud = ccHObjectCaster::ToGenericPointCloud(ent);
//we create a new sensor //创建相机传感器
ccCameraSensor* sensor = new ccCameraSensor();
// 添加孩子传感器
cloud->addChild(sensor);
//we init its parameters with the dialog
spDlg.updateCamSensor(sensor);
//we try to guess the sensor relative size (dirty)
ccBBox bb = cloud->getOwnBB();
double diag = bb.getDiagNorm();
if (diag < 1.0)
sensor->setGraphicScale(static_cast<PointCoordinateType>(1.0e-3));
else if (diag > 10000.0)
sensor->setGraphicScale(static_cast<PointCoordinateType>(1.0e3));
//set position
ccIndexedTransformation trans;
sensor->addPosition(trans,0); // 将当前位置添加到PosBuffer缓冲器中
ccGLWindow* win = static_cast<ccGLWindow*>(cloud->getDisplay());
if (win){
sensor->setDisplay(win);
sensor->setVisible(true);
ccBBox box = cloud->getOwnBB();
win->updateConstellationCenterAndZoom(&box);
}
addToDB(sensor);
}
}
updateUI();
}
//====================================doActionCreateCameraSensors===================//
void MainWindow::doActionCreateCameraSensorFromFile(){
//persistent settings
QSettings settings;
settings.beginGroup(ccPS::LoadFile());
QString currentPath = settings.value(ccPS::CurrentPath(),QApplication::applicationDirPath()).toString();
QString currentOpenDlgFilter = settings.value(ccPS::SelectedInputFilter(), BinFilter::GetFileFilter()).toString();
// Add all available file I/O filters (with import capabilities)
QStringList fileFilters;
fileFilters.append(s_allFilesFilter);
bool defaultFilterFound = false;
{
const FileIOFilter::FilterContainer& filters = FileIOFilter::GetFilters();
for (size_t i=0; i<filters.size(); ++i){
if (filters[i]->importSupported()){
QStringList ff = filters[i]->getFileFilters(true);
for (int j=0; j<ff.size(); ++j){
fileFilters.append(ff[j]);
//is it the (last) default filter?
if (!defaultFilterFound && currentOpenDlgFilter == ff[j]){
defaultFilterFound = true;
}
}
}
}
}
//default filter is still valid?
if (!defaultFilterFound)
currentOpenDlgFilter = s_allFilesFilter;
//file choosing dialog
QStringList selectedFiles = QFileDialog::getOpenFileNames( this,
"Open file(s)",
currentPath,
fileFilters.join(s_fileFilterSeparator),
¤tOpenDlgFilter
#ifdef _DEBUG
,QFileDialog::DontUseNativeDialog
#endif
);
if (selectedFiles.isEmpty())
return;
//save last loading parameters
currentPath = QFileInfo(selectedFiles[0]).absolutePath();
settings.setValue(ccPS::CurrentPath(),currentPath);
settings.setValue(ccPS::SelectedInputFilter(),currentOpenDlgFilter);
settings.endGroup();
if (currentOpenDlgFilter == s_allFilesFilter)
currentOpenDlgFilter.clear(); //this way FileIOFilter will try to guess the file type automatically!
//to handle same 'shift on load' for multiple files
CCVector3d loadCoordinatesShift(0,0,0);
bool loadCoordinatesTransEnabled = false;
FileIOFilter::LoadParameters parameters;
parameters.alwaysDisplayLoadDialog = false; //显示对话框
parameters.shiftHandlingMode = ccGlobalShiftManager::DIALOG_IF_NECESSARY;
parameters.coordinatesShift = &loadCoordinatesShift;
parameters.coordinatesShiftEnabled = &loadCoordinatesTransEnabled;
//the same for 'addToDB' (if the first one is not supported, or if the scale remains too big)
CCVector3d addCoordinatesShift(0,0,0);
for (int i=0; i<selectedFiles.size(); ++i){
ccHObject* group = FileIOFilter::LoadFromFile(selectedFiles[i],parameters, currentOpenDlgFilter);
if(!group|| group->getChildrenNumber()==0) return;
ccHObject * sensor = group->getFirstChild();
if(!sensor)return;
ccHObject * CameraGroup = m_ccRoot->getRootEntity()->find("CameraLists");
if(!CameraGroup){
CameraGroup = new ccHObject();
addToDB(CameraGroup);
CameraGroup->setName("CameraLists");
}
CameraGroup->addChild(sensor);
ccGLWindow* win = getActiveGLWindow();
if (win){
sensor->setDisplay(win);
sensor->setVisible(true);
}
addToDB(sensor);
}
//QMainWindow::statusBar()->showMessage(QString("%1 file(s) loaded").arg(filenames.size()),2000);
QMainWindow::statusBar()->showMessage(QString("%1 file(s) 加载完成").arg(selectedFiles.size()),2000);
}
//====================================doActionPointCloudGeneration==================//
void MainWindow:: doActionTextureGeneration(){
PointCloudGenDlg pcDlg;
QString FileFolder;
if(!pcDlg.exec()){
if(QFile::exists("imgList.txt")){
QFile::remove("imgList.txt");
}
FileFolder = pcDlg.getFolderDir();
QMainWindow::statusBar()->showMessage(FileFolder,2000);
}
loadTexturedResults(FileFolder);
loadPMVSCameras("./TempData.nvm.cmvs/00/txt");
}
//====================================update3DViewsMenu============================//
void MainWindow::update3DViewsMenu(){
menu3DViews->clear();
menu3DViews->addAction(actionNew3DView);
menu3DViews->addSeparator();
menu3DViews->addAction(actionClose3DView);
menu3DViews->addAction(actionCloseAll3DViews);
menu3DViews->addSeparator();
menu3DViews->addAction(actionTile3DViews);
menu3DViews->addAction(actionCascade3DViews);
menu3DViews->addSeparator();
menu3DViews->addAction(actionNext3DView);
menu3DViews->addAction(actionPrevious3DView);
QList<QMdiSubWindow*> windows = m_mdiArea->subWindowList();
if(!windows.isEmpty()){
//Dynamc Separator
QAction* seperator = new QAction(this);
seperator->setSeparator(true);
menu3DViews->addAction(seperator);
for(int i=0; i<windows.size(); i++){
QWidget * child = windows.at(i)->widget();
QString text = QString("&%1 %2").arg(i+1).arg(child->windowTitle());
QAction * action = menu3DViews->addAction(text);
// checkable
action->setCheckable(true);
action->setChecked(child == getActiveGLWindow());
// using singnalmapper to maganize all the signals and slots
connect(action, SIGNAL(triggered()), m_windowMapper, SLOT(map()));
m_windowMapper->setMapping(action, windows.at(i));
}
}
}