forked from adrienkaiser/DTIAtlasBuilder
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GUI.cxx
executable file
·3909 lines (3354 loc) · 163 KB
/
GUI.cxx
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
/*Qt classes*/
#include <QFileDialog>
#include <QMessageBox>
#include <QProcess>
#include <QFile>
#include <QTextStream>
#include <QShortcut>
#include <QCloseEvent>
#include <QDropEvent>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QUrl>
#include <QSignalMapper>
#include <QDialog>
#include <QLabel>
#include <QComboBox>
#include <QStackedWidget>
#include <QLineEdit>
#include <QTimer>
#include <QDebug>
#include <QItemSelection>
/*std classes*/
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <iomanip>
#include <iostream>
/*itk classes*/
#include "itkImage.h"
#include "itkImageFileReader.h"
#include <itksys/SystemTools.hxx> // for FindProgram() and GetFilenamePath()
/* ITK modes = same values than the C variables: F_OK W_OK R_OK X_OK */
mode_t ITKmode_F_OK = 0;
mode_t ITKmode_W_OK = 2;
mode_t ITKmode_R_OK = 4;
mode_t ITKmode_X_OK = 1;
#ifndef DTIAtlasBuilder_VERSION
#define DTIAtlasBuilder_VERSION "Unknown version"
#endif
/* DTIAB version check:
Version will be written in a log file when computing
to display a warning if a new compute is done afterwards with a newer version
1.0 : No version file
1.1 : Introducing version file
Renaming AW folder to Diffeomorphic folders (folders renamed in python script)
Renaming GreedyAtlas' Def Fields to HField
Renaming Final Def Fields to GlobalDisplacementField
*/
/* homemade */
#include "GUI.h"
#include "ScriptWriter.h"
// Q_OS_WIN32 Q_OS_LINUX Q_OS_MAC are Qt macros
#if defined Q_OS_WIN32
#define Platform "win"
#elif defined Q_OS_MAC
#define Platform "mac"
#elif defined Q_OS_LINUX
#define Platform "linux"
#endif
//We want to search the extension path first, and then we look for the tools on the system
std::string FindProgram( const char* name , std::vector< std::string > m_FindProgramDTIABExecDirVec )
{
std::string path ;
path = itksys::SystemTools::FindProgram( name , m_FindProgramDTIABExecDirVec , true ) ;
if( path.empty() )
{
path = itksys::SystemTools::FindProgram( name ) ;
}
return path ;
}
template< class T > std::string IntOrDoubleToStr(T IntOrDoubleVar) // T is int or double
{
std::ostringstream oss;
oss << IntOrDoubleVar;
return oss.str();
}
/////////////////////////////////////////
// CONSTRUCTOR //
/////////////////////////////////////////
// bool Testing: If automatic testing (constructor called from DTIAtllasBuilderGUITest.cxx), this flag will prevent any pop up window to show
GUI::GUI(std::string ParamFile, std::string ConfigFile, std::string CSVFile, bool overwrite, bool noGUI, bool Testing, std::string commandRan) : QMainWindow()
{
setupUi(this);
QStringList version = QString(DTIAtlasBuilder_VERSION).split("|");
setWindowTitle( "DTI Atlas Builder: " + version[0] ) ;
this->setAcceptDrops(true);
m_ErrorDetectedInConstructor=false;
/* Hierarchy model */
m_HierarchyModel= new CaseHierarchyModel(QString(""));
/* Script writing object */
m_scriptwriter = new ScriptWriter; // delete in "void GUI::ExitProgram()"
/* Variables */
m_ExecutableDir = commandRan;
m_scriptwriter->setExecutableDir(m_ExecutableDir);
m_CSVseparator = QString(",");
m_ParamSaved=1;
m_lastCasePath="";
m_noGUI=noGUI;
m_Testing = Testing;
if( overwrite ) OverwritecheckBox->setChecked(true);
m_ScriptRunning=false;
m_ScriptQProcess = new QProcess;
QObject::connect(m_ScriptQProcess, SIGNAL(finished(int)), this, SLOT(ScriptQProcessDone(int)));
m_ScriptRunningQTimer = new QTimer(this);
QObject::connect(m_ScriptRunningQTimer, SIGNAL(timeout()), this, SLOT(UpdateScriptRunningGUIDisplay()));
/* Error message if windows or mac */
// if ( !m_Testing )
// {
// if( (std::string)Platform == "mac" || (std::string)Platform == "win")
// {
// if(DTIAtlasBuilder_BUILD_SLICER_EXTENSION) QMessageBox::critical(this, "DTIAtlasBuilder not working", "This program is currently not working as it should on this platform.\nPlease do not hit the compute button, or the process will fail.\nYou can find other useful tools in Slicer:\n> DTI-Reg\n>Resample DTI Volume - log euclidean");
// else QMessageBox::critical(this, "DTIAtlasBuilder not working", "This program is currently not working as it should on this platform.\nPlease do not hit the compute button, or the process will fail.\nIf the package was compiled or downloaded, you will find other useful tools in the specified install directory.");
// }
// }
/* Initialize the options */
InitOptions();
if(!m_noGUI)
{
/* Objects connections */
QObject::connect(ComputepushButton, SIGNAL(clicked()), this, SLOT(Compute()));
// Compute button triggered when user presses ENTER key
QShortcut* EnterShortcut = new QShortcut(QKeySequence(Qt::Key_Return), this); // ENTER on main keyboard (RETURN)
QObject::connect(EnterShortcut, SIGNAL(activated()), ComputepushButton, SLOT(click()));
QShortcut* NumPadEnterShortcut = new QShortcut(QKeySequence(Qt::Key_Enter), this); // ENTER on num pad
QObject::connect(NumPadEnterShortcut, SIGNAL(activated()), ComputepushButton, SLOT(click()));
// Hierarchical objects & Treeview set
QObject::connect(openHierarchyButton,SIGNAL(clicked()), this, SLOT(openHierarchyFile()));
QObject::connect(saveHierarchyButton,SIGNAL(clicked()), this, SLOT(saveHierarchyFile()));
QObject::connect(addNodeButton,SIGNAL(clicked()), this, SLOT(addNode()));
QObject::connect(removeNodeButton,SIGNAL(clicked()), this, SLOT(removeNode()));
caseHierarchyTreeView->setModel(m_HierarchyModel);
enableTreeViewWidget(false);
QObject::connect(caseHierarchyTreeView, SIGNAL(clicked(const QModelIndex)), this, SLOT(treeViewItemSelected(const QModelIndex)));
QObject::connect(m_HierarchyModel, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),this,SLOT(treeViewItemChanged(const QModelIndex)));
//std::cout << b << std::endl;
//
//QModelIndex idx= m_HierarchyModel->item(0)->index();
//caseHierarchyTreeView->clicked(idx);
//caseHierarchyTreeView->selectionModel()->select(QItemSelection(idx,idx), QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
enableCaseWidget(0);
QObject::connect(StoppushButton, SIGNAL(clicked()), this, SLOT(KillScriptQProcess()));
QObject::connect(BrowseCSVPushButton, SIGNAL(clicked()), this, SLOT(ReadCSVSlot()));
QObject::connect(SaveCSVPushButton, SIGNAL(clicked()), this, SLOT(SaveCSVDatasetBrowse()));
QObject::connect(BrowseOutputPushButton, SIGNAL(clicked()), this, SLOT(OpenOutputBrowseWindow()));
QObject::connect(BrowseDTIRegExtraPathPushButton, SIGNAL(clicked()), this, SLOT(OpenDTIRegExtraPathBrowseWindow()));
QObject::connect(TemplateBrowsePushButton, SIGNAL(clicked()), this, SLOT(OpenTemplateBrowseWindow()));
QObject::connect(AddPushButton, SIGNAL(clicked()), this, SLOT(OpenAddCaseBrowseWindow()));
// Remove button triggered when user presses PLUS key
QShortcut* PlusShortcut = new QShortcut(QKeySequence(Qt::Key_Plus), this);
QObject::connect(PlusShortcut, SIGNAL(activated()), AddPushButton, SLOT(click()));
QObject::connect(RemovePushButton, SIGNAL(clicked()), this, SLOT(RemoveSelectedCases()));
// Remove button triggered when user presses DEL or MINUS key
QShortcut* DelShortcut = new QShortcut(QKeySequence(Qt::Key_Delete), this); // DELETE key
QObject::connect(DelShortcut, SIGNAL(activated()), RemovePushButton, SLOT(click()));
QShortcut* MinusShortcut = new QShortcut(QKeySequence(Qt::Key_Minus), this); // MINUS key
QObject::connect(MinusShortcut, SIGNAL(activated()), RemovePushButton, SLOT(click()));
RemovePushButton->setEnabled(false);
ComputepushButton->setEnabled(false);
StoppushButton->setEnabled(false);
CleanOutputPushButton->setEnabled(false);
DisableQC(); // will be enable when cases are loaded
QObject::connect(actionNew_Project, SIGNAL(triggered()), this, SLOT(newHierarchyProject()));
QObject::connect(actionOpen_Project_File, SIGNAL(triggered()), this, SLOT(openHierarchyFile()));
QObject::connect(actionSave_Project_File, SIGNAL(triggered()), this, SLOT(saveHierarchyFile()));
QObject::connect(actionOpen_Project_Directory,SIGNAL(triggered()),this,SLOT(openProjectDirectorySlot()));
QObject::connect(actionLoad_parameters, SIGNAL(triggered()), this, SLOT(LoadParametersSlot()));
QObject::connect(actionSave_parameters, SIGNAL(triggered()), this, SLOT(SaveParametersSlot()));
QObject::connect(actionExit, SIGNAL(triggered()), this, SLOT(ExitProgram()));
QObject::connect(actionLoad_Software_Configuration, SIGNAL(triggered()), this, SLOT(LoadConfigSlot()));
QObject::connect(actionSave_Software_Configuration, SIGNAL(triggered()), this, SLOT(SaveConfig()));
QObject::connect(actionRead_Me, SIGNAL(triggered()), this, SLOT(ReadMe()));
QObject::connect(actionKeyboard_Shortcuts, SIGNAL(triggered()), this, SLOT(KeyShortcuts()));
//Tools actions
QObject::connect(actionGenerate_Project_Directory,SIGNAL(triggered()),this,SLOT(GenerateProjectDirectorySlot()));
QObject::connect(InterpolTypeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(InterpolTypeComboBoxChanged(int)));
QObject::connect(TensInterpolComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(TensorInterpolComboBoxChanged(int)));
QObject::connect(RegMethodcomboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(RegMethodComboBoxChanged(int)));
QObject::connect(DefaultButton, SIGNAL(clicked()), this, SLOT(ConfigDefault()));
QObject::connect(GAPath, SIGNAL(editingFinished()), this, SLOT(testGA())); // test the version of GreedyAtlas automatically when the text is changed manually ( not by a setText() )
QObject::connect(DTIRegPath, SIGNAL(editingFinished()), this, SLOT(testDTIReg())); // test the version of DTI-Reg automatically when the text is changed manually ( not by a setText() )
QObject::connect(GridProcesscheckBox, SIGNAL(stateChanged(int)), this, SLOT(GridProcesscheckBoxHasChanged(int)));
QObject::connect(OutputFolderLineEdit, SIGNAL(textChanged(QString)), this, SLOT(OutputFolderLineEditHasChanged(QString)));
QObject::connect(AffineQCButton, SIGNAL(clicked()), this, SLOT(DisplayAffineQC()));
QObject::connect(DeformQCButton, SIGNAL(clicked()), this, SLOT(DisplayDeformQC()));
QObject::connect(ResampQCButton, SIGNAL(clicked()), this, SLOT(DisplayResampQC()));
QObject::connect(CleanOutputPushButton, SIGNAL(clicked()), this, SLOT(CleanOutputFolder()));
/* Browse software path Buttons */
QSignalMapper *SoftButtonMapper = new QSignalMapper();
QObject::connect(SoftButtonMapper, SIGNAL(mapped(int)), this, SLOT( BrowseSoft(int) ));
QObject::connect(ImagemathButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(ImagemathButton,1);
QObject::connect(ResampButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(ResampButton,2);
QObject::connect(CropDTIButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(CropDTIButton,3);
QObject::connect(dtiprocButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(dtiprocButton,4);
QObject::connect(BRAINSFitButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(BRAINSFitButton,5);
QObject::connect(GAButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(GAButton,6);
QObject::connect(dtiavgButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(dtiavgButton,7);
QObject::connect(DTIRegButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(DTIRegButton,8);
QObject::connect(unuButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(unuButton,9);
QObject::connect(MriWatcherButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(MriWatcherButton,10);
QObject::connect(ITKTransformToolsButton, SIGNAL(clicked()), SoftButtonMapper, SLOT(map()));
SoftButtonMapper->setMapping(ITKTransformToolsButton,11);
/* Reset software path Buttons */
QSignalMapper *ResetSoftButtonMapper = new QSignalMapper();
QObject::connect(ResetSoftButtonMapper, SIGNAL(mapped(int)), this, SLOT( ResetSoft(int) ));
QObject::connect(ImagemathResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(ImagemathResetButton,1);
QObject::connect(ResampResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(ResampResetButton,2);
QObject::connect(CropDTIResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(CropDTIResetButton,3);
QObject::connect(dtiprocResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(dtiprocResetButton,4);
QObject::connect(BRAINSFitResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(BRAINSFitResetButton,5);
QObject::connect(GAResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(GAResetButton,6);
QObject::connect(dtiavgResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(dtiavgResetButton,7);
QObject::connect(DTIRegResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(DTIRegResetButton,8);
QObject::connect(unuResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(unuResetButton,9);
QObject::connect(MriWatcherResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(MriWatcherResetButton,10);
QObject::connect(ITKTransformToolsResetButton, SIGNAL(clicked()), ResetSoftButtonMapper, SLOT(map()));
ResetSoftButtonMapper->setMapping(ITKTransformToolsResetButton,11);
/* When any value changes, the value of m_ParamSaved is set to 0 */
QObject::connect(TemplateLineEdit, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(OutputFolderLineEdit, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SafetyMargincheckBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(BFAffineTfmModecomboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(OverwritecheckBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL4checkBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL2checkBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL1checkBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(NbLoopsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL4spinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(nbIter4SpinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(alpha4DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(beta4DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(gamma4DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(maxPerturbation4DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL2spinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(nbIter2SpinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(alpha2DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(beta2DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(gamma2DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(maxPerturbation2DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(SL1spinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(nbIter1SpinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(alpha1DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(beta1DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(gamma1DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(maxPerturbation1DoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(TensTfmComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(InterpolTypeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(TensInterpolComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(DTIRegExtraPathlineEdit, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(RegMethodcomboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_windowComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_BSplineComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_nologComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_BRegTypeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_TfmModeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_NbPyrLevSpin, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_PyrLevItLine, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_ARegTypeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_TfmStepLine, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_IterLine, SIGNAL(textChanged(QString)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_SimMetComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_SimParamDble, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_GSigmaDble, SIGNAL(valueChanged(double)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(m_SmoothOffCheck, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(NbThreadsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
QObject::connect(GridProcesscheckBox, SIGNAL(stateChanged(int)), this, SLOT(WidgetHasChangedParamNoSaved()));
} //if(!m_noGUI)
m_FromConstructor=1; // do not test GA path if 'Default' called from constructor -> test at the end of constructor
/* SET the soft config */
// std::vector
std::string DTIABExecutablePath = itksys::SystemTools::GetRealPath( itksys::SystemTools::GetFilenamePath(commandRan).c_str() );
if( DTIABExecutablePath=="" ) // if DTIAtlasBuilder called without path (e.g. $ DTIAtlasBuilder) => either found in the PATH or in the current dir => FindProgram will find it
{
DTIABExecutablePath = itksys::SystemTools::GetFilenamePath( itksys::SystemTools::FindProgram( itksys::SystemTools::GetFilenameName(commandRan).c_str() ).c_str() );
// get the name of the executable used (i.e. DTIAtlasBuilder, DTIAtlasBuilder_vX.X (GetFilenameName), then search it in the PATH or current dir (FindProgram) and get the parent dir (GetFilenamePath)
}
// set the path to the executable directory for FindProgram
m_FindProgramDTIABExecDirVec.push_back(DTIABExecutablePath); // FindProgram will search in the executable directory too
// If DTIAB is built as an SlicerExtension, give the path to the folder containing external non cli tools
// If no SicerExtension, find_program will just search there and find nothing -> not an issue
m_DTIABSlicerExtensionExternalBinDir = DTIABExecutablePath + "/../ExternalBin";
m_FindProgramDTIABExecDirVec.push_back(m_DTIABSlicerExtensionExternalBinDir);
// On Mac if Slicer Ext, paths to BRAINS (compiled within Slicer) are not set in the PATH env var, so add it to the search vector
if(DTIAtlasBuilder_BUILD_SLICER_EXTENSION && (std::string)Platform=="mac")
{
std::string SlicerExtMacBRAINSPath = m_DTIABSlicerExtensionExternalBinDir + "/../../../cli_modules";
m_FindProgramDTIABExecDirVec.push_back(SlicerExtMacBRAINSPath);
}
// Because ANTS is in m_DTIABSlicerExtensionExternalBinDir when Slicer Ext
if(DTIAtlasBuilder_BUILD_SLICER_EXTENSION)
{
// There are always 2 elements at least in m_FindProgramDTIABExecDirVec when build as an extension: DTIABExecutablePath and DTIABExecutablePath + "/../ExternalBin"
QString listPath = m_FindProgramDTIABExecDirVec[ 0 ].c_str() ;
for( size_t i = 1 ; i < m_FindProgramDTIABExecDirVec.size() ; i++ )
{
listPath += QString(",") + m_FindProgramDTIABExecDirVec[i].c_str() ;
}
DTIRegExtraPathlineEdit->setText( listPath ) ;
}
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../ResampleDTIlogEuclidean/" + std::string(Slicer_CLIMODULES_BIN_DIR));
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../ResampleDTIlogEuclidean/" + std::string(Slicer_CLIMODULES_BIN_DIR) + "/../ExternalBin");
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../DTI-Reg/" + std::string(Slicer_CLIMODULES_BIN_DIR));
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../DTI-Reg/" + std::string(Slicer_CLIMODULES_BIN_DIR) + "/../ExternalBin");
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../DTIProcess/" + std::string(Slicer_CLIMODULES_BIN_DIR));
// m_FindProgramDTIABExecDirVec.push_back(commandRan + "/../../../../DTIProcess/" + std::string(Slicer_CLIMODULES_BIN_DIR) + "/../ExternalBin");
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/ResampleDTIlogEuclidean/bin/");
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/DTI-Reg/bin/" );
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/DTIProcess/bin/");
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/niral_utilities/bin/");
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/AtlasWerks/bin/" );
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/teem/bin/" );
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/BRAINSTools/bin/" );
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/MriWatcher/bin/");
m_FindProgramDTIABExecDirVec.push_back(commandRan + "/ITKTransformTools/bin/");
// look for the programs with the itk function
ConfigDefault(commandRan);
// Look for the config file in the executable directory
//std::string SoftConfigPath= DTIABExecutablePath + "/DTIAtlasBuilderSoftConfig.txt";
std::string SoftConfigPath= m_ExecutableDir + "/DTIAtlasBuilderSoftConfig.txt";
std::cout << m_ExecutableDir;
if( itksys::SystemTools::GetPermissions(SoftConfigPath.c_str(),ITKmode_F_OK) )
{
if( LoadConfig(QString( SoftConfigPath.c_str() )) == -1 )
{
m_ErrorDetectedInConstructor=true; // if file exists
}
}
// Look for the config file in the current directory
std::string CurrentPath = itksys::SystemTools::GetRealPath( itksys::SystemTools::GetCurrentWorkingDirectory().c_str() ); //GetRealPath() to remove symlinks
SoftConfigPath = CurrentPath + "/DTIAtlasBuilderSoftConfig.txt";
if( itksys::SystemTools::GetPermissions( SoftConfigPath.c_str() , ITKmode_F_OK) )
{
if( LoadConfig(QString( SoftConfigPath.c_str() )) == -1 )
{
m_ErrorDetectedInConstructor=true; // if file exists
}
}
// Look for the config file in the env variable
const char * value = itksys::SystemTools::GetEnv("DTIAtlasBuilderSoftPath"); // C function = const char * getenv(const char *)
if (value!=NULL)
{
printf ("| Environment variable read. The config file is \'%s\'\n",value);
if( LoadConfig(QString(value)) == -1 )
{
m_ErrorDetectedInConstructor=true; // replace the paths by the paths given in the config file
}
}
else
{
std::cout<<"| No environment variable found"<<std::endl;
}
/* Look for the parameter file in the current directory */ // Load only if no param file given and if CSV file is given, only load the given CSV file.
std::string ParamPath = CurrentPath + "/DTIAtlasBuilderParameters.txt";
if( ParamFile.empty() && itksys::SystemTools::GetPermissions( ParamPath.c_str() , ITKmode_F_OK) )
{
if( LoadParameters(QString( ParamPath.c_str() ), !CSVFile.empty()) == -1 )
{
m_ErrorDetectedInConstructor=true;
}
}
/* Load Parameters from Command Line => cmd line arguments a taking into account at last and change the parameters at last because they have priority */
if( !ParamFile.empty() )
{
if( LoadParameters(QString(ParamFile.c_str()), !CSVFile.empty()) == -1 )
{
m_ErrorDetectedInConstructor=true;
}
}
else if(m_noGUI) // no parameters and nogui => not possible
{
std::cout<<"| Please give a parameter file"<<std::endl; // command line display
m_ErrorDetectedInConstructor=true;
}
if( !CSVFile.empty() )
{
if( ReadCSV( QString(CSVFile.c_str())) == -1 )
{
m_ErrorDetectedInConstructor=true;
}
}
if( !ConfigFile.empty() )
{
if( LoadConfig( QString(ConfigFile.c_str())) == -1 )
{
m_ErrorDetectedInConstructor=true;
}
}
m_FromConstructor=0;
/* NOW that all the files have been loaded => test if all the paths are here */
bool GAFound=true;
bool DTIRegFound=true;
std::string notFound;
if(ImagemathPath->text().isEmpty()) notFound = notFound + "> ImageMath\n";
if(ResampPath->text().isEmpty()) notFound = notFound + "> ResampleDTIlogEuclidean\n";
if(CropDTIPath->text().isEmpty()) notFound = notFound + "> CropDTI\n";
if(dtiprocPath->text().isEmpty()) notFound = notFound + "> dtiprocess\n";
if(BRAINSFitPath->text().isEmpty()) notFound = notFound + "> BRAINSFit\n";
if(GAPath->text().isEmpty())
{
notFound = notFound + "> GreedyAtlas\n";
GAFound=false; // so it will not test the version
}
if(dtiavgPath->text().isEmpty()) notFound = notFound + "> dtiaverage\n";
if(DTIRegPath->text().isEmpty())
{
notFound = notFound + "> DTI-Reg\n";
DTIRegFound=false; // so it will not test the version
}
if(unuPath->text().isEmpty()) notFound = notFound + "> unu\n";
if(ITKTransformToolsPath->text().isEmpty()) notFound = notFound + "> ITKTransformTools\n";
if(MriWatcherPath->text().isEmpty()) notFound = notFound + "> MriWatcher (Program will work, but QC will not be available)\n";
if( !notFound.empty() )
{
if(!m_noGUI && !m_Testing)
{
std::string text = "The following programs have not been found.\nPlease enter the path manually or open a configuration file:\n" + notFound;
QMessageBox::warning(this, "Program missing", QString(text.c_str()) );
}
else
{
std::cout<<"| The following programs have not been found. Please give a configuration file or modify it or enter the path manually in the GUI:\n"<< notFound <<std::endl;
}
}
if(GAFound)
{
testGA(); // test the version of GreedyAtlas only if found
}
if(DTIRegFound)
{
testDTIReg(); // test the version of DTI-Reg only if found
}
}
/////////////////////////////////////////
// INITIALIZATIONS //
/////////////////////////////////////////
void GUI::InitOptions()
{
/* Init options for Final AtlasBuilding param : Interpolation algo */
m_optionStackLayout = new QStackedWidget;
optionHLayout->addWidget(m_optionStackLayout);
QWidget *emptyWidget= new QWidget;
m_optionStackLayout->addWidget(emptyWidget);
QLabel *windowLabel = new QLabel("Type:", this);
m_windowComboBox = new QComboBox(this);
m_windowComboBox->addItem("Hamming");
m_windowComboBox->addItem("Cosine");
m_windowComboBox->addItem("Welch");
m_windowComboBox->addItem("Lanczos");
m_windowComboBox->addItem("Blackman");
m_windowComboBox->setCurrentIndex(1);
QHBoxLayout *windowLayout= new QHBoxLayout;
windowLayout->addWidget(windowLabel);
windowLayout->addWidget(m_windowComboBox);
QWidget *windowWidget= new QWidget;
windowWidget->setLayout(windowLayout);
m_optionStackLayout->addWidget(windowWidget);
QLabel *BSplineLabel = new QLabel("Order:", this);
m_BSplineComboBox = new QComboBox(this);
m_BSplineComboBox->addItem("0");
m_BSplineComboBox->addItem("1");
m_BSplineComboBox->addItem("2");
m_BSplineComboBox->addItem("3");
m_BSplineComboBox->addItem("4");
m_BSplineComboBox->addItem("5");
m_BSplineComboBox->setCurrentIndex(3);
QHBoxLayout *BSplineLayout= new QHBoxLayout;
BSplineLayout->addWidget(BSplineLabel);
BSplineLayout->addWidget(m_BSplineComboBox);
QWidget *BSplineWidget= new QWidget;
BSplineWidget->setLayout(BSplineLayout);
m_optionStackLayout->addWidget(BSplineWidget);
m_optionStackLayout->setCurrentIndex(0);
/* Init options for Final AtlasBuilding param : Tensor Interpolation */
m_logOptionStackLayout = new QStackedWidget;
logOptionHLayout->addWidget(m_logOptionStackLayout);
QWidget *logEmptyWidget= new QWidget;
m_logOptionStackLayout->addWidget(logEmptyWidget);
QLabel *nologLabel = new QLabel("Correction:", this);
m_nologComboBox = new QComboBox(this);
m_nologComboBox->addItem("Zero");
m_nologComboBox->addItem("None");
m_nologComboBox->addItem("Absolute Value");
m_nologComboBox->addItem("Nearest");
m_nologComboBox->setCurrentIndex(1);
QHBoxLayout *nologLayout= new QHBoxLayout;
nologLayout->addWidget(nologLabel);
nologLayout->addWidget(m_nologComboBox);
QWidget *nologWidget= new QWidget;
nologWidget->setLayout(nologLayout);
m_logOptionStackLayout->addWidget(nologWidget);
m_logOptionStackLayout->setCurrentIndex(0);
/* Init options for DTI-Reg: Reg Method */
m_DTIRegOptionStackLayout = new QStackedWidget;
DTIRegOptionsVLayout->addWidget(m_DTIRegOptionStackLayout);
/*BRAINS*/
QHBoxLayout *BRAINSHLayout = new QHBoxLayout;
QVBoxLayout *BRAINSLabelVLayout = new QVBoxLayout;
BRAINSHLayout->addLayout(BRAINSLabelVLayout);
QVBoxLayout *BRAINSWidgetVLayout = new QVBoxLayout;
BRAINSHLayout->addLayout(BRAINSWidgetVLayout);
QLabel *BRegTypeLabel = new QLabel("Registration Type:", this);
BRAINSLabelVLayout->addWidget(BRegTypeLabel);
m_BRegTypeComboBox = new QComboBox(this);
m_BRegTypeComboBox->addItem("None");
m_BRegTypeComboBox->addItem("Rigid");
m_BRegTypeComboBox->addItem("BSpline");
m_BRegTypeComboBox->addItem("Diffeomorphic");
m_BRegTypeComboBox->addItem("Demons");
m_BRegTypeComboBox->addItem("FastSymmetricForces");
m_BRegTypeComboBox->setCurrentIndex(3);
BRAINSWidgetVLayout->addWidget(m_BRegTypeComboBox);
QLabel *TfmModeLabel = new QLabel("Transform Mode:", this);
BRAINSLabelVLayout->addWidget(TfmModeLabel);
m_TfmModeComboBox = new QComboBox(this);
m_TfmModeComboBox->addItem("Off");
m_TfmModeComboBox->addItem("useMomentsAlign");
m_TfmModeComboBox->addItem("useCenterOfHeadAlign");
m_TfmModeComboBox->addItem("useGeometryAlign");
m_TfmModeComboBox->addItem("Use computed affine transform");
m_TfmModeComboBox->setCurrentIndex(4);
BRAINSWidgetVLayout->addWidget(m_TfmModeComboBox);
QLabel *NbPyrLevLabel = new QLabel("Number Of Pyramid Levels:", this);
BRAINSLabelVLayout->addWidget(NbPyrLevLabel);
m_NbPyrLevSpin = new QSpinBox(this);
m_NbPyrLevSpin->setValue(5);
BRAINSWidgetVLayout->addWidget(m_NbPyrLevSpin);
QLabel *PyrLevItLabel = new QLabel("Number Of Iterations for the Pyramid Levels:", this);
BRAINSLabelVLayout->addWidget(PyrLevItLabel);
m_PyrLevItLine = new QLineEdit(this);
m_PyrLevItLine->setText("300,50,30,20,15");
BRAINSWidgetVLayout->addWidget(m_PyrLevItLine);
QWidget *BRAINSWidget = new QWidget;
BRAINSWidget->setLayout(BRAINSHLayout);
m_DTIRegOptionStackLayout->addWidget(BRAINSWidget);
/*ANTS*/
QHBoxLayout *ANTSHLayout = new QHBoxLayout;
QVBoxLayout *ANTSLabelVLayout = new QVBoxLayout;
ANTSHLayout->addLayout(ANTSLabelVLayout);
QVBoxLayout *ANTSWidgetVLayout = new QVBoxLayout;
ANTSHLayout->addLayout(ANTSWidgetVLayout);
QLabel *ARegTypeLabel = new QLabel("Registration Type:", this);
ANTSLabelVLayout->addWidget(ARegTypeLabel);
m_ARegTypeComboBox = new QComboBox(this);
m_ARegTypeComboBox->addItem("None");
m_ARegTypeComboBox->addItem("Rigid");
m_ARegTypeComboBox->addItem("Elast");
m_ARegTypeComboBox->addItem("Exp");
m_ARegTypeComboBox->addItem("GreedyExp");
m_ARegTypeComboBox->addItem("GreedyDiffeo (SyN)");
m_ARegTypeComboBox->addItem("SpatioTempDiffeo (SyN)");
m_ARegTypeComboBox->setCurrentIndex(5);
QObject::connect(m_ARegTypeComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(ANTSRegTypeChanged( int )));
ANTSWidgetVLayout->addWidget(m_ARegTypeComboBox);
QLabel *TfmStepLabel = new QLabel("Transformation Step:", this);
ANTSLabelVLayout->addWidget(TfmStepLabel);
m_TfmStepLine = new QLineEdit(this);
m_TfmStepLine->setText("0.25");
ANTSWidgetVLayout->addWidget(m_TfmStepLine);
QLabel *IterLabel = new QLabel("Iterations:", this);
ANTSLabelVLayout->addWidget(IterLabel);
m_IterLine = new QLineEdit(this);
m_IterLine->setText("100x50x25");
ANTSWidgetVLayout->addWidget(m_IterLine);
QLabel *SimMetLabel = new QLabel("Similarity Metric:", this);
ANTSLabelVLayout->addWidget(SimMetLabel);
m_SimMetComboBox = new QComboBox(this);
m_SimMetComboBox->addItem("Cross-Correlation (CC)");
m_SimMetComboBox->addItem("Mutual Information (MI)");
m_SimMetComboBox->addItem("Mean Square Difference (MSQ)");
m_SimMetComboBox->setCurrentIndex(0);
QObject::connect(m_SimMetComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(SimMetChanged( int )));
ANTSWidgetVLayout->addWidget(m_SimMetComboBox);
m_SimParamLabel = new QLabel("Region Radius:", this);
ANTSLabelVLayout->addWidget(m_SimParamLabel);
m_SimParamDble = new QDoubleSpinBox(this);
m_SimParamDble->setValue(2);
ANTSWidgetVLayout->addWidget(m_SimParamDble);
QLabel *GSigmaLabel = new QLabel("Gaussian Sigma:", this);
ANTSLabelVLayout->addWidget(GSigmaLabel);
m_GSigmaDble = new QDoubleSpinBox(this);
m_GSigmaDble->setValue(3);
ANTSWidgetVLayout->addWidget(m_GSigmaDble);
m_SmoothOffCheck = new QCheckBox("Gaussian Smoothing Off", this);
m_SmoothOffCheck->setChecked(false);
m_SmoothOffCheck->setLayoutDirection(Qt::RightToLeft);
ANTSLabelVLayout->addWidget(m_SmoothOffCheck);
QLabel *emptyL = new QLabel("", this);
ANTSWidgetVLayout->addWidget(emptyL);
QWidget *ANTSWidget = new QWidget;
ANTSWidget->setLayout(ANTSHLayout);
m_DTIRegOptionStackLayout->addWidget(ANTSWidget);
m_DTIRegOptionStackLayout->setCurrentIndex(0); //BRAINS is the default
}
/////////////////////////////////////////
// Hierarchy //
/////////////////////////////////////////
void GUI::newHierarchyProject(){
bool ok;
QString name= QInputDialog::getText(this, QString("Project Name"), QString("Project Name : "), QLineEdit::Normal, "FinalAtlas", &ok);
if(ok){
m_HierarchyModel->initialize(name);
QModelIndex idx=m_HierarchyModel->getCurrentItem()->index();
caseHierarchyTreeView->setModel(m_HierarchyModel);
enableTreeViewWidget(true);
caseHierarchyTreeView->clicked(idx);
caseHierarchyTreeView->selectionModel()->select(QItemSelection(idx,idx),QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
caseHierarchyTreeView->setExpanded(m_HierarchyModel->getCurrentItem()->index(),1);
SelectCasesLabel->setText(QString(""));
//std::cout << m_HierarchyModel->toString().toStdString() << std::endl;
}
}
void GUI::openHierarchyFile() /*SLOT*/
{
QString fileBrowse=QFileDialog::getOpenFileName(this, "Open Case Hierarchy File", QString(), "JSON File (*.json);;All Files (*.*)");
if(!fileBrowse.isEmpty())
{
//load and set the caseHierarchyTreeView
try{
m_HierarchyModel->loadFile(fileBrowse);
QModelIndex idx=m_HierarchyModel->getCurrentItem()->index();
enableTreeViewWidget(true);
caseHierarchyTreeView->clicked(idx);
caseHierarchyTreeView->selectionModel()->select(QItemSelection(idx,idx),QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
caseHierarchyTreeView->setExpanded(m_HierarchyModel->getCurrentItem()->index(),1);
SelectCasesLabel->setText(fileBrowse);
}catch(const std::exception &e){
m_HierarchyModel->clear();
QMessageBox::warning(this,"Failed to load","Failed to load hierarchy file.");
}
//std::cout << m_HierarchyModel->toString().toStdString() << std::endl;
}
}
void GUI::openProjectDirectorySlot() //
{
QString CurrentOutputFolder = "";
if( !OutputFolderLineEdit->text().isEmpty() )
{
CurrentOutputFolder = OutputFolderLineEdit->text();
}
QString OutputBrowse = QFileDialog::getExistingDirectory( this, "Find Directory", CurrentOutputFolder );
if(!OutputBrowse.isEmpty())
{
OutputFolderLineEdit->setText(OutputBrowse);
//Load hiearchical build file
try{
QString filename = OutputBrowse + "/common/h-build.json";
m_HierarchyModel->loadFile(filename);
QModelIndex idx=m_HierarchyModel->getCurrentItem()->index();
enableTreeViewWidget(true);
caseHierarchyTreeView->clicked(idx);
caseHierarchyTreeView->selectionModel()->select(QItemSelection(idx,idx),QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
caseHierarchyTreeView->setExpanded(m_HierarchyModel->getCurrentItem()->index(),1);
SelectCasesLabel->setText(filename);
}catch(const std::exception &e){
m_HierarchyModel->clear();
QMessageBox::warning(this,"Failed to load","Failed to load hierarchy file.");
}
//Load parameter file
try{
QString paramfilename=OutputBrowse+"/common/DTIAtlasBuilderParameters.txt";
LoadParameters(paramfilename,false);
}catch(const std::exception &e){
QMessageBox::warning(this,"Failed to load","Failed to load parameter file.");
}
}
}
void GUI::saveHierarchyFile() /*SLOT*/
{
QString fileBrowse=QFileDialog::getSaveFileName(this, "Save Case Hierarchy File", QString(), "JSON File (*.json);;All Files (*.*)");
if(!fileBrowse.isEmpty())
{
//load and set the caseHierarchyTreeView
m_HierarchyModel->saveFile(fileBrowse);
SelectCasesLabel->setText(fileBrowse);
//std::cout << m_HierarchyModel->toString().toStdString() << std::endl;
}
}
void GUI::addNode(){
std::cout << " Adding node" << std::endl;
// first to change the node type to 'node' to current selected item
// second to choose the node type of generated node. (node / end_node)
//production codes
bool ok;
QString prefix="";
QString currentTag=m_HierarchyModel->getCurrentTag();
QString currentType=m_HierarchyModel->getCurrentType();
int dlg_ret=QMessageBox::Yes;
if(m_HierarchyModel->checkCaseExists(currentTag))
{
dlg_ret=QMessageBox::warning(this,"Containing filed","This operation removes the current node's case list, are you sure to proceed?",QMessageBox::No|QMessageBox::Yes);
}
if(dlg_ret==QMessageBox::Yes){
if(m_HierarchyModel->getCurrentItem()!=m_HierarchyModel->getRoot()){
prefix=m_HierarchyModel->getCurrentTag() + QString("-");
}
QString name= QInputDialog::getText(this, QString("Input the name of new atlas node"), QString("New atlas name : ") + prefix, QLineEdit::Normal, "myatlas", &ok);
if(ok){
if(m_HierarchyModel->checkNodename(prefix+name)){
QMessageBox::warning(this, "Failed to add a node", QString("There is an existing node with the name of ")+name);
}else{
m_HierarchyModel->addNode(prefix+name);
caseHierarchyTreeView->setExpanded(m_HierarchyModel->getCurrentItem()->index(),1);
caseHierarchyTreeView->clicked(m_HierarchyModel->getCurrentItem()->index());
}
}
}
}
void GUI::removeNode(){
//std::cout << " Current node " << m_HierarchyModel->getCurrentItem()->text().toStdString() << std::endl;
bool ok;
QString currentTag=m_HierarchyModel->getCurrentTag();
if(m_HierarchyModel->isRoot(currentTag)){
QMessageBox::warning(this,"Warning","Root node cannot be removed. If you want to start a new project, select New project in menu");
}else{
int ret=QMessageBox::warning(this,"Remove Node","Are you sure to delete the node : " + currentTag + " ?",QMessageBox::No | QMessageBox::Yes);
if(ret==QMessageBox::Yes){
m_HierarchyModel->removeCurrentNode();
QModelIndexList idxl=caseHierarchyTreeView->selectionModel()->selectedIndexes();
foreach(const QModelIndex &idx, idxl){
//std::cout << idx.data().toString().toStdString() << std::endl;
m_HierarchyModel->setCurrentTag(idx);
}
caseHierarchyTreeView->clicked(m_HierarchyModel->getCurrentItem()->index());
}
}
}
void GUI::treeViewItemSelected(const QModelIndex idx){
//std::cout << "item clicked (" << idx.row()<<","<<idx.column() << ")" <<std::endl;
QString tag = idx.data().toString();
//std::cout << tag.toStdString() << std::endl;
m_HierarchyModel->setCurrentTag(idx);
QString _type=m_HierarchyModel->getCurrentType();
CaseListWidget->clear();
QStringList CL=m_HierarchyModel->getFileList(tag);
AddCasesToListWidget(CL,QString(""));
if(_type==QString("node")){
enableCaseWidget(0);
}else{
enableCaseWidget(1);
}
}
void GUI::treeViewItemChanged(const QModelIndex idx){
QString tag = idx.data().toString();
int res=m_HierarchyModel->changeCurrentNode(idx,tag);
m_HierarchyModel->update();
//std::cout << m_HierarchyModel->toString().toStdString() << std::endl;
}
void GUI::updateHierarchyFiles(){
QStringList ql;
QString nodename = m_HierarchyModel->getCurrentTag();
for(int i=0; i < CaseListWidget->count() ;i++){
QString s=CaseListWidget->item(i)->text().split(QString(": ")).at(1);
//std::cout << s.toStdString() << std::endl;
ql.append(s);
}
m_HierarchyModel->setFiles(nodename,ql);
}
void GUI::enableCaseWidget(bool tf){
CaseListWidget->setEnabled(tf);
AddPushButton->setEnabled(tf);
RemovePushButton->setEnabled(tf);
BrowseCSVPushButton->setEnabled(tf);
SaveCSVPushButton->setEnabled(tf);
}
void GUI::enableTreeViewWidget(bool tf){
caseHierarchyTreeView->setEnabled(tf);
addNodeButton->setEnabled(tf);
removeNodeButton->setEnabled(tf);
saveHierarchyButton->setEnabled(tf);
ComputepushButton->setEnabled(tf);
StoppushButton->setEnabled(tf);
AffineQCButton->setEnabled(tf);
DeformQCButton->setEnabled(tf);
CleanOutputPushButton->setEnabled(tf);
ResampQCButton->setEnabled(tf);
}
/////////////////////////////////////////
// CASES //
/////////////////////////////////////////
bool GUI::FileIsParameterFile( std::string filepath ) // TODO
{
if( itksys::SystemTools::GetFilenameLastExtension( filepath ) != ".txt" )
{
return false;
}
QFile file(filepath.c_str());
if (file.open(QFile::ReadOnly))
{
QTextStream stream(&file);
QString line = stream.readLine();
QStringList list = line.split("=");
if( ! list.at(0).contains("DTIAtlasBuilderParameterFileVersion") )
{
return false;
}
}
return true;
}
bool GUI::FileIsSoftConfigFile( std::string filepath ) // TODO
{
if( itksys::SystemTools::GetFilenameLastExtension( filepath ) != ".txt" )
{
return false;
}
QFile file(filepath.c_str());
if (file.open(QFile::ReadOnly))
{
QTextStream stream(&file);
QString line = stream.readLine();
QStringList list = line.split("=");
if( ! list.at(0).contains("ImageMath") )
{
return false;
}
line = stream.readLine();
list = line.split("=");
if( ! list.at(0).contains("ResampleDTIlogEuclidean") )
{
return false;
}
}
return true;
}
void GUI::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void GUI::dropEvent(QDropEvent* event)
{
const QMimeData* mimeData = event->mimeData();
// check for needed mime type, a file or a list of files
if( mimeData->hasUrls() )
{
QStringList pathList;
QList<QUrl> urlList = mimeData->urls();
// extract the local paths of the files
for (int i = 0; i < urlList.size(); ++i)
{
QString CurrentFile = urlList.at(i).toLocalFile();
if ( itksys::SystemTools::GetFilenameLastExtension( CurrentFile.toStdString() ) == ".csv" ) // load possible csv file(s)
{
ReadCSV( CurrentFile );
}
else if ( FileIsParameterFile( CurrentFile.toStdString() ) ) // load possible parameter file(s)
{
LoadParameters(CurrentFile,false);
}
else if ( FileIsSoftConfigFile( CurrentFile.toStdString() ) ) // load possible soft config file(s)