1 | %'set_object': GUI to edit a projection object |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function hset_object= set_object(data, PlotHandles,ZBounds) |
---|
4 | % associated with the GUI set_object.fig |
---|
5 | % |
---|
6 | % OUTPUT: |
---|
7 | % hset_object: handle of the GUI figure |
---|
8 | % |
---|
9 | % INTPUT: |
---|
10 | % data: structure describing the object properties |
---|
11 | % PlotHandles: handles for projection plots |
---|
12 | % Zbounds: bounds on Z ( 3D case) |
---|
13 | % |
---|
14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
15 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
16 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
17 | % This file is part of the toolbox UVMAT. |
---|
18 | % |
---|
19 | % UVMAT is free software; you can redistribute it and/or modify |
---|
20 | % it under the terms of the GNU General Public License as published by |
---|
21 | % the Free Software Foundation; either version 2 of the License, or |
---|
22 | % (at your option) any later version. |
---|
23 | % |
---|
24 | % UVMAT is distributed in the hope that it will be useful, |
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
27 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
28 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
29 | |
---|
30 | function varargout = set_object(varargin) |
---|
31 | |
---|
32 | % Last Modified by GUIDE v2.5 24-Nov-2008 14:29:06 |
---|
33 | |
---|
34 | % Begin initialization code - DO NOT PLOT |
---|
35 | gui_Singleton = 1; |
---|
36 | gui_State = struct('gui_Name', mfilename, ... |
---|
37 | 'gui_Singleton', gui_Singleton, ... |
---|
38 | 'gui_OpeningFcn', @set_object_OpeningFcn, ... |
---|
39 | 'gui_OutputFcn', @set_object_OutputFcn, ... |
---|
40 | 'gui_LayoutFcn', [] , ... |
---|
41 | 'gui_Callback', []); |
---|
42 | if nargin & isstr(varargin{1}) |
---|
43 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
44 | end |
---|
45 | |
---|
46 | if nargout |
---|
47 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
48 | else |
---|
49 | gui_mainfcn(gui_State, varargin{:}); |
---|
50 | end |
---|
51 | % End initialization code - DO NOT PLOT |
---|
52 | |
---|
53 | %------------------------------------------------------------------- |
---|
54 | % --- Executes just before set_object is made visible. |
---|
55 | %INPUT: |
---|
56 | % handles: handles of the set_object interface elements |
---|
57 | %'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify |
---|
58 | % if =[] or absent: index still undefined (create mode in uvmat) |
---|
59 | % if=0; no associated object (used for series), the button 'PLOT' is then unvisible |
---|
60 | %'data': read from an existing object selected in the interface |
---|
61 | % .TITLE : class of object ('POINTS','LINE',....) |
---|
62 | % .DX,DY,DZ; meshes for regular grids |
---|
63 | % .Coord: object position coordinates |
---|
64 | % .ParentButton: handle of the uicontrol object calling the interface |
---|
65 | % PlotHandles: set of handles of the elements contolling the plotting of the projected field: |
---|
66 | % if =[] or absent, no plot (mask mode in uvmat) |
---|
67 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
68 | function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds) |
---|
69 | %------------------------------------------------------------------- |
---|
70 | % Choose default command line output for set_object |
---|
71 | handles.output = hObject; |
---|
72 | |
---|
73 | % Update handles structure |
---|
74 | guidata(hObject, handles); |
---|
75 | |
---|
76 | %default |
---|
77 | if ~exist('ZBound','var') |
---|
78 | ZBound=0; %default |
---|
79 | end |
---|
80 | set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front) |
---|
81 | set(handles.MenuCoord,'ListboxTop',1) |
---|
82 | if ~exist('PlotHandles','var') |
---|
83 | PlotHandles=[]; |
---|
84 | end |
---|
85 | desable_open=0;%default: allow reading of object from xml file |
---|
86 | desable_plot=0;%default |
---|
87 | SetData.PlotHandles=PlotHandles; |
---|
88 | if exist('data','var') & isfield(data,'ParentButton') |
---|
89 | SetData.ParentButton=data.ParentButton; |
---|
90 | set(hObject,'DeleteFcn',{@closefcn,SetData.ParentButton})% |
---|
91 | end |
---|
92 | set(hObject,'UserData',SetData) |
---|
93 | |
---|
94 | % fill the interface as set in the input data: |
---|
95 | if exist('data','var') |
---|
96 | % if isfield(data,'desable_open') |
---|
97 | % desable_open=data.desable_open;%test to desable button OPEN (edit or display mode) |
---|
98 | % end |
---|
99 | if isfield(data,'desable_plot') |
---|
100 | desable_plot=data.desable_plot;%test to desable button PLOT (display mode) |
---|
101 | end |
---|
102 | if ~isfield(data,'NbDim')|~isequal(data.NbDim,3)%2D case |
---|
103 | set(handles.ZObject,'Visible','off') |
---|
104 | set(handles.z_slider,'Visible','off') |
---|
105 | else |
---|
106 | set(handles.ZObject,'Visible','on') |
---|
107 | set(handles.z_slider,'Visible','on') |
---|
108 | if isfield(data,'Coord') && size(data.Coord,2)==3 |
---|
109 | set(handles.ZObject,'String',num2str(data.Coord(1,3),4)) |
---|
110 | end |
---|
111 | end |
---|
112 | % if isfield(data,'ProjMode') && isfield(data,'Style') |
---|
113 | % data.TITLE=set_title(data.Style,data.ProjMode);% define TITLE in set_object (POINTS, LINE, PATCH,...) |
---|
114 | % end |
---|
115 | % if isfield(data,'TITLE') |
---|
116 | % menutitle=get(handles.TITLE,'String'); |
---|
117 | % for iline=1:length(menutitle) |
---|
118 | % strmenu=menutitle{iline}; |
---|
119 | % if isequal(data.TITLE,strmenu) |
---|
120 | % set(handles.TITLE,'Value',iline) |
---|
121 | % break |
---|
122 | % end |
---|
123 | % end |
---|
124 | % TITLE_Callback(hObject, eventdata, handles)% enable edit boxes depending on TITLE |
---|
125 | % end |
---|
126 | % if isfield(data,'fixedtitle')&isequal(data.fixedtitle,1) |
---|
127 | % set(handles.TITLE,'enable','off') |
---|
128 | % end |
---|
129 | if isfield(data,'Style') |
---|
130 | menu=get(handles.ObjectStyle,'String'); |
---|
131 | for iline=1:length(menu) |
---|
132 | if isequal(menu{iline},data.Style) |
---|
133 | set(handles.ObjectStyle,'Value',iline) |
---|
134 | break |
---|
135 | end |
---|
136 | end |
---|
137 | end |
---|
138 | ObjectStyle_Callback(hObject, eventdata, handles) |
---|
139 | if isfield(data,'ProjMode') |
---|
140 | menu=get(handles.ProjMode,'String'); |
---|
141 | for iline=1:length(menu) |
---|
142 | if isequal(menu{iline},data.ProjMode) |
---|
143 | set(handles.ProjMode,'Value',iline) |
---|
144 | break |
---|
145 | end |
---|
146 | end |
---|
147 | end |
---|
148 | ProjMode_Callback(hObject, eventdata, handles) |
---|
149 | if isfield(data,'Coord') & size(data.Coord,2)>=2 |
---|
150 | sizcoord=size(data.Coord); |
---|
151 | for i=1:sizcoord(1) |
---|
152 | XObject{i}=num2str(data.Coord(i,1),4); |
---|
153 | YObject{i}=num2str(data.Coord(i,2),4); |
---|
154 | end |
---|
155 | set(handles.XObject,'String',XObject) |
---|
156 | set(handles.YObject,'String',YObject) |
---|
157 | %set(handles.XObject,'String',mat2cell(data.Coord(:,1),sizcoord(1))) |
---|
158 | %set(handles.YObject,'String',mat2cell(data.Coord(:,2),sizcoord(1))) |
---|
159 | if sizcoord(2)>3 |
---|
160 | for i=1:sizcoord(1) |
---|
161 | ZObject{i}=num2str(data.Coord(i,3),4); |
---|
162 | end |
---|
163 | set(handles.ZObject,'String',ZObject) |
---|
164 | end |
---|
165 | end |
---|
166 | if isfield(data,'DX') |
---|
167 | set(handles.DX,'String',num2str(data.DX,3)) |
---|
168 | end |
---|
169 | if isfield(data,'DY') |
---|
170 | set(handles.DY,'String',num2str(data.DY,3)) |
---|
171 | end |
---|
172 | %OBSOLETE (replaced by Range) |
---|
173 | % if isfield(data,'XMin') |
---|
174 | % set(handles.XMin,'String',num2str(data.XMin,3)) |
---|
175 | % end |
---|
176 | % if isfield(data,'XMax') |
---|
177 | % set(handles.XMax,'String',num2str(data.XMax,3)) |
---|
178 | % end |
---|
179 | % if isfield(data,'YMin') |
---|
180 | % set(handles.YMin,'String',num2str(data.YMin,3)) |
---|
181 | % end |
---|
182 | % if isfield(data,'YMax') |
---|
183 | % set(handles.YMax,'String',num2str(data.YMax,3)) |
---|
184 | % end |
---|
185 | if isfield(data,'RangeZ') && length(ZBounds) >= 2 |
---|
186 | set(handles.ZMax,'String',num2str(max(data.RangeZ),3)) |
---|
187 | DZ=max(data.RangeZ);%slider step |
---|
188 | if ZBounds(2)~=ZBounds(1) |
---|
189 | rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1 |
---|
190 | rel_step(2)=0.1; |
---|
191 | set(handles.z_slider,'Visible','on') |
---|
192 | set(handles.z_slider,'Min',ZBounds(1)) |
---|
193 | set(handles.z_slider,'Max',ZBounds(2)) |
---|
194 | set(handles.z_slider,'SliderStep',rel_step) |
---|
195 | set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2) |
---|
196 | end |
---|
197 | end |
---|
198 | if isfield(data,'RangeX') |
---|
199 | set(handles.XMax,'String',num2str(max(data.RangeX),3)) |
---|
200 | set(handles.XMin,'String',num2str(min(data.RangeX),3)) |
---|
201 | end |
---|
202 | if isfield(data,'RangeY') |
---|
203 | set(handles.YMax,'String',num2str(max(data.RangeY),3)) |
---|
204 | set(handles.YMin,'String',num2str(min(data.RangeY),3)) |
---|
205 | end |
---|
206 | if isfield(data,'RangeZ') |
---|
207 | set(handles.ZMax,'String',num2str(max(data.RangeZ),3)) |
---|
208 | set(handles.ZMin,'String',num2str(min(data.RangeZ),3)) |
---|
209 | end |
---|
210 | if isfield(data,'Phi') |
---|
211 | set(handles.Phi,'String',num2str(data.Phi,3)) |
---|
212 | end |
---|
213 | if isfield(data,'Theta') |
---|
214 | set(handles.Theta,'String',num2str(data.Theta,3)) |
---|
215 | end |
---|
216 | if isfield(data,'Psi') |
---|
217 | set(handles.Psi,'String',num2str(data.Psi,3)) |
---|
218 | end |
---|
219 | if isfield(data,'DZ') |
---|
220 | set(handles.DZ,'String',num2str(data.DZ,3)) |
---|
221 | end |
---|
222 | if isfield(data,'CoordType') |
---|
223 | if isequal(data.CoordType,'phys') |
---|
224 | set(handles.MenuCoord,'Value',1) |
---|
225 | elseif isequal(data.CoordType,'px') |
---|
226 | set(handles.MenuCoord,'Value',2) |
---|
227 | end |
---|
228 | end |
---|
229 | end |
---|
230 | % if desable_open |
---|
231 | % set(handles.OPEN,'Visible','off') |
---|
232 | % else |
---|
233 | % set(handles.OPEN,'Visible','on') |
---|
234 | % end |
---|
235 | if desable_plot |
---|
236 | set(handles.PLOT,'Visible','off') |
---|
237 | else |
---|
238 | set(handles.PLOT,'Visible','on') |
---|
239 | end |
---|
240 | |
---|
241 | |
---|
242 | % --- Outputs from this function are returned to the command line. |
---|
243 | function varargout = set_object_OutputFcn(hObject, eventdata, handles) |
---|
244 | % varargout cell array for returning output args (see VARARGOUT); |
---|
245 | % hObject handle to figure |
---|
246 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
247 | % handles structure with handles and user data (see GUIDATA) |
---|
248 | |
---|
249 | % Get default command line output from handles structure |
---|
250 | varargout{1} = handles.output; |
---|
251 | varargout{2}=handles; |
---|
252 | |
---|
253 | %----------------------------------------------- |
---|
254 | % --- Executes on selection change in ObjectStyle. |
---|
255 | function ObjectStyle_Callback(hObject, eventdata, handles) |
---|
256 | style_prev=get(handles.ObjectStyle,'UserData');%previous object style |
---|
257 | str=get(handles.ObjectStyle,'String'); |
---|
258 | val=get(handles.ObjectStyle,'Value'); |
---|
259 | style=str{val}; |
---|
260 | % make correspondance between different object styles |
---|
261 | % if ~isequal(str{val},style_prev) |
---|
262 | Xcolumn=get(handles.XObject,'String'); |
---|
263 | Ycolumn=get(handles.YObject,'String'); |
---|
264 | if ischar(Xcolumn) |
---|
265 | sizchar=size(Xcolumn); |
---|
266 | for icol=1:sizchar(1) |
---|
267 | Xcolumn_cell{icol}=Xcolumn(icol,:); |
---|
268 | end |
---|
269 | Xcolumn=Xcolumn_cell; |
---|
270 | end |
---|
271 | if ischar(Ycolumn) |
---|
272 | sizchar=size(Ycolumn); |
---|
273 | for icol=1:sizchar(1) |
---|
274 | Ycolumn_cell{icol}=Ycolumn(icol,:); |
---|
275 | end |
---|
276 | Ycolumn=Ycolumn_cell; |
---|
277 | end |
---|
278 | Zcolumn={};%default |
---|
279 | z_new={}; |
---|
280 | if isequal(get(handles.ZObject,'Visible'),'on') |
---|
281 | data.NbDim=3; %test 3D object |
---|
282 | Zcolumn=get(handles.ZObject,'String'); |
---|
283 | if ischar(Zcolumn) |
---|
284 | Zcolumn={Zcolumn}; |
---|
285 | end |
---|
286 | end |
---|
287 | x_new{1}=Xcolumn{1}; |
---|
288 | y_new{1}=Ycolumn{1}; |
---|
289 | if ~isempty(Zcolumn) |
---|
290 | z_new{1}=Zcolumn{1}; |
---|
291 | end |
---|
292 | if isequal(style,'line') |
---|
293 | if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse') |
---|
294 | XMax=get(handles.XMax,'String'); |
---|
295 | YMax=get(handles.YMax,'String'); |
---|
296 | x_new{2}=num2str(XMax,4); |
---|
297 | y_new{2}=num2str(YMax,4); |
---|
298 | set(handles.XObject,'String',x_new) |
---|
299 | set(handles.YObject,'String',y_new) |
---|
300 | set(handles.ZObject,'String',z_new) |
---|
301 | end |
---|
302 | elseif isequal(style,'polyline') |
---|
303 | elseif isequal(style,'rectangle')| isequal(style,'ellipse') |
---|
304 | set(handles.XObject,'String',x_new) |
---|
305 | set(handles.YObject,'String',y_new) |
---|
306 | set(handles.ZObject,'String',z_new) |
---|
307 | end |
---|
308 | % end |
---|
309 | switch style |
---|
310 | case {'points','line','polyline','plane'} |
---|
311 | menu_proj={'projection';'interp';'filter';'none'}; |
---|
312 | case {'polygon','rectangle','ellipse'} |
---|
313 | menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; |
---|
314 | case 'volume' |
---|
315 | menu_proj={'none'}; |
---|
316 | end |
---|
317 | proj_index=get(handles.ProjMode,'Value'); |
---|
318 | if proj_index<numel(menu_proj) |
---|
319 | set(handles.ProjMode,'Value',1);% value index must not exceed the menu length |
---|
320 | end |
---|
321 | set(handles.ProjMode,'String',menu_proj) |
---|
322 | ProjMode_Callback(hObject, eventdata, handles) |
---|
323 | %store the current option |
---|
324 | str=get(handles.ObjectStyle,'String'); |
---|
325 | val=get(handles.ObjectStyle,'Value'); |
---|
326 | set(handles.ObjectStyle,'UserData',style) |
---|
327 | |
---|
328 | %---------------------------------------------- |
---|
329 | function xObject_Callback(hObject, eventdata, handles) |
---|
330 | |
---|
331 | |
---|
332 | function yObject_Callback(hObject, eventdata, handles) |
---|
333 | |
---|
334 | |
---|
335 | % --- Executes on selection change in zObject. |
---|
336 | function zObject_Callback(hObject, eventdata, handles) |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | % --- Executes on selection change in ProjMode. |
---|
341 | function ProjMode_Callback(hObject, eventdata, handles) |
---|
342 | menu=get(handles.ProjMode,'String'); |
---|
343 | value=get(handles.ProjMode,'Value'); |
---|
344 | ProjMode=menu{value}; |
---|
345 | menu=get(handles.ObjectStyle,'String'); |
---|
346 | value=get(handles.ObjectStyle,'Value'); |
---|
347 | ObjectStyle=menu{value}; |
---|
348 | test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case |
---|
349 | |
---|
350 | %default setting |
---|
351 | set(handles.Phi,'Visible','off') |
---|
352 | set(handles.Theta,'Visible','off') |
---|
353 | set(handles.Psi,'Visible','off') |
---|
354 | set(handles.XMin,'Visible','off') |
---|
355 | set(handles.XMax,'Visible','off') |
---|
356 | set(handles.YMin,'Visible','off') |
---|
357 | if isequal(ProjMode,'interp') |
---|
358 | set(handles.YMax,'Visible','off') |
---|
359 | else |
---|
360 | set(handles.YMax,'Visible','on') |
---|
361 | end |
---|
362 | if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse') |
---|
363 | set(handles.XMax,'Visible','on') |
---|
364 | else |
---|
365 | set(handles.XMax,'Visible','off') |
---|
366 | end |
---|
367 | set(handles.ZMin,'Visible','off') |
---|
368 | set(handles.ZMax,'Visible','off') |
---|
369 | set(handles.DX,'Visible','off') |
---|
370 | set(handles.DY,'Visible','off') |
---|
371 | set(handles.DZ,'Visible','off') |
---|
372 | |
---|
373 | switch ObjectStyle |
---|
374 | case 'points' |
---|
375 | set(handles.YMax,'TooltipString','YMax: range of averaging around each point') |
---|
376 | set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points') |
---|
377 | set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points') |
---|
378 | set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points') |
---|
379 | case {'line','polyline','polygon'} |
---|
380 | set(handles.YMax,'TooltipString','YMax: range of averaging around the line') |
---|
381 | set(handles.XObject,'TooltipString','XObject: set of x coordinates defining the line') |
---|
382 | set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line') |
---|
383 | set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line') |
---|
384 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
385 | set(handles.DX,'Visible','on') |
---|
386 | set(handles.DX,'TooltipString','DX: mesh for the interpolated field along the line') |
---|
387 | end |
---|
388 | case {'rectangle','ellipse'} |
---|
389 | set(handles.XMax,'TooltipString',['XMax: half length of the ' ObjectStyle]) |
---|
390 | set(handles.YMax,'TooltipString',['YMax: half width of the ' ObjectStyle]) |
---|
391 | set(handles.XObject,'TooltipString',['XObject: x coordinate of the ' ObjectStyle ' centre']) |
---|
392 | set(handles.YObject,'TooltipString',['YObject: y coordinate of the ' ObjectStyle ' centre']) |
---|
393 | case {'plane','volume'} |
---|
394 | set(handles.Phi,'Visible','on') |
---|
395 | set(handles.XMin,'Visible','on') |
---|
396 | set(handles.XMax,'Visible','on') |
---|
397 | set(handles.YMin,'Visible','on') |
---|
398 | set(handles.YMax,'Visible','on') |
---|
399 | set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' ObjectStyle]) |
---|
400 | set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' ObjectStyle]) |
---|
401 | if test3D |
---|
402 | set(handles.Theta,'Visible','on') |
---|
403 | set(handles.Psi,'Visible','on') |
---|
404 | set(handles.ZMin,'Visible','on') |
---|
405 | set(handles.ZMax,'Visible','on') |
---|
406 | end |
---|
407 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
408 | set(handles.DX,'Visible','on') |
---|
409 | set(handles.DY,'Visible','on') |
---|
410 | else |
---|
411 | set(handles.DX,'Visible','off') |
---|
412 | set(handles.DY,'Visible','off') |
---|
413 | end |
---|
414 | if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp') |
---|
415 | set(handles.DZ,'Visible','on') |
---|
416 | end |
---|
417 | end |
---|
418 | % |
---|
419 | % %--------------------------------------------- |
---|
420 | % % --- Executes on selection change in TITLE. |
---|
421 | % function TITLE_Callback(style, handles) |
---|
422 | % %--------------------------------------------- |
---|
423 | % switch style |
---|
424 | % case {'points','line','polyline','plane'} |
---|
425 | % menu_proj={'projection';'interp';'filter';'none'}; |
---|
426 | % case {'polygon','rectangle','ellipse'} |
---|
427 | % menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; |
---|
428 | % case 'volume' |
---|
429 | % menu_proj={'none'}; |
---|
430 | % end |
---|
431 | % |
---|
432 | % |
---|
433 | % old_menu=get(handles.ObjectStyle,'String'); |
---|
434 | % value=get(handles.ObjectStyle,'Value'); |
---|
435 | % old_style=old_menu{value}; |
---|
436 | % teststyle=0; |
---|
437 | % for iline=1:length(menu_style) |
---|
438 | % if isequal(menu_style{iline},old_style) |
---|
439 | % styleval=iline; |
---|
440 | % teststyle=1; |
---|
441 | % break |
---|
442 | % end |
---|
443 | % end |
---|
444 | % if ~teststyle |
---|
445 | % new_style=[];%default |
---|
446 | % switch old_style |
---|
447 | % case 'polyline' |
---|
448 | % new_style='polygon'; |
---|
449 | % case 'polygon' |
---|
450 | % new_style='polyline'; |
---|
451 | % end |
---|
452 | % if ~isempty(new_style) |
---|
453 | % for iline=1:length(menu_style) |
---|
454 | % if isequal(menu_style{iline},new_style) |
---|
455 | % styleval=iline; |
---|
456 | % teststyle=1; |
---|
457 | % break |
---|
458 | % end |
---|
459 | % end |
---|
460 | % end |
---|
461 | % end |
---|
462 | % if ~teststyle |
---|
463 | % styleval=1; |
---|
464 | % end |
---|
465 | % set(handles.ObjectStyle,'String',menu_style) |
---|
466 | % set(handles.ObjectStyle,'Value',styleval) |
---|
467 | % set(handles.ProjMode,'String',menu_proj) |
---|
468 | % set(handles.ProjMode,'Value',1) |
---|
469 | % ObjectStyle_Callback(hObject, eventdata, handles) |
---|
470 | |
---|
471 | %--------------------------------------------- |
---|
472 | function Phi_Callback(hObject, eventdata, handles) |
---|
473 | update_slider(hObject, eventdata,handles) |
---|
474 | %--------------------------------------------- |
---|
475 | |
---|
476 | function Theta_Callback(hObject, eventdata, handles) |
---|
477 | update_slider(hObject, eventdata,handles) |
---|
478 | |
---|
479 | function update_slider(hObject, eventdata,handles) |
---|
480 | %rotation angles |
---|
481 | Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian |
---|
482 | Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian |
---|
483 | |
---|
484 | %components of the unitiy vector normal to the projection plane |
---|
485 | NormVec_X=-sin(Phi)*sin(Theta); |
---|
486 | NormVec_Y=cos(Phi)*sin(Theta); |
---|
487 | NormVec_Z=cos(Theta); |
---|
488 | huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle |
---|
489 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
490 | if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z') |
---|
491 | Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z); |
---|
492 | set(handles.z_slider,'Min',min(Z)) |
---|
493 | set(handles.z_slider,'Max',max(Z)) |
---|
494 | ZMax_Callback(hObject, eventdata, handles) |
---|
495 | end |
---|
496 | |
---|
497 | function DX_Callback(hObject, eventdata, handles) |
---|
498 | |
---|
499 | |
---|
500 | function DY_Callback(hObject, eventdata, handles) |
---|
501 | |
---|
502 | |
---|
503 | function DZ_Callback(hObject, eventdata, handles) |
---|
504 | |
---|
505 | |
---|
506 | |
---|
507 | %----------------------------------------------------- |
---|
508 | % --- Executes on button press in OPEN. |
---|
509 | function OPEN_Callback(hObject, eventdata, handles) |
---|
510 | %get the object file |
---|
511 | oldfile=' '; |
---|
512 | huvmat=findobj('Tag','uvmat'); |
---|
513 | hchild=get(huvmat,'Children'); |
---|
514 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
515 | if ~isempty(hrootpath) |
---|
516 | oldfile=get(hrootpath,'String'); |
---|
517 | if iscell(oldfile) |
---|
518 | oldfile=oldfile{1}; |
---|
519 | end |
---|
520 | end |
---|
521 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
522 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
523 | '*.xml', '.xml files '; ... |
---|
524 | '*.mat', '.mat matlab files '}, ... |
---|
525 | 'Pick a file',oldfile); |
---|
526 | fileinput=[PathName FileName];%complete file name |
---|
527 | testblank=findstr(fileinput,' ');%look for blanks |
---|
528 | if ~isempty(testblank) |
---|
529 | msgbox_uvmat('ERROR','forbidden input file name: contain blanks') |
---|
530 | return |
---|
531 | end |
---|
532 | sizf=size(fileinput); |
---|
533 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
534 | |
---|
535 | %read the file |
---|
536 | t=xmltree(fileinput); |
---|
537 | s=convert(t); |
---|
538 | if ~isfield(s,'Style') |
---|
539 | s.Style='points'; |
---|
540 | end |
---|
541 | if ~isfield(s,'ProjMode') |
---|
542 | s.ProjMode='none'; |
---|
543 | end |
---|
544 | %Display title |
---|
545 | % title=set_title(s.Style,s.ProjMode);%update the title |
---|
546 | % if ~isempty(huvmat) |
---|
547 | % hhuvmat=guidata(huvmat); |
---|
548 | % end |
---|
549 | % menu=get(handles.TITLE,'String'); |
---|
550 | % for iline=1:length(menu) |
---|
551 | % if isequal(menu{iline},title) |
---|
552 | % set(handles.TITLE,'Value',iline) |
---|
553 | % break |
---|
554 | % end |
---|
555 | % end |
---|
556 | %TITLE_Callback(hObject, eventdata, handles) |
---|
557 | teststyle=0; |
---|
558 | |
---|
559 | switch s.Style |
---|
560 | case {'points','line','polyline','plane'} |
---|
561 | menu_proj={'projection';'interp';'filter';'none'}; |
---|
562 | case {'polygon','rectangle','ellipse'} |
---|
563 | menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; |
---|
564 | case 'volume' |
---|
565 | menu_proj={'none'}; |
---|
566 | end |
---|
567 | set(handles.ObjectStyle,'String',menu_proj) |
---|
568 | menu=get(handles.ObjectStyle,'String'); |
---|
569 | for iline=1:length(menu) |
---|
570 | if isequal(menu{iline},s.Style) |
---|
571 | set(handles.ObjectStyle,'Value',iline) |
---|
572 | teststyle=1; |
---|
573 | break |
---|
574 | end |
---|
575 | end |
---|
576 | testmode=0; |
---|
577 | %menu=get(handles.ProjMode,'String'); |
---|
578 | for iline=1:length(menu_proj) |
---|
579 | if isequal(menu_proj{iline},s.ProjMode) |
---|
580 | set(handles.ProjMode,'Value',iline) |
---|
581 | testmode=1; |
---|
582 | break |
---|
583 | end |
---|
584 | end |
---|
585 | |
---|
586 | ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes |
---|
587 | if isfield(s,'CoordType') |
---|
588 | if isequal(s.CoordType,'phys') |
---|
589 | set(handles.MenuCoord,'Value',1) |
---|
590 | elseif isequal(s.CoordType,'px') |
---|
591 | set(handles.MenuCoord,'Value',2) |
---|
592 | else |
---|
593 | warndlg('unknown CoordType (px or phys) in set_object.m') |
---|
594 | end |
---|
595 | end |
---|
596 | if isfield(s,'XMax') |
---|
597 | set(handles.XMax,'String',s.XMax) |
---|
598 | end |
---|
599 | if isfield(s,'XMin') |
---|
600 | set(handles.XMin,'String',s.XMin) |
---|
601 | end |
---|
602 | if isfield(s,'YMax') |
---|
603 | set(handles.YMax,'String',s.YMax) |
---|
604 | end |
---|
605 | if isfield(s,'YMin') |
---|
606 | set(handles.YMin,'String',s.YMin) |
---|
607 | end |
---|
608 | Range=0; |
---|
609 | if isfield(s,'Range') |
---|
610 | if ischar(s.Range) |
---|
611 | Range=str2num(s.Range); |
---|
612 | else |
---|
613 | Range(1,:)=str2num(s.Range{1}); |
---|
614 | Range(2,:)=str2num(s.Range{2}); |
---|
615 | end |
---|
616 | end |
---|
617 | if size(Range,2)>=3 |
---|
618 | if size(Range,1)>=2 |
---|
619 | set(handles.ZMin,'String',num2str(Range(2,3),3)) |
---|
620 | end |
---|
621 | if size(Range,1)>=2 |
---|
622 | set(handles.ZMax,'String',num2str(Range(1,3),3)) |
---|
623 | end |
---|
624 | end |
---|
625 | if size(Range,2)>=2 |
---|
626 | if size(Range,1)>=2 |
---|
627 | set(handles.YMin,'String',num2str(Range(2,2),3)) |
---|
628 | end |
---|
629 | if size(Range,1)>=2 |
---|
630 | set(handles.YMax,'String',num2str(Range(1,2),3)) |
---|
631 | end |
---|
632 | end |
---|
633 | if size(Range,2)>=1 |
---|
634 | if size(Range,1)>=2 |
---|
635 | set(handles.XMin,'String',num2str(Range(2,1),3)) |
---|
636 | end |
---|
637 | if size(Range,1)>=2 |
---|
638 | set(handles.XMax,'String',num2str(Range(1,1),3)) |
---|
639 | end |
---|
640 | end |
---|
641 | if isfield(s,'RangeX') & ischar(s.RangeX) |
---|
642 | RangeX=str2num(s.RangeX); |
---|
643 | set(handles.XMax,'String',num2str(max(RangeX),3)) |
---|
644 | set(handles.XMin,'String',num2str(min(RangeX),3)) |
---|
645 | end |
---|
646 | |
---|
647 | if isfield(s,'RangeY') |
---|
648 | if ischar(s.RangeY) |
---|
649 | RangeY=str2num(s.RangeY); |
---|
650 | set(handles.YMax,'String',num2str(max(RangeY),3)) |
---|
651 | set(handles.YMin,'String',num2str(min(RangeY),3)) |
---|
652 | end |
---|
653 | end |
---|
654 | if isfield(s,'RangeZ') |
---|
655 | if ischar(s.RangeZ) |
---|
656 | RangeZ=str2num(s.RangeZ); |
---|
657 | set(handles.ZMax,'String',num2str(max(RangeZ),3)) |
---|
658 | set(handles.ZMin,'String',num2str(min(RangeZ),3)) |
---|
659 | end |
---|
660 | end |
---|
661 | if isfield(s,'Phi') |
---|
662 | set(handles.Phi,'String',s.Phi) |
---|
663 | end |
---|
664 | if isfield(s,'Theta') |
---|
665 | set(handles.Theta,'String',s.Theta) |
---|
666 | end |
---|
667 | if isfield(s,'Psi') |
---|
668 | set(handles.Psi,'String',s.Psi) |
---|
669 | end |
---|
670 | |
---|
671 | if isfield(s,'DX') |
---|
672 | set(handles.DX,'String',s.DX) |
---|
673 | end |
---|
674 | if isfield(s,'DY') |
---|
675 | set(handles.DY,'String',s.DY) |
---|
676 | end |
---|
677 | if ~isfield(s,'Coord') |
---|
678 | XObject='0';%default |
---|
679 | YObject='0'; |
---|
680 | elseif ischar(s.Coord) |
---|
681 | line=str2num(s.Coord); |
---|
682 | XObject=num2str(line(1),4); |
---|
683 | YObject=num2str(line(2),4); |
---|
684 | else |
---|
685 | for i=1:length(s.Coord) |
---|
686 | line=str2num(s.Coord{i}); |
---|
687 | XObject{i}=num2str(line(1),4); |
---|
688 | YObject{i}=num2str(line(2),4); |
---|
689 | end |
---|
690 | end |
---|
691 | set(handles.XObject,'String',XObject) |
---|
692 | set(handles.YObject,'String',YObject) |
---|
693 | %METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening |
---|
694 | |
---|
695 | %---------------------------------------------------- |
---|
696 | % executed when closing: set the parent interface button to value 0 |
---|
697 | function closefcn(gcbo,eventdata,parent_button) |
---|
698 | |
---|
699 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
700 | if ~isempty(huvmat) |
---|
701 | hhuvmat=guidata(huvmat); |
---|
702 | set(hhuvmat.create,'Value',0) |
---|
703 | set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
704 | % set(hhuvmat.LINE,'Value',0) |
---|
705 | % set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
706 | % set(hhuvmat.PATCH,'Value',0) |
---|
707 | % set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
708 | % set(hhuvmat.PLANE,'Value',0) |
---|
709 | % set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
710 | % set(hhuvmat.VOLUME,'Value',0) |
---|
711 | % set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
712 | set(hhuvmat.edit,'Value',0) |
---|
713 | set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree |
---|
714 | end |
---|
715 | hseries=findobj(allchild(0),'Name','series');%find the current series interface handle |
---|
716 | if ~isempty(hseries) |
---|
717 | hhseries=guidata(hseries); |
---|
718 | set(hhseries.GetObject,'Value',0) |
---|
719 | set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
720 | end |
---|
721 | |
---|
722 | %----------------------------------------------------------------------- |
---|
723 | % --- Executes on button press in PLOT: PLOT the defined object and its projected field |
---|
724 | function PLOT_Callback(hObject, eventdata, handles) |
---|
725 | |
---|
726 | hsetobject=get(handles.PLOT,'parent'); |
---|
727 | SetData=get(hsetobject,'UserData');%get the hidden interface data |
---|
728 | huvmat=findobj('Name','uvmat');%find the current uvmat interface handle |
---|
729 | hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object list in the GUI uvmat |
---|
730 | IndexObj=get(hlist_object,'Value');%position in the objet list |
---|
731 | UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat |
---|
732 | ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object |
---|
733 | ObjectData.HandlesDisplay=[]; % new object plot by default |
---|
734 | if length(UvData.Object) >= IndexObj && isfield(UvData.Object{IndexObj},'HandlesDisplay') |
---|
735 | hdisplay=UvData.Object{IndexObj}.HandlesDisplay; |
---|
736 | if isequal(UvData.Object{IndexObj}.Style, ObjectData.Style) && isequal(UvData.Object{IndexObj}.ProjMode, ObjectData.ProjMode) |
---|
737 | ObjectData.HandlesDisplay=UvData.Object{IndexObj}.HandlesDisplay; |
---|
738 | else % for a new object styl, delete the existing object plots |
---|
739 | for ih=1:length(hdisplay) |
---|
740 | PlotData=get(hdisplay(ih),'UserData'); |
---|
741 | if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject) |
---|
742 | delete(PlotData.SubObject); |
---|
743 | end |
---|
744 | if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint) |
---|
745 | delete(PlotData.DeformPoint); |
---|
746 | end |
---|
747 | if ~isequal(hdisplay(ih),0) |
---|
748 | delete(hdisplay(ih)); |
---|
749 | end |
---|
750 | end |
---|
751 | if isfield(ObjectData,'plotaxes') && ishandle(ObjectData.plotaxes) |
---|
752 | delete(ObjectData.plotaxes)%delete the axes for plotting the current projection result |
---|
753 | end |
---|
754 | end |
---|
755 | end |
---|
756 | |
---|
757 | % update the object plot and projection field |
---|
758 | UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles); |
---|
759 | |
---|
760 | set(huvmat,'UserData',UvData)%update the data in the uvmat interface |
---|
761 | list_str=get(hlist_object,'String'); |
---|
762 | % TITLE=set_title(ObjectData.Style,ObjectData.ProjMode); |
---|
763 | % list_str{IndexObj}=[num2str(IndexObj) '-' TITLE]; |
---|
764 | list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style]; |
---|
765 | if isequal(length(list_str),IndexObj) |
---|
766 | list_str{IndexObj+1}='more...'; |
---|
767 | end |
---|
768 | set(hlist_object,'String',list_str) |
---|
769 | set(hlist_object,'Value',IndexObj) |
---|
770 | |
---|
771 | %update create buttons on the GUI uvmat: set to object edit mode after object plotting |
---|
772 | hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI |
---|
773 | %desactivate all create buttons in mode edit |
---|
774 | % if isequal(get(hhuvmat.edit,'Value'),0) |
---|
775 | set(hhuvmat.create,'Value',0) |
---|
776 | set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
777 | % set(hhuvmat.LINE,'Value',0) |
---|
778 | % set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
779 | % set(hhuvmat.PATCH,'Value',0) |
---|
780 | % set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
781 | % set(hhuvmat.PLANE,'Value',0) |
---|
782 | % set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
783 | % set(hhuvmat.VOLUME,'Value',0) |
---|
784 | % set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
785 | % end |
---|
786 | set(hhuvmat.edit,'Value',1) |
---|
787 | set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow |
---|
788 | set(hhuvmat.edit,'Value',1);% |
---|
789 | UvData.MouseAction='edit_object'; % set the edit button to 'on' |
---|
790 | set(huvmat,'UserData',UvData) |
---|
791 | |
---|
792 | % --- Executes on button press in MenuCoord. |
---|
793 | function MenuCoord_Callback(hObject, eventdata, handles) |
---|
794 | |
---|
795 | %---------------------------------------------------- |
---|
796 | function YMin_Callback(hObject, eventdata, handles) |
---|
797 | |
---|
798 | |
---|
799 | function ZMin_Callback(hObject, eventdata, handles) |
---|
800 | |
---|
801 | |
---|
802 | function ZMax_Callback(hObject, eventdata, handles) |
---|
803 | DZ=str2num(get(handles.ZMax,'String')); |
---|
804 | ZMin=get(handles.z_slider,'Min'); |
---|
805 | ZMax=get(handles.z_slider,'Max'); |
---|
806 | if ~isequal(ZMax-ZMin,0) |
---|
807 | rel_step(1)=DZ/(ZMax-ZMin); |
---|
808 | rel_step(2)=0.2; |
---|
809 | set(handles.z_slider,'SliderStep',rel_step) |
---|
810 | end |
---|
811 | |
---|
812 | function YMax_Callback(hObject, eventdata, handles) |
---|
813 | |
---|
814 | |
---|
815 | function XMin_Callback(hObject, eventdata, handles) |
---|
816 | |
---|
817 | |
---|
818 | function XMax_Callback(hObject, eventdata, handles) |
---|
819 | |
---|
820 | |
---|
821 | % ------------------------------------------------------ |
---|
822 | function SAVE_Callback(hObject, eventdata, handles) |
---|
823 | % ------------------------------------------------------ |
---|
824 | Object=read_set_object(handles); |
---|
825 | huvmat=findobj('Tag','uvmat'); |
---|
826 | % UvData=get(huvmat,'UserData'); |
---|
827 | if isempty(huvmat) |
---|
828 | huvmat=findobj(allchild(0),'Name','series'); |
---|
829 | end |
---|
830 | hchild=get(huvmat,'Children'); |
---|
831 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
832 | if isempty(hrootpath) |
---|
833 | RootPath=''; |
---|
834 | else |
---|
835 | RootPath=get(hrootpath,'String'); |
---|
836 | if iscell(RootPath) |
---|
837 | RootPath=RootPath{1}; |
---|
838 | end |
---|
839 | end |
---|
840 | title={'object name'}; |
---|
841 | dir_save=uigetdir(RootPath); |
---|
842 | def={fullfile(dir_save,['Object' Object.CoordType '.xml'])}; |
---|
843 | options.Resize='on'; |
---|
844 | displ_txt='save object as an .xml file';%default display |
---|
845 | menu=get(handles.ProjMode,'String'); |
---|
846 | value=get(handles.ProjMode,'Value'); |
---|
847 | ProjMode=menu{value}; |
---|
848 | if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside') |
---|
849 | displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)'; |
---|
850 | end |
---|
851 | answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def); |
---|
852 | %answer=inputdlg('','save object in a new .xml file',1,def,'on'); |
---|
853 | if ~isempty(answer) |
---|
854 | t=struct2xml(Object); |
---|
855 | save(t,answer{1}) |
---|
856 | end |
---|
857 | msgbox_uvmat('CONFIRMATION',[answer{1} ' saved']) |
---|
858 | |
---|
859 | %--------------------------------------------------------- |
---|
860 | % --- Executes on slider movement. |
---|
861 | function z_slider_Callback(hObject, eventdata, handles) |
---|
862 | %--------------------------------------------------------- |
---|
863 | %A ADAPTER |
---|
864 | Z_value=get(handles.z_slider,'Value'); |
---|
865 | |
---|
866 | %rotation angles |
---|
867 | Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian |
---|
868 | Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian |
---|
869 | |
---|
870 | %components of the unity vector normal to the projection plane |
---|
871 | NormVec_X=-sin(Phi)*sin(Theta); |
---|
872 | NormVec_Y=cos(Phi)*sin(Theta); |
---|
873 | NormVec_Z=cos(Theta); |
---|
874 | |
---|
875 | %set new plane position and update graph |
---|
876 | set(handles.XObject,'String',num2str(NormVec_X*Z_value,4)) |
---|
877 | set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4)) |
---|
878 | set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4)) |
---|
879 | PLOT_Callback(hObject, eventdata, handles) |
---|
880 | |
---|
881 | |
---|
882 | % --- Executes on button press in HELP. |
---|
883 | function HELP_Callback(hObject, eventdata, handles) |
---|
884 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
885 | pathelp=fileparts(path_to_uvmat); |
---|
886 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
887 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
---|
888 | else |
---|
889 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
890 | web([helpfile '#set_object']) |
---|
891 | end |
---|
892 | |
---|
893 | |
---|
894 | |
---|