forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLMPRViewer.m
1864 lines (1559 loc) · 70 KB
/
LLMPRViewer.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.
=========================================================================*/
#include <Accelerate/Accelerate.h>
#import "LLMPRViewer.h"
#import "LLSubtraction.h"
#import "LLMPRView.h"
#import "LLDCMView.h"
#import "ITKSegmentation3D.h"
#import "AppController.h"
#import "VRController.h"
#import "VRControllerVPRO.h"
#import "WaitRendering.h"
#import "VRView.h"
#import "Notifications.h"
#define BONEVALUE 250
#define MORPH_RESAMPLE 3
@class Window3DController;
extern AppController *appController;
static NSString* LLMPRToolbarIdentifier = @"Lower Limbs MPR Viewer Toolbar Identifier";
static NSString* ToolsToolbarItemIdentifier = @"Tools";
static NSString* WLWWToolbarItemIdentifier = @"WLWW";
static NSString* ThickSlabToolbarItemIdentifier = @"ThickSlab";
static NSString* Produce2DResultToolbarItemIdentifier = @"Axial";
static NSString* Produce3DResultToolbarItemIdentifier = @"MIP";
static NSString* ParameterPanelToolbarItemIdentifier = @"3D";
@implementation LLMPRViewer
- (id) initWithPixList: (NSArray*) pix : (NSArray*) pixToSubstract :(NSArray*) files :(NSData*) vData :(ViewerController*) vC :(ViewerController*) bC :(LLScoutViewer*)sV;
{
self = [super initWithWindowNibName:@"LLMPR"];
viewer = [vC retain]; // released in super-class
notInjectedViewer = [bC retain];
scoutViewer = sV;
[[self window] setDelegate:self];
[[self window] setShowsResizeIndicator:YES];
[[self window] performZoom:self];
NSRect selfWindowRect = [[self window] frame];
NSRect scoutWindowRect = [[scoutViewer window] frame];
selfWindowRect.size.width -= scoutWindowRect.size.width;
selfWindowRect.origin.x = scoutWindowRect.size.width;
[[self window] setFrame:selfWindowRect display:YES animate:NO];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CloseViewerNotification:) name:OsirixCloseViewerNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resliceFromNotification:) name:OsirixLLMPRResliceNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeWLWW:) name:OsirixChangeWLWWNotification object:nil];
[splitView setDelegate:self];
// initialisations
[injectedMPRController initWithPixList: pix : files : vData : vC : nil: self];
[(LLMPRController*)controller initWithPixList: pixToSubstract : files : vData : bC : nil: self];
isFullWindow = NO;
displayResliceAxes = 1;
// thick slab
[thickSlabTextField setStringValue:[NSString stringWithFormat:@"%d",2]];
[thickSlabSlider setMinValue:2];
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
// // WL/WW Menu
curWLWWMenu = [NSLocalizedString(@"Other", nil) retain];
[nc addObserver:self selector:@selector(UpdateWLWWMenu:) name:OsirixUpdateWLWWMenuNotification object:nil];
[nc postNotificationName: OsirixUpdateWLWWMenuNotification object:curWLWWMenu userInfo:nil];
subtractedOriginalBuffer = nil;
subtractedXReslicedBuffer = nil;
subtractedYReslicedBuffer = nil;
xShift = 0;
yShift = 0;
zShift = 0;
closingRadius = 1;//2;
// [closingRadiusSlider setIntValue:MORPH_RESAMPLE];
[closingRadiusSlider setMaxValue:10.0];
[closingRadiusSlider setMinValue:1.0];
// [closingRadiusSlider setNumberOfTickMarks:MORPH_RESAMPLE*2+1];
[closingRadiusSlider setNumberOfTickMarks:10];
[closingRadiusSlider setFloatValue:(float)closingRadius];
dilatationRadius = 1;
[dilatationRadiusSlider setMaxValue:10.0];
[dilatationRadiusSlider setMinValue:1.0];
// [dilatationRadiusSlider setNumberOfTickMarks:MORPH_RESAMPLE*2+1];
[dilatationRadiusSlider setNumberOfTickMarks:10];
[dilatationRadiusSlider setFloatValue:dilatationRadius];
lowPassFilterSize = 0;
[lowPassFilterSizeSlider setIntValue:lowPassFilterSize];
displayBones = NO;
bonesThreshold = 200;
// [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LLSubtractionParameters"];
[self initialDefaultSettings];
[self buildSettingsMenu];
settingsName = [[settingsPopup itemAtIndex:0] title];
[self applySettingsForTitle:settingsName];
[settingsPopup selectItemAtIndex:0];
[self buildConvolutionsMenu];
return self;
}
-(void)setPixListRange:(NSRange)range;
{
pixListRange = range;
[injectedMPRController setPixListRange:range];
[(LLMPRController*)controller setPixListRange:range];
}
- (void)dealloc
{
//NSLog(@"LLMPRViewer dealloc");
if(subtractedOriginalBuffer)
{
free(subtractedOriginalBuffer);
subtractedOriginalBuffer = nil;
}
if(subtractedXReslicedBuffer)
{
free(subtractedXReslicedBuffer);
subtractedXReslicedBuffer = nil;
}
if(subtractedYReslicedBuffer)
{
free(subtractedYReslicedBuffer);
subtractedYReslicedBuffer = nil;
}
// [[NSNotificationCenter defaultCenter] removeObserver:self];
[notInjectedViewer release];
//[scoutViewer release];
[super dealloc];
}
- (IBAction)showWindow:(id)sender
{
[super showWindow:sender];
[injectedMPRController showViews:sender];
[[injectedMPRController originalView] setFusion:0 :1];
[[controller originalView] setFusion:0 :1];
//[self refreshSubtractedViews];
}
- (IBAction)changeTool:(id)sender
{
[super changeTool:sender];
if( [sender isMemberOfClass: [NSMatrix class]]) [injectedMPRController setCurrentTool: [[sender selectedCell] tag]];
else [injectedMPRController setCurrentTool: [sender tag]];
}
- (void)toggleDisplayResliceAxes
{
if(!isFullWindow)
{
displayResliceAxes++;
if( displayResliceAxes >= 3) displayResliceAxes = 0;
[controller toggleDisplayResliceAxes:self];
[injectedMPRController toggleDisplayResliceAxes:self];
}
}
- (void)blendingPropagate:(LLDCMView*)sender;
{
//NSLog(@"LLMPRViewer blendingPropagate");
if ([sender isEqual:subtractedOriginalView])
{
//[self blendingPropagateOriginal: (OrthogonalMPRView*) sender];
[self blendingPropagateOriginal:[controller originalView]];
}
else if ([sender isEqual:subtractedXReslicedView])
{
//[self blendingPropagateX: (OrthogonalMPRView*) sender];
[self blendingPropagateOriginal:[controller xReslicedView]];
}
else if ([sender isEqual:subtractedYReslicedView])
{
//[self blendingPropagateY: (OrthogonalMPRView*) sender];
[self blendingPropagateOriginal:[controller yReslicedView]];
}
}
- (void)blendingPropagateOriginal:(OrthogonalMPRView*)sender
{
// MPR Views
[controller blendingPropagateOriginal: sender];
[injectedMPRController blendingPropagateOriginal: sender];
// Subtracted Views
float fValue = [sender scaleValue] / [sender pixelSpacing];
[subtractedOriginalView setScaleValue: fValue * [subtractedOriginalView pixelSpacing]];
[subtractedOriginalView setRotation: [sender rotation]];
[subtractedOriginalView setOrigin: [sender origin]];
NSPoint pt;
// X - Views
[subtractedXReslicedView setScaleValue: fValue * [subtractedXReslicedView pixelSpacing]];
pt.y = [subtractedXReslicedView origin].y;
pt.x = [sender origin].x;
[subtractedXReslicedView setOrigin: pt];
// Y - Views
[subtractedYReslicedView setScaleValue: fValue * [subtractedYReslicedView pixelSpacing]];
pt.y = [subtractedYReslicedView origin].y;
pt.x = -[sender origin].y;
[subtractedYReslicedView setOrigin: pt];
[subtractedOriginalView setNeedsDisplay:YES];
}
- (void)blendingPropagateX:(OrthogonalMPRView*)sender
{
// MPR Views
[controller blendingPropagateX: sender];
[injectedMPRController blendingPropagateX: sender];
// Subtracted Views
float fValue = [sender scaleValue] / [sender pixelSpacing];
[subtractedXReslicedView setScaleValue: fValue * [subtractedXReslicedView pixelSpacing]];
[subtractedXReslicedView setRotation: [sender rotation]];
[subtractedXReslicedView setOrigin: [sender origin]];
NSPoint pt;
// X - Views
[subtractedOriginalView setScaleValue: fValue * [subtractedOriginalView pixelSpacing]];
pt.y = [subtractedOriginalView origin].y;
pt.x = [sender origin].x;
[subtractedOriginalView setOrigin: pt];
// Y - Views
[subtractedYReslicedView setScaleValue: fValue * [subtractedYReslicedView pixelSpacing]];
pt.x = [subtractedYReslicedView origin].x;
pt.y = [sender origin].y;
[subtractedYReslicedView setOrigin: pt];
[subtractedXReslicedView setNeedsDisplay:YES];
}
- (void) blendingPropagateY:(OrthogonalMPRView*) sender
{
// MPR Views
[controller blendingPropagateY: sender];
[injectedMPRController blendingPropagateY: sender];
// Subtracted Views
float fValue = [sender scaleValue] / [sender pixelSpacing];
[subtractedYReslicedView setScaleValue: fValue * [subtractedYReslicedView pixelSpacing]];
[subtractedYReslicedView setRotation: [sender rotation]];
[subtractedYReslicedView setOrigin: [sender origin]];
NSPoint pt;
// X - Views
[subtractedOriginalView setScaleValue: fValue * [subtractedOriginalView pixelSpacing]];
pt.x = [subtractedOriginalView origin].x;
pt.y = -[sender origin].x;
[subtractedOriginalView setOrigin: pt];
// Y - Views
[subtractedXReslicedView setScaleValue: fValue * [subtractedXReslicedView pixelSpacing]];
pt.x = [subtractedXReslicedView origin].x;
pt.y = [sender origin].y;
[subtractedXReslicedView setOrigin: pt];
[subtractedYReslicedView setNeedsDisplay:YES];
}
- (void)changeWLWW:(NSNotification*)note;
{
// if([[[injectedMPRController originalView] dcmPixList] count]==0 || [[[injectedMPRController xReslicedView] dcmPixList] count]==0 || [[[injectedMPRController yReslicedView] dcmPixList] count]==0) return;
// if([[[controller originalView] dcmPixList] count]==0 || [[[controller xReslicedView] dcmPixList] count]==0 || [[[controller yReslicedView] dcmPixList] count]==0) return;
// if([[subtractedOriginalView dcmPixList] count]==0 || [[subtractedXReslicedView dcmPixList] count]==0 || [[subtractedYReslicedView dcmPixList] count]==0) return;
DCMPix *otherPix = [note object];
if( [[controller originalDCMPixList] containsObject: otherPix] || [[injectedMPRController originalDCMPixList] containsObject: otherPix] || [[subtractedOriginalView dcmPixList] containsObject: otherPix] || [[subtractedXReslicedView dcmPixList] containsObject: otherPix] || [[subtractedYReslicedView dcmPixList] containsObject: otherPix])
{
float iwl, iww;
iww = [otherPix ww];
iwl = [otherPix wl];
if( iww != [[[controller originalView] curDCM] ww] || iwl != [[[controller originalView] curDCM] wl])
[controller setWLWW: iwl :iww];
if( iww != [[[injectedMPRController originalView] curDCM] ww] || iwl != [[[injectedMPRController originalView] curDCM] wl])
[injectedMPRController setWLWW: iwl :iww];
if( iww != [[subtractedOriginalView curDCM] ww] || iwl != [[subtractedOriginalView curDCM] wl])
[subtractedOriginalView setWLWW: iwl :iww];
if( iww != [[subtractedXReslicedView curDCM] ww] || iwl != [[subtractedXReslicedView curDCM] wl])
[subtractedXReslicedView setWLWW: iwl :iww];
if( iww != [[subtractedYReslicedView curDCM] ww] || iwl != [[subtractedYReslicedView curDCM] wl])
[subtractedYReslicedView setWLWW: iwl :iww];
}
}
- (IBAction) resetImage:(id) sender
{
[injectedMPRController resetImage];
[super resetImage:sender];
[self refreshSubtractedViews];
}
- (void) CloseViewerNotification: (NSNotification*) note
{
if([note object] == viewer || [note object] == notInjectedViewer)
{
[[self window] close];
}
}
- (void)windowWillClose:(NSNotification *)aNotification
{
[[self window] setAcceptsMouseMovedEvents: NO];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[[self window] setDelegate:nil];
[self autorelease];
}
#pragma mark-
#pragma mark MPR
- (void) resliceFromNotification: (NSNotification*) notification;
{
if(injectedMPRController==nil) return;
if(controller==nil) return;
if([injectedMPRController thickSlab]!=[controller thickSlab] || [injectedMPRController thickSlabMode]!=[controller thickSlabMode])
return;
[injectedMPRController resliceFromNotification: notification];
[(LLMPRController*)controller resliceFromNotification: notification];
if([[[injectedMPRController originalView] dcmPixList] count]==0 || [[[injectedMPRController xReslicedView] dcmPixList] count]==0 || [[[injectedMPRController yReslicedView] dcmPixList] count]==0)
return;
if([[[controller originalView] dcmPixList] count]==0 || [[[controller xReslicedView] dcmPixList] count]==0 || [[[controller yReslicedView] dcmPixList] count]==0)
return;
[self refreshSubtractedViews];
}
- (void)refreshSubtractedViews;
{
//NSLog(@"refreshSubtractedViews");
DCMPix *curPix;
int width, height;
float pixelSpacingX, pixelSpacingY;
float *buffer, *resampledBuffer;
long byteCount;
float fValue;
NSMutableArray *axialPixList, *coronalPixList, *sagitalPixList;
int i, minI, maxI;
// axial
if(thickSlabMode != 0)
{
minI = [[injectedMPRController originalView] curImage];
maxI = minI + thickSlab;
minI = (minI<0)? 0: minI;
//maxI = (maxI>=[[[injectedMPRController originalView] curDCM] pheight])? [[[injectedMPRController originalView] curDCM] pheight]-1 : maxI;
maxI = (maxI>=[[[injectedMPRController originalView] dcmPixList] count])? (long)[[[injectedMPRController originalView] dcmPixList] count]-1 : maxI;
}
else
{
minI = [[injectedMPRController originalView] curImage];
maxI = minI + 1;
}
axialPixList = [NSMutableArray array];//[[NSMutableArray alloc] initWithCapacity:maxI-minI];
DCMPix *newAxialPix;
width = [[[[injectedMPRController originalView] dcmPixList] objectAtIndex:0] pwidth];
height = [[[[injectedMPRController originalView] dcmPixList] objectAtIndex:0] pheight];
pixelSpacingX = [[[[injectedMPRController originalView] dcmPixList] objectAtIndex:0] pixelSpacingX];
pixelSpacingY = [[[[injectedMPRController originalView] dcmPixList] objectAtIndex:0] pixelSpacingY];
BOOL resample = (xShift%4 != 0) || (yShift%4 != 0);
//tempPool = [[NSAutoreleasePool alloc] init];
for(i=minI; i<maxI; i++)
{
curPix = [[[injectedMPRController originalView] dcmPixList] objectAtIndex:i];
buffer = [curPix fImage];
byteCount = width*height*sizeof(float);
if(subtractedOriginalBuffer)
{
free(subtractedOriginalBuffer);
subtractedOriginalBuffer = nil;
}
subtractedOriginalBuffer = malloc(byteCount);
memcpy(subtractedOriginalBuffer,buffer,byteCount);
if(resample)
{
resampledBuffer = malloc(byteCount*16);
[self resampleBuffer:subtractedOriginalBuffer withWidth:width height:height factor:4.0 inNewBuffer:resampledBuffer];
[self applyShiftX:xShift y:yShift toBuffer:resampledBuffer withWidth:width*4 height:height*4];
[self resampleBuffer:resampledBuffer withWidth:width*4 height:height*4 factor:0.25 inNewBuffer:subtractedOriginalBuffer];
free(resampledBuffer);
}
else
{
[self applyShiftX:xShift/4 y:yShift/4 toBuffer:subtractedOriginalBuffer withWidth:width height:height];
}
//newAxialPix = [[[DCMPix alloc] initWithData:subtractedOriginalBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]] autorelease];
//newAxialPix = [[DCMPix alloc] initWithData:subtractedOriginalBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]];
newAxialPix = [[DCMPix alloc] initWithData:subtractedOriginalBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]];
[LLSubtraction subtractDCMPix:[[[controller originalView] dcmPixList] objectAtIndex:i] to:newAxialPix minValueA:injectedMinValue maxValueA:injectedMaxValue minValueB:notInjectedMinValue maxValueB:notInjectedMaxValue minValueSubtraction:subtractionMinValue maxValueSubtraction:subtractionMaxValue displayBones:displayBones bonesThreshold:bonesThreshold];// subtraction
// [LLSubtraction dilate:[newAxialPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius];
// [LLSubtraction close:[newAxialPix fImage] withWidth:width height:height structuringElementRadius:closingRadius];
BOOL resampleMorph = ((closingRadius-1)%MORPH_RESAMPLE != 0) || ((dilatationRadius-1)%MORPH_RESAMPLE != 0);
// resampleMorph = YES;
if(resampleMorph)
{
//NSLog(@"resampleMorph");
resampledBuffer = malloc(byteCount*MORPH_RESAMPLE*MORPH_RESAMPLE);
[self resampleBuffer:[newAxialPix fImage] withWidth:width height:height factor:MORPH_RESAMPLE*1.0 inNewBuffer:resampledBuffer];
// if(dilatationRadius>1)
[LLSubtraction dilate:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:dilatationRadius];
// if(closingRadius>1)
[LLSubtraction close:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:closingRadius];
[self resampleBuffer:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE factor:1.0/MORPH_RESAMPLE inNewBuffer:[newAxialPix fImage]];
free(resampledBuffer);
}
else
{
if(dilatationRadius>1)
[LLSubtraction dilate:[newAxialPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius/MORPH_RESAMPLE+1];
if(closingRadius>1)
[LLSubtraction close:[newAxialPix fImage] withWidth:width height:height structuringElementRadius:closingRadius/MORPH_RESAMPLE+1];
}
//[LLSubtraction removeSmallConnectedPartDCMPix:newAxialPix];
if(lowPassFilterSize>1)
[LLSubtraction lowPassFilterOnBuffer:[newAxialPix fImage] withWidth:width height:height structuringElementSize:lowPassFilterSize];
if(applyConvolution)
[LLSubtraction convolveBuffer:[newAxialPix fImage] withWidth:width height:height withKernel:convolutionKernel kernelSize:5];
[axialPixList addObject:newAxialPix];
[newAxialPix release];
}
//[tempPool release];
[subtractedOriginalView setPixels:axialPixList files:nil rois:nil firstImage:0 level:'i' reset:NO];
for( i = 0; i < [axialPixList count]; i++)
{
[[axialPixList objectAtIndex: i] setArrayPix: axialPixList :i];
}
[subtractedOriginalView setFusion:thickSlabMode :thickSlab];
fValue = [[controller originalView] scaleValue] / [[controller originalView] pixelSpacing];
[subtractedOriginalView setScaleValue: fValue * [subtractedOriginalView pixelSpacing]];
[subtractedOriginalView setRotation: [[controller originalView] rotation]];
[subtractedOriginalView setOrigin: [[controller originalView] origin]];
//[axialPixList release];
// [newAxialPix release];
// coronal
if(thickSlabMode != 0)
{
minI = [[injectedMPRController originalView] crossPositionY]-floor((float)[(LLMPRView*)[injectedMPRController xReslicedView] thickSlabX]/2.0);
maxI = [[injectedMPRController originalView] crossPositionY]+ceil((float)[(LLMPRView*)[injectedMPRController xReslicedView] thickSlabX]/2.0);
minI = (minI<0)? 0: minI;
maxI = (maxI>=[[[injectedMPRController originalView] curDCM] pheight])? [[[injectedMPRController originalView] curDCM] pheight]-1 : maxI;
}
else
{
minI = 0;
maxI = 1;
}
coronalPixList = [NSMutableArray array];// [[NSMutableArray alloc] initWithCapacity:maxI-minI];
DCMPix *newCoronalPix;
width = [[[[injectedMPRController xReslicedView] dcmPixList] objectAtIndex:0] pwidth];
height = [[[[injectedMPRController xReslicedView] dcmPixList] objectAtIndex:0] pheight];
pixelSpacingX = [[[[injectedMPRController xReslicedView] dcmPixList] objectAtIndex:0] pixelSpacingX];
pixelSpacingY = [[[[injectedMPRController xReslicedView] dcmPixList] objectAtIndex:0] pixelSpacingY];
resample = (xShift%4 != 0) || (zShift%4 != 0);
//tempPool = [[NSAutoreleasePool alloc] init];
//for(i=0; i<[[[injectedMPRController xReslicedView] dcmPixList] count]; i++)
for(i=0; i<maxI-minI; i++)
{
curPix = [[[injectedMPRController xReslicedView] dcmPixList] objectAtIndex:i];
buffer = [curPix fImage];
byteCount = [curPix pwidth]*[curPix pheight]*sizeof(float);
if(subtractedXReslicedBuffer)
{
free(subtractedXReslicedBuffer);
subtractedXReslicedBuffer = nil;
}
subtractedXReslicedBuffer = malloc(byteCount);
memcpy(subtractedXReslicedBuffer,buffer,byteCount);
if(resample)
{
resampledBuffer = malloc(byteCount*16);
[self resampleBuffer:subtractedXReslicedBuffer withWidth:width height:height factor:4.0 inNewBuffer:resampledBuffer];
[self applyShiftX:xShift y:zShift toBuffer:resampledBuffer withWidth:width*4 height:height*4];
[self resampleBuffer:resampledBuffer withWidth:width*4 height:height*4 factor:0.25 inNewBuffer:subtractedXReslicedBuffer];
free(resampledBuffer);
}
else
{
[self applyShiftX:xShift/4 y:zShift/4 toBuffer:subtractedXReslicedBuffer withWidth:width height:height];
}
//newCoronalPix = [[[DCMPix alloc] initWithData :subtractedXReslicedBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]] autorelease];
newCoronalPix = [[DCMPix alloc] initWithData :subtractedXReslicedBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]];
[LLSubtraction subtractDCMPix:[[[controller xReslicedView] dcmPixList] objectAtIndex:i] to:newCoronalPix minValueA:injectedMinValue maxValueA:injectedMaxValue minValueB:notInjectedMinValue maxValueB:notInjectedMaxValue minValueSubtraction:subtractionMinValue maxValueSubtraction:subtractionMaxValue displayBones:displayBones bonesThreshold:bonesThreshold];// subtraction
// [LLSubtraction dilate:[newCoronalPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius];
// [LLSubtraction close:[newCoronalPix fImage] withWidth:width height:height structuringElementRadius:closingRadius];
BOOL resampleMorph = ((closingRadius-1)%MORPH_RESAMPLE != 0) || ((dilatationRadius-1)%MORPH_RESAMPLE != 0);
// resampleMorph = YES;
if(resampleMorph)
{
resampledBuffer = malloc(byteCount*MORPH_RESAMPLE*MORPH_RESAMPLE);
[self resampleBuffer:[newCoronalPix fImage] withWidth:width height:height factor:MORPH_RESAMPLE*1.0 inNewBuffer:resampledBuffer];
// if(dilatationRadius>1)
[LLSubtraction dilate:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:dilatationRadius];
// if(closingRadius>1)
[LLSubtraction close:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:closingRadius];
[self resampleBuffer:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE factor:1.0/MORPH_RESAMPLE inNewBuffer:[newCoronalPix fImage]];
free(resampledBuffer);
}
else
{
if(dilatationRadius>1)
[LLSubtraction dilate:[newCoronalPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius/MORPH_RESAMPLE+1];
if(closingRadius>1)
[LLSubtraction close:[newCoronalPix fImage] withWidth:width height:height structuringElementRadius:closingRadius/MORPH_RESAMPLE+1];
}
if(lowPassFilterSize>1)
[LLSubtraction lowPassFilterOnBuffer:[newCoronalPix fImage] withWidth:width height:height structuringElementSize:lowPassFilterSize];
if(applyConvolution)
[LLSubtraction convolveBuffer:[newCoronalPix fImage] withWidth:width height:height withKernel:convolutionKernel kernelSize:5];
//[LLSubtraction removeSmallConnectedPartDCMPix:newCoronalPix];
[coronalPixList addObject:newCoronalPix];
[newCoronalPix release];
}
//[tempPool release];
[subtractedXReslicedView setPixels:coronalPixList files:nil rois:nil firstImage:[[injectedMPRController xReslicedView] curImage] level:'i' reset:NO];
for( i = 0; i < [coronalPixList count]; i++)
{
[[coronalPixList objectAtIndex: i] setArrayPix: coronalPixList :i];
}
[subtractedXReslicedView setFusion:thickSlabMode :[(LLMPRView*)[injectedMPRController xReslicedView] thickSlabX]];
fValue = [[controller xReslicedView] scaleValue] / [[controller xReslicedView] pixelSpacing];
[subtractedXReslicedView setScaleValue: fValue * [subtractedXReslicedView pixelSpacing]];
[subtractedXReslicedView setRotation: [[controller xReslicedView] rotation]];
[subtractedXReslicedView setOrigin: [[controller xReslicedView] origin]];
//[coronalPixList release];
// [newCoronalPix release];
// sagital
if(thickSlabMode != 0)
{
minI = [[injectedMPRController originalView] crossPositionX]-floor((float)[(LLMPRView*)[injectedMPRController yReslicedView] thickSlabX]/2.0);
maxI = [[injectedMPRController originalView] crossPositionX]+ceil((float)[(LLMPRView*)[injectedMPRController yReslicedView] thickSlabX]/2.0);
minI = (minI<0)? 0: minI;
maxI = (maxI>=[[[injectedMPRController originalView] curDCM] pwidth])? [[[injectedMPRController originalView] curDCM] pwidth]-1 : maxI;
}
else
{
minI = 0;
maxI = 1;
}
sagitalPixList = [NSMutableArray array];//[[NSMutableArray alloc] initWithCapacity:maxI-minI];
DCMPix *newSagitalPix;
width = [[[[injectedMPRController yReslicedView] dcmPixList] objectAtIndex:0] pwidth];
height = [[[[injectedMPRController yReslicedView] dcmPixList] objectAtIndex:0] pheight];
pixelSpacingX = [[[[injectedMPRController yReslicedView] dcmPixList] objectAtIndex:0] pixelSpacingX];
pixelSpacingY = [[[[injectedMPRController yReslicedView] dcmPixList] objectAtIndex:0] pixelSpacingY];
resample = (yShift%4 != 0) || (zShift%4 != 0);
//tempPool = [[NSAutoreleasePool alloc] init];
//for(i=0; i<[[[injectedMPRController yReslicedView] dcmPixList] count]; i++)
for(i=0; i<maxI-minI; i++)
{
curPix = [[[injectedMPRController yReslicedView] dcmPixList] objectAtIndex:i];
buffer = [curPix fImage];
byteCount = [curPix pwidth]*[curPix pheight]*sizeof(float);
if(subtractedYReslicedBuffer)
{
free(subtractedYReslicedBuffer);
subtractedYReslicedBuffer = nil;
}
subtractedYReslicedBuffer = malloc(byteCount);
memcpy(subtractedYReslicedBuffer,buffer,byteCount);
if(resample)
{
resampledBuffer = malloc(byteCount*16);
[self resampleBuffer:subtractedYReslicedBuffer withWidth:width height:height factor:4.0 inNewBuffer:resampledBuffer];
[self applyShiftX:yShift y:zShift toBuffer:resampledBuffer withWidth:width*4 height:height*4];
[self resampleBuffer:resampledBuffer withWidth:width*4 height:height*4 factor:0.25 inNewBuffer:subtractedYReslicedBuffer];
free(resampledBuffer);
}
else
{
[self applyShiftX:yShift/4 y:zShift/4 toBuffer:subtractedYReslicedBuffer withWidth:width height:height];
}
//newSagitalPix = [[[DCMPix alloc] initWithData :subtractedYReslicedBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]] autorelease];
newSagitalPix = [[DCMPix alloc] initWithData :subtractedYReslicedBuffer :32 :width :height :pixelSpacingX :pixelSpacingY :[curPix originX] :[curPix originY] :[curPix originZ]];
[LLSubtraction subtractDCMPix:[[[controller yReslicedView] dcmPixList] objectAtIndex:i] to:newSagitalPix minValueA:injectedMinValue maxValueA:injectedMaxValue minValueB:notInjectedMinValue maxValueB:notInjectedMaxValue minValueSubtraction:subtractionMinValue maxValueSubtraction:subtractionMaxValue displayBones:displayBones bonesThreshold:bonesThreshold];// subtraction
// [LLSubtraction dilate:[newSagitalPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius];
// [LLSubtraction close:[newSagitalPix fImage] withWidth:width height:height structuringElementRadius:closingRadius];
BOOL resampleMorph = ((closingRadius-1)%MORPH_RESAMPLE != 0) || ((dilatationRadius-1)%MORPH_RESAMPLE != 0);
// resampleMorph = YES;
if(resampleMorph)
{
resampledBuffer = malloc(byteCount*MORPH_RESAMPLE*MORPH_RESAMPLE);
[self resampleBuffer:[newSagitalPix fImage] withWidth:width height:height factor:MORPH_RESAMPLE*1.0 inNewBuffer:resampledBuffer];
// if(dilatationRadius>1)
[LLSubtraction dilate:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:dilatationRadius];
// if(closingRadius>1)
[LLSubtraction close:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE structuringElementRadius:closingRadius];
[self resampleBuffer:resampledBuffer withWidth:width*MORPH_RESAMPLE height:height*MORPH_RESAMPLE factor:1.0/MORPH_RESAMPLE inNewBuffer:[newSagitalPix fImage]];
free(resampledBuffer);
}
else
{
if(dilatationRadius>1)
[LLSubtraction dilate:[newSagitalPix fImage] withWidth:width height:height structuringElementRadius:dilatationRadius/MORPH_RESAMPLE+1];
if(closingRadius>1)
[LLSubtraction close:[newSagitalPix fImage] withWidth:width height:height structuringElementRadius:closingRadius/MORPH_RESAMPLE+1];
}
if(lowPassFilterSize>1)
[LLSubtraction lowPassFilterOnBuffer:[newSagitalPix fImage] withWidth:width height:height structuringElementSize:lowPassFilterSize];
if(applyConvolution)
[LLSubtraction convolveBuffer:[newSagitalPix fImage] withWidth:width height:height withKernel:convolutionKernel kernelSize:5];
//[LLSubtraction removeSmallConnectedPartDCMPix:newSagitalPix];
[sagitalPixList addObject:newSagitalPix];
[newSagitalPix release];
}
//[tempPool release];
[subtractedYReslicedView setPixels:sagitalPixList files:nil rois:nil firstImage:[[injectedMPRController yReslicedView] curImage] level:'i' reset:NO];
for( i = 0; i < [sagitalPixList count]; i++)
{
[[sagitalPixList objectAtIndex: i] setArrayPix: sagitalPixList :i];
}
[subtractedYReslicedView setFusion:thickSlabMode :[(LLMPRView*)[injectedMPRController yReslicedView] thickSlabX]];
fValue = [[controller yReslicedView] scaleValue] / [[controller yReslicedView] pixelSpacing];
[subtractedYReslicedView setScaleValue: fValue * [subtractedYReslicedView pixelSpacing]];
[subtractedYReslicedView setRotation: [[controller yReslicedView] rotation]];
[subtractedYReslicedView setOrigin: [[controller yReslicedView] origin]];
//[sagitalPixList release];
// [newSagitalPix release];
float iwl, iww;
[[injectedMPRController originalView] getWLWW:&iwl :&iww];
[subtractedOriginalView discretelySetWLWW: iwl : iww];
[subtractedXReslicedView discretelySetWLWW: iwl : iww];
[subtractedYReslicedView discretelySetWLWW: iwl : iww];
}
#pragma mark-
#pragma mark Thick Slab
- (IBAction)setThickSlabMode:(id)sender;
{
[self _setThickSlabMode:[[sender selectedItem] tag]];
}
- (void)_setThickSlabMode:(int)mode;
{
thickSlabMode = mode;
if(mode==0)
{
[thickSlabSlider setIntValue:0];
[thickSlabTextField setIntValue:2];
[thickSlabSlider setEnabled:NO];
thickSlab = [thickSlabSlider intValue];
[injectedMPRController setThickSlab:0];
[controller setThickSlab:0];
}
else
{
thickSlab = [thickSlabSlider intValue];
[injectedMPRController setThickSlab: [thickSlabSlider intValue]];
[controller setThickSlab: [thickSlabSlider intValue]];
[thickSlabSlider setEnabled:YES];
}
[injectedMPRController setThickSlabMode : mode];
[controller setThickSlabMode : mode];
[thickSlabModePopUp selectItemWithTag:mode];
[self refreshSubtractedViews];
}
- (IBAction)setThickSlab:(id)sender;
{
[injectedMPRController setThickSlab:[sender intValue]];
[super setThickSlab: sender];
thickSlab = [sender intValue];
[self refreshSubtractedViews];
}
#pragma mark-
#pragma mark NSToolbar Related Methods
- (void) setupToolbar {
// Create a new toolbar instance, and attach it to our document window
toolbar = [[NSToolbar alloc] initWithIdentifier: LLMPRToolbarIdentifier];
// Set up toolbar properties: Allow customization, give a default display mode, and remember state in user defaults
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
// We are the delegate
[toolbar setDelegate: self];
// Attach the toolbar to the document window
[[self window] setToolbar: toolbar];
[[self window] setShowsToolbarButton: YES];
[[[self window] toolbar] setVisible: YES];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
// Required delegate method: Returns the ordered list of items to be shown in the toolbar by default
// If during the toolbar's initialization, no overriding values are found in the user defaults, or if the
// user chooses to revert to the default items this set will be used
return [NSArray arrayWithObjects: ToolsToolbarItemIdentifier,
WLWWToolbarItemIdentifier,
Produce2DResultToolbarItemIdentifier,
Produce3DResultToolbarItemIdentifier,
nil];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
// Required delegate method: Returns the list of all allowed items by identifier. By default, the toolbar
// does not assume any items are allowed, even the separator. So, every allowed item must be explicitly listed
// The set of allowed items is used to construct the customization palette
return [NSArray arrayWithObjects: NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
WLWWToolbarItemIdentifier,
ToolsToolbarItemIdentifier,
ThickSlabToolbarItemIdentifier,
Produce2DResultToolbarItemIdentifier,
Produce3DResultToolbarItemIdentifier,
ParameterPanelToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted
{
// Required delegate method: Given an item identifier, this method returns an item
// The toolbar will use this method to obtain toolbar items that can be displayed in the customization sheet, or in the toolbar itself
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
if([itemIdent isEqualToString: ToolsToolbarItemIdentifier])
{
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"Mouse button function",nil)];
[toolbarItem setPaletteLabel: NSLocalizedString(@"Mouse button function",nil)];
[toolbarItem setToolTip:NSLocalizedString( @"Change the mouse function",nil)];
// Use a custom view, a text field, for the search item
[toolbarItem setView: toolsView];
[toolbarItem setMinSize:NSMakeSize(NSWidth([toolsView frame]), NSHeight([toolsView frame]))];
[toolbarItem setMaxSize:NSMakeSize(NSWidth([toolsView frame]), NSHeight([toolsView frame]))];
}
else if([itemIdent isEqualToString: WLWWToolbarItemIdentifier])
{
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"WL/WW & CLUT", nil)];
[toolbarItem setPaletteLabel: NSLocalizedString(@"WL/WW & CLUT", nil)];
[toolbarItem setToolTip: NSLocalizedString(@"Modify WL/WW & CLUT", nil)];
// Use a custom view, a text field, for the search item
[toolbarItem setView: WLWWView];
[toolbarItem setMinSize:NSMakeSize(NSWidth([WLWWView frame]), NSHeight([WLWWView frame]))];
[toolbarItem setMaxSize:NSMakeSize(NSWidth([WLWWView frame]), NSHeight([WLWWView frame]))];
[[wlwwPopup cell] setUsesItemFromMenu:YES];
}
else if([itemIdent isEqualToString: ThickSlabToolbarItemIdentifier]) {
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"Thick Slab", @"Thick Slab")];
[toolbarItem setPaletteLabel: NSLocalizedString(@"Thick Slab", @"Thick Slab")];
// Use a custom view, a text field, for the search item
[toolbarItem setView: ThickSlabView];
// [toolbarItem setMinSize:NSMakeSize(NSWidth([ThickSlabView frame]), NSHeight([ThickSlabView frame]))];
[toolbarItem setMinSize:NSMakeSize(NSWidth([ThickSlabView frame]) + 200, NSHeight([ThickSlabView frame]))];
}
else if([itemIdent isEqualToString: Produce2DResultToolbarItemIdentifier]) {
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"2D Result", nil)];
[toolbarItem setPaletteLabel: NSLocalizedString(@"2D Result", nil)];
[toolbarItem setToolTip: NSLocalizedString(@"2D Result",nil)];
[toolbarItem setImage: [NSImage imageNamed: Produce2DResultToolbarItemIdentifier]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(produceResultInMemory:)];
}
else if([itemIdent isEqualToString: Produce3DResultToolbarItemIdentifier]) {
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"3D Result", nil)];
[toolbarItem setPaletteLabel: NSLocalizedString(@"3D Result", nil)];
[toolbarItem setToolTip: NSLocalizedString(@"3D Result",nil)];
[toolbarItem setImage: [NSImage imageNamed: Produce3DResultToolbarItemIdentifier]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(produce3DResult:)];
}
else if([itemIdent isEqualToString: ParameterPanelToolbarItemIdentifier]) {
// Set up the standard properties
[toolbarItem setLabel: NSLocalizedString(@"Parameters", nil)];
[toolbarItem setPaletteLabel: NSLocalizedString(@"Parameters", nil)];
[toolbarItem setToolTip: NSLocalizedString(@"Parameters",nil)];
[toolbarItem setImage: [NSImage imageNamed: ParameterPanelToolbarItemIdentifier]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(showParametersPanel:)];
}
else
{
[toolbarItem release];
toolbarItem = nil;
}
return [toolbarItem autorelease];
}
- (void) setWLWW:(float) iwl :(float) iww
{
[super setWLWW:iwl :iww];
[injectedMPRController setWLWW: iwl : iww];
[injectedMPRController setCurWLWWMenu:curWLWWMenu];
// curWLWWMenu = NSLocalizedString(@"Other", nil);
}
-(void) windowDidBecomeKey:(NSNotification *)aNotification
{
// [[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateCLUTMenuNotification object: curCLUTMenu userInfo: nil];
[[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateWLWWMenuNotification object: curWLWWMenu userInfo: nil];
//[[NSNotificationCenter defaultCenter] postNotificationName: OsirixUpdateConvolutionMenuNotification object: curConvMenu userInfo: nil];
//[self refreshSubtractedViews];
}
#pragma mark-
#pragma mark Shift
- (int)xShift { return xShift; }
- (int)yShift { return yShift; }
- (int)zShift { return zShift; }
- (void)shiftSubtractionX:(int)deltaX y:(int)deltaY z:(int)deltaZ;
{
xShift += deltaX;
yShift += deltaY;
zShift += deltaZ;
//NSLog(@"shiftSubtractionX : %d, %d, %d", xShift, yShift, zShift);
[xShiftTextField setIntValue:xShift];
[yShiftTextField setIntValue:yShift];
[zShiftTextField setIntValue:zShift];
}
- (IBAction)resetShift:(id)sender;
{
[self resetShift];
[self refreshSubtractedViews];
}
- (void)resetShift;
{
xShift = 0;
yShift = 0;
zShift = 0;
[xShiftTextField setIntValue:0];
[yShiftTextField setIntValue:0];
[zShiftTextField setIntValue:0];
}
- (void)applyShiftX:(int)x y:(int)y toBuffer:(float*)buffer withWidth:(int)width height:(int)height;
{
if(x==0 && y==0) return;
float *tempBuffer = malloc(width*height*sizeof(float));
if(tempBuffer)
{
int i,j;
// shift Y
if(y > 0)
{
for(i=0; i<y*width; i++)
{
tempBuffer[i] = -1000;
}
memcpy(tempBuffer+y*width, buffer, (height-y)*width*sizeof(float));
memcpy(buffer, tempBuffer, height*width*sizeof(float));
}
else if (y < 0)
{
memcpy(tempBuffer, buffer-y*width, (height+y)*width*sizeof(float));
for(i=(height+y)*width; i<height*width; i++)
{
tempBuffer[i] = -1000;
}
memcpy(buffer, tempBuffer, height*width*sizeof(float));
}
// shift X
if(x > 0)
{
for(i=0; i<height; i++)
{
for(j=0; j<x; j++)
tempBuffer[i*width+j] = -1000;
memcpy(tempBuffer+i*width+x, buffer+i*width, (width-x)*sizeof(float));
}
}
else if(x < 0)
{
for(i=0; i<height; i++)
{
memcpy(tempBuffer+i*width, buffer+i*width-x, (width+x)*sizeof(float));
for(j=width+x; j<width; j++)
tempBuffer[i*width+j] = -1000;
}
}