-
Notifications
You must be signed in to change notification settings - Fork 2
/
UMMPPrefController.m
978 lines (828 loc) · 40.4 KB
/
UMMPPrefController.m
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
//
// UMMPPrefController.m
// UMMPerfusion
//
// Created by Sven Kaiser on 02.11.11.
// Copyright (c) 2012, Marcel Reich & Sven Kaiser & Markus Daab & Patrick Schülein & Engin Aslan
// All rights reserved.
//
#import "UMMPPrefController.h"
#import "UMMPPanelController.h"
#import "UMMPPreset.h"
#import "UMMPUserDefaults.h"
#import <OsiriXAPI/Notifications.h>
#define PresetsTableViewDataType @"de.umm.ummperfusion.PresetTableViewDataType"
@implementation UMMPPrefController
@synthesize presets;
@synthesize maxIterations;
@synthesize maxFunctionEvaluation;
@synthesize extROIFilename;
@synthesize extROI;
@synthesize extROIExists;
@synthesize extROIFilePathForReport;
enum {
general = 0,
presetValues,
mapSelection,
mpFit,
aifImport
};
- (id)init {
self = [super init];
aifExportData = [[NSMutableArray alloc] init];
return self;
}
- (id)initWithPanelController:(UMMPPanelController *)givenPanelController
{
self = [super initWithWindowNibName:@"UMMPPreferencePanel"];
if (self) {
panelController = givenPanelController;
extROIFilePathForReport = [[NSMutableString alloc] initWithString:@""];
extROIFilename = [[NSString alloc] init];
}
return self;
}
-(void)initValues
{
NSData *archive = [[panelController userDefaults] obj:@"UMMPPresets" otherwise:nil];
NSString *maxIterationData = [[panelController userDefaults] string:@"UMMPMaxIterations" otherwise:nil];
NSString *maxFunctionEvaluationData = [[panelController userDefaults] string:@"UMMPMaxFunctionEvaluation" otherwise:nil];
if (archive) {
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
presets = [[NSMutableArray arrayWithArray:array] retain];
} else {
presets = [[NSMutableArray alloc] init];
UMMPPreset *presetItem = [[UMMPPreset alloc] init];
[presets addObject: presetItem];
[presetItem release];
}
if (!maxIterationData) {
[[panelController userDefaults] setString:@"200" forKey:@"UMMPMaxIterations"];
}
if (!maxFunctionEvaluationData) {
[[panelController userDefaults] setString:@"1000" forKey:@"UMMPMaxFunctionEvaluation"];
}
if (![[panelController userDefaults] keyExists:@"soundOnMapsCalcEnd"]) {
[[panelController userDefaults] setInt:1 forKey:@"soundOnMapsCalcEnd"];
}
if (![[panelController userDefaults] keyExists:@"soundOnAllMapsCalcEnd"]) {
[[panelController userDefaults] setInt:1 forKey:@"soundOnAllMapsCalcEnd"];
}
if (![[panelController userDefaults] keyExists:@"printPresetsToConsole"]) {
[[panelController userDefaults] setInt:1 forKey:@"printPresetsToConsole"];
}
if (![[panelController userDefaults] keyExists:@"useExternalAifCheckBox"]) {
[[panelController userDefaults] setInt:0 forKey:@"useExternalAifCheckBox"];
}
if(![[panelController userDefaults] keyExists:@"aifImportValidation"]){
[[panelController userDefaults] setInt:0 forKey:@"aifImportValidation"];
}
[presetsTableView reloadData];
[parametersTableView reloadData];
[self refreshStatusOfMapSelection];
[self setRemoveButtonState];
}
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:nil];
[presetsTableView registerForDraggedTypes:[NSArray arrayWithObject:PresetsTableViewDataType]];
[presetsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
[self setRemoveButtonState];
[_toolbar setSelectedItemIdentifier:@"general"];
[self changeViewForTag:0];
[self refreshStatusOfMapSelection];
[maxIterations setIntValue: [[[panelController userDefaults] string:@"UMMPMaxIterations" otherwise:nil] intValue]];
[maxFunctionEvaluation setIntValue: [[[panelController userDefaults] string:@"UMMPMaxFunctionEvaluation" otherwise:nil] intValue]];
[soundOnMapsCalcEnd setState:[[panelController userDefaults] int:@"soundOnMapsCalcEnd" otherwise:0]];
[soundOnAllMapsCalcEnd setState:[[panelController userDefaults] int:@"soundOnAllMapsCalcEnd" otherwise:0]];
[printPresetsToConsole setState:[[panelController userDefaults] int:@"printPresetsToConsole" otherwise:0]];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[self refreshStatusOfMapSelection];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[aifExportData release]; aifExportData = nil;
[extROIFilePathForReport release]; extROIFilePathForReport = nil;
[extROIFilename release]; extROIFilename = nil;
[super dealloc];
}
- (void)windowWillClose:(NSNotification *)notification
{
/* ACHTUNG TEST */
if ([notification object] == [self window]) {
//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:presets];
//[defaults setObject:archive forKey:@"UMMPpresets"];
[[panelController userDefaults] setObj:archive forKey:@"UMMPPresets"];
if ([maxIterations intValue] < 1 || [maxIterations intValue] > 999) {
[[panelController userDefaults] setString:@"200" forKey:@"UMMPMaxIterations"];
//[[NSUserDefaults standardUserDefaults] setValue:@"200" forKey:@"UMMPmaxIterations"];
} else {
[[panelController userDefaults] setString:[maxIterations stringValue] forKey:@"UMMPMaxIterations"];
//[[NSUserDefaults standardUserDefaults] setValue:[maxIterations stringValue] forKey:@"UMMPmaxIterations"];
}
[maxIterations setStringValue:[[panelController userDefaults] string:@"UMMPMaxIterations" otherwise:nil]];
}
}
- (IBAction)addPresetItem:(id)sender
{
[presets addObject: [[UMMPPreset alloc] init]];
[presetsTableView noteNumberOfRowsChanged];
NSInteger rowIndex = [presets count]-1;
[presetsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex]
byExtendingSelection:NO];
[[panelController algorithmController] loadPresets:presets];
[self setRemoveButtonState];
}
- (void)addPresetItemForNewVersion
{
[presets addObject: [[UMMPPreset alloc] init]];
[presetsTableView noteNumberOfRowsChanged];
NSInteger rowIndex = [presets count]-1;
[presetsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex]
byExtendingSelection:NO];
[[panelController algorithmController] loadPresets:presets];
[self setRemoveButtonState];
}
- (IBAction)removePresetItem:(id)sender
{
NSUInteger numberIndexes = [[presetsTableView selectedRowIndexes] count];
if ([presets count] > 1 && numberIndexes != [presets count]) {
NSIndexSet *indexes = [presetsTableView selectedRowIndexes];
[presets removeObjectsAtIndexes:indexes];
[presetsTableView noteNumberOfRowsChanged];
}
[presetsTableView reloadData];
[parametersTableView reloadData];
[[panelController algorithmController] loadPresets:presets];
[self setRemoveButtonState];
}
- (void)removeAllPresetItems
{
[presets removeAllObjects];
[presetsTableView noteNumberOfRowsChanged];
[presetsTableView reloadData];
[parametersTableView reloadData];
[[panelController algorithmController] loadPresets:presets];
[self setRemoveButtonState];
}
- (IBAction)exportPreset:(id)sender
{
NSInteger presetIndex = [presetsTableView selectedRow];
UMMPPreset *preset = [presets objectAtIndex: presetIndex];
NSData *presetData = [NSKeyedArchiver archivedDataWithRootObject: preset];
NSSavePanel *savePanelObj = [NSSavePanel savePanel];
int status = [savePanelObj runModal];
if (status == NSOKButton)
{
NSURL *urlPath = [savePanelObj URL];
NSString *filename = [urlPath path];
[presetData writeToFile: filename atomically:YES];
}
}
- (IBAction)importPreset:(id)sender
{
NSSavePanel *openPanelObj = [NSOpenPanel openPanel];
int status = [openPanelObj runModal];
if (status == NSOKButton)
{
NSURL *urlPath = [openPanelObj URL];
NSString *filename = [urlPath path];
NSData *presetData = [NSData dataWithContentsOfFile: filename];
if (presetData)
{
UMMPPreset *preset = [[NSKeyedUnarchiver unarchiveObjectWithData: presetData] retain];
if (preset)
{
[presets addObject: preset];
[presetsTableView reloadData];
[self setRemoveButtonState];
}
}
}
}
- (IBAction)pushAlgorithmButton:(id)sender
{
[parametersTableView reloadData];
}
- (IBAction)pushSelectAllButton:(id)sender
{
[[panelController userDefaults] setBool:YES forKey:@"UMMPcompartmentMapPF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPcompartmentMapPMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPcompartmentMapPV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPcompartmentMapAFE"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPcompartmentMapCS"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapPF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapPMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapPV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapIMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapIV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapEF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapPSAP"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapAFE"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPexchangeMapCS"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapPF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapPMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapPV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapIMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapEF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapPSAP"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapAFE"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPfiltrationMapCS"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapPF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapPMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapPV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapEF"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapPSAP"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapAFE"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPuptakeMapCS"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapPV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapIMTT"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapIV"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapPSAP"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapAFE"];
[[panelController userDefaults] setBool:YES forKey:@"UMMPtoftsMapCS"];
[self refreshStatusOfMapSelection];
}
- (IBAction)pushDeselectAllButton:(id)sender
{
[[panelController userDefaults] setBool:NO forKey:@"UMMPcompartmentMapPF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPcompartmentMapPMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPcompartmentMapPV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPcompartmentMapAFE"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPcompartmentMapCS"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapPF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapPMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapPV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapIMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapIV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapEF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapPSAP"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapAFE"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPexchangeMapCS"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapPF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapPMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapPV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapIMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapEF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapPSAP"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapAFE"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPfiltrationMapCS"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapPF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapPMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapPV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapEF"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapPSAP"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapAFE"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPuptakeMapCS"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapPV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapIMTT"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapIV"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapPSAP"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapAFE"];
[[panelController userDefaults] setBool:NO forKey:@"UMMPtoftsMapCS"];
[self refreshStatusOfMapSelection];
}
- (IBAction)pushSetDefaultMPFitButton:(id)sender
{
[[panelController userDefaults] setString:@"200" forKey:@"UMMPMaxIterations"];
[[panelController userDefaults] setString:@"1000" forKey:@"UMMPMaxFunctionEvaluation"];
[maxIterations setStringValue:@"200"];
[maxFunctionEvaluation setStringValue:@"1000"];
}
#pragma mark -
#pragma mark TableView delegates
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
NSTableView *tableView = [aNotification object];
if (tableView == presetsTableView) {
[parametersTableView reloadData];
}
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if (tableView == presetsTableView) {
return [presets count];
} else if (tableView == parametersTableView) {
NSString *algorithmTitle = [selectedAlgorithm titleOfSelectedItem];
NSInteger presetsRow = [presetsTableView selectedRow];
if (presetsRow < 0 || presetsRow > [presets count])
return 0;
NSMutableArray *parameters = [[[presets objectAtIndex:presetsRow] algorithms] objectForKey:algorithmTitle];
return [parameters count];
} else {
return 0;
}
return 0;
}
- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row
{
if (tableView == presetsTableView) {
NSString *name = [[presets objectAtIndex:row] name];
return name;
} else if (tableView == parametersTableView) {
NSInteger presetsRow = [presetsTableView selectedRow];
UMMPPreset *preset = [presets objectAtIndex:presetsRow];
NSMutableDictionary *dict = [preset algorithms];
NSString *algorithmTitle = [selectedAlgorithm titleOfSelectedItem];
NSMutableArray *array = [dict objectForKey: algorithmTitle];
UMMPParameter *parameter = [array objectAtIndex:row];
id param = [parameter valueForKey:[tableColumn identifier]];
return param;
} else {
return nil;
}
}
- (NSString *)tableView:(NSTableView *)aTableView
toolTipForCell:(NSCell *)aCell
rect:(NSRectPointer)rect
tableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)row
mouseLocation:(NSPoint)mouseLocation
{
NSString *toolTip = @"";
if (aTableView == parametersTableView) {
if ([[aTableColumn identifier] isEqualToString:@"name"]) {
NSInteger presetsRow = [presetsTableView selectedRow];
UMMPPreset *preset = [presets objectAtIndex:presetsRow];
NSMutableDictionary *dict = [preset algorithms];
NSString *algorithmTitle = [selectedAlgorithm titleOfSelectedItem];
NSMutableArray *array = [dict objectForKey: algorithmTitle];
UMMPParameter *parameter = [array objectAtIndex:row];
toolTip = [parameter valueForKey:@"toolTip"];
}
}
return toolTip;
}
- (void)tableView:(NSTableView *)aTableView
setObjectValue:anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
if (aTableView == presetsTableView) {
[[presets objectAtIndex:rowIndex] setValue:anObject forKey:[aTableColumn identifier]];
[[panelController algorithmController] loadPresets:presets];
} else if (aTableView == parametersTableView) {
NSInteger presetsRow = [presetsTableView selectedRow];
UMMPPreset *preset = [presets objectAtIndex:presetsRow];
NSMutableDictionary *dict = [preset algorithms];
NSString *algorithmTitle = [selectedAlgorithm titleOfSelectedItem];
NSMutableArray *array = [dict objectForKey: algorithmTitle];
UMMPParameter *parameter = [array objectAtIndex:rowIndex];
NSMutableArray *parameters = [self findParametersByTag:[preset presetTag] forAlgorithm:algorithmTitle];
int *fixed;
int *limited;
double *limits;
double *p;
fixed = (int*)calloc(1, sizeof(int));
limited = (int*)calloc(2, sizeof(int));
limits = (double*)calloc(2, sizeof(double));
p = (double*)calloc(1, sizeof(double));
if ([[aTableColumn identifier] isEqualToString: @"fixed"])
{
[parameter setValue:anObject forKey:[aTableColumn identifier]];
double v = [[parameters objectAtIndex:rowIndex] fixed];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"fixed"];
[parametersTableView setNeedsDisplay:YES];
}
else if([[parameters objectAtIndex:rowIndex] fixed]){
NSRunAlertPanel(@"Cannot change values", @"Table data can not be changed while \"fixed\" is checked!", @"OK", nil, nil);
}
else
{
[parameter setValue:anObject forKey:[aTableColumn identifier]];
if ([[aTableColumn identifier] isEqualToString: @"pValue"])
{
if([[parameters objectAtIndex:rowIndex] limitedLow])
{
if([[parameters objectAtIndex:rowIndex] pValue] < [[parameters objectAtIndex:rowIndex] low])
{
double v = [[parameters objectAtIndex:rowIndex] low];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
}
if([[parameters objectAtIndex:rowIndex] limitedHigh])
{
if([[parameters objectAtIndex:rowIndex] pValue] > [[parameters objectAtIndex:rowIndex] high])
{
double v = [[parameters objectAtIndex:rowIndex] high];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
}
}
if ([[aTableColumn identifier] isEqualToString: @"high"])
{
if([[parameters objectAtIndex:rowIndex] limitedHigh])
{
if([[parameters objectAtIndex:rowIndex] pValue] > [[parameters objectAtIndex:rowIndex] high])
{
double v = [[parameters objectAtIndex:rowIndex] high];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
if(([[parameters objectAtIndex:rowIndex] high] < [[parameters objectAtIndex:rowIndex] low]) && [[parameters objectAtIndex:rowIndex] limitedLow])
{
double v = [[parameters objectAtIndex:rowIndex] low];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"high"];
[parameter setValue:versuch forKey:@"pValue"];
}
}
}
if ([[aTableColumn identifier] isEqualToString: @"low"])
{
if([[parameters objectAtIndex:rowIndex] limitedLow])
{
if([[parameters objectAtIndex:rowIndex] pValue] < [[parameters objectAtIndex:rowIndex] low])
{
double v = [[parameters objectAtIndex:rowIndex] low];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
if(([[parameters objectAtIndex:rowIndex] high] < [[parameters objectAtIndex:rowIndex] low]) &&[[parameters objectAtIndex:rowIndex] limitedHigh])
{
double v = [[parameters objectAtIndex:rowIndex] high];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"low"];
[parameter setValue:versuch forKey:@"pValue"];
}
}
}
if ([[aTableColumn identifier] isEqualToString: @"limitedHigh"])
{
if([[parameters objectAtIndex:rowIndex] limitedHigh])
{
if([[parameters objectAtIndex:rowIndex] pValue] > [[parameters objectAtIndex:rowIndex] high])
{
double v = [[parameters objectAtIndex:rowIndex] high];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
if(([[parameters objectAtIndex:rowIndex] high] < [[parameters objectAtIndex:rowIndex] low]) && [[parameters objectAtIndex:rowIndex] limitedLow])
{
double v = [[parameters objectAtIndex:rowIndex] low];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"high"];
[parameter setValue:versuch forKey:@"pValue"];
}
}
}
if ([[aTableColumn identifier] isEqualToString: @"limitedLow"])
{
NSLog(@"limitedLow");
if([[parameters objectAtIndex:rowIndex] limitedLow])
{
if([[parameters objectAtIndex:rowIndex] pValue] < [[parameters objectAtIndex:rowIndex] low])
{
NSLog(@"limitedLow erste if abfrage");
double v = [[parameters objectAtIndex:rowIndex] low];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"pValue"];
}
if(([[parameters objectAtIndex:rowIndex] high] < [[parameters objectAtIndex:rowIndex] low]) &&[[parameters objectAtIndex:rowIndex] limitedHigh])
{
double v = [[parameters objectAtIndex:rowIndex] high];
NSNumber* versuch = [NSNumber numberWithDouble:v];
[parameter setValue:versuch forKey:@"low"];
[parameter setValue:versuch forKey:@"pValue"];
}
}
}
}
[parametersTableView setNeedsDisplay:YES];
free(p);
free(fixed);
free(limited);
free(limits);
}
}
- (BOOL)tableView:(NSTableView *)tableView
writeRowsWithIndexes:(NSIndexSet *)rowIndexes
toPasteboard:(NSPasteboard *)pboard
{
if (tableView == presetsTableView) {
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
[pboard declareTypes:[NSArray arrayWithObject:PresetsTableViewDataType]
owner:self];
[pboard setData:data forType:PresetsTableViewDataType];
return YES;
} else {
return NO;
}
}
- (NSDragOperation)tableView:(NSTableView *)tableView
validateDrop:(id<NSDraggingInfo>)info
proposedRow:(NSInteger)row
proposedDropOperation:(NSTableViewDropOperation)dropOperation
{
if (tableView == presetsTableView)
return (dropOperation == NSTableViewDropAbove) ? NSDragOperationMove : NSDragOperationNone;
else
return NSDragOperationNone;
}
- (BOOL)tableView:(NSTableView *)tableView
acceptDrop:(id<NSDraggingInfo>)info
row:(NSInteger)row
dropOperation:(NSTableViewDropOperation)dropOperation
{
NSPasteboard *pboard = [info draggingPasteboard];
NSData *rowData = [pboard dataForType:PresetsTableViewDataType];
NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
if (tableView == presetsTableView) {
NSInteger aboveInsertIndexCount = 0;
NSInteger removeIndex = 0;
NSInteger dragRow = [rowIndexes lastIndex];
while (dragRow != NSNotFound) {
if (dragRow >= row) {
removeIndex = dragRow + aboveInsertIndexCount;
aboveInsertIndexCount++;
} else {
removeIndex = dragRow;
row--;
}
UMMPPreset *preset = [presets objectAtIndex:removeIndex];
[preset retain];
[presets removeObjectAtIndex:removeIndex];
[presets insertObject:preset atIndex:row];
[preset release];
dragRow =[rowIndexes indexLessThanIndex:dragRow];
}
[tableView reloadData];
NSRange range = NSMakeRange(row, [rowIndexes count]);
NSIndexSet *newSelection = [NSIndexSet indexSetWithIndexesInRange:range];
[presetsTableView selectRowIndexes:newSelection
byExtendingSelection:NO];
[parametersTableView reloadData];
[[panelController algorithmController] loadPresets:presets];
return YES;
} else {
return NO;
}
}
#pragma mark -
- (void)setRemoveButtonState
{
if ([presets count] > 1)
[removeButton setEnabled:YES];
else
[removeButton setEnabled:NO];
}
- (NSMutableArray*)findParametersByTag:(NSInteger)tag forAlgorithm:(NSString*)algorithm
{
for (UMMPPreset *tmpPreset in presets)
if ([tmpPreset presetTag] == tag)
return [[tmpPreset algorithms] objectForKey:algorithm];
return nil;
}
#pragma mark -
#pragma mark new methods
- (IBAction)changeView:(id)sender
{
NSToolbarItemGroup *item = sender;
NSInteger tag = [item tag];
[self changeViewForTag: tag];
}
- (IBAction)setDefaultParameters:(id)sender
{
}
- (void)changeViewForTag:(NSInteger)preferences
{
NSView *newView = nil;
NSWindow *window = [self window];
NSRect windowFrame = [[self window] frame];
NSSize currentSize = windowFrame.size;
float newSizeWidth = 0.0;
float newSizeHeight = 0.0;
float deltaWidth = 0.0;
float deltaHeight = 0.0;
switch (preferences) {
case general:
newView = _general;
break;
case presetValues:
newView = _presetValues;
break;
case mapSelection:
newView = _mapSelections;
[self refreshStatusOfMapSelection];
break;
case mpFit:
newView = _mpFit;
break;
case aifImport:
// check if algorithm is choosed
if ([panelController algorithmIsChoosed]) {
// check if external AIF already exists
if (extROIExists) {
int choice = NSRunAlertPanel(@"Attention: Only one external ROI can be used", @"Do you want to delete the existing external ROI to load a new external ROI?", @"NO",@"YES",nil);
if (choice == deleteExternalAIF) {
[self deleteExternalAIF];
[self loadExternalAIF];
newView = _general;
}
newView = _general;
} else {
[self loadExternalAIF];
newView = _general;
}
} else {
NSRunAlertPanel(@"External AIF can not be load", @"Please choose an algorithm at first, before loading the external AIF", @"OK",nil,nil);
newView = _general;
}
break;
default:
break;
}
newSizeWidth = newView.frame.size.width;
newSizeHeight = newView.frame.size.height;
deltaWidth = newSizeWidth - currentSize.width;
deltaHeight = newSizeHeight - currentSize.height + 78.0; // 63.0 is the toolbar height
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;
[window setContentView: NULL];
[window setFrame: windowFrame display: YES animate: YES];
[window setContentView: newView];
}
-(IBAction)pushMapSelButtonState:(id)sender
{
[[panelController userDefaults] setBool:[sender state] forKey:[sender title]];
}
-(IBAction)pushButtonOnGeneralSettings:(id)sender
{
if (sender == soundOnMapsCalcEnd) {
[[panelController userDefaults] setInt:[soundOnMapsCalcEnd state] forKey:@"soundOnMapsCalcEnd"];
}
if (sender == soundOnAllMapsCalcEnd) {
[[panelController userDefaults] setInt:[soundOnAllMapsCalcEnd state] forKey:@"soundOnAllMapsCalcEnd"];
}
if (sender == printPresetsToConsole) {
[[panelController userDefaults] setInt:[printPresetsToConsole state] forKey:@"printPresetsToConsole"];
}
}
-(IBAction)changeMPFitValues:(id)sender
{
if ([[sender identifier]isEqualToString:@"maxiter"]) {
[[panelController userDefaults] setString:[sender stringValue] forKey:@"UMMPMaxIterations"];
}
if ([[sender identifier]isEqualToString:@"maxfev"]) {
[[panelController userDefaults] setString:[sender stringValue] forKey:@"UMMPMaxFunctionEvaluation"];
}
}
-(void) refreshStatusOfMapSelection
{
// Compartmentview
[compartmentMapPF setState:[[panelController userDefaults] bool:@"UMMPcompartmentMapPF" otherwise:0]];
[compartmentMapPMTT setState:[[panelController userDefaults] bool:@"UMMPcompartmentMapPMTT" otherwise:0]];
[compartmentMapPV setState:[[panelController userDefaults] bool:@"UMMPcompartmentMapPV" otherwise:0]];
[compartmentMapAFE setState:[[panelController userDefaults] bool:@"UMMPcompartmentMapAFE" otherwise:0]];
[compartmentMapCS setState:[[panelController userDefaults] bool:@"UMMPcompartmentMapCS" otherwise:0]];
// 2C Exchangeview
[exchangeMapPF setState:[[panelController userDefaults] bool:@"UMMPexchangeMapPF" otherwise:0]];
[exchangeMapPMTT setState:[[panelController userDefaults] bool:@"UMMPexchangeMapPMTT" otherwise:0]];
[exchangeMapPV setState:[[panelController userDefaults] bool:@"UMMPexchangeMapPV" otherwise:0]];
[exchangeMapIMTT setState:[[panelController userDefaults] bool:@"UMMPexchangeMapIMTT" otherwise:0]];
[exchangeMapIV setState:[[panelController userDefaults] bool:@"UMMPexchangeMapIV" otherwise:0]];
[exchangeMapEF setState:[[panelController userDefaults] bool:@"UMMPexchangeMapEF" otherwise:0]];
[exchangeMapPSAP setState:[[panelController userDefaults] bool:@"UMMPexchangeMapPSAP" otherwise:0]];
[exchangeMapAFE setState:[[panelController userDefaults] bool:@"UMMPexchangeMapAFE" otherwise:0]];
[exchangeMapCS setState:[[panelController userDefaults] bool:@"UMMPexchangeMapCS" otherwise:0]];
// 2C Filtrationview
[filtrationMapPF setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapPF" otherwise:0]];
[filtrationMapPMTT setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapPMTT" otherwise:0]];
[filtrationMapPV setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapPV" otherwise:0]];
[filtrationMapIMTT setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapIMTT" otherwise:0]];
[filtrationMapEF setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapEF" otherwise:0]];
[filtrationMapPSAP setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapPSAP" otherwise:0]];
[filtrationMapAFE setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapAFE" otherwise:0]];
[filtrationMapCS setState:[[panelController userDefaults] bool:@"UMMPfiltrationMapCS" otherwise:0]];
// 2C Uptakeview
[uptakeMapPF setState:[[panelController userDefaults] bool:@"UMMPuptakeMapPF" otherwise:0]];
[uptakeMapPMTT setState:[[panelController userDefaults] bool:@"UMMPuptakeMapPMTT" otherwise:0]];
[uptakeMapPV setState:[[panelController userDefaults] bool:@"UMMPuptakeMapPV" otherwise:0]];
[uptakeMapEF setState:[[panelController userDefaults] bool:@"UMMPuptakeMapEF" otherwise:0]];
[uptakeMapPSAP setState:[[panelController userDefaults] bool:@"UMMPuptakeMapPSAP" otherwise:0]];
[uptakeMapAFE setState:[[panelController userDefaults] bool:@"UMMPuptakeMapAFE" otherwise:0]];
[uptakeMapCS setState:[[panelController userDefaults] bool:@"UMMPuptakeMapCS" otherwise:0]];
// Modified Toftsview
[toftsMapPV setState:[[panelController userDefaults] bool:@"UMMPtoftsMapPV" otherwise:0]];
[toftsMapIMTT setState:[[panelController userDefaults] bool:@"UMMPtoftsMapIMTT" otherwise:0]];
[toftsMapIV setState:[[panelController userDefaults] bool:@"UMMPtoftsMapIV" otherwise:0]];
[toftsMapPSAP setState:[[panelController userDefaults] bool:@"UMMPtoftsMapPSAP" otherwise:0]];
[toftsMapAFE setState:[[panelController userDefaults] bool:@"UMMPtoftsMapAFE" otherwise:0]];
[toftsMapCS setState:[[panelController userDefaults] bool:@"UMMPtoftsMapCS" otherwise:0]];
}
#pragma mark -
#pragma mark file import / aif import
-(void)loadExternalAIF {
if (!extROIExists) {
// initialize an NSOpenPanel Window
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
// Enable options for the panel
[openPanel setCanChooseFiles:YES];
[openPanel setAllowsMultipleSelection:FALSE];
// open the "NSOpenPanel Window" and check if the user clicked on ok button.
if([openPanel runModal] == NSOKButton) {
// get the directory of the choosen file
NSURL *directory = [openPanel URL];
// convert the directory of the file into a string
NSString *filePath = [directory path];
// create filepath for the UMMPerfusion report
extROIFilePathForReport = [filePath mutableCopy];
// with the Filemanager you can locate, move, copy, link remove or get information about files or directories
NSFileManager *filemgr = [NSFileManager defaultManager];
// check if the opened file is the correct one which is needed to create the external ROI
if ([filePath hasSuffix:@".csv"]) {
// check if the choosen file exists and check if is a readable file
if ([filemgr fileExistsAtPath:filePath] && [filemgr isReadableFileAtPath:filePath]){
NSData *databuffer = [filemgr contentsAtPath:filePath];
NSString* newStr = [[[NSString alloc] initWithData:databuffer
encoding:NSUTF8StringEncoding] autorelease];
// creates an array with all values in the file
NSArray *substrings = [newStr componentsSeparatedByString:@";"];
// check if the selected csv file is valid
if ([[substrings objectAtIndex:7] isEqualTo:@"aif"] || [[substrings objectAtIndex:2] isEqualTo:@"aif"]) {
NSString *allAifValues;
NSString *currentAifValue;
// index is 7 because the first aif value in the csv file is "objectAtIndex:7". The next aif value is "index + 6"
int index = 7;
if ([[substrings objectAtIndex:7] isEqualTo:@"aif"]) {
// if the csv file modified by the user, the first aif value is "objectAtIndex:12". The next aif value is "index + 5"
index = 12;
while (index < [substrings count]) {
currentAifValue = [substrings objectAtIndex:index];
if (index == 12) {
allAifValues = [NSString stringWithFormat:@"%@", currentAifValue];
index = index + 5;
} else {
allAifValues = [NSString stringWithFormat:@"%@;%@", allAifValues, currentAifValue];
index = index + 5;
}
}
} else {
while (index < [substrings count]) {
currentAifValue = [substrings objectAtIndex:index];
if (index == 7) {
allAifValues = [NSString stringWithFormat:@"%@", currentAifValue];
index = index + 6;
} else {
allAifValues = [NSString stringWithFormat:@"%@;%@", allAifValues, currentAifValue];
index = index + 6;
}
}
}
// creates an array only with the aif values
NSArray *aifData = [allAifValues componentsSeparatedByString:@";"];
// check if the opened file has the same number of AIF values like the Timepoints of the 4-D dataset
if ([[panelController viewerController] maxMovieIndex] == [aifData count] && [[aifData objectAtIndex:[[panelController viewerController] maxMovieIndex]-1]floatValue] != 0.000000) {
// mutable array to access from other classes
aifExportData = [aifData mutableCopy];
// get the file name of the choosen file
NSString *filename = [filePath stringByDeletingPathExtension];
extROIFilename = [filename lastPathComponent];
extROI = YES;
extROIExists = YES;
externalROI = [[ROI alloc] init];
// creates an external ROIRec
UMMPROIRec *artROIRec = [[panelController roiList] createRoiRecForRoi:externalROI];
// add externalROI into the ROI list
[[panelController algorithmController] addROIRec:artROIRec];
// close preferences panel after importing the external ROI
[[self window] close];
NSRunAlertPanel(@"External ROI loaded", @"The name of the external ROI is the same as for the selected csv file", @"OK", nil, nil);
} else {
NSRunAlertPanel(@"Invalid csv file", @"Number of AIF values not equal to the 4-D dataset Timepoints number", @"OK", nil, nil); }
} else {
NSRunAlertPanel(@"Invalid csv file", @"Please choose a supported csv file", @"OK", nil, nil);
}
}
}
// if the choosen file is not a csv file then open an alert window
else if(![filePath hasSuffix:@".csv"]) {
NSRunAlertPanel(@"Invalid file type", @"Only csv files are supported", @"OK", nil, nil);
}
}
} else {
// Alert by trying to load another external ROI when a external ROI already exists
NSRunAlertPanel(@"External ROI already exists", @"Only one external ROI can be loaded. Delete the existing external ROI to load another one", @"OK", nil, nil);
}
}
-(float)getAifValue:(int)i {
float aifValue;
aifValue = [[aifExportData objectAtIndex:i] floatValue];
return aifValue;
}
-(void)deleteExternalAIF {
[[panelController roiList] removeExternalRoi:externalROI];
[[panelController algorithmController] loadROIRecs:[[panelController roiList] records]];
extROIExists = NO;
}
@end