-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsegment_main.m
4118 lines (3560 loc) · 112 KB
/
segment_main.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
function varargout = segment_main(varargin)
% SEGMENT_MAIN Main file for cardiac image analysis software
% Einar Heiberg
% Revision history
% Written by Einar Heiberg, spring/autumn 2002.
% Continously improved ever since 2002-2016.
% The documentation and version history is found in the file changelog.m
%%%%%%%%%%%%%%%%%%
%%%% Main body %%%
fileinput = false;
if nargin > 0
%Check if input appears to be a filename
if regexp(varargin{1}, '^[c-zC-Z]:\\')
fileinput = true;
end
end
if nargin == 0 || fileinput % LAUNCH and initalize GUI
%Check if os is supported
arch = mexext();
switch arch
case {'mexglx','mexmaci'}
myfailed('Your platform is not supported. Supported platforms are Windows and Linux 64 bit.');
return;
case {'mexmaci64', 'mexa64'}
mywarning('This platform is not officially supported. Bugs and errors may occur.')
end
if not(isdeployed())
%source code version, check matlab version
try
matlabversion = ver;
[toolboxindex] = find(ismember({matlabversion.Name},'MATLAB'));
if isempty(toolboxindex), toolboxindex=1; end
if not(strcmp(matlabversion(toolboxindex).Release,'(R2019a)'))
myfailed(sprintf('Recommended Matlab version for Segment is R2019a.\nPlease use this version for best performance of Segment.\nVersions prior to Matlab 2015a will NOT work for this version of Segment.'));
end
catch
end
end
programversion = changelog;
fig = initializesegment(programversion); %Program version number
try
compilerpragmas;
catch
end
varargout = cell(1,nargout);
if nargout>0
varargout{1} = fig;
end
% Load the mat file
if fileinput
openfile('loadfiles', {varargin{1}}, false, []); %#ok<CCAT1>
end
else
%%%% main clause %%%
macro_helper(varargin{:}); %future macro recording use
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
end
%%%%%%%%%%%%%%%
%-----------------------------------------------
function fig = initializesegment(programversion)
%-----------------------------------------------
%Initialization of Segment GUI
global DATA
if isa(DATA,'maingui')
try
disp('Already running.');
if ~isempty(DATA.fig)
figure(DATA.fig);
fig = DATA.fig;
return;
else
fig = [];
end
catch me
disp('Program not aborted properly last time, all data will be lost and program restarted.');
mydispexception(me);
end
end
%--- Find source
if isdeployed()
%Compiled version
disp('Standalone');
else
%Check if platform is supported.
ext = mexext;
all = mexext('all');
arch = '';
for loop = 1:length(all)
if isequal(ext,all(loop).ext)
arch = all(loop).arch;
end
end
switch arch
case {'mac','sol64','glnx86'}
myfailed('Platform is currently not supported. Mex-files are missing.');
return;
otherwise
disp(['Running from Matlab on platform ' arch '.']);
end
%Do nothing
end
%Make sure fresh start
DATA = []; %#ok<NASGU>
SET = []; %#ok<NASGU>
%This is where we create object
DATA = segmentgui(programversion);%Load standard Segment GUI
DATA.GUISettings.ShowColorbar = false; %until the colorbar is impelemented
% Register where segment.m is located and if we are running from source
if isdeployed()
[status, result] = system('set PATH');
pathname = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
DATA.SegmentFolder=pathname;
cd(pathname);
else
[segmentfolder_, ~, ~] = fileparts(which('segment'));
DATA.SegmentFolder = segmentfolder_;
clear segmentfolder_
end
DATA.init;
try
fig = DATA.fig;
catch
disp('Software initialization aborted')
fig = [];
return
end
checkpath(DATA.SegmentFolder); %ensure running on correct path
%---------------------
function resetpreview %#ok<DEFNU>
%---------------------
%Reset preview structure in DATA.Preview
global DATA;
DATA.Preview = genemptypreview(DATA.Pref.datapath);
%---------------------------------
function preview = genemptypreview(datapath)
%---------------------------------
%Generate an empty preview struct
global DATA
roisize = 150;
try %inside try catch if DATA is not set.
if isempty(DATA.Preview) || isempty(DATA.Preview.ROISize)
roisize = 'full'; %150;
else
roisize = DATA.Preview.ROISize;
end
catch
end
preview = [];
preview.PathName = datapath;
preview.SelectType = 'AUTO';
preview.SliceThickness = 0;
preview.SliceGap = 0;
preview.ResolutionX = 0;
preview.ResolutionY = 0;
preview.TIncr = 0; %s
preview.TimeVector = 0;
preview.TDelay = 0; %for future use to shift datasets in time
preview.EchoTime = 0;
preview.RepetitionTime = 0;
preview.InversionTime = 0;
preview.FlipAngle = 0;
preview.AccessionNumber = '';
preview.StudyUID = '';
preview.StudyID = '';
preview.NumberOfAverages = 0;
preview.VENC = 0;
preview.GEVENCSCALE = 0;
preview.ImagingTechnique = 'MRSSFP';
preview.ImageType = 'General';
preview.ImageViewPlane = 'Unspecified';
preview.ImagePosition = [0 0 0];
preview.ImageOrientation = [1 0 0 0 1 0];
preview.MultiDataSet = false;
preview.Modality = 'MR';
preview.ItemsSelected = 0;
preview.Cyclic = true;
preview.Rotated = false;
preview.ROISize = roisize;
preview.XMin = 1;
preview.YMin = 1;
preview.XSize = 1;
preview.YSize = 1;
preview.PreviewFile = '';
preview.Stable = false;
preview.Scanner = '';
preview.NoNormalize = false;
preview.NSlices = 1; %Number of Slices per DICOM image.
preview.NFrames = 1; %Number of Frames per DICOM image.
preview.NumSlices = 1; %Number of Slices in final image stack
preview.NumFrames = 1; %Number of Frames in final image stack
preview.VENCDirSkipped = 0;
preview.FileType = '';
preview.Silent = false;
preview.SequenceName = ''; % JU comment:
preview.SeriesDescription = ''; % new since merge
preview.AcquisitionTime = ''; % added by JS
preview.SeriesNumber = ''; % new since merge
preview.DICOMImageType = ''; % new since merge
preview.LoadAll=false; % new since merge
%-----------------
function initmenu %#ok<DEFNU>
%-----------------
%Initalize the main menu, for instance adds extra utilities, and plugins.
global DATA
%--- Initialize utilities
utility('init');
%--- Initialize plug-ins
try
load('plugins.mat');
catch %#ok<CTCH>
disp('Could not read plugin file.');
pluginfiles = {};
end
if isdeployed()
if ~exist('pluginfiles','var')
myfailed('Problems reading file containing plugins.');
return;
end
else
%Use filenames
f = dir([DATA.SegmentFolder filesep 'plugin_*.m']);
pluginfiles = cell(1,length(f));
for loop=1:length(f)
pluginfiles{loop} = f(loop).name;
end
end
%Initialize menus
for loop=1:length(pluginfiles)
stri = pluginfiles{loop};
stri = stri(1:(end-2)); %Remove .m
handle = uimenu(DATA.Handles.pluginmenu,...
'Label','temp',...
'Callback','');
namestri = feval(stri,'getname',handle);
set(handle,'Label',namestri);
end
%--------------------------------
function singleframemode_Callback %#ok<DEFNU>
%--------------------------------
%define if single (one) or all frames mode
global DATA
DATA.ThisFrameOnly = not(DATA.Handles.configiconholder.findindented('selectoneall'));
%--------------------------
function cinetool_Callback %#ok<DEFNU>
%--------------------------
%Starts the cinetool that allows simultanues segmentation at the
%same time as it plays.
global DATA SET NO
if SET(NO).TSize==1
try %icon might be there and might not
stateandicon=viewfunctions('iconson','cineplay');
stateandicon{2}.isindented=0;
stateandicon{2}.cdataDisplay=stateandicon{2}.cdata;
DATA.Handles.configiconholder.render
catch
end
myfailed('Need a timeresolved image stack.')
return;
end
if isa(DATA.CineTimer,'timer')
cinewindow('update','kill');
try %icon might be there and might not
stateandicon=viewfunctions('iconson','cineplay');
stateandicon{2}.isindented=0;
stateandicon{2}.cdataDisplay=stateandicon{2}.cdata;
DATA.Handles.configiconholder.render
catch
end
else
try %icon might be there and might not
stateandicon=viewfunctions('iconson','cineplay');
stateandicon{2}.isindented=1;
stateandicon{2}.cdataDisplay=stateandicon{2}.cdataIndent;
DATA.Handles.configiconholder.render
catch
end
cinewindow;
end
%----------------------------
function addtopanels(no,mode) %#ok<DEFNU>
%----------------------------
%Finds an open space, otherwise increases number of panels
global DATA SET
%---Find out what view mode to take
if nargin<2
if not(isempty(SET(no).Flow))
mode = 'one';
elseif not(isempty(SET(no).Scar))
mode = 'montage';
elseif (SET(no).ZSize>1)&&(SET(no).ZSize<21)&&(SET(no).XSize*SET(no).YSize<1e4)
mode = 'montage';
else
mode = 'one';
end
end
%--- if space exists then add it
temp = find(DATA.ViewPanels==0);
if ~isempty(temp)
DATA.ViewPanels(temp(1)) = no;
DATA.ViewPanelsType{temp(1)} = mode;
DATA.ViewIM{temp(1)} = [];
return;
end
%--- if space does not exist then add
DATA.ViewPanels = [DATA.ViewPanels no];
DATA.ViewPanelsType = cat(2,DATA.ViewPanelsType,{mode});
[rows,cols] = calcfunctions('calcrowscols',no,SET(no).ZSize);
DATA.ViewPanelsMatrix = [DATA.ViewPanelsMatrix {[rows cols]}];
DATA.ViewIM{length(DATA.ViewPanels)} = [];
%---------------------------
function mainresize_Callback %#ok<DEFNU>
%---------------------------
%This fcn is called when user resizes GUI
global DATA
if isempty(DATA)
%This prevents validate callbacks from reporting error when opening
%segment.fig for inspection.
return;
end
try
if isfield(DATA.GUI,'Segment')
if not(isempty(DATA.GUI.Segment))
saveguiposition(DATA.GUI.Segment)
end
end
catch me
disp('Could not do mainresize');
mydispexception(me);
end
try
figunits=get(DATA.fig,'units');
set(DATA.fig,'units','pixels');
pfig = get(DATA.fig,'position');
set(DATA.fig,'units',figunits);
panelunits = get(DATA.Handles.reportpanel,'units');
set(DATA.Handles.reportpanel,'units','pixels');
p = get(DATA.Handles.reportpanel,'position');
rpwidth=round(min(DATA.GUISettings.ReportPanelPixelMax,pfig(3)*DATA.GUISettings.RightGapWidth)); %0.21DATA.GUISettings.RightGapWidth));
set(DATA.Handles.reportpanel,'position',[...
pfig(3)-rpwidth ...
p(2) ...
rpwidth ...
p(4)]);
set(DATA.Handles.reportpanel,'units',panelunits);
if any(strcmp(DATA.ProgramName,{'Segment 3DPrint'}))
panelunits = get(DATA.Handles.printuipanel,'units');
set(DATA.Handles.printuipanel,'units','pixels');
rpwidth=round(pfig(3)*DATA.GUISettings.RightGapWidth); %0.21DATA.GUISettings.RightGapWidth));
set(DATA.Handles.printuipanel,'position',[...
pfig(3)-rpwidth ...
p(2) ...
rpwidth ...
p(4)]);
set(DATA.Handles.printuipanel,'units',panelunits)
if ~isempty(DATA.Handles.iconholder2.cdata)
DATA.Handles.iconholder2.render
end
if ~isempty(DATA.Handles.iconholder3.cdata)
DATA.Handles.iconholder3.render
end
if ~isempty(DATA.Handles.iconholder4.cdata)
DATA.Handles.iconholder4.render
end
end
DATA.GUISettings.RightGapWidth = rpwidth/pfig(3);
%Render iconplaceholders aswell
DATA.Handles.toggleiconholder.render
if not(contains(DATA.ProgramName,'3D'))
DATA.Handles.permanenticonholder.render
if ~isempty(DATA.Handles.hideiconholder.cdata)
DATA.Handles.hideiconholder.render
end
end
if ~isempty(DATA.Handles.configiconholder.cdata)
DATA.Handles.configiconholder.render
end
try
if ~isempty(DATA.ViewMatrix)
rows=DATA.ViewMatrix(1);
cols=DATA.ViewMatrix(2);
if length(DATA.ViewPanelsType) == 4 && all(strcmp(DATA.ViewPanelsType, {'orth', 'hla', 'vla', 'gla'}))
viewfunctions('setview',rows,cols,DATA.ViewPanels,DATA.ViewPanelsType);
else
viewfunctions('setview',rows,cols); %drawfunctions('drawall',rows,cols);
end
end
catch me
mydispexception(me)
DATA.Handles.toggleiconholder.render
DATA.Handles.permanenticonholder.render
if ~isempty(DATA.Handles.configiconholder.cdata)
DATA.Handles.configiconholder.render
end
end
catch me
if ~isempty(DATA.fig)
%Mainresize is called uponloading when .fig is not initialized.
disp('Could not do mainresize');
mydispexception(me);
end
end
%---------------------------------
function renderstacksfromdicom(no) %#ok<DEFNU>
%---------------------------------
%Render image stacks in main gui. This function is typically called upon
%loading.
%Do not mess with .Silent here since it will be taken care of by lower
%routine images.
%New routine doesnt need this function perhaps
global DATA SET
if ~DATA.Silent
%This is an ugly hack to have PC data load two-panel.
if isempty(DATA.ViewPanels)
if (length(SET)==2)
DATA.ViewMatrix=[1 2];
DATA.ViewPanels=[1 2];
if (SET(no).ZSize==1)
DATA.ViewPanelsType{1} = 'one';
DATA.ViewPanelsType{2} = 'one';
else
DATA.ViewPanelsType{1} = DATA.GUISettings.ViewPanelsTypeDefault;
DATA.ViewPanelsType{2} = DATA.GUISettings.ViewPanelsTypeDefault;
end
[rows1,cols1] = calcfunctions('calcrowscols',1,SET(1).ZSize);
[rows2,cols2] = calcfunctions('calcrowscols',2,SET(2).ZSize);
DATA.ViewPanelsMatrix = {[cols1 rows1] [cols2 rows2]};
else
DATA.ViewPanels=1;
if (SET(no).ZSize==1)
DATA.ViewPanelsType{1} = 'one';
else
DATA.ViewPanelsType{1} = DATA.GUISettings.ViewPanelsTypeDefault;
end
if strcmp(DATA.ViewPanelsType,'montage')
[rows,cols] = calcfunctions('calcrowscols',1,SET(1).ZSize);
else
rows = 1;
cols = 1;
end
DATA.ViewPanelsMatrix = {[cols rows]};
DATA.ViewMatrix=[1 1];
end
end
% if (~DATA.Preview.Silent)
% %Normal loading
%
% %DATA.switchtoimagestack(no,true); %force
% %drawfunctions('drawthumbnails',isempty(DATA.DATASETPREVIEW));
%
% %The refresh starts everything
% %viewfunctions('setview',DATA.ViewMatrix(1),DATA.ViewMatrix(2))
% end;
end
disp('Files loaded.');
%endoffcalculation;
%----------------------------
function update_thumbnail(nos)
%----------------------------
%This fcn updates thumbnail no
global DATA SET
%if DATA.Silent
% return
%end
%Check if empty DATASETPREVIEW and generate if so.
if isempty(DATA.DATASETPREVIEW)
calcfunctions('calcdatasetpreview');
end
for loop = 1:length(nos)
no = nos(loop);
%Remap
if isempty(SET(no).Colormap)
tempim = calcfunctions('remapuint8',...
SET(no).IM(:,:,round(SET(no).TSize/2),round(SET(no).ZSize/2)),...
no,calcfunctions('returnmapping',no,true));
else
tempim = calcfunctions('remapuint8',...
SET(no).IM(:,:,round(SET(no).TSize/2),round(SET(no).ZSize/2)),...
no);
end
% zero padding, elegantly done, no? :) /JU
sz=size(tempim);
tempim=padarray(tempim,round((length(tempim)-sz(1:2))/2));
tempim = imresize(tempim,DATA.GUISettings.ThumbnailSize*[1 1],'bilinear');
%Store, vertically
DATA.DATASETPREVIEW((no-1)*DATA.GUISettings.ThumbnailSize+(1:DATA.GUISettings.ThumbnailSize),:,:) = tempim;
end
if ~DATA.Silent
set(DATA.Handles.datasetpreviewimage,'cdata',DATA.DATASETPREVIEW);
end
%---------------------------
function out=thumbnailno(in)
%---------------------------
%Helper fcn to remember what image stack were clicked.
persistent no
if nargin==1
no = in;
end
out = no;
%-----------------------------
function thumbnail_Buttondown %#ok<DEFNU>
%-----------------------------
%Buttondown fcn for thumbnails.
global DATA
thumbsize=DATA.GUISettings.ThumbnailSize;
switch get(DATA.fig,'SelectionType')
case {'extend','normal'}
%--- Prepare to drag the thumbnail
%Set up
set(DATA.fig,'WindowButtonUpFcn',...
'segment(''thumbnail_Buttonup'')');
set(DATA.fig,'WindowButtonMotionFcn',...
'segment(''thumbnail_Motion'')');
%Get clicked position
[x,y] = mygetcurrentpoint(DATA.Handles.datasetaxes);
%Find clicked image stack
no = getclickedpreview(x,y);
thumbnailno(no); %store
%Create axes
temp = get(DATA.imagefig,'unit');
set(DATA.imagefig,'unit','pixels');
try
delete(DATA.Handles.thumbnaildragaxes);
catch %#ok<CTCH>
end
%then we want the fig position
[x,y] = mygetcurrentpoint(DATA.fig);
DATA.Handles.thumbnaildragaxes = axes(...
'unit','pixels',...
'position',...
[x-32 y-32 64 64],...
'parent',DATA.imagefig);
set(DATA.imagefig,'unit',temp);
%Draw image
try
delete(DATA.Handles.thumbnailimage);
catch %#ok<CTCH>
end
DATA.Handles.thumbnailimage=imagesc(...
DATA.DATASETPREVIEW(thumbsize*(no-1)+(1:thumbsize),:,:),...
'parent',DATA.Handles.thumbnaildragaxes);
axis(DATA.Handles.thumbnaildragaxes,'off');
case 'alt'
%---Right mouse click
%Get clicked coordinate
%Set up
set(DATA.fig,'WindowButtonUpFcn',...
'segment(''thumbnail_Buttonup'')');
%Get clicked position
[x,y] = mygetcurrentpoint(DATA.Handles.datasetaxes);
%Find clicked image stack
no = getclickedpreview(x,y);
thumbnailno(no); %store
%add no in DATA.lastobject field so that it can be loaded into panels
%if user clicks this
DATA.LastObject = no;
%Bring up popup menu
[p(1),p(2)] = mygetcurrentpoint(DATA.fig);
set(DATA.Handles.datasetpreviewmenu,...
'Position',p,...
'Visible','on');
end
%------------------------
function thumbnail_Motion %#ok<DEFNU>
%------------------------
%Motion fcn for thumbnails.
global DATA
%Get coordinate
[x,y] = mygetcurrentpoint(DATA.imagefig);
set(DATA.Handles.thumbnaildragaxes,'position',...
[x-32 y-32 64 64]);
%--------------------------
function thumbnail_Buttonup %#ok<DEFNU>
%--------------------------
%Buttonup fcn for thumbnails.
global DATA NO
%Get coordinate
[x,y] = mygetcurrentpoint(DATA.Handles.boxaxes);
if nargin==1
x=-1;
end
%Restore motion etc
set(DATA.fig,'WindowButtonMotionFcn',@DATA.toggleplaceholdermotion);
set(DATA.fig,'WindowButtonUpFcn','buttonupfunctions(''buttonup_Callback'')');
%Hide the image
try
delete(DATA.Handles.thumbnaildragaxes);
delete(DATA.Handles.thumbnailimage);
catch %#ok<CTCH>
end
%Retrieve what image stack chosen
no=thumbnailno;
% Only change panel im if pointer has moved out of the sidebar.
if (size(DATA.ViewPanels)==1)
ind=1;
elseif (x < 0)
allreadyout=find(DATA.ViewPanels==no);
if ~isempty(allreadyout)
viewfunctions('switchpanel',allreadyout(1));
return;
end
ind = find(DATA.ViewPanels==0,1);
else
if strcmp(DATA.CurrentTheme,'3dp') %If in 3dp mode disperse the image according to current view.
DATA.LevelSet = [];
segment3dp.tools('check3dpfields');
segment3dp.tools('storetoobject');
oldno = NO;
NO = no;
ok = segment3dp.tools('init3DP',0,1);
if ~ok
NO = oldno;
end
segment3dp.tools('update3DP');
drawfunctions('drawthumbnailframes')
return
elseif strcmp(DATA.ViewPanelsType{1},'orth')
%then we switch to single view mode
viewfunctions('setview',1, 1, no,{'one'});
drawfunctions('drawthumbnailframes')
return
else
%Find at which image panel we drop it.
%dist = zeros(1,length(DATA.Handles.imageaxes));
dist=zeros(1,length(DATA.ViewPanels));
% for loop=1:length(DATA.Handles.imageaxes)
for loop=1:length(DATA.ViewPanels)
p = get(DATA.Handles.imageaxes(loop),'position');
p = p(1:2)+0.5*p(3:4); %Center position
dist(loop) = sqrt(sum(([x y]-p).^2)); %Euklidean distance
end
[~,ind] = min(dist);
ind=ind(1); %just in case equal distance..!
end
end
if ~isempty(ind)
viewfunctions('addno2panel',ind,no)
end
%--------------------------
function z = remap(im,cmap,c,b) %#ok<DEFNU>
%--------------------------
%Remap data according to cmap
global SET NO
if nargin<2
cmap = SET(NO).Colormap;
end
if nargin<4
c=SET(NO).IntensityMapping.Contrast;
b=SET(NO).IntensityMapping.Brightness;
end
if isempty(cmap)
z = im;
else
map = cmap(:,1);
switch class(im)
case 'double'
map = double(map);
outsize = size(im);
im=c*im(:)+(b-0.5);
z = map(max(min(round(im(:)*256),length(map)),1));
z = reshape(z,outsize);
case 'single'
% This is turned off because this is where calls from fusion.m are made,
% and it currently has it's own contrast/brightness settings, that have
% already been applied to colormap. Ideally, this would be reorganized so
% that even remap() accepted a local NO argument. /JU
% im=c*im+(b-0.5);
outsize = size(im);
if nargin > 3
im=single(c*im(:)+(b-0.5));
end
z = fastremap(im,single(map));
z = reshape(z,outsize);
end
end
%-------------------------
function updatemeasurement %#ok<DEFNU>
%-------------------------
%calculate measurement and graphically update
global DATA
DATA.updatemeasurementreport;
%updateplot
DATA.updatemeasurementaxes;
%----------------------------------
function updatevolume(lvsegchanged)
%----------------------------------
%Calc volume of segmentation and graphically update.
global DATA SET NO
if nargin < 1
lvsegchanged = false;
end
rotstring = '';
specstring = newline;
%Error check
if isempty(SET(NO).ImageViewPlane)
SET(NO).ImageViewPlane = 'Unspecified';
end
calcd = -1;
if ismember(SET(NO).ImageViewPlane,{'2CH','3CH','4CH'})
[calcd,usednos] = longaxistools('calcbiplanevolume');
% if all(isnan(SET(NO).LVV)) || ~ismember(NO,usednos)
% calcd = 0;
% end
for no = DATA.LVNO
calcfunctions('volume_helper',no);
end
%if current stack is a new contribution to a lax volume calculation in
%DATA.LVNO
%we need to add it to that
if any(ismember(usednos,DATA.LVNO))
LAX_group = findfunctions('findlaxset',1);
LAX_group = LAX_group(LAX_group~=0);
if ~isempty(LAX_group)
DATA.LVNO = LAX_group;
str = [];
for i = 1:length(LAX_group)
str = [str, num2str(LAX_group(i)),','];
end
str(end) = [];
if isfield(DATA.Handles,'lvstackpushbutton')
set(DATA.Handles.lvstackpushbutton,'String',sprintf('Stack #%s',str));
end
else
if isfield(DATA.Handles,'lvstackpushbutton')
set(DATA.Handles.lvstackpushbutton,'String',sprintf('Stack #%d',DATA.LVNO(1)));
end
end
end
end
if calcd == -1
calcfunctions('calcvolume',NO);
else
calcfunctions('volume_helper',NO);
end
% if calcd > 0
% for no = DATA.LVNO
% calcfunctions('volume_helper',no);
% end
% elseif calcd == -1
% calcfunctions('calcvolume',NO);
% else
% calcfunctions('volume_helper',NO);
% end
if DATA.Silent
return;
end
%update all reports
DATA.updatelvreport
DATA.updatervreport
% DATA.updateflowreport
%updateplot
DATA.updatevolumeaxes
%DATA.updatetimebaraxes
% if strcmp(DATA.ProgramName,'Segment')
% %update all reports
% DATA.updatelvreport
% DATA.updatervreport
% %DATA.updatemeasurementreport
%
% %updateplot
% DATA.updatevolumeaxes
% elseif DATA.LVNO == NO || DATA.RVNO == NO
% %update all reports
% DATA.updatelvreport
% DATA.updatervreport
% %DATA.updatemeasurementreport
%
% %updateplot
% DATA.updatevolumeaxes
% end
if lvsegchanged
if ismember('Strain from tagging',{SET.ImageType})
taggingno = find(strcmp('Strain from tagging',{SET.ImageType}));
if ismember(NO,taggingno) && ~isempty(SET(NO).StrainTagging)
SET(NO).StrainTagging.LVupdated = true;
end
for tno = taggingno
if ~isempty(SET(tno).StrainTagging) && isfield(SET(tno).StrainTagging,'cineno') && NO == SET(tno).StrainTagging.cineno
if isfield(SET(tno).StrainTagging,'importfromcine') && SET(tno).StrainTagging.importfromcine
SET(tno).StrainTagging.LVupdated = true;
end
end
end
end
end
%--------------------------------------
function [x,y,slice] = getclickedcoords
%--------------------------------------
%Find coordinates where the user last clicked. x & y are given in internal
%coordinate system, i.e the functions determines slice in montage view.
global DATA SET NO
%Extract coordinates clicked
[x,y] = mygetcurrentpoint(DATA.Handles.imageaxes(DATA.CurrentPanel));
panel = DATA.CurrentPanel;
type = DATA.ViewPanelsType{panel};
if any(strcmp(type,{'montage','montagerow','montagefit','sax3','montagesegmented'}))%ismember(type,{'montage','montagerow','montagefit','sax3','montagesegmented'})
%Find slice
col = 1+floor((x-0.5)/SET(NO).YSize);
row = 1+floor((y-0.5)/SET(NO).XSize);
slice = col+(row-1)*DATA.ViewPanelsMatrix{panel}(2);
%Special case for SAX3 view
if strcmp(type,'sax3') && slice > 0 && slice <= size(SET(NO).SAX3.slices,1)
slice = SET(NO).SAX3.slices(slice,SET(NO).CurrentTimeFrame);
elseif strcmp(type,'montagesegmented')
slicestoinclude = getmontagesegmentedslices(NO);
slice = slice + slicestoinclude(1)-1;
end
%Find coordinates within image
x = x-(col-1)*SET(NO).YSize;
y = y-(row-1)*SET(NO).XSize;
elseif strcmp(type,'hla')
slice = SET(NO).HLA.slice;
elseif strcmp(type,'vla')
slice = SET(NO).VLA.slice;
elseif strcmp(type,'gla')
slice = 0;
else
%set slice
slice = SET(NO).CurrentSlice;
end
%--------------------------------
function no=getclickedpreview(~,y)
%--------------------------------
%function which returns the clicked preview image
global DATA
if nargin==0
[~,y] = mygetcurrentpoint(DATA.Handles.datasetaxes);
end
no = floor(y/DATA.GUISettings.ThumbnailSize)+1;
%--------------------
function r = getfieldifcommon(SET, fname) %#ok<DEFNU>
%--------------------
%Helper function to filesavedicom_Callback
if numel(SET) == 0
r = [];
return
end
r = SET(1).(fname);
for n=2:numel(SET)
if not(isequalwithequalnans(r, SET(n).(fname)))
r = [];
return;
end
end
%----------------------------------------------------
function sameview = orientationcomparison(setindex1,setindex2)
%----------------------------------------------------
% Compares the SET.ImageOrientation between two SETs.
% Help function to updateparallelsets
%
% Return values:
% sameview : true if the orientations are parallel.
% Marten Larsson, June, 3, 2009