-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUMMPerfusionFilter.m
151 lines (118 loc) · 5.19 KB
/
UMMPerfusionFilter.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
//
// UMMPerfusionFilter.m
// UMMPerfusion
//
// Copyright (c) 2012, Marcel Reich & Sven Kaiser & Markus Daab & Patrick SchŸlein & Engin Aslan
// All rights reserved.
//
#import "UMMPerfusionFilter.h"
#import "UMMPPanelController.h"
#import <OsiriXAPI/Notifications.h>
//#import <OsiriXAPI/AppController.h>
#import "UMMPUserDefaults.h"
@implementation UMMPerfusionFilter
- (void) initPlugin
{
}
- (long) filterImage:(NSString*) menuName
{
NSString *osirixVersion = [[[NSBundle bundleForClass:[viewerController class]] infoDictionary] valueForKey:@"CFBundleShortVersionString"];
// test auf 4D Daten, Fkt isDataVolumicIn4D funktioniert nicht richtig , speziell mit unterschiedlicher Schichtorientierung und OsiriX > 4.0
if ([viewerController maxMovieIndex] <= 1) { /* Check for 4D-Viewer */
NSRunAlertPanel(@"Invalid Viewer", @"This Plugin is designed for working with a 4D-Viewer.",@"OK", nil,nil);
//[userDefaults release]; userDefaults = NULL;
return -1;
}
// initializing user defaults in extra plist
UMMPUserDefaults *userDefaults = [[UMMPUserDefaults alloc] init];
// method to get the actual OS X Version
NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
// at least required OS X version
NSString *requiredVersion = @"10.8.4";
// get the version number of the OS X Version String and convert it to a string
NSRange range = NSMakeRange(8, 6);
NSString *actualVersion = [version substringWithRange: range];
// supported OS X version -> 10.8.4 or higher
if ([requiredVersion compare:actualVersion options:NSNumericSearch] == NSOrderedDescending) {
NSRunAlertPanel(@"Unsupported Mac OS", @"This Plugin requires at least Mac OS 10.8.4", @"OK",nil,nil);
[userDefaults release]; userDefaults=NULL;
return 0;
}
// supported OsiriX versions -> 5.6
if (!([osirixVersion isEqualToString:@"5.9"] /*|| [osirixVersion isEqualToString:@"4.1.1"]|| [osirixVersion isEqualToString:@"5.0.1"] || [osirixVersion isEqualToString:@"5.6"]*/))
NSRunAlertPanel(@"Unsupported Osirix version", [NSString stringWithFormat:@"This Plugin has not been tested with your version of OsiriX(%@). \nUse this version at your own risk.", osirixVersion], @"OK", nil, nil);
id wait = [viewerController startWaitWindow:@"Loading contents..."];
[viewerController setROIToolTag:tOval]; // Usual oval ROITool used
panel = [[UMMPPanelController alloc] initWithFilter:self andViewer:viewerController];
[viewerController endWaitWindow:wait];
[userDefaults release]; userDefaults=NULL;
return 0;
}
/* Method by Andreas Klein @ Aycan 2011-08-02 */
- (ViewerController*) duplicateViewer:(ViewerController *)vc deleteROIs:(BOOL)deleteROIs
{
long i;
NSInteger x, y, z;
ViewerController *new2DViewer;
unsigned char *fVolumePtr;
// We will read our current series, and duplicate it by creating a new series!
// First calculate the amount of memory needed for the new serie
NSArray *pixList = [vc pixList];
DCMPix *curPix;
long mem = 0;
for( i = 0; i < [pixList count]; i++)
{
curPix = [pixList objectAtIndex: i];
mem += [curPix pheight] * [curPix pwidth] * 4; // each pixel contains either a 32-bit float or a 32-bit ARGB value
}
fVolumePtr = malloc( mem); // ALWAYS use malloc for allocating memory !
if( fVolumePtr)
{
// Copy the source series in the new one !
memcpy( fVolumePtr, [vc volumePtr], mem);
// Create a NSData object to control the new pointer
NSData *volumeData = [[[NSData alloc] initWithBytesNoCopy:fVolumePtr length:mem freeWhenDone:YES] autorelease];
// Now copy the DCMPix with the new fVolumePtr
NSMutableArray *newPixList = [NSMutableArray arrayWithCapacity:0];
for( i = 0; i < [pixList count]; i++)
{
curPix = [[[pixList objectAtIndex: i] copy] autorelease];
[curPix setfImage: (float*) (fVolumePtr + [curPix pheight] * [curPix pwidth] * 4 * i)];
[newPixList addObject: curPix];
}
// We don't need to duplicate the DicomFile array, because it is identical!
// A 2D Viewer window needs 3 things:
// A mutable array composed of DCMPix objects
// A mutable array composed of DicomFile objects
// Number of DCMPix and DicomFile has to be EQUAL !
// NSData volumeData contains the images, represented in the DCMPix objects
new2DViewer = [vc newWindow:newPixList :[vc fileList] :volumeData];
//[new2DViewer roiDeleteAll:self];
[new2DViewer addToUndoQueue: @"roi"];
if (deleteROIs) {
DCMView *imageView = [new2DViewer imageView];
[imageView stopROIEditingForce: YES];
for( y = 0; y < [new2DViewer maxMovieIndex]; y++)
{
NSMutableArray *pixList = [new2DViewer pixList:y];
NSMutableArray *roiList = [new2DViewer roiList:y];
for( x = 0; x < [pixList count]; x++)
{
for( z = [roiList count]-1; z >= 0 ; z--)
{
ROI *curROI = [roiList objectAtIndex:z];
if(curROI.locked == NO)
{
[[NSNotificationCenter defaultCenter] postNotificationName: OsirixRemoveROINotification object:curROI userInfo: nil];
[roiList removeObject: curROI];
}
}
}
}
[imageView setIndex: [imageView curImage]];
}
return new2DViewer;
}
return nil;
}
@end