-
Notifications
You must be signed in to change notification settings - Fork 3
/
BidsOutputFilter.m
112 lines (88 loc) · 4.11 KB
/
BidsOutputFilter.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
//
// BidsOutputFilter.m
// OsirixBidsOutput
//
// Copyright (c) 2018 Michał Szczepanik.
//
// This file is part of Osirix / Horos BIDS Output Extension.
//
// BIDS Output Extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// BIDS Output Extension is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with BIDS Output Extension. If not, see <http://www.gnu.org/licenses/>.
#import "BidsOutputFilter.h"
#import <OsiriXAPI/DicomStudy.h>
#import <OsiriXAPI/DicomSeries.h>
#import <OsiriXAPI/BrowserController.h>
#import "OBOCollectedData.h"
#import "OBOSeries.h"
@interface BidsOutputFilter()
@property (nonatomic, strong) NSWindowController *TableWindow;
@end
@implementation BidsOutputFilter
- (void) initPlugin
{
}
- (long) filterImage:(NSString*) menuName
{
// just predicates for filtering
NSPredicate *takeOnlyStudies = [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
return [evaluatedObject isKindOfClass:[DicomStudy class]];
}];
NSPredicate *takeOnlyMR = [NSPredicate predicateWithFormat:@"modality = %@", @"MR"];
// get the selection
BrowserController *currentBrowser = [BrowserController currentBrowser];
NSArray *currentSelection = [currentBrowser databaseSelection];
// take only studies (ignore selected series)
NSArray *selectedStudies = [currentSelection filteredArrayUsingPredicate:takeOnlyStudies];
// find out what are the unique study names
NSMutableSet *uniqueStudyNames = [[NSMutableSet alloc] init];
for (DicomStudy *currentStudy in selectedStudies) {
NSArray *listOfSeries = [[currentStudy imageSeries] filteredArrayUsingPredicate:takeOnlyMR ];
for (DicomSeries *currentSeries in listOfSeries) {
NSString *seriesName = [currentSeries valueForKey:@"name"];
[uniqueStudyNames addObject:seriesName];
}
}
// initialise the singleton shared data storage
OBOCollectedData *sharedData = [OBOCollectedData sharedManager];
// clean up possible leftovers from previous usages
// (closing plugin window doesn't clear the underlying data, possibly should implement a delegate
if ([sharedData.listOfStudies count] > 0) {
[sharedData.listOfStudies removeAllObjects];
[sharedData.seriesDescription removeAllObjects];
[sharedData.listOfSeries removeAllObjects];
}
// store the selected studies for later access
[sharedData.listOfStudies addObjectsFromArray:selectedStudies];
// create a "template" description (empty strings in all fields)
NSMutableDictionary *descriptionTemplate = [NSMutableDictionary dictionary];
[descriptionTemplate setValue:@"" forKey:@"suffix"];
[descriptionTemplate setValue:@"" forKey:@"session"];
[descriptionTemplate setValue:@"" forKey:@"task"];
[descriptionTemplate setValue:@"" forKey:@"run"];
[descriptionTemplate setValue:@"" forKey:@"acq"];
// Add series descriptions to the dictionary
for (NSString *name in uniqueStudyNames) {
[sharedData.seriesDescription setObject:[NSMutableDictionary dictionaryWithDictionary:descriptionTemplate] forKey:name];
}
// show the general mapping window
_TableWindow = [[NSWindowController alloc] initWithWindowNibName:@"GeneralMappingWindow" owner:self];
[_TableWindow showWindow:self];
// // check if that worked
// NSAlert *alert = [[NSAlert alloc] init];
// [alert addButtonWithTitle:@"OK"];
// [alert setMessageText:@"Created so many entries"];
// [alert setInformativeText:[@([sharedData.seriesDescription count]) stringValue]];
// [alert runModal];
return 0;
}
@end