forked from justinblaber/ncorr_2D_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncorr_gui_viewplots.m
2803 lines (2438 loc) · 126 KB
/
ncorr_gui_viewplots.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 handles_gui = ncorr_gui_viewplots(reference,current,data_dic,type_plot,pos_parent,params_init)
% This is a GUI for viewing the displacement/strain plots.
%
% Inputs -----------------------------------------------------------------%
% reference - ncorr_class_img; used for displaying the background image.
% current - ncorr_class_img; used for displaying the background image.
% data_dic - struct; contains displacement and strain info. This is the
% main data structure used in Ncorr.
% type_plot - string; specifies whether plot is u, v, exx, exy, or eyy.
% pos_parent - integer array; this is the position of the parent figure
% which determines where to position this figure
% params_init - cell; {1} = num_cur, {2} = scalebarlength,
% {3} = if handle_scalebar is on, {4} = if handle_axes is on, {5} if
% Lagrangian or Eulerian, {6} if zoomed; {7} if panned. Used to
% coordinate with any existing open plots.
%
% Outputs ----------------------------------------------------------------%
% handles_gui - handles; these are the GUI handles which allow Ncorr to
% manage the closing and synchronization of the open plots
%
% Note that this function checks both roi_ref_formatted and
% roi_cur_formatted to make sure all ROIs are non-empty. This is a very
% unlikely scenario, but if it happens this function will display and error
% dialogue and return.
% Data ---------------------------------------------------------------%
% Get GUI handles
handles_gui = init_gui();
% Run c-tor
feval(ncorr_util_wrapcallbacktrycatch(@constructor,handles_gui.figure));
% Callbacks and functions --------------------------------------------%
function constructor()
% Check to make sure ROIs are full
roifull = true;
if (strcmp(type_plot,'u') || strcmp(type_plot,'v'))
field = 'displacements';
else
field = 'strains';
end
for i = 0:length(current)-1
if (data_dic.(field)(i+1).roi_ref_formatted.get_fullregions == 0 || ...
data_dic.(field)(i+1).roi_cur_formatted.get_fullregions == 0)
roifull = false;
break;
end
end
if (~roifull)
% One of the ROIs is empty, return; CloseRequestFcn is disabled,
% in gui_init(), so reenable it before closing.
set(handles_gui.figure,'CloseRequestFcn','closereq');
h_error = errordlg('Some data plots are empty, please rerun analysis.','Error','modal');
uiwait(h_error);
close(handles_gui.figure);
return;
end
% Set zoom and pan
handle_zoom = zoom(handles_gui.figure);
handle_pan = pan(handles_gui.figure);
% Initialize buffers -----------------------------------------%
if (isempty(params_init))
% Set num_cur - by default show last image in set
num_cur = length(current)-1;
% Set scalebar length - initialize to 3/4 the width of the
% reference image. This uses real units.
scalebarlength_prelim = (3/4)*reference.width*data_dic.dispinfo.pixtounits;
if (floor(scalebarlength_prelim) > 3)
% Use integer
scalebarlength = floor(scalebarlength_prelim);
else
% Use decimal
scalebarlength = scalebarlength_prelim;
end
% handle_scalebar checkbox
val_checkbox_scalebar = true;
% handle_axes checkbox
val_checkbox_axes = true;
% Lagrangian or Eulerian; 1 == Lagrangian
val_popupmenu = 1;
else
% Set num_cur
num_cur = params_init{1};
% Units and handle_scalebar buffer
scalebarlength = params_init{2};
% handle_scalebar checkbox
val_checkbox_scalebar = params_init{3};
% handle_axes checkbox
val_checkbox_axes = params_init{4};
% Lagrangian or Eulerian
val_popupmenu = params_init{5};
% Zoomed
if (params_init{6})
set(handle_zoom,'Enable','on');
end
% Panned
if (params_init{7})
set(handle_pan,'Enable','on');
end
end
% Transparency buffer
transparency_prelim = 0.75;
% Contour lines buffer
contourlines_prelim = 20;
max_contourlines = 100;
% Set slider buffer
slider_buffer = struct('lagrangian',{},'eulerian',{});
for i = 0:length(current)-1
% Set parameters
% Get the data vector corresponding to this plot
data_ref = get_data(type_plot,'lagrangian',i);
slider_buffer(i+1).lagrangian(1) = 0.5; % Initialize to half
slider_buffer(i+1).lagrangian(2) = 0.5; % Initialize to half
slider_buffer(i+1).lagrangian(3:7) = get_sliderparams(data_ref);
% Get the data vector corresponding to this plot
data_cur = get_data(type_plot,'eulerian',i);
slider_buffer(i+1).eulerian(1) = 0.5; % Initialize to half
slider_buffer(i+1).eulerian(2) = 0.5; % Initialize to half
slider_buffer(i+1).eulerian(3:7) = get_sliderparams(data_cur);
end
max_upperbound = 1e10;
min_lowerbound = -1e10;
max_scalebarlength = 1e10;
% Set data
setappdata(handles_gui.figure,'num_cur',num_cur);
setappdata(handles_gui.figure,'transparency_prelim',transparency_prelim);
setappdata(handles_gui.figure,'contourlines_prelim',contourlines_prelim);
setappdata(handles_gui.figure,'max_contourlines',max_contourlines);
setappdata(handles_gui.figure,'scalebarlength',scalebarlength);
setappdata(handles_gui.figure,'slider_buffer',slider_buffer);
setappdata(handles_gui.figure,'max_upperbound',max_upperbound);
setappdata(handles_gui.figure,'min_lowerbound',min_lowerbound);
setappdata(handles_gui.figure,'max_scalebarlength',max_scalebarlength);
setappdata(handles_gui.figure,'type_plot',type_plot); % Store this explicitly so type and other parameters can be deduced from 'friends'
setappdata(handles_gui.figure,'friends',[]); % This is used for modifying other viewplots; it stores their figure handles
setappdata(handles_gui.figure,'text_info',[]); % This is the text box that displays when the cursor is over the data plot
setappdata(handles_gui.figure,'val_checkbox_contour',false);
setappdata(handles_gui.figure,'val_checkbox_scalebar',val_checkbox_scalebar);
setappdata(handles_gui.figure,'val_checkbox_axes',val_checkbox_axes);
setappdata(handles_gui.figure,'val_checkbox_minmaxmarkers',false);
setappdata(handles_gui.figure,'val_popupmenu',val_popupmenu);
setappdata(handles_gui.figure,'handle_preview',[]);
setappdata(handles_gui.figure,'handle_scalebar',[]);
setappdata(handles_gui.figure,'handle_axes',[]);
setappdata(handles_gui.figure,'handle_colorbar',[]);
setappdata(handles_gui.figure,'handle_point_max',[]);
setappdata(handles_gui.figure,'handle_point_min',[]);
setappdata(handles_gui.figure,'handle_zoom',handle_zoom);
setappdata(handles_gui.figure,'handle_pan',handle_pan);
% Update - must send the GUI handles; this is because
% update_axes can be used to update other figure handles stored
% in 'friends'.
update_axes('set',handles_gui);
update_sidemenu(handles_gui);
% Set resize and hover function callbacks; This GUI is
% resizable and displays a data cursor when the cursor hovers
% over the data plot.
% Set resize function
set(handles_gui.figure,'ResizeFcn',ncorr_util_wrapcallbacktrycatch(@callback_resizefunction,handles_gui.figure));
% Set hover function
set(handles_gui.figure,'WindowButtonMotionFcn',ncorr_util_wrapcallbacktrycatch(@callback_moveplot,handles_gui.figure));
% Set Visible
set(handles_gui.figure,'Visible','on');
end
function callback_topmenu_save(hObject,eventdata,includeinfo) %#ok<INUSL>
% Get info
num_cur = getappdata(handles_gui.figure,'num_cur');
% Form save figure -----------------------------------------------%
handles_gui_savefig = form_savefig(num_cur,includeinfo,[]);
% Disable close function so figure isnt inadvertently closed.
set(handles_gui_savefig.figure,'CloseRequestFcn','');
% Set size(s) ----------------------------------------------------%
% gui_savesize is a local function with a GUI; it allows the user
% to modify the size of the image
[size_savefig,timedelay,outstate] = gui_savesize(handles_gui_savefig, ...
false, ...
get(handles_gui.figure,'OuterPosition')); %#ok<*ASGLU>
if (outstate == out.success)
% Save image -------------------------------------------------%
[filename,pathname] = uiputfile({'*.jpg';'*.png';'*.bmp';'*.tif'},'Save Image');
if (~isequal(filename,0) && ~isequal(pathname,0))
overwrite = true;
if (exist(fullfile(pathname,filename),'file'))
contbutton = questdlg('File already exists. Do you want to overwrite?','Continue Operation','Yes','No','No');
if strcmp(contbutton,'No')
overwrite = false;
end
end
if (overwrite)
% Get image ------------------------------------------%
img_printscreen = getframe(handles_gui_savefig.figure);
% Save the image
imwrite(img_printscreen.cdata,fullfile(pathname,filename));
end
end
end
% Exit -----------------------------------------------------------%
set(handles_gui_savefig.figure,'CloseRequestFcn','closereq');
close(handles_gui_savefig.figure);
end
function callback_topmenu_savegif(hObject,eventdata) %#ok<INUSD>
% Get data
val_popupmenu = getappdata(handles_gui.figure,'val_popupmenu');
% All current images must have the same size to use this feature
% with the eulerian description
size_cur = size(current(1).get_gs());
samesize_cur = true;
for i = 1:length(current)-1
if (~isequal(size_cur,[current(i+1).height current(i+1).width]))
samesize_cur = false;
break;
end
end
% Save image -----------------------------------------------------%
% Note val_popupmenu equals 1 for the lagrangian perspective, and 2
% for the eulerian perspective
if (val_popupmenu == 1 || (val_popupmenu == 2 && samesize_cur))
% Form initial save figure -----------------------------------%
handles_gui_savefig = form_savefig(0,0,[]);
% Disable close function so figure isnt inadvertently closed
set(handles_gui_savefig.figure,'CloseRequestFcn','');
% Set Size(s) ------------------------------------------------%
% gui_savesize is a local function with a GUI; it allows the user
% to modify the size of the image
[size_savefig,timedelay,outstate] = gui_savesize(handles_gui_savefig, ...
true, ...
get(handles_gui.figure,'OuterPosition'));
if (outstate == out.success)
[filename,pathname] = uiputfile({'*.gif'},'Save Image');
if (~isequal(filename,0) && ~isequal(pathname,0))
overwrite = true;
if (exist(fullfile(pathname,filename),'file'))
contbutton = questdlg('File already exists. Do you want to overwrite?','Continue Operation','Yes','No','No');
if strcmp(contbutton,'No')
overwrite = false;
end
end
if (overwrite)
% Save initial image -----------------------------%
img_printscreen = getframe(handles_gui_savefig.figure);
img_printscreen = frame2im(img_printscreen);
[imind,cm] = rgb2ind(img_printscreen,256);
% Save
imwrite(imind,cm,[pathname filename],'gif','Loopcount',inf);
% Cycle over other images to save
for i = 1:length(current)-1
% Close figure
set(handles_gui_savefig.figure,'CloseRequestFcn','closereq');
close(handles_gui_savefig.figure);
% Form updated save figure -------------------%
handles_gui_savefig = form_savefig(i,0,size_savefig);
% Disable close function for now
set(handles_gui_savefig.figure,'CloseRequestFcn','');
% Get image ----------------------------------%
img_printscreen = getframe(handles_gui_savefig.figure);
img_printscreen = frame2im(img_printscreen);
[imind,cm] = rgb2ind(img_printscreen,256);
% Append
if (i ~= length(current)-1)
imwrite(imind,cm,[pathname filename],'gif','WriteMode','append','DelayTime',timedelay);
else
% This is the last image, make the time
% delay longer so there's a pause at the
% end.
imwrite(imind,cm,[pathname filename],'gif','WriteMode','append','DelayTime',timedelay+0.5);
end
end
end
end
end
% Close last figure
set(handles_gui_savefig.figure,'CloseRequestFcn','closereq');
close(handles_gui_savefig.figure);
else
h_error = errordlg('All current images must have the same size to save gif with the Eulerian description.','Error','modal');
uiwait(h_error);
end
end
%---------------------------------------------------------------------%
% These functions can potentially modify other viewplots -------------%
%---------------------------------------------------------------------%
function callback_popupmenu(hObject,eventdata) %#ok<INUSD>
% Get data
friends = getappdata(handles_gui.figure,'friends');
val_popupmenu = get(handles_gui.popupmenu,'Value');
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'val_popupmenu',val_popupmenu);
% Update
update_axes('set',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
% Set data
setappdata(handles_gui.figure,'val_popupmenu',val_popupmenu);
% Update this plot
update_axes('set',handles_gui);
update_sidemenu(handles_gui);
end
function callback_checkbox_scalebar(hObject,eventdata) %#ok<INUSD>
% Get data
friends = getappdata(handles_gui.figure,'friends');
val_checkbox_scalebar = get(handles_gui.checkbox_scalebar,'Value');
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'val_checkbox_scalebar',val_checkbox_scalebar);
% Update
update_axes('update',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
% Set data
setappdata(handles_gui.figure,'val_checkbox_scalebar',val_checkbox_scalebar);
% Update this plot
update_axes('update',handles_gui);
update_sidemenu(handles_gui);
end
function callback_checkbox_axes(hObject,eventdata) %#ok<INUSD>
% Get data
friends = getappdata(handles_gui.figure,'friends');
val_checkbox_axes = get(handles_gui.checkbox_axes,'Value');
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'val_checkbox_axes',val_checkbox_axes);
% Update
update_axes('update',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
% Set data
setappdata(handles_gui.figure,'val_checkbox_axes',val_checkbox_axes);
% Update
update_axes('update',handles_gui);
update_sidemenu(handles_gui);
end
function callback_edit_scalebarlength(hObject,eventdata) %#ok<INUSD>
% Get data
scalebarlength = getappdata(handles_gui.figure,'scalebarlength');
max_scalebarlength = getappdata(handles_gui.figure,'max_scalebarlength');
friends = getappdata(handles_gui.figure,'friends');
% Get Value
scalebarlength_buffer = str2double(get(handles_gui.edit_scalebarlength,'string'));
if (ncorr_util_isrealbb(scalebarlength_buffer,0,max_scalebarlength,'Scalebar Length') == out.success)
% Update buffer
scalebarlength = scalebarlength_buffer;
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'scalebarlength',scalebarlength);
% Update
update_axes('update',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
end
% Set data
setappdata(handles_gui.figure,'scalebarlength',scalebarlength);
% Update
update_axes('update',handles_gui);
update_sidemenu(handles_gui);
end
function callback_edit_imgnum(hObject,eventdata) %#ok<INUSD>
% Get data
num_cur = getappdata(handles_gui.figure,'num_cur');
friends = getappdata(handles_gui.figure,'friends');
% Get Value - uses one based indexing
num_cur_prelim = str2double(get(handles_gui.edit_imgnum,'string'));
if (ncorr_util_isintbb(num_cur_prelim,1,length(current),'Current Image number') == out.success)
% Store value - convert back to zero based indexing
num_cur = num_cur_prelim-1;
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'num_cur',num_cur);
% Update
update_axes('set',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
end
% Set data
setappdata(handles_gui.figure,'num_cur',num_cur);
% Update this plot
update_axes('set',handles_gui);
update_sidemenu(handles_gui);
end
function callback_button_zoom(hObject,eventdata) %#ok<INUSD>
% Get data
friends = getappdata(handles_gui.figure,'friends');
handle_zoom = getappdata(handles_gui.figure,'handle_zoom');
if (strcmp(get(handle_zoom,'Enable'),'on'))
% Zoom is already enabled; disable it
val_zoom = false;
set(handle_zoom,'Enable','off');
else
% Zoom not enabled; enable it
val_zoom = true;
set(handle_zoom,'Enable','on');
end
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Get zoom handle from other plot
handle_zoom_sub = getappdata(friends{i+1}.figure,'handle_zoom');
if (val_zoom)
set(handle_zoom_sub,'Enable','on');
else
set(handle_zoom_sub,'Enable','off');
end
% Set data
setappdata(friends{i+1}.figure,'handle_zoom',handle_zoom_sub);
% Update
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
% Set data
setappdata(handles_gui.figure,'handle_zoom',handle_zoom);
% Update
update_sidemenu(handles_gui);
end
function callback_button_pan(hObject,eventdata) %#ok<INUSD>
% Get data
friends = getappdata(handles_gui.figure,'friends');
handle_pan = getappdata(handles_gui.figure,'handle_pan');
if (strcmp(get(handle_pan,'Enable'),'on'))
% Pan is already enabled; disable it
val_pan = false;
set(handle_pan,'Enable','off');
else
% Pan not enabled; enable it
val_pan = true;
set(handle_pan,'Enable','on');
end
% Update other plots in friend list
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Get Pan handle from other plot
handle_pan_sub = getappdata(friends{i+1}.figure,'handle_pan');
if (val_pan)
set(handle_pan_sub,'Enable','on');
else
set(handle_pan_sub,'Enable','off');
end
% Set data
setappdata(friends{i+1}.figure,'handle_pan',handle_pan_sub);
% Update
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
% Set data
setappdata(handles_gui.figure,'handle_pan',handle_pan);
% Update
update_sidemenu(handles_gui);
end
function callback_button_left(hObject,eventdata) %#ok<INUSD>
% Get data
num_cur = getappdata(handles_gui.figure,'num_cur');
friends = getappdata(handles_gui.figure,'friends');
% Check for overshoot
if (num_cur > 0)
% Update other plots in friend list
num_cur = num_cur-1;
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'num_cur',num_cur);
% Update
update_axes('set',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
end
% Set data
setappdata(handles_gui.figure,'num_cur',num_cur);
% Update this plot
update_axes('set',handles_gui);
update_sidemenu(handles_gui);
end
function callback_button_right(hObject,eventdata) %#ok<INUSD>
% Get data
num_cur = getappdata(handles_gui.figure,'num_cur');
friends = getappdata(handles_gui.figure,'friends');
% Check for overshoot
if (num_cur < length(current)-1)
% Update other plots in friend list
num_cur = num_cur+1;
for i = 0:length(friends)-1
if (~strcmp(getappdata(friends{i+1}.figure,'type_plot'),type_plot))
% Must check to make sure figure has not been closed during
% callback since protection is only gauranteed for this
% figure.
try
% Set data
setappdata(friends{i+1}.figure,'num_cur',num_cur);
% Update
update_axes('set',friends{i+1});
update_sidemenu(friends{i+1});
catch err
if (ishandle(friends{i+1}.figure))
rethrow(err);
end
end
end
end
end
% Set data
setappdata(handles_gui.figure,'num_cur',num_cur);
% Update this plot
update_axes('set',handles_gui);
update_sidemenu(handles_gui);
end
function update_sidemenu(handles_gui_sub)
% Get data - MUST USE HANDLES_GUI_SUB!!!
num_cur = getappdata(handles_gui_sub.figure,'num_cur');
scalebarlength = getappdata(handles_gui_sub.figure,'scalebarlength');
transparency_prelim = getappdata(handles_gui_sub.figure,'transparency_prelim');
contourlines_prelim = getappdata(handles_gui_sub.figure,'contourlines_prelim');
slider_buffer = getappdata(handles_gui_sub.figure,'slider_buffer');
val_checkbox_scalebar = getappdata(handles_gui_sub.figure,'val_checkbox_scalebar');
val_checkbox_axes = getappdata(handles_gui_sub.figure,'val_checkbox_axes');
val_checkbox_contour = getappdata(handles_gui_sub.figure,'val_checkbox_contour');
val_popupmenu = getappdata(handles_gui_sub.figure,'val_popupmenu');
handle_zoom = getappdata(handles_gui_sub.figure,'handle_zoom');
handle_pan = getappdata(handles_gui_sub.figure,'handle_pan');
if (val_popupmenu == 1)
lore = 'lagrangian';
else
lore = 'eulerian';
end
% Sliders:
set(handles_gui_sub.slider_transparency,'value',transparency_prelim);
set(handles_gui_sub.slider_upperbound,'value',min(1,max(0,slider_buffer(num_cur+1).(lore)(1))));
set(handles_gui_sub.slider_lowerbound,'value',min(1,max(0,slider_buffer(num_cur+1).(lore)(2))));
% Edit:
set(handles_gui_sub.edit_transparency,'String',num2str(transparency_prelim,'%6.4f'));
set(handles_gui_sub.edit_upperbound,'String',num2str((slider_buffer(num_cur+1).(lore)(3)-slider_buffer(num_cur+1).(lore)(4))*slider_buffer(num_cur+1).(lore)(1)+slider_buffer(num_cur+1).(lore)(4),'%6.4f'));
set(handles_gui_sub.edit_lowerbound,'String',num2str((slider_buffer(num_cur+1).(lore)(5)-slider_buffer(num_cur+1).(lore)(4))*slider_buffer(num_cur+1).(lore)(2)+slider_buffer(num_cur+1).(lore)(4),'%6.4f'));
set(handles_gui_sub.edit_contour,'String',num2str(contourlines_prelim));
set(handles_gui_sub.edit_scalebarlength,'String',num2str(scalebarlength,'%6.2f'));
% Popupmenu:
set(handles_gui_sub.popupmenu,'Value',val_popupmenu);
% Enable scalebar
if (val_checkbox_scalebar)
set(handles_gui_sub.edit_scalebarlength,'Enable','on','backgroundcolor',[0.9412 0.9412 0.9412]);
set(handles_gui_sub.checkbox_scalebar,'Value',true);
else
set(handles_gui_sub.edit_scalebarlength,'Enable','off','backgroundcolor',[0.9412 0.9412 0.9412]);
set(handles_gui_sub.checkbox_scalebar,'Value',false);
end
% Enable axes
if (val_checkbox_axes)
set(handles_gui_sub.checkbox_axes,'Value',true);
else
set(handles_gui_sub.checkbox_axes,'Value',false);
end
% Enable contour
if (val_checkbox_contour)
% Disable trans
set(handles_gui_sub.edit_transparency,'Enable','off');
set(handles_gui_sub.slider_transparency,'Enable','off');
% Enable contours
set(handles_gui_sub.edit_contour,'Enable','on','backgroundcolor',[0.9412 0.9412 0.9412]);
else
% Enable trans
set(handles_gui_sub.edit_transparency,'Enable','on','backgroundcolor',[0.9412 0.9412 0.9412]);
set(handles_gui_sub.slider_transparency,'Enable','on');
% Disable contours
set(handles_gui_sub.edit_contour,'Enable','off');
end
if (strcmp(get(handle_pan,'Enable'),'on'))
set(handles_gui_sub.button_pan,'FontWeight','bold');
else
set(handles_gui_sub.button_pan,'FontWeight','normal');
end
if (strcmp(get(handle_zoom,'Enable'),'on'))
set(handles_gui_sub.button_zoom,'FontWeight','bold');
else
set(handles_gui_sub.button_zoom,'FontWeight','normal');
end
end
function update_axes(action,handles_gui_sub)
% Get data - MUST USE HANDLES_GUI_SUB AND TYPE_PLOT_SUB!!!
num_cur = getappdata(handles_gui_sub.figure,'num_cur');
transparency_prelim = getappdata(handles_gui_sub.figure,'transparency_prelim');
contourlines_prelim = getappdata(handles_gui_sub.figure,'contourlines_prelim');
scalebarlength = getappdata(handles_gui_sub.figure,'scalebarlength');
slider_buffer = getappdata(handles_gui_sub.figure,'slider_buffer');
type_plot_sub = getappdata(handles_gui_sub.figure,'type_plot');
text_info = getappdata(handles_gui_sub.figure,'text_info');
val_checkbox_contour = getappdata(handles_gui_sub.figure,'val_checkbox_contour');
val_checkbox_scalebar = getappdata(handles_gui_sub.figure,'val_checkbox_scalebar');
val_checkbox_axes = getappdata(handles_gui_sub.figure,'val_checkbox_axes');
val_checkbox_minmaxmarkers = getappdata(handles_gui_sub.figure,'val_checkbox_minmaxmarkers');
val_popupmenu = getappdata(handles_gui_sub.figure,'val_popupmenu');
handle_preview = getappdata(handles_gui_sub.figure,'handle_preview');
handle_scalebar = getappdata(handles_gui_sub.figure,'handle_scalebar');
handle_axes = getappdata(handles_gui_sub.figure,'handle_axes');
handle_colorbar = getappdata(handles_gui_sub.figure,'handle_colorbar');
handle_point_max = getappdata(handles_gui_sub.figure,'handle_point_max');
handle_point_min = getappdata(handles_gui_sub.figure,'handle_point_min');
if (val_popupmenu == 1)
lore = 'lagrangian';
img_bg = reference;
else
lore = 'eulerian';
img_bg = current(num_cur+1);
end
% Get data
data = get_data(type_plot_sub,lore,num_cur);
plot_data = get_dataplot(type_plot_sub,lore,num_cur);
roi_data = get_roi(type_plot_sub,lore,num_cur);
if (strcmp(action,'set') || strcmp(action,'save'))
% Get reduced img
img_reduced = img_bg.reduce(data_dic.dispinfo.spacing);
% Set Background Image
imshow(img_reduced.get_img(),[img_reduced.min_gs img_reduced.max_gs],'Parent',handles_gui_sub.axes_formatplot);
hold(handles_gui_sub.axes_formatplot,'on');
% Overlay plot - See if it's a contour plot
if (val_checkbox_contour)
% Format plot
[grid_x,grid_y] = meshgrid(1:size(plot_data,2),1:size(plot_data,1));
alphamap_nan = ~roi_data.mask;
plot_data(alphamap_nan) = NaN;
% Form contour plot
[data_contour,handle_preview] = contourf(grid_x,grid_y,plot_data,contourlines_prelim,'Parent',handles_gui_sub.axes_formatplot);
% Overlay image in NaN regions
% This only works properly when opengl is disabled. When opengl
% is enabled, stacking order is determined by projected Z
% value. This is a problem because images and contourf functions
% have z = 0 value, so sometimes the image will not overlay the
% white regions.
handle_trans = imshow(img_reduced.get_img(),[img_reduced.min_gs img_reduced.max_gs],'Parent',handles_gui_sub.axes_formatplot);
set(handle_trans,'AlphaData',imdilate(alphamap_nan,true(3))); % This dilation covers the border
else
% Regular Plot
handle_preview = imshow(plot_data,[],'Parent',handles_gui_sub.axes_formatplot);
end
% Set axes grid off
set(handles_gui_sub.axes_formatplot,'Visible','off');
% Place markers in min/max location
datamax = max(data);
datamin = min(data);
% Max marker
[y_max,x_max] = find(plot_data == datamax,1);
handle_point_max = impoint(handles_gui_sub.axes_formatplot,x_max,y_max);
setColor(handle_point_max,'g');
set(handle_point_max,'UIContextMenu','');
set(handle_point_max,'ButtonDownFcn','');
% Min Marker
[y_min,x_min] = find(plot_data == datamin,1);
handle_point_min = impoint(handles_gui_sub.axes_formatplot,x_min,y_min);
setColor(handle_point_min,'r');
set(handle_point_min,'UIContextMenu','');
set(handle_point_min,'ButtonDownFcn','');
% Set invisible if markers are disabled
if (~val_checkbox_minmaxmarkers)
set(handle_point_max,'Visible','off');
set(handle_point_min,'Visible','off');
end
% Turn hold off
hold(handles_gui_sub.axes_formatplot,'off');
% Set left/right buttons
if (~strcmp(action,'save'))
set(handles_gui_sub.edit_imgnum,'String',num2str(num_cur+1));
if (length(current) == 1)
set(handles_gui_sub.button_right,'Enable','off');
set(handles_gui_sub.button_left,'Enable','off');
set(handles_gui_sub.edit_imgnum,'Enable','off');
elseif (num_cur == 0)
set(handles_gui_sub.button_right,'Enable','on');
set(handles_gui_sub.button_left,'Enable','off');
set(handles_gui_sub.edit_imgnum,'Enable','on');
elseif (num_cur == length(current)-1)
set(handles_gui_sub.button_right,'Enable','off');
set(handles_gui_sub.button_left,'Enable','on');
set(handles_gui_sub.edit_imgnum,'Enable','on');
else
set(handles_gui_sub.button_right,'Enable','on');
set(handles_gui_sub.button_left,'Enable','on');
set(handles_gui_sub.edit_imgnum,'Enable','on');
end
end
% Static Texts:
if (strcmp(action,'set') || (strcmp(action,'save') && getappdata(handles_gui_sub.figure,'includeinfo')))
set(handles_gui_sub.text_ref_name,'String',['Reference Name: ' reference.name(1:min(end,40))]);
set(handles_gui_sub.text_cur_name,'String',['Current Name: ' current(num_cur+1).name(1:min(end,40))]);
set(handles_gui_sub.text_type,'String',['Analysis type: ' data_dic.dispinfo.type]);
if (strcmp(type_plot_sub,'u') || strcmp(type_plot_sub,'v'))
string_dicparams = ['RG-DIC Radius: ' num2str(data_dic.dispinfo.radius) ' | Subset Spacing: ' num2str(data_dic.dispinfo.spacing)];
else
string_dicparams = ['RG-DIC Radius: ' num2str(data_dic.dispinfo.radius) ' | Strain Radius: ' num2str(data_dic.straininfo.radius) ' | Subset Spacing: ' num2str(data_dic.dispinfo.spacing)];
end
set(handles_gui_sub.text_dicparams,'String', string_dicparams);
set(handles_gui_sub.text_itparams,'String', ['Diffnorm Cutoff: ' num2str(data_dic.dispinfo.cutoff_diffnorm) ' | Iteration Cutoff: ' num2str(data_dic.dispinfo.cutoff_iteration) ' | Threads: ' num2str(data_dic.dispinfo.total_threads)]);
if (data_dic.dispinfo.stepanalysis.enabled)
if (strcmp(data_dic.dispinfo.stepanalysis.type,'seed'))
string_stepanalysis = 'Step Analysis: Enabled | Type: Seed Propagation ';
else
string_stepanalysis = ['Step Analysis: Enabled | Type: Leap Frog | Step: ' num2str(data_dic.dispinfo.stepanalysis.step)];
end
else
string_stepanalysis = 'Step Analysis: Disabled';
end
set(handles_gui_sub.text_stepanalysis,'String',string_stepanalysis);
if (data_dic.dispinfo.subsettrunc)
string_subsettrunc = 'RG-DIC Subset Truncation: Enabled';
else
string_subsettrunc = 'RG-DIC Subset Truncation: Disabled';
end
if (strcmp(type_plot_sub,'exx') || strcmp(type_plot_sub,'exy') || strcmp(type_plot_sub,'eyy'))
if (data_dic.straininfo.subsettrunc)
string_subsettrunc = horzcat(string_subsettrunc,' | Strain Subset Truncation: Enabled');
else
string_subsettrunc = horzcat(string_subsettrunc,' | Strain Subset Truncation: Disabled');
end
end
set(handles_gui_sub.text_subsettrunc,'String',string_subsettrunc);
string_imgcorr = 'Image Correspondences: ';
for i = 0:length(data_dic.dispinfo.imgcorr)-1 % Might be large
string_imgcorr = horzcat(string_imgcorr,['[' num2str(data_dic.dispinfo.imgcorr(i+1).idx_ref) ' ' num2str(data_dic.dispinfo.imgcorr(i+1).idx_cur) '] ']); %#ok<AGROW>
end
set(handles_gui_sub.text_imgcorr,'String',string_imgcorr);
set(handles_gui_sub.text_pixtounits,'String', ['Units/pixels: ' num2str(data_dic.dispinfo.pixtounits) ' ' data_dic.dispinfo.units '/pixels']);
set(handles_gui_sub.text_cutoff_corrcoef,'String', ['Correlation Coefficient Cutoff: ' num2str(data_dic.dispinfo.cutoff_corrcoef(num_cur+1),'%6.4f')]);
set(handles_gui_sub.text_lenscoef,'String',['Radial Lens Distortion Coefficient: ' num2str(data_dic.dispinfo.lenscoef)]);
if (strcmp(type_plot_sub,'u') || strcmp(type_plot_sub,'v'))
set(handles_gui_sub.text_minmedianmax,'String',['Max: ' num2str(slider_buffer(num_cur+1).(lore)(6),'%6.4f') ' ' data_dic.dispinfo.units ' | Median: ' num2str(slider_buffer(num_cur+1).(lore)(4),'%6.4f') ' ' data_dic.dispinfo.units ' | Min: ' num2str(slider_buffer(num_cur+1).(lore)(7),'%6.4f') ' ' data_dic.dispinfo.units]);
elseif (strcmp(type_plot_sub,'exx') || strcmp(type_plot_sub,'exy') || strcmp(type_plot_sub,'eyy'))
set(handles_gui_sub.text_minmedianmax,'String',['Max: ' num2str(slider_buffer(num_cur+1).(lore)(6),'%6.4f') ' | Median: ' num2str(slider_buffer(num_cur+1).(lore)(4),'%6.4f') ' | Min: ' num2str(slider_buffer(num_cur+1).(lore)(7),'%6.4f')]);
end
end
% Set empty text info
text_info = text(0,0,2,'','Parent',handles_gui_sub.axes_formatplot,'HorizontalAlignment','left','VerticalAlignment','top','BackgroundColor',[1 1 1],'EdgeColor',[0.7 0.7 0.7],'tag','text_info','FontSize',8);
% Update panel text if its strain, since it also displays the
% strain tensor name
if (~strcmp(action,'save') && (strcmp(type_plot_sub,'exx') || strcmp(type_plot_sub,'exy') || strcmp(type_plot_sub,'eyy')))
if (strcmp(type_plot_sub,'exx'))
group_title = 'Exx ';
elseif (strcmp(type_plot_sub,'exy'))
group_title = 'Exy ';
elseif (strcmp(type_plot_sub,'eyy'))
group_title = 'Eyy ';
end
if (val_popupmenu == 1)
group_title = [group_title 'Green-Lagrangian'];
else
group_title = [group_title 'Eulerian-Almansi'];
end
% Update title
set(handles_gui_sub.group_formataxes,'Title',group_title)
end
% Set colormap
ncorr_util_colormap(handles_gui_sub.figure);
end
if (strcmp(action,'set') || strcmp(action,'update') || strcmp(action,'save'))
% Get limits
cmax = (slider_buffer(num_cur+1).(lore)(3)-slider_buffer(num_cur+1).(lore)(4))*slider_buffer(num_cur+1).(lore)(1)+slider_buffer(num_cur+1).(lore)(4);
cmin = (slider_buffer(num_cur+1).(lore)(5)-slider_buffer(num_cur+1).(lore)(4))*slider_buffer(num_cur+1).(lore)(2)+slider_buffer(num_cur+1).(lore)(4);
if (abs(cmin-cmax)<1e-4)
cmax = cmax + 1e-5; % add a small increment to ensure they are not the same number
cmin = cmin - 1e-5;
end
% Update Plot
caxis(handles_gui_sub.axes_formatplot,[cmin cmax]);
% Update transparency for regular plot
if (~val_checkbox_contour)
transparency = transparency_prelim;
alphamap_plot = roi_data.mask.*transparency;
set(handle_preview,'AlphaData',alphamap_plot);
end
% Set colorbar
handle_colorbar = colorbar('peer',handles_gui_sub.axes_formatplot);
set(handle_colorbar,'UIContextMenu','');
set(get(handle_colorbar,'child'),'YData',[cmin cmax]);
set(handle_colorbar,'YLim',[cmin cmax]);
set(handle_colorbar,'Units','Pixels');
% Set max/min markers
if (val_checkbox_minmaxmarkers)
set(handle_point_max,'Visible','on');
set(handle_point_min,'Visible','on');
else
set(handle_point_max,'Visible','off');