-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUMMPRoiList.m
295 lines (219 loc) · 7.33 KB
/
UMMPRoiList.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
//
// UMMPRoiList.m
// UMMPerfusion
//
// Created by Sven Kaiser on 05.10.11.
// Copyright (c) 2012, Marcel Reich & Sven Kaiser & Markus Daab & Patrick Schülein & Engin Aslan
// All rights reserved.
//
#import "UMMPRoiList.h"
#import "UMMPPanelController.h"
#import <OsiriXAPI/Notifications.h>
#import <OsiriXAPI/ROI.h>
#import "GRDataSet.h"
#import "GRLineDataSet.h"
@implementation UMMPROIRec
@synthesize roi;
@synthesize viewerController;
@synthesize slice;
@synthesize timePoint;
@synthesize tag;
@synthesize meanDataSet;
@synthesize activated;
- (id)init:(ROI *)aRoi withViewerController:(ViewerController *)aViewerController onSlice:(NSInteger)aSlice atTimePoint:(NSInteger)aTimePoint withDataSet:(GRLineDataSet *)aDataSet
{
self = [super init];
roi = [aRoi retain];
viewerController = [aViewerController retain];
activated = [[NSNumber alloc] initWithBool:NO];
slice = aSlice;
timePoint = aTimePoint;
tag = [[NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]] integerValue] + rand() % 100 + 1;
meanDataSet = aDataSet;
return self;
}
- (void)dealloc
{
[meanDataSet release]; meanDataSet = NULL;
[roi release]; roi = NULL;
[activated release]; activated=nil;
[viewerController release]; viewerController = NULL;
[super dealloc];
}
- (void)computeMeanValue:(float*)mean forImageIndex:(NSInteger)index
{
int maxMovieIndex = [viewerController maxMovieIndex];
if (maxMovieIndex == 1) {
[[[viewerController pixList] objectAtIndex:index] computeROI:roi :mean :NULL :NULL :NULL :NULL];
} else {
[[[viewerController pixList:index] objectAtIndex:slice] computeROI:roi :mean :NULL :NULL :NULL :NULL];
}
}
@end
@implementation UMMPRoiList
@synthesize records;
@synthesize recordsForAllRoisAlgorithm;
@synthesize externalRoiRecTag;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (void)awakeFromNib
{
records = [[NSMutableArray alloc] init];
recordsForAllRoisAlgorithm = [[NSMutableArray alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roiChange:) name:OsirixROIChangeNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeROI:) name:OsirixRemoveROINotification object:NULL];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[records release]; records = nil;
[recordsForAllRoisAlgorithm release]; recordsForAllRoisAlgorithm = nil;
[super dealloc];
}
- (void)loadViewerROIs
{
unsigned i, j, k;
ViewerController *viewerController = [controller viewerController];
for (i=0; i<[viewerController maxMovieIndex]; i++) {
NSArray *roiTimeList = [[controller viewerController] roiList:i];
for (j=0; j<[roiTimeList count]; j++) {
NSArray *roiList = [roiTimeList objectAtIndex:j];
for (k=0; k< [roiList count]; k++) {
ROI *roi = [roiList objectAtIndex:k];
[self createRoiRecForRoi:roi withSlice:j andTimePoint:i];
}
}
}
}
- (UMMPROIRec *)createRoiRecForRoi:(ROI*)roi
{
NSInteger slice = [[[controller viewerController] imageView] curImage];
NSInteger timePoint = [[controller viewerController] curMovieIndex];
return [self createRoiRecForRoi:roi withSlice:slice andTimePoint:timePoint];
}
- (UMMPROIRec *)createRoiRecForRoi:(ROI*)roi withSlice:(NSInteger)slice andTimePoint:(NSInteger)timePoint
{
ViewerController *vc = [self viewerControllerForRoi:roi];
GRLineDataSet *dataSet = [[[controller chart] createOwnedLineDataSet] retain];
UMMPROIRec *roiRec = [[UMMPROIRec alloc] init:roi withViewerController:vc onSlice:slice atTimePoint:timePoint withDataSet:dataSet];
// checks if the current added ROIRec is from an external file. If this is the case --> save the tag of it
if ([[controller prefController] extROI] == YES) {
externalRoiRecTag = [roiRec tag];
}
if (externalRoiRecTag == [roiRec tag]) {
[records addObject:roiRec];
} else {
[records addObject:roiRec];
[recordsForAllRoisAlgorithm addObject:roiRec];
}
[[controller chart] addDataSet:dataSet loadData:YES];
[[controller chart] refresh:roiRec];
return roiRec;
}
- (void)roiChange:(NSNotification *)notification
{
ROI *roi = [notification object];
// rois from other viewers are not allowed
if (![self isInViewer:roi])
return;
// can't get roiArea from roi painted with brush
if ([[[controller viewerController] imageView] currentTool] != 20) {
// Eliminate ROIs which have no area
if (![roi roiArea])
return;
}
UMMPROIRec *roiRec = [self findRecordByROI:roi];
// new ROI
if (!roiRec) {
roiRec = [self createRoiRecForRoi:roi];
// inform algorithmController about new ROI
[[controller algorithmController] addROIRec:roiRec];
// rename roi, existing roi
} else {
[[controller algorithmController] changeROIRec:roiRec];
}
[[controller chart] refresh:roiRec];
}
- (UMMPROIRec *)findRecordByROI:(ROI *)roi
{
unsigned i;
for (i = 0; i < [records count]; i++) {
UMMPROIRec * roiRec = [records objectAtIndex:i];
if ([roiRec roi] == roi)
return roiRec;
}
return NULL;
}
- (UMMPROIRec *)findRecordByTag:(NSInteger)tag
{
unsigned i;
for (i = 0; i < [records count]; i++) {
UMMPROIRec * roiRec = [records objectAtIndex:i];
if ([roiRec tag] == tag)
return roiRec;
}
return NULL;
}
- (UMMPROIRec *)findRecordByDataSet:(GRDataSet *)dataSet
{
unsigned i;
for (i = 0; i < [records count]; i++) {
UMMPROIRec * roiRec = [records objectAtIndex:i];
if ([roiRec meanDataSet] == dataSet)
return roiRec;
}
return NULL;
}
- (void)removeROI:(NSNotification *)notification
{
ROI *roi = [notification object];
UMMPROIRec *roiRec = [self findRecordByROI:roi];
if (roiRec) {
[[controller chart] removeDataSet:[roiRec meanDataSet]];
[records removeObject:roiRec];
[recordsForAllRoisAlgorithm removeObject:roiRec];
[[controller algorithmController] removeROIRec:roiRec];
}
}
- (void)removeExternalRoi:(ROI *)artROI {
ROI *roi = artROI;
UMMPROIRec *roiRec = [self findRecordByROI:roi];
if (roiRec) {
[[controller chart] removeDataSet:[roiRec meanDataSet]];
[records removeObject:roiRec];
[[controller algorithmController] removeExternalROIRec:roiRec];
}
}
- (BOOL)isInViewer:(ROI *)roi
{
return [self isRoi:roi inViewer:[controller viewerController]];
}
- (BOOL)isRoi:(ROI *)roi inViewer:(ViewerController *)viewerController
{
unsigned i, j;
for (i=0; i<[viewerController maxMovieIndex]; i++) {
NSArray *roiTimeList = [viewerController roiList:i];
for (j=0; j<[roiTimeList count]; j++) {
NSArray *roiList = [roiTimeList objectAtIndex:j];
if ([roiList containsObject:roi])
return YES;
}
}
return NO;
}
- (ViewerController *)viewerControllerForRoi:(ROI *)roi
{
NSMutableArray *viewerControllerList = [ViewerController get2DViewers];
for (ViewerController *vc in viewerControllerList) {
if ([self isRoi:roi inViewer:vc])
return vc;
}
return nil;
}
@end