forked from bettar/miele-lxiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPRController.m
4989 lines (4107 loc) · 179 KB
/
CPRController.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
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import "CPRController.h"
#import "BrowserController.h"
#import "Wait.h"
#import "DICOMExport.h"
#import "DicomImage.h"
#import "ROI.h"
#import "iPhoto.h"
#import "Notifications.h"
#import "ROIWindow.h"
#import "NSUserDefaultsController+OsiriX.h"
#import "CPRCurvedPath.h"
#import "CPRDisplayInfo.h"
#import "N3BezierPath.h"
#import "CPRView.h"
#import "CPRVolumeData.h"
#import "N3BezierCoreAdditions.h"
#import "CPRTransverseView.h"
#import "CPRGeneratorRequest.h"
#import "CPRGenerator.h"
#import "CPRUnsignedInt16ImageRep.h"
#import "CPRMPRDCMView.h"
#import "N2OpenGLViewWithSplitsWindow.h"
#import "AppController.h"
#import "DicomDatabase.h"
#import <N2Debug.h>
#import "PluginManager.h"
#define PRESETS_DIRECTORY @"/3DPRESETS/"
#define CLUTDATABASE @"/CLUTs/"
#define DATABASEPATH @"/DATABASE.noindex/"
static NSString *MPRPlaneObservationContext = @"MPRPlaneObservationContext";
extern void setvtkMeanIPMode( int m);
extern short intersect3D_2Planes( float *Pn1, float *Pv1, float *Pn2, float *Pv2, float *u, float *iP);
static float deg2rad = M_PI / 180.0;
@interface CPRController ()
@property (nonatomic, readwrite, copy) CPRCurvedPath *curvedPath;
@property (readwrite, copy) CPRDisplayInfo *displayInfo;
@end
@implementation CPRController
@synthesize clippingRangeThickness, clippingRangeMode, mousePosition, mouseViewID, originalPix, wlwwMenuItems, LOD;
@synthesize colorAxis1, colorAxis2, colorAxis3, displayMousePosition, movieRate, blendingPercentage, horizontalSplit1, horizontalSplit2, verticalSplit, lowLOD;
@synthesize mprView1, mprView2, mprView3, curMovieIndex, maxMovieIndex, blendingMode, blendingModeAvailable, highResolutionMode;
@synthesize curvedPath, displayInfo, curvedPathCreationMode, curvedPathColor, straightenedCPRAngle, cprType, cprView;//, assistantPathMode;
@synthesize topTransverseView, middleTransverseView, bottomTransverseView;
// export related synthesize
@synthesize exportSeriesName;
@synthesize exportImageFormat;
@synthesize exportSequenceType;
@synthesize exportSeriesType;
@synthesize exportRotationSpan;
@synthesize exportReverseSliceOrder;
//@synthesize exportSlabThinknessSameAsSlabThickness;
@synthesize exportSlabThickness, exportNumberOfRotationFrames;
@synthesize exportSliceIntervalSameAsVolumeSliceInterval;
@synthesize exportSliceInterval, exportTransverseSliceInterval;
@synthesize dcmIntervalMin, dcmIntervalMax;
+ (double) angleBetweenVector:(float*) a andPlane:(float*) orientation
{
double sc[ 2];
// double la = sqrt( a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
// double lo = sqrt( orientation[0]*orientation[0] + orientation[1]*orientation[1] + orientation[2]*orientation[2]);
//
// sc[ 0 ] = a[ 0]/la * orientation[ 0 ]/lo + a[ 1]/la * orientation[ 1 ]/lo + a[ 2]/la * orientation[ 2 ]/lo;
// sc[ 1 ] = a[ 0]/la * orientation[ 3 ]/lo + a[ 1]/la * orientation[ 4 ]/lo + a[ 2]/la * orientation[ 5 ]/lo;
sc[ 0 ] = a[ 0] * orientation[ 0 ] + a[ 1] * orientation[ 1 ] + a[ 2] * orientation[ 2 ];
sc[ 1 ] = a[ 0] * orientation[ 3 ] + a[ 1] * orientation[ 4 ] + a[ 2] * orientation[ 5 ];
return ((atan2( sc[1], sc[0])) / deg2rad);
}
- (DCMPix*) emptyPix: (DCMPix*) oP width: (long) w height: (long) h
{
long size = sizeof( float) * w * h;
float *imagePtr = malloc( size);
DCMPix *emptyPix = [[DCMPix alloc] initWithData: imagePtr :32 :w :h :[oP pixelSpacingX] :[oP pixelSpacingY] :[oP originX] :[oP originY] :[oP originZ]];
free( imagePtr);
[emptyPix setImageObjectID: [oP imageObjectID]];
[emptyPix setSourceFile: [oP sourceFile]];
[emptyPix setAnnotationsDictionary: [oP annotationsDictionary]];
return [emptyPix autorelease];
}
- (void) setHighResolutionMode: (BOOL) newValue
{
highResolutionMode = newValue;
if( highResolutionMode)
{
if( HR_PixList == nil)
{
HR_PixList = [[NSMutableArray array] retain];
HR_FileList = [[NSMutableArray array] retain];
HR_Data = nil;
DCMPix* firstObject = [pixList[0] objectAtIndex:0];
float originalSliceInterval = [firstObject sliceInterval];
float factor = 1.0 / 1.5;
WaitRendering *www = [[[WaitRendering alloc] init:NSLocalizedString( @"Computing High Resolution data...", nil)] autorelease];
[www start];
BOOL succeed = [ViewerController resampleDataFromPixArray: pixList[0] fileArray: filesList[0] inPixArray: HR_PixList fileArray: HR_FileList data: &HR_Data withXFactor: factor yFactor: factor zFactor: factor];
[www end];
[www close];
if( succeed == NO)
{
if( NSRunAlertPanel( NSLocalizedString(@"32-bit",nil), NSLocalizedString( @"Cannot compute the high resolution data.\r\rUpgrade to OsiriX 64-bit or OsiriX MD to solve this issue.",nil), NSLocalizedString(@"OK", nil), NSLocalizedString(@"OsiriX 64-bit", nil), nil) == NSAlertAlternateReturn)
[[AppController sharedAppController] osirix64bit: self];
[HR_PixList release];
HR_PixList = nil;
[HR_FileList release];
HR_FileList = nil;
HR_Data = nil;
[self performSelector: @selector(setHighResolutionMode:) withObject: nil afterDelay: 0.1];
}
else
{
for( DCMPix *p in HR_PixList)
p.sliceInterval = originalSliceInterval*factor;
[HR_Data retain];
}
}
if( HR_PixList)
{
[cprVolumeData release];
cprVolumeData = [[CPRVolumeData alloc] initWithWithPixList:HR_PixList volume:HR_Data];
cprView.volumeData = cprVolumeData;
topTransverseView.volumeData = cprView.volumeData;
middleTransverseView.volumeData = cprView.volumeData;
bottomTransverseView.volumeData = cprView.volumeData;
}
}
else
{
[cprVolumeData release];
cprVolumeData = [[CPRVolumeData alloc] initWithWithPixList: pixList[0] volume: volumeData[0]];
cprView.volumeData = cprVolumeData;
topTransverseView.volumeData = cprView.volumeData;
middleTransverseView.volumeData = cprView.volumeData;
bottomTransverseView.volumeData = cprView.volumeData;
}
self.straightenedCPRAngle = self.straightenedCPRAngle + 0.1; // To force the update...
}
- (id)initWithDCMPixList:(NSMutableArray*)pix filesList:(NSMutableArray*)files volumeData:(NSData*)volume viewerController:(ViewerController*)viewer fusedViewerController:(ViewerController*)fusedViewer;
{
@try
{
if( [[NSUserDefaults standardUserDefaults] integerForKey: @"ANNOTATIONS"] == annotNone)
[[NSUserDefaults standardUserDefaults] setInteger: annotGraphics forKey: @"ANNOTATIONS"];
viewer2D = viewer;
self = [super initWithWindowNibName:@"CPR"];
originalPix = [pix lastObject];
if( [originalPix isRGB])
{
NSRunCriticalAlertPanel( NSLocalizedString(@"RGB",nil), NSLocalizedString( @"RGB images are not supported.",nil), NSLocalizedString(@"OK",nil), nil, nil);
[self autorelease];
return nil;
}
[[self window] setWindowController: self];
[[[self window] toolbar] setDelegate: self];
pixList[0] = pix;
filesList[0] = files;
volumeData[0] = volume;
fusedViewer2D = fusedViewer;
clippingRangeMode = 1;
LOD = 1;
if( LOD < 1) LOD = 1;
if( fusedViewer2D)
self.blendingModeAvailable = YES;
self.displayMousePosition = [[NSUserDefaults standardUserDefaults] boolForKey: @"MPRDisplayMousePosition"];
self.maxMovieIndex = 0;
[self updateToolbarItems];
for( int i = 0; i < [popupRoi numberOfItems]; i++)
[[popupRoi itemAtIndex: i] setImage: [self imageForROI: [[popupRoi itemAtIndex: i] tag]]];
int dim[3];
DCMPix* firstObject = [pix objectAtIndex:0];
dim[0] = [firstObject pwidth];
dim[1] = [firstObject pheight];
dim[2] = [pix count];
float spacing[3];
spacing[0]=[firstObject pixelSpacingX];
spacing[1]=[firstObject pixelSpacingY];
float sliceThickness = [firstObject sliceInterval];
if( sliceThickness == 0)
{
NSLog(@"Slice interval = slice thickness!");
sliceThickness = [firstObject sliceThickness];
}
spacing[2]=sliceThickness;
float resamplesize=spacing[0];
if(dim[0]>256 || dim[1]>256)
{
if(spacing[0]*(float)dim[0]>spacing[1]*(float)dim[1])
resamplesize = spacing[0]*(float)dim[0]/256.0;
else {
resamplesize = spacing[1]*(float)dim[1]/256.0;
}
}
assistant = [[FlyAssistant alloc] initWithVolume:(float*)[volume bytes] WidthDimension:dim Spacing:spacing ResampleVoxelSize:resamplesize];
[assistant setCenterlineResampleStepLength:3.0];
centerline = [[NSMutableArray alloc] init];
nodeRemovalCost = [[NSMutableArray alloc] init];
delHistory = [[NSMutableArray alloc] init];
delNodes = [[NSMutableArray alloc] init];
curvedPath = [[CPRCurvedPath alloc] init];
displayInfo = [[CPRDisplayInfo alloc] init];
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0], @"CPRColorR",
[NSNumber numberWithFloat:1], @"CPRColorG",
[NSNumber numberWithFloat:0], @"CPRColorB", nil]];
self.curvedPathCreationMode = YES;
cprVolumeData = [[CPRVolumeData alloc] initWithWithPixList:pix volume:volume];
cprView.volumeData = cprVolumeData;
mprView1.delegate = self;
mprView2.delegate = self;
mprView3.delegate = self;
cprView.delegate = self;
mprView1.curvedPath = curvedPath;
mprView2.curvedPath = curvedPath;
mprView3.curvedPath = curvedPath;
cprView.curvedPath = curvedPath;
mprView1.displayInfo = displayInfo;
mprView2.displayInfo = displayInfo;
mprView3.displayInfo = displayInfo;
topTransverseView.displayInfo = displayInfo;
middleTransverseView.displayInfo = displayInfo;
bottomTransverseView.displayInfo = displayInfo;
cprView.displayInfo = displayInfo;
topTransverseView.delegate = self;
topTransverseView.curvedPath = curvedPath;
topTransverseView.sectionType = CPRTransverseViewLeftSectionType;
middleTransverseView.delegate = self;
middleTransverseView.curvedPath = curvedPath;
middleTransverseView.sectionType = CPRTransverseViewCenterSectionType;
bottomTransverseView.delegate = self;
bottomTransverseView.curvedPath = curvedPath;
bottomTransverseView.sectionType = CPRTransverseViewRightSectionType;
topTransverseView.sectionWidth = cprView.generatedHeight;
middleTransverseView.sectionWidth = cprView.generatedHeight;
bottomTransverseView.sectionWidth = cprView.generatedHeight;
topTransverseView.volumeData = cprView.volumeData;
middleTransverseView.volumeData = cprView.volumeData;
bottomTransverseView.volumeData = cprView.volumeData;
DCMPix *emptyPix = [self emptyPix: originalPix width: 100 height: 100];
[mprView1 setDCMPixList: [NSMutableArray arrayWithObject: emptyPix] filesList: [NSArray arrayWithObject: [files lastObject]] roiList: nil firstImage:0 type:'i' reset:YES];
[mprView1 setFlippedData: [[viewer imageView] flippedData]];
emptyPix = [self emptyPix: originalPix width: 100 height: 100];
[mprView2 setDCMPixList: [NSMutableArray arrayWithObject: emptyPix] filesList: [NSArray arrayWithObject: [files lastObject]] roiList: nil firstImage:0 type:'i' reset:YES];
[mprView2 setFlippedData: [[viewer imageView] flippedData]];
emptyPix = [self emptyPix: originalPix width: 100 height: 100];
[mprView3 setDCMPixList: [NSMutableArray arrayWithObject: emptyPix] filesList: [NSArray arrayWithObject: [files lastObject]] roiList: nil firstImage:0 type:'i' reset:YES];
[mprView3 setFlippedData: [[viewer imageView] flippedData]];
// emptyPix = [self emptyPix: originalPix width: 100 height: 100];
// [cprView setDCMPixList: [NSMutableArray arrayWithObject: emptyPix] filesList: [NSArray arrayWithObject: [files lastObject]] roiList: nil firstImage:0 type:'i' reset:YES];
// [cprView setFlippedData: [[viewer imageView] flippedData]];
//
if( fusedViewer2D)
{
blendedMprView1 = [[DCMView alloc] initWithFrame: [mprView1 frame]];
blendedMprView2 = [[DCMView alloc] initWithFrame: [mprView2 frame]];
blendedMprView3 = [[DCMView alloc] initWithFrame: [mprView3 frame]];
emptyPix = [[[[fusedViewer2D imageView] curDCM] copy] autorelease];
[blendedMprView1 setPixels: [NSMutableArray arrayWithObject: emptyPix] files: [NSArray arrayWithObject: [files lastObject]] rois:nil firstImage:0 level:'i' reset:YES];
emptyPix = [[[[fusedViewer2D imageView] curDCM] copy] autorelease];
[blendedMprView2 setPixels: [NSMutableArray arrayWithObject: emptyPix] files: [NSArray arrayWithObject: [files lastObject]] rois:nil firstImage:0 level:'i' reset:YES];
emptyPix = [[[[fusedViewer2D imageView] curDCM] copy] autorelease];
[blendedMprView3 setPixels: [NSMutableArray arrayWithObject: emptyPix] files: [NSArray arrayWithObject: [files lastObject]] rois:nil firstImage:0 level:'i' reset:YES];
unsigned char *aR, *aG, *aB;
[[fusedViewer2D imageView] getCLUT: &aR :&aG :&aB];
[blendedMprView1 setCLUT: aR :aG :aB];
[blendedMprView2 setCLUT: aR :aG :aB];
[blendedMprView3 setCLUT: aR :aG :aB];
[mprView1 setBlending: blendedMprView1];
[mprView2 setBlending: blendedMprView2];
[mprView3 setBlending: blendedMprView3];
[mprView1 setBlendingFactor: 0.5];
[mprView2 setBlendingFactor: 0.5];
[mprView3 setBlendingFactor: 0.5];
[blendedMprView1 setWLWW: [[fusedViewer2D imageView] curDCM].wl :[[fusedViewer2D imageView] curDCM].ww];
[blendedMprView2 setWLWW: [[fusedViewer2D imageView] curDCM].wl :[[fusedViewer2D imageView] curDCM].ww];
[blendedMprView3 setWLWW: [[fusedViewer2D imageView] curDCM].wl :[[fusedViewer2D imageView] curDCM].ww];
self.blendingPercentage = 50;
self.blendingMode = 0;
}
hiddenVRController = [[VRController alloc] initWithPix:pix :files :volume :fusedViewer2D :viewer style:@"noNib" mode:@"MIP"];
[hiddenVRController retain];
// To avoid the "invalid drawable" message
[[hiddenVRController window] setLevel: 0];
[[hiddenVRController window] orderBack: self];
[[hiddenVRController window] orderOut: self];
[hiddenVRController load3DState];
hiddenVRView = [hiddenVRController view];
[hiddenVRView setClipRangeActivated: YES];
[hiddenVRView resetImage: self];
[hiddenVRView setLOD: 20];
hiddenVRView.keep3DRotateCentered = YES;
[mprView1 setVRView: hiddenVRView viewID: 1];
[mprView1 setWLWW: [[viewer imageView] curWL] :[[viewer imageView] curWW]];
[mprView2 setVRView: hiddenVRView viewID: 2];
[mprView2 setWLWW: [[viewer imageView] curWL] :[[viewer imageView] curWW]];
[mprView3 setVRView: hiddenVRView viewID: 3];
[mprView3 setWLWW: [[viewer imageView] curWL] :[[viewer imageView] curWW]];
[hiddenVRView setWLWW: [[viewer imageView] curWL] :[[viewer imageView] curWW]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultToolModified:) name:OsirixDefaultToolModifiedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateWLWWMenu:) name:OsirixUpdateWLWWMenuNotification object:nil];
curWLWWMenu = [[viewer2D curWLWWMenu] retain];
[[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateWLWWMenuNotification object: curWLWWMenu userInfo: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateCLUTMenu:) name:OsirixUpdateCLUTMenuNotification object: nil];
curCLUTMenu = [[viewer2D curCLUTMenu] retain];
[[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateCLUTMenuNotification object: curCLUTMenu userInfo: nil];
startingOpacityMenu = [[viewer2D curOpacityMenu] retain];
curOpacityMenu = [startingOpacityMenu retain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateOpacityMenu:) name:OsirixUpdateOpacityMenuNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateOpacityMenuNotification object: curOpacityMenu userInfo: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CloseViewerNotification:) name:OsirixCloseViewerNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(changeWLWW:) name: OsirixChangeWLWWNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(updateCurvedPathCost) name:OsirixUpdateCurvedPathCostNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(resetSlider) name:OsirixDeletedCurvedPathNotification object: nil];
[shadingCheck setAction:@selector(switchShading:)];
[shadingCheck setTarget:self];
// self.dcmNumberOfFrames = 50;
// self.dcmRotationDirection = 0;
// self.dcmRotation = 360;
// self.dcmSeriesName = @"CPR";
self.exportSeriesName = @"CPR";;
self.exportSequenceType = CPRCurrentOnlyExportSequenceType;
self.exportSeriesType = CPRRotationExportSeriesType;
self.exportRotationSpan = CPR180ExportRotationSpan;
self.exportReverseSliceOrder = NO;
float r1, g1, b1, a1, r2, g2, b2, a2, r3, g3, b3, a3;
r1 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_1_RED"];
g1 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_1_GREEN"];
b1 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_1_BLUE"];
a1 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_1_ALPHA"];
r2 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_2_RED"];
g2 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_2_GREEN"];
b2 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_2_BLUE"];
a2 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_2_ALPHA"];
r3 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_3_RED"];
g3 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_3_GREEN"];
b3 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_3_BLUE"];
a3 = [[NSUserDefaults standardUserDefaults] floatForKey:@"MPR_AXIS_3_ALPHA"];
if(r1==0.0 && g1==0.0 && b1==0.0 && a1==0.0 && r2==0.0 && g2==0.0 && b2==0.0 && a2==0.0 && r3==0.0 && g3==0.0 && b3==0.0 && a3==0.0)
{
r1 = 1.0; g1 = 0.67; b1 = 0.0; a1 = 0.8;
r2 = 0.6; g2 = 0.0; b2 = 1.0; a2 = 0.8;
r3 = 0.0; g3 = 0.5; b3 = 1.0; a3 = 0.8;
}
self.colorAxis1 = [NSColor colorWithDeviceRed:r1 green:g1 blue:b1 alpha:a1];
self.colorAxis2 = [NSColor colorWithDeviceRed:r2 green:g2 blue:b2 alpha:a2];
self.colorAxis3 = [NSColor colorWithDeviceRed:r3 green:g3 blue:b3 alpha:a3];
cprView.orangePlaneColor = self.colorAxis1;
cprView.purplePlaneColor = self.colorAxis2;
cprView.bluePlaneColor = self.colorAxis3;
[mprView1 addObserver:self forKeyPath:@"plane" options:0 context:MPRPlaneObservationContext];
[mprView2 addObserver:self forKeyPath:@"plane" options:0 context:MPRPlaneObservationContext];
[mprView3 addObserver:self forKeyPath:@"plane" options:0 context:MPRPlaneObservationContext];
[[NSColorPanel sharedColorPanel] setShowsAlpha: YES];
undoQueue = [[NSMutableArray alloc] initWithCapacity: 0];
redoQueue = [[NSMutableArray alloc] initWithCapacity: 0];
[self setToolIndex: tWL];
self.cprType = [[NSUserDefaults standardUserDefaults] integerForKey: @"SavedCPRType"];
[[self window] registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
[self setupToolbar];
}
@catch (NSException *e)
{
NSLog( @"CPR Init failed: %@", e);
return nil;
}
return self;
}
- (void) delayedFullLODRendering:(id) sender
{
if( windowWillClose) return;
if( hiddenVRView.lowResLODFactor > 1 || sender != nil)
{
lowLOD = NO;
[self updateViewsAccordingToFrame: sender];
lowLOD = YES;
}
}
- (void) updateViewsAccordingToFrame:(id) sender // see setFrame in CPRMPRDCMView.m
{
if( windowWillClose) return;
id view = [[self window] firstResponder];
[mprView1 camera].forceUpdate = YES;
[mprView2 camera].forceUpdate = YES;
[mprView3 camera].forceUpdate = YES;
if( sender)
{
if( [[self window] firstResponder] != sender)
[[self window] makeFirstResponder: sender];
[sender restoreCamera];
[sender updateViewMPR];
}
else
{
CPRMPRDCMView *selectedView = [self selectedView];
if( [[self window] firstResponder] != selectedView)
[[self window] makeFirstResponder: selectedView];
[selectedView restoreCamera];
[selectedView updateViewMPR];
}
if( view)
if( [[self window] firstResponder] != view)
[[self window] makeFirstResponder: view];
[mprView1 setNeedsDisplay: YES];
[mprView2 setNeedsDisplay: YES];
[mprView3 setNeedsDisplay: YES];
}
- (void) showWindow:(id) sender
{
mprView1.dontUseAutoLOD = YES;
mprView2.dontUseAutoLOD = YES;
mprView3.dontUseAutoLOD = YES;
mprView1.LOD = 40;
mprView2.LOD = 40;
mprView3.LOD = 40;
BOOL c = [[NSUserDefaults standardUserDefaults] boolForKey: @"syncZoomLevelMPR"];
[[NSUserDefaults standardUserDefaults] setBool: YES forKey: @"syncZoomLevelMPR"];
// Default Init
[self setClippingRangeMode: 1]; // MIP
self.clippingRangeThickness = 0.5;
int min = [self getClippingRangeThicknessInMm] * 100.;
self.dcmIntervalMin = (float) min / 100.;
self.dcmIntervalMin -= 0.001;
if( self.dcmIntervalMin < 0.01)
self.dcmIntervalMin = 0.01;
self.dcmIntervalMax = 100;
[[self window] makeFirstResponder: mprView1];
[mprView1.vrView resetImage: self];
mprView1.angleMPR = 0;
mprView2.angleMPR = 0;
mprView3.angleMPR = 0;
[mprView1 updateViewMPR];
mprView2.camera.viewUp = [Point3D pointWithX:0 y:-1 z:0];
[[self window] makeFirstResponder: mprView3];
mprView3.camera.viewUp = [Point3D pointWithX:0 y:0 z:1];
mprView3.camera.rollAngle = 0;
mprView3.angleMPR = 0;
mprView3.camera.parallelScale /= 1.5;
[mprView3 restoreCamera];
[mprView3 updateViewMPR];
[super showWindow: sender];
[self setTool: toolsMatrix];
if( c == NO)
[[NSUserDefaults standardUserDefaults] setBool: c forKey: @"syncZoomLevelMPR"];
mprView1.dontUseAutoLOD = NO;
mprView2.dontUseAutoLOD = NO;
mprView3.dontUseAutoLOD = NO;
[self setLOD: 1];
[self CPRViewWillEditCurvedPath: mprView1];
while( mprView1.curvedPath.nodes.count > 0)
[mprView1.curvedPath removeNodeAtIndex: 0];
[self CPRViewDidUpdateCurvedPath: mprView1];
[self CPRViewDidEditCurvedPath: mprView1];
// Restore previous path, if it exists
NSString *path = [[[BrowserController currentBrowser] documentsDirectory] stringByAppendingPathComponent:STATEDATABASE];
if (![[NSFileManager defaultManager] fileExistsAtPath: path])
[[NSFileManager defaultManager] createDirectoryAtPath: path attributes: nil];
path = [path stringByAppendingPathComponent: [NSString stringWithFormat:@"CPR-%@", [[[viewer2D fileList: 0] objectAtIndex:0] valueForKey:@"uniqueFilename"]]];
if( path)
[self loadBezierPathFromFile: path];
}
-(void) awakeFromNib
{
NSScreen *s = [viewer2D get3DViewerScreen: viewer2D];
[horizontalSplit1 setDelegate: self];
[horizontalSplit2 setDelegate: self];
[verticalSplit setDelegate: self];
if( [s frame].size.height > [s frame].size.width)
{
[horizontalSplit1 setVertical: NO];
[horizontalSplit2 setVertical: NO];
[verticalSplit setVertical: YES];
}
[shadingsPresetsController setWindowController: self];
[shadingCheck setAction:@selector(switchShading:)];
[shadingCheck setTarget:self];
}
-(void)splitViewWillResizeSubviews:(NSNotification *)notification
{
N2OpenGLViewWithSplitsWindow *window = (N2OpenGLViewWithSplitsWindow*)self.window;
if( [window respondsToSelector:@selector(disableUpdatesUntilFlush)])
[window disableUpdatesUntilFlush];
}
- (void) dealloc
{
[cprVolumeData invalidateData];
[cprVolumeData release];
[mprView1 removeObserver:self forKeyPath:@"plane"];
[mprView2 removeObserver:self forKeyPath:@"plane"];
[mprView3 removeObserver:self forKeyPath:@"plane"];
[mousePosition release];
[wlwwMenuItems release];
[toolbar release];
[colorAxis1 release];
[colorAxis2 release];
[colorAxis3 release];
[undoQueue release];
[redoQueue release];
[movieTimer release];
[blendedMprView1 release];
[blendedMprView2 release];
[blendedMprView3 release];
[curvedPath release];
[curvedPathColor release];
[displayInfo release];
mprView1.delegate = nil;
mprView2.delegate = nil;
mprView3.delegate = nil;
cprView.delegate = nil;
topTransverseView.delegate = nil;
middleTransverseView.delegate = nil;
bottomTransverseView.delegate = nil;
[startingOpacityMenu release];
[exportSeriesName release];
[_delegateCurveViewDebugging release];
_delegateCurveViewDebugging = nil;
[_delegateDisplayInfoDebugging release];
_delegateDisplayInfoDebugging = nil;
[assistant release];
[centerline release];
[nodeRemovalCost release];
[delHistory release];
[delNodes release];
[HR_PixList release];
[HR_FileList release];
[HR_Data release];
[super dealloc];
NSLog( @"dealloc CPRController");
}
- (BOOL) is2DViewer
{
return NO;
}
- (void) CloseViewerNotification: (NSNotification*) note
{
if( [note object] == viewer2D || [note object] == fusedViewer2D)
{
[self offFullScreen];
[[self window] close];
}
}
- (NSArray*) pixList
{
return pixList[ curMovieIndex];
}
- (void) setToolIndex: (ToolMode) toolIndex
{
[mprView1 setCurrentTool:toolIndex];
[mprView2 setCurrentTool:toolIndex];
[mprView3 setCurrentTool:toolIndex];
[cprView setCurrentTool:toolIndex];
[topTransverseView setCurrentTool:toolIndex];
[middleTransverseView setCurrentTool:toolIndex];
[bottomTransverseView setCurrentTool:toolIndex];
[mprView1.vrView setCurrentTool:toolIndex];
[mprView2.vrView setCurrentTool:toolIndex];
[mprView3.vrView setCurrentTool:toolIndex];
}
- (IBAction) setTool:(id)sender;
{
int toolIndex = 0;
if([sender isKindOfClass:[NSMatrix class]])
toolIndex = [[sender selectedCell] tag];
else if([sender respondsToSelector:@selector(tag)])
toolIndex = [sender tag];
[self setToolIndex: toolIndex];
[self setROIToolTag: toolIndex];
}
- (void) computeCrossReferenceLinesBetween: (CPRMPRDCMView*) mp1 and:(CPRMPRDCMView*) mp2 result: (float[2][3]) s
{
float vectorA[ 9], vectorB[ 9];
float originA[ 3], originB[ 3];
s[ 0][ 0] = HUGE_VALF; s[ 0][ 1] = HUGE_VALF; s[ 0][ 2] = HUGE_VALF;
s[ 1][ 0] = HUGE_VALF; s[ 1][ 1] = HUGE_VALF; s[ 1][ 2] = HUGE_VALF;
if( mp2.frame.size.height > 10 && mp2.frame.size.width > 10)
{
originA[ 0] = mp2.pix.originX; originA[ 1] = mp2.pix.originY; originA[ 2] = mp2.pix.originZ;
originB[ 0] = mp1.pix.originX; originB[ 1] = mp1.pix.originY; originB[ 2] = mp1.pix.originZ;
[mp2.pix orientation: vectorA];
[mp1.pix orientation: vectorB];
float slicePoint[ 3];
float sliceVector[ 3];
if( intersect3D_2Planes( vectorA+6, originA, vectorB+6, originB, sliceVector, slicePoint) == noErr)
{
[mp1 computeSliceIntersection: mp2.pix sliceFromTo: s vector: vectorB origin: originB];
}
}
}
- (void) propagateOriginRotationAndZoomToTransverseViews: (CPRTransverseView*) sender
{
[topTransverseView setOrigin: [sender origin]];
[middleTransverseView setOrigin: [sender origin]];
[bottomTransverseView setOrigin: [sender origin]];
[topTransverseView setScaleValue: [sender scaleValue]];
[middleTransverseView setScaleValue: [sender scaleValue]];
[bottomTransverseView setScaleValue: [sender scaleValue]];
[topTransverseView setRotation: [sender rotation]];
[middleTransverseView setRotation: [sender rotation]];
[bottomTransverseView setRotation: [sender rotation]];
}
- (void) propagateWLWW:(DCMView*) sender
{
[mprView1 setWLWW: [sender curWL] :[sender curWW]];
[mprView2 setWLWW: [sender curWL] :[sender curWW]];
[mprView3 setWLWW: [sender curWL] :[sender curWW]];
[cprView setWLWW: [sender curWL] :[sender curWW]];
[topTransverseView setWLWW: [sender curWL] :[sender curWW]];
[middleTransverseView setWLWW: [sender curWL] :[sender curWW]];
[bottomTransverseView setWLWW: [sender curWL] :[sender curWW]];
mprView1.camera.wl = [sender curWL]; mprView1.camera.ww = [sender curWW];
mprView2.camera.wl = [sender curWL]; mprView2.camera.ww = [sender curWW];
mprView3.camera.wl = [sender curWL]; mprView3.camera.ww = [sender curWW];
}
- (void) computeCrossReferenceLines:(CPRMPRDCMView*) sender
{
float a[2][3];
float b[2][3];
if( sender)
{
if( [[NSUserDefaults standardUserDefaults] boolForKey: @"syncZoomLevelMPR"])
{
CPRMPRDCMView *selectedView = [self selectedView];
if( selectedView != mprView1) mprView1.camera.parallelScale = selectedView.camera.parallelScale;
if( selectedView != mprView2) mprView2.camera.parallelScale = selectedView.camera.parallelScale;
if( selectedView != mprView3) mprView3.camera.parallelScale = selectedView.camera.parallelScale;
}
}
// Center other views on the sender view
if( sender && [sender isKeyView] == YES && avoidReentry == NO)
{
avoidReentry = YES;
float x, y, z;
Camera *cam = sender.camera;
Point3D *position = cam.position;
// Point3D *viewUp = cam.viewUp;
float halfthickness = sender.vrView.clippingRangeThickness / 2.;
float cos[ 9];
[sender.pix orientation: cos];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
position = [Point3D pointWithX: position.x + halfthickness*cos[ 6] y:position.y + halfthickness*cos[ 7] z:position.z + halfthickness*cos[ 8]];
if( sender != mprView1) mprView1.camera.position = position;
if( sender != mprView2) mprView2.camera.position = position;
if( sender != mprView3) mprView3.camera.position = position;
if( sender == mprView1)
{
float angle = mprView1.angleMPR;
XYZ vector, rotationVector;
rotationVector.x = cos[ 6]; rotationVector.y = cos[ 7]; rotationVector.z = cos[ 8];
vector.x = cos[ 3]; vector.y = cos[ 4]; vector.z = cos[ 5];
vector = ArbitraryRotate(vector, (angle-180.)*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView2.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
Point3D *p = mprView2.camera.position;
mprView2.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
vector.x = cos[ 0]; vector.y = cos[ 1]; vector.z = cos[ 2];
vector = ArbitraryRotate(vector, angle*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView3.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
p = mprView3.camera.position;
mprView3.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
}
if( sender == mprView2)
{
float angle = mprView2.angleMPR;
XYZ vector, rotationVector;
rotationVector.x = cos[ 6]; rotationVector.y = cos[ 7]; rotationVector.z = cos[ 8];
vector.x = cos[ 3]; vector.y = cos[ 4]; vector.z = cos[ 5];
vector = ArbitraryRotate(vector, angle*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView3.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
Point3D *p = mprView3.camera.position;
mprView3.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
vector.x = cos[ 0]; vector.y = cos[ 1]; vector.z = cos[ 2];
vector = ArbitraryRotate(vector, (angle-180.)*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView1.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
p = mprView1.camera.position;
mprView1.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
}
if( sender == mprView3)
{
float angle = mprView3.angleMPR;
XYZ vector, rotationVector;
rotationVector.x = cos[ 6]; rotationVector.y = cos[ 7]; rotationVector.z = cos[ 8];
vector.x = cos[ 3]; vector.y = cos[ 4]; vector.z = cos[ 5];
vector = ArbitraryRotate(vector, (angle-180.)*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView2.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
Point3D *p = mprView2.camera.position;
mprView2.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
vector.x = -cos[ 0]; vector.y = -cos[ 1]; vector.z = -cos[ 2];
vector = ArbitraryRotate(vector, angle*deg2rad, rotationVector);
x = position.x + vector.x; y = position.y + vector.y; z = position.z + vector.z;
mprView1.camera.focalPoint = [Point3D pointWithX:x y:y z:z];
// Correct slice position according to slice center (VR: position is the beginning of the slice)
p = mprView1.camera.position;
mprView1.camera.position = [Point3D pointWithX: p.x + halfthickness*-vector.x y:p.y + halfthickness*-vector.y z:p.z + halfthickness*-vector.z];
}
float l, w;
[sender.vrView getWLWW: &l : &w];
if( sender != mprView1)
{
[mprView1 restoreCamera];
if( clippingRangeMode == 0) // VR mode
{
[mprView1.vrView setOpacity: [sender.vrView currentOpacityArray]];
[mprView1.vrView setWLWW: l : w];
}
[mprView1 updateViewMPR];
}
if( sender != mprView2)
{
[mprView2 restoreCamera];
if( clippingRangeMode == 0) // VR mode
{
[mprView2.vrView setOpacity: [sender.vrView currentOpacityArray]];
[mprView2.vrView setWLWW: l : w];
}
[mprView2 updateViewMPR];
}
if( sender != mprView3)
{
[mprView3 restoreCamera];
if( clippingRangeMode == 0) // VR mode
{
[mprView3.vrView setOpacity: [sender.vrView currentOpacityArray]];
[mprView3.vrView setWLWW: l : w];
}
[mprView3 updateViewMPR];
}
if( sender == mprView1)
{
float o[ 9], orientation[ 9];
[sender.pix orientation: o];
[mprView2.pix orientation: orientation];
mprView2.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation]-180.;
[mprView3.pix orientation: orientation];
mprView3.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation]-180.;
}
if( sender == mprView2)
{
float o[ 9], orientation[ 9];
[sender.pix orientation: o];
[mprView1.pix orientation: orientation];
mprView1.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation]+90.;
[mprView3.pix orientation: orientation];
mprView3.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation]+90.;
}
if( sender == mprView3)
{
float o[ 9], orientation[ 9];
[sender.pix orientation: o];
[mprView1.pix orientation: orientation];
mprView1.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation];
[mprView2.pix orientation: orientation];
mprView2.angleMPR = [CPRController angleBetweenVector: o+6 andPlane:orientation]-90.;
}
}
[self computeCrossReferenceLinesBetween: mprView1 and: mprView2 result: a];
[self computeCrossReferenceLinesBetween: mprView1 and: mprView3 result: b];
[mprView1 setCrossReferenceLines: a and: b];
[self computeCrossReferenceLinesBetween: mprView2 and: mprView1 result: a];
[self computeCrossReferenceLinesBetween: mprView2 and: mprView3 result: b];
[mprView2 setCrossReferenceLines: a and: b];
[self computeCrossReferenceLinesBetween: mprView3 and: mprView1 result: a];
[self computeCrossReferenceLinesBetween: mprView3 and: mprView2 result: b];
[mprView3 setCrossReferenceLines: a and: b];
[mprView1 setNeedsDisplay: YES];
[mprView2 setNeedsDisplay: YES];
[mprView3 setNeedsDisplay: YES];
avoidReentry = NO;
}