forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EndoscopyVRController.m
295 lines (223 loc) · 8.98 KB
/
EndoscopyVRController.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
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - GPL
See http://homepage.mac.com/rossetantoine/osirix/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
/*
MODIFICATION HISTORY
20051212 JH Created.
20060110 DDP Reducing the variable duplication of userDefault objects (work in progress).
*/
#import "EndoscopyVRController.h"
#import "DCMView.h"
#import "ROI.h"
extern NSString * documentsDirectory();
@implementation EndoscopyVRController
-(id) initWithPix:(NSMutableArray*) pix :(NSArray*) f :(NSData*) vData :(ViewerController*) bC :(ViewerController*) vC
{
unsigned long i;
short err = 0;
BOOL testInterval = YES;
for( i = 0; i < 100; i++) undodata[ i] = 0L;
// [[NSUserDefaults standardUserDefaults] setInteger: 1 forKey: @"MAPPERMODEVR"]; // texture mapping
flyThruController = 0L;
curMovieIndex = 0;
maxMovieIndex = 1;
fileList = f;
[fileList retain];
pixList[0] = pix;
volumeData[0] = vData;
DCMPix *firstObject = [pixList[0] objectAtIndex:0];
float sliceThickness = fabs( [firstObject sliceInterval]);
// Find Minimum Value
if( [firstObject isRGB] == NO)
{
float *tempData = (float*) [volumeData[0] bytes];
i = [firstObject pwidth] * [firstObject pheight] * [pix count] / 16;
i -= 32;
minimumValue = *tempData;
while( i-- > 0)
{
if( *tempData < minimumValue) minimumValue = *tempData;
tempData += 16;
}
}
else minimumValue = 0;
if( sliceThickness == 0)
{
sliceThickness = [firstObject sliceThickness];
testInterval = NO;
if( sliceThickness > 0) NSRunCriticalAlertPanel( NSLocalizedString(@"Slice interval",nil), NSLocalizedString( @"I'm not able to find the slice interval. Slice interval will be equal to slice thickness.",nil), NSLocalizedString(@"OK",nil), nil, nil);
else
{
NSRunCriticalAlertPanel(NSLocalizedString( @"Slice interval/thickness",nil), NSLocalizedString( @"Problems with slice thickness/interval to do a 3D reconstruction.",nil),NSLocalizedString( @"OK",nil), nil, nil);
return 0L;
}
}
// CHECK IMAGE SIZE
for( i =0 ; i < [pixList[0] count]; i++)
{
if( [firstObject pwidth] != [[pixList[0] objectAtIndex:i] pwidth]) err = -1;
if( [firstObject pheight] != [[pixList[0] objectAtIndex:i] pheight]) err = -1;
}
if( err)
{
NSRunCriticalAlertPanel(NSLocalizedString( @"Images size",nil), NSLocalizedString(@"These images don't have the same height and width to allow a 3D reconstruction...",nil),NSLocalizedString( @"OK",nil), nil, nil);
return 0L;
}
[pixList[0] retain];
[volumeData[0] retain];
self = [super init];
//[[self window] setDelegate:self];
[view setViewportResizable: NO];
err = [view setPixSource:pixList[0] :(float*) [volumeData[0] bytes]];
if( err != 0)
{
[self dealloc];
return 0L;
}
blendingController = bC;
// if( blendingController) // Blending! Activate image fusion
// {
// [view setBlendingPixSource: blendingController];
//
// [blendingSlider setEnabled:YES];
// [blendingPercentage setStringValue:[NSString stringWithFormat:@"%0.0f%%", (float) ([blendingSlider floatValue] + 256.) / 5.12]];
//
// //[self updateBlendingImage];
// }
curWLWWMenu = NSLocalizedString(@"Other", nil);
roi2DPointsArray = [[NSMutableArray alloc] initWithCapacity:0];
sliceNumber2DPointsArray = [[NSMutableArray alloc] initWithCapacity:0];
x2DPointsArray = [[NSMutableArray alloc] initWithCapacity:0];
y2DPointsArray = [[NSMutableArray alloc] initWithCapacity:0];
z2DPointsArray = [[NSMutableArray alloc] initWithCapacity:0];
viewer2D = [vC retain];
if (viewer2D)
{
long i, j;
float x, y, z;
NSMutableArray *curRoiList;
ROI *curROI;
for(i=0; i<[[[viewer2D imageView] dcmPixList] count]; i++)
{
curRoiList = [[viewer2D roiList] objectAtIndex: i];
for(j=0; j<[curRoiList count];j++)
{
curROI = [curRoiList objectAtIndex:j];
if ([curROI type] == t2DPoint)
{
float location[ 3 ];
[[[viewer2D pixList] objectAtIndex: i] convertPixX: [[[curROI points] objectAtIndex:0] x] pixY: [[[curROI points] objectAtIndex:0] y] toDICOMCoords: location];
x = location[ 0 ];
y = location[ 1 ];
z = location[ 2 ];
// add the 3D Point to the SR view
[[self view] add3DPoint: x : y : z];
// add the 2D Point to our list
[roi2DPointsArray addObject:curROI];
[sliceNumber2DPointsArray addObject:[NSNumber numberWithLong:i]];
[x2DPointsArray addObject:[NSNumber numberWithFloat:x]];
[y2DPointsArray addObject:[NSNumber numberWithFloat:y]];
[z2DPointsArray addObject:[NSNumber numberWithFloat:z]];
}
}
}
}
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self
selector: @selector(remove3DPoint:)
name: @"removeROI"
object: nil];
[nc addObserver: self
selector: @selector(add3DPoint:)
//name: @"roiChange"
name: @"roiSelected"
object: nil];
[nc addObserver: self
selector: @selector(UpdateWLWWMenu:)
name: @"UpdateWLWWMenu"
object: nil];
[nc addObserver: self
selector: @selector(updateVolumeData:)
name: @"updateVolumeData"
object: nil];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateWLWWMenu" object: curWLWWMenu userInfo: 0L];
curCLUTMenu = NSLocalizedString(@"No CLUT", nil);
[curCLUTMenu retain];
[nc addObserver: self
selector: @selector(UpdateCLUTMenu:)
name: @"UpdateCLUTMenu"
object: nil];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateCLUTMenu" object: curCLUTMenu userInfo: 0L];
curOpacityMenu = NSLocalizedString(@"Linear Table", nil);
[curOpacityMenu retain];
[nc addObserver: self
selector: @selector(UpdateOpacityMenu:)
name: @"UpdateOpacityMenu"
object: nil];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOpacityMenu" object: curOpacityMenu userInfo: 0L];
[nc addObserver: self
selector: @selector(CLUTChanged:)
name: @"CLUTChanged"
object: nil];
[[self window] performZoom:self];
[movieRateSlider setEnabled: NO];
[moviePosSlider setEnabled: NO];
[moviePlayStop setEnabled: NO];
[[enginePopup menu] setAutoenablesItems : NO];
//[[[enginePopup menu] itemAtIndex: 3] setEnabled: NO];
[[[enginePopup menu] itemAtIndex: [[NSUserDefaults standardUserDefaults] integerForKey: @"MAPPERMODEVR"]+1] setState:NSOnState]; // texture mapping
// NSLog(@"[[NSUserDefaults standardUserDefaults] integerForKey: @"MAPPERMODEVR"] : %d", [[NSUserDefaults standardUserDefaults] integerForKey: @"MAPPERMODEVR"]);
//[self updateEngine];
//[view updateScissorStateButtons];
return self;
}
-(void) save3DState
{
NSString *path = [documentsDirectory() stringByAppendingString:STATEDATABASE];
BOOL isDir = YES;
long i;
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] && isDir)
{
[[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil];
}
NSString *str = [path stringByAppendingFormat: @"VRENDOSCOPY-%@", [[fileList objectAtIndex:0] valueForKey:@"uniqueFilename"]];
NSMutableDictionary *dict = [view get3DStateDictionary];
[dict setObject:curCLUTMenu forKey:@"CLUTName"];
[dict setObject:curOpacityMenu forKey:@"OpacityName"];
[dict writeToFile:str atomically:YES];
}
-(void) load3DState
{
NSString *path = [documentsDirectory() stringByAppendingString:STATEDATABASE];
BOOL isDir = YES;
long i;
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] && isDir)
{
[[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil];
}
NSString *str = [path stringByAppendingFormat: @"VRENDOSCOPY-%@", [[fileList objectAtIndex:0] valueForKey:@"uniqueFilename"]];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: str];
[view set3DStateDictionary:dict];
if(dict==nil)
{
[self setWLWW: -500 : 600];
}
if( [dict objectForKey:@"CLUTName"]) [self ApplyCLUTString:[dict objectForKey:@"CLUTName"]];
else [self ApplyCLUTString:@"VR Muscles-Bones"];
if( [dict objectForKey:@"CLUTName"]) [self ApplyOpacityString:[dict objectForKey:@"OpacityName"]];
else [self ApplyOpacityString:NSLocalizedString(@"Logarithmic Inverse Table", nil)];
if( [view shading]) [shadingCheck setState: NSOnState];
else [shadingCheck setState: NSOffState];
float ambient, diffuse, specular, specularpower;
[view getShadingValues: &ambient :&diffuse :&specular :&specularpower];
[shadingValues setStringValue: [NSString stringWithFormat:@"Ambient: %2.1f\nDiffuse: %2.1f\nSpecular :%2.1f-%2.1f", ambient, diffuse, specular, specularpower]];
}
@end