forked from gjeschke/MMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepth_cue_control.m
More file actions
478 lines (390 loc) · 15.6 KB
/
depth_cue_control.m
File metadata and controls
478 lines (390 loc) · 15.6 KB
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
function varargout = depth_cue_control(varargin)
% DEPTH_CUE_CONTROL M-file for depth_cue_control.fig
% DEPTH_CUE_CONTROL, by itself, creates a new DEPTH_CUE_CONTROL or raises the existing
% singleton*.
%
% H = DEPTH_CUE_CONTROL returns the handle to a new DEPTH_CUE_CONTROL or the handle to
% the existing singleton*.
%
% DEPTH_CUE_CONTROL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DEPTH_CUE_CONTROL.M with the given input arguments.
%
% DEPTH_CUE_CONTROL('Property','Value',...) creates a new DEPTH_CUE_CONTROL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before depth_cue_control_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to depth_cue_control_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help depth_cue_control
% Last Modified by GUIDE v2.5 12-Jan-2018 12:41:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @depth_cue_control_OpeningFcn, ...
'gui_OutputFcn', @depth_cue_control_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before depth_cue_control is made visible.
function depth_cue_control_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to depth_cue_control (see VARARGIN)
% Choose default command line output for depth_cue_control
handles.output = hObject;
global hMain
global model
% global MMM_icon
% Old version with MMM figure icon, blocked because of warning
% j = get(hObject,'javaframe');
% j.setFigureIcon(javax.swing.ImageIcon(im2java(MMM_icon))); %create a java image and set the figure icon
handles.old_bckg_color=hMain.color;
hMain.depthcue_control=hObject;
command=sprintf('bckg white');
cmd(hMain,command);
if isfield(model,'selections')
if model.selections>=1
set(handles.slider_focus,'Value',0);
set(handles.slider_back,'Value',1.5);
set(handles.edit_focus,'String','0.00');
set(handles.edit_back,'String','1.50');
else
set(handles.slider_focus,'Value',0);
set(handles.slider_back,'Value',1.5);
set(handles.edit_focus,'String','0.00');
set(handles.edit_back,'String','1.50');
end
else
set(handles.slider_focus,'Value',0);
set(handles.slider_back,'Value',1.5);
set(handles.edit_focus,'String','0.00');
set(handles.edit_back,'String','1.50');
end
guidata(hObject,handles);
handles=depth_cueing(handles);
load helpicon
set(handles.pushbutton_help,'CData',cdata);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes depth_cue_control wait for user response (see UIRESUME)
% uiwait(handles.figure);
% --- Outputs from this function are returned to the command line.
function varargout = depth_cue_control_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function slider_focus_Callback(hObject, eventdata, handles)
% hObject handle to slider_focus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
newval=get(hObject,'Value');
set(handles.edit_focus,'String',sprintf('%6.2f',newval));
% --- Executes during object creation, after setting all properties.
function slider_focus_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_focus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_focus_Callback(hObject, eventdata, handles)
% hObject handle to edit_focus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_focus as text
% str2double(get(hObject,'String')) returns contents of edit_focus as a double
oldval=get(handles.slider_focus,'Value');
minval=get(handles.slider_focus,'Min');
maxval=get(handles.slider_focus,'Max');
newval=str2double(get(hObject,'String'));
if isnan(newval),
set(hObject,'String',sprintf('%6.2f',oldval));
msgbox('Only numbers are allowed input. Focus plane position was reset to previous value.','Input error','warn');
else
if newval<minval,
set(handles.slider_focus,'Min',newval);
end;
if newval>maxval,
set(handles.slider_focus,'Max',newval);
end;
set(handles.slider_focus,'Value',newval);
set(hObject,'String',sprintf('%6.2f',newval));
end;
% --- Executes during object creation, after setting all properties.
function edit_focus_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_focus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on slider movement.
function slider_back_Callback(hObject, eventdata, handles)
% hObject handle to slider_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
newval=get(hObject,'Value');
set(handles.edit_back,'String',sprintf('%6.2f',newval));
% --- Executes during object creation, after setting all properties.
function slider_back_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_back_Callback(hObject, eventdata, handles)
% hObject handle to edit_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_back as text
% str2double(get(hObject,'String')) returns contents of edit_back as a double
oldval=get(handles.slider_back,'Value');
minval=get(handles.slider_back,'Min');
maxval=get(handles.slider_back,'Max');
newval=str2double(get(hObject,'String'));
if isnan(newval),
set(hObject,'String',sprintf('%6.2f',oldval));
msgbox('Only numbers are allowed input. Back plane position was reset to previous value.','Input error','warn');
else
if newval<minval,
set(handles.slider_back,'Min',newval);
end;
if newval>maxval,
set(handles.slider_back,'Max',newval);
end;
set(handles.slider_back,'Value',newval);
set(hObject,'String',sprintf('%6.2f',newval));
end;
% --- Executes during object creation, after setting all properties.
function edit_back_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_back (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_update.
function pushbutton_update_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_update (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=depth_cueing(handles);
% --- Executes on button press in pushbutton_cancel.
function pushbutton_cancel_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global hMain
set(hMain.togglebutton_depth_cueing,'Value',0);
handles=cancel_depth_cueing(handles);
delete(handles.figure);
% --- Executes on button press in pushbutton_OK.
function pushbutton_OK_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_OK (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global hMain
set(hMain.togglebutton_depth_cueing,'Value',1);
delete(handles.figure);
function handles=depth_cueing(handles)
global hMain
global model
global hModel
set(hMain.figure,'Pointer','watch');
if hMain.detached
set(hModel.figure,'Pointer','watch');
end
switch hMain.color
case 'white'
bckg=[1,1,1];
case 'grey'
bckg=[0.941,0.941,0.941];
case 'black'
bckg=[0,0,0];
end
% Get list of objects with xyz and indices data
obj = hMain.axes_model.Children;
rmv = arrayfun(@(o)isempty(o.UserData),obj);
obj(rmv) = [];
nObjects = numel(obj);
campos=get(hMain.axes_model,'CameraPosition');
camtarget=get(hMain.axes_model,'CameraTarget');
camvec=camtarget-campos;
camvec=camvec/norm(camvec);
z=linspace(0,1,nObjects);
xyzmat=zeros(nObjects,3);
for k=1:nObjects
xyzext=obj(k).UserData.xyz;
xyz=(xyzext(1:3)+xyzext(4:6))/2-campos;
xyzmat(k,:)=xyz;
z(k)=norm(xyz.*camvec);
end
minz=min(z);
maxz=max(z);
selection_flag=0;
if isfield(model,'selections')
if model.selections>=1
minz=1e6;
maxz=-1e6;
selection_flag=1;
z2=zeros(1,model.selections);
for k=1:model.selections
cindices=model.selected{k};
cindices=cindices(cindices>0);
[msg,xyz]=get_object(cindices,'xyz');
ma=max(xyz);
ma=norm((ma-campos).*camvec);
mi=min(xyz);
mi=norm((mi-campos).*camvec);
if mi>ma
tmp=mi; mi=ma; ma=tmp;
end
if ma>maxz, maxz=ma; end
if mi<minz, minz=mi; end
z2(k)=norm((mean(xyz)-campos).*camvec);
end
maxz=maxz+2.5;
minz=minz-2.5;
end
end
if minz>=maxz
minz=maxz-2.5;
maxz=minz+2.5;
end
dz=(z-minz)/(maxz-minz);
backplane=get(handles.slider_back,'Value');
focusplane=get(handles.slider_focus,'Value');
dz=(dz-focusplane)/(backplane-focusplane);
trans=ones(size(dz));
trans(find(dz<focusplane))=0;
dz(find(dz<0))=0;
dz(find(dz>1))=1;
dz=sqrt(dz);
db=1-dz;
dz=dz.^2;
admix=0.3;
ambient=sqrt((1-admix)*dz+admix);
for kk=1:nObjects
indices=obj(k).UserData.lookup(2:end);
if indices(4)<0
[msg,allgraphics]=get_object(indices(1:3),'secondary_graphics');
else
indices=indices(indices>0);
[msg,allgraphics]=get_object(indices,'graphics');
end;
if ~isempty(allgraphics)
for kkk=1:length(allgraphics)
graphics=allgraphics(kkk);
if ~isempty(graphics)
setcolor=dz(kk)*bckg+db(kk)*graphics.color(1,:);
for k=1:length(graphics.objects)
if ishandle(graphics.objects(k)) && graphics.objects(k)~=0,
if isprop(graphics.objects(k),'Color')
set(graphics.objects(k),'Color',setcolor);
elseif isprop(graphics.objects(k),'FaceColor')
set(graphics.objects(k),'FaceColor',setcolor,'AmbientStrength',ambient(kk),'FaceAlpha',graphics.opaque(1,:)*trans(kk));
end
end
end
end
end
end
end
set(hMain.figure,'Pointer','arrow');
if hMain.detached
set(hModel.figure,'Pointer','arrow');
end
function handles=cancel_depth_cueing(handles)
global hMain
global model
global hModel
set(hMain.figure,'Pointer','watch');
if hMain.detached
set(hModel.figure,'Pointer','watch');
end
% Get list of objects with xyz and indices data
obj = hMain.axes_model.Children;
rmv = arrayfun(@(o)isempty(o.UserData),obj);
obj(rmv) = [];
nObjects = numel(obj);
for kk=1:nObjects
indices=obj(kk).UserData.lookup(2:end);
if indices(4)<0
[msg,allgraphics]=get_object(indices(1:3),'secondary_graphics');
else
indices=indices(indices>0);
[msg,allgraphics]=get_object(indices,'graphics');
end
if ~isempty(allgraphics)
for kkk=1:length(allgraphics)
graphics=allgraphics(kkk);
if ~isempty(graphics)
for k=1:length(graphics.objects)
if ishandle(graphics.objects(k)) && graphics.objects(k)~=0,
if isprop(graphics.objects(k),'Color')
set(graphics.objects(k),'Color',graphics.color(1,:));
elseif isprop(graphics.objects(k),'FaceColor')
set(graphics.objects(k),'FaceColor',graphics.color(1,:),'FaceAlpha',graphics.opaque(1,:),'AmbientStrength',0.3);
end
end
end
end
end
end
end
highlight_selection;
camlight(hMain.camlight);
command=sprintf('bckg %s',handles.old_bckg_color);
cmd(hMain,command);
set(hMain.figure,'Pointer','arrow');
if hMain.detached
set(hModel.figure,'Pointer','arrow');
end
% --- Executes when user attempts to close figure.
function figure_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
global hMain
set(hMain.togglebutton_depth_cueing,'Value',0);
handles=cancel_depth_cueing(handles);
delete(hObject);
% --- Executes on button press in pushbutton_help.
function pushbutton_help_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global help_files
entry=strcat(help_files,'depth_cueing.html');
webcall(entry,'-helpbrowser');