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 | % INPUT: |
---|
10 | % data: structure describing the object properties |
---|
11 | % .Style=... |
---|
12 | % .ProjMode |
---|
13 | % .CoordType: 'phys' or 'px' |
---|
14 | % .num_DX,.num_DY,.num_DZ : mesh along each dirction |
---|
15 | % .RangeX, RangeY |
---|
16 | % .Coord(j,i), i=1, 2, 3, components x, y, z of j=1...n position(s) characterizing the object components |
---|
17 | % PlotHandles: handles for projection plots NO MORE USED |
---|
18 | % Zbounds: bounds on Z ( 3D case) |
---|
19 | % |
---|
20 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
21 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
22 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
23 | % This file is part of the toolbox UVMAT. |
---|
24 | % |
---|
25 | % UVMAT is free software; you can redistribute it and/or modify |
---|
26 | % it under the terms of the GNU General Public License as published by |
---|
27 | % the Free Software Foundation; either version 2 of the License, or |
---|
28 | % (at your option) any later version. |
---|
29 | % |
---|
30 | % UVMAT is distributed in the hope that it will be useful, |
---|
31 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
32 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
33 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
34 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
35 | |
---|
36 | function varargout = set_object(varargin) |
---|
37 | |
---|
38 | % Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47 |
---|
39 | |
---|
40 | % Begin initialization code - DO NOT PLOT |
---|
41 | gui_Singleton = 1; |
---|
42 | gui_State = struct('gui_Name', mfilename, ... |
---|
43 | 'gui_Singleton', gui_Singleton, ... |
---|
44 | 'gui_OpeningFcn', @set_object_OpeningFcn, ... |
---|
45 | 'gui_OutputFcn', @set_object_OutputFcn, ... |
---|
46 | 'gui_LayoutFcn', [] , ... |
---|
47 | 'gui_Callback', []); |
---|
48 | if nargin & ischar(varargin{1}) |
---|
49 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
50 | end |
---|
51 | |
---|
52 | if nargout |
---|
53 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
54 | else |
---|
55 | gui_mainfcn(gui_State, varargin{:}); |
---|
56 | end |
---|
57 | % End initialization code - DO NOT PLOT |
---|
58 | %------------------------------------------------------------------------ |
---|
59 | %------------------------------------------------------------------------ |
---|
60 | % --- Executes just before set_object is made visible. |
---|
61 | %INPUT: |
---|
62 | % handles: handles of the set_object interface elements |
---|
63 | %'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify |
---|
64 | % if =[] or absent: index still undefined (create mode in uvmat) |
---|
65 | % if=0; no associated object (used for series), the button 'PLOT' is then unvisible |
---|
66 | %'data': read from an existing object selected in the interface |
---|
67 | % .Name : class of object ('POINTS','LINE',....) |
---|
68 | % .num_DX,num_DY,num_DZ; meshes for regular grids |
---|
69 | % .Coord: object position coordinates |
---|
70 | % .ParentButton: handle of the uicontrol object calling the interface |
---|
71 | % PlotHandles: set of handles of the elements contolling the plotting of the projected field: |
---|
72 | % if =[] or absent, no plot (mask mode in uvmat) |
---|
73 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
74 | function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds) |
---|
75 | %------------------------------------------------------------------- |
---|
76 | % Choose default command line output for set_object |
---|
77 | handles.output = hObject; |
---|
78 | % Update handles structure |
---|
79 | guidata(hObject, handles); |
---|
80 | |
---|
81 | %default |
---|
82 | if ~exist('ZBounds','var') |
---|
83 | ZBounds=0; %default |
---|
84 | end |
---|
85 | set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front) |
---|
86 | set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function |
---|
87 | set(hObject,'DeleteFcn',{@closefcn}) |
---|
88 | |
---|
89 | % fill the interface as set in the input data: |
---|
90 | if exist('data','var') |
---|
91 | if isfield(data,'Coord') &&size(data.Coord,2)==3 |
---|
92 | set(handles.z_slider,'Visible','on') |
---|
93 | else |
---|
94 | set(handles.z_slider,'Visible','off') |
---|
95 | end |
---|
96 | if isfield(data,'TypeMenu') |
---|
97 | set(handles.Type,'String',data.TypeMenu) |
---|
98 | end |
---|
99 | if isfield(data,'ProjModeMenu') |
---|
100 | set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback) |
---|
101 | end |
---|
102 | errormsg=fill_GUI(data,handles); |
---|
103 | if ~isempty(errormsg) |
---|
104 | msgbox_uvmat('ERROR','bad data input in set_object') |
---|
105 | return |
---|
106 | end |
---|
107 | Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type |
---|
108 | |
---|
109 | if isfield(data,'RangeZ') && length(ZBounds) >= 2 |
---|
110 | set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3)) |
---|
111 | DZ=max(data.RangeZ);%slider step |
---|
112 | if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1) |
---|
113 | rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1 |
---|
114 | rel_step(2)=0.1; |
---|
115 | set(handles.z_slider,'Visible','on') |
---|
116 | set(handles.z_slider,'Min',ZBounds(1)) |
---|
117 | set(handles.z_slider,'Max',ZBounds(2)) |
---|
118 | set(handles.z_slider,'SliderStep',rel_step) |
---|
119 | set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2) |
---|
120 | end |
---|
121 | end |
---|
122 | if isfield(data,'RangeX') |
---|
123 | if ischar(data.RangeX) |
---|
124 | data.RangeX=str2num(data.RangeX); |
---|
125 | end |
---|
126 | set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3)) |
---|
127 | set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3)) |
---|
128 | end |
---|
129 | if isfield(data,'RangeY') |
---|
130 | if ischar(data.RangeY) |
---|
131 | data.RangeY=str2num(data.RangeY); |
---|
132 | end |
---|
133 | set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3)) |
---|
134 | set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3)) |
---|
135 | end |
---|
136 | if isfield(data,'RangeZ') |
---|
137 | if ischar(data.RangeZ) |
---|
138 | data.RangeZ=str2num(data.RangeZ); |
---|
139 | end |
---|
140 | set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3)) |
---|
141 | if numel(data.RangeZ)>=2 |
---|
142 | set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3)) |
---|
143 | end |
---|
144 | end |
---|
145 | if isfield(data,'Angle') && isequal(numel(data.Angle),3) |
---|
146 | set(handles.num_Angle_1,'String',num2str(data.Angle(1))) |
---|
147 | set(handles.num_Angle_2,'String',num2str(data.Angle(2))) |
---|
148 | set(handles.num_Angle_3,'String',num2str(data.Angle(3))) |
---|
149 | end |
---|
150 | end |
---|
151 | % if enable_plot |
---|
152 | % set(handles.PLOT,'enable','on') |
---|
153 | % else |
---|
154 | % enable the PLOT (REFRESH) button by default |
---|
155 | set(handles.PLOT,'enable','off') |
---|
156 | % end |
---|
157 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
158 | UvData=get(huvmat,'UserData'); |
---|
159 | pos_uvmat=get(huvmat,'Position'); |
---|
160 | %position the set_object GUI with respect to uvmat |
---|
161 | if isfield(UvData,'SetObjectOrigin') |
---|
162 | pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2); |
---|
163 | pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); |
---|
164 | set(hObject,'Position',pos_set_object) |
---|
165 | end |
---|
166 | |
---|
167 | %------------------------------------------------------------------------ |
---|
168 | % --- Outputs from this function are returned to the command line. |
---|
169 | function varargout = set_object_OutputFcn(hObject, eventdata, handles) |
---|
170 | %------------------------------------------------------------------------ |
---|
171 | % Get default command line output from handles structure |
---|
172 | varargout{1} = handles.output; |
---|
173 | varargout{2}=handles; |
---|
174 | |
---|
175 | %------------------------------------------------------------------------ |
---|
176 | % executed when closing the GUI set_object |
---|
177 | function closefcn(gcbo,eventdata) |
---|
178 | %------------------------------------------------------------------------ |
---|
179 | huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle |
---|
180 | if ~isempty(huvmat) |
---|
181 | hhuvmat=guidata(huvmat); |
---|
182 | set(hhuvmat.ViewObject_1,'value',0)% desactivate the two view buttons |
---|
183 | set(hhuvmat.ViewObject,'value',0)% |
---|
184 | set(hhuvmat.edit_object,'Value',0)% desactivate the edit option |
---|
185 | set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree |
---|
186 | % deselect the object in ListObject when view_field is closed |
---|
187 | if isempty(findobj(allchild(0),'Tag','view_field')) |
---|
188 | ObjIndex=get(hhuvmat.ListObject,'Value'); |
---|
189 | ObjIndex=ObjIndex(1);%keep only the first object selected |
---|
190 | set(hhuvmat.ListObject,'Value',ObjIndex) |
---|
191 | % draw all object colors in blue (unselected) in uvmat |
---|
192 | hother=[findobj(hhuvmat.axes3,'Tag','proj_object');findobj(hhuvmat.axes3,'Tag','DeformPoint')];%find all the proj object and deform point representations |
---|
193 | for iobj=1:length(hother) |
---|
194 | if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch') |
---|
195 | set(hother(iobj),'EdgeColor','b') |
---|
196 | if isequal(get(hother(iobj),'FaceColor'),'m') |
---|
197 | set(hother(iobj),'FaceColor','b') |
---|
198 | end |
---|
199 | elseif isequal(get(hother(iobj),'Type'),'image') |
---|
200 | Acolor=get(hother(iobj),'CData'); |
---|
201 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
202 | set(hother(iobj),'CData',Acolor); |
---|
203 | else |
---|
204 | set(hother(iobj),'Color','b') |
---|
205 | end |
---|
206 | set(hother(iobj),'Selected','off') |
---|
207 | end |
---|
208 | end |
---|
209 | end |
---|
210 | hseries=findobj(allchild(0),'Name','series');%find the current series interface handle |
---|
211 | if ~isempty(hseries) |
---|
212 | hhseries=guidata(hseries); |
---|
213 | set(hhseries.GetObject,'Value',0) |
---|
214 | set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
215 | end |
---|
216 | |
---|
217 | |
---|
218 | %------------------------------------------------------------------------ |
---|
219 | % --- Executes on selection change in Type. |
---|
220 | function Type_Callback(hObject, eventdata, handles) |
---|
221 | %------------------------------------------------------------------------ |
---|
222 | %style_prev=get(handles.Type,'UserData');%previous object style |
---|
223 | ListType=get(handles.Type,'String'); |
---|
224 | Type=ListType{get(handles.Type,'Value')}; |
---|
225 | % make correspondance between different object styles |
---|
226 | Coord=get(handles.Coord,'Data'); |
---|
227 | |
---|
228 | %% set the number of lines in the Coord table depending on object type |
---|
229 | switch Type |
---|
230 | case{'line'} |
---|
231 | if size(Coord,1)<2 |
---|
232 | if isequal(size(Coord,2),3) |
---|
233 | Coord=[Coord; 0 0 0];%add a line for edition (3D case) |
---|
234 | else |
---|
235 | Coord=[Coord; 0 0]; %add a line for edition (2D case) |
---|
236 | end |
---|
237 | else |
---|
238 | Coord=Coord(1:2,:); |
---|
239 | end |
---|
240 | case{'rectangle','ellipse','plane','volume'} |
---|
241 | Coord=Coord(1,:); |
---|
242 | end |
---|
243 | set(handles.Coord,'Data',Coord) |
---|
244 | |
---|
245 | %% set the projection menu and the corresponding options |
---|
246 | if isempty(get(handles.ProjMode,'UserData')) |
---|
247 | switch Type |
---|
248 | case {'points','line','polyline','plane'} |
---|
249 | menu_proj={'projection';'interp';'filter';'none'}; |
---|
250 | case {'polygon','rectangle','ellipse'} |
---|
251 | menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; |
---|
252 | case 'volume' |
---|
253 | menu_proj={'interp';'none'}; |
---|
254 | otherwise |
---|
255 | menu_proj={'projection';'interp';'filter';'none'};%default |
---|
256 | end |
---|
257 | else |
---|
258 | menu_proj=get(handles.ProjMode,'UserData'); |
---|
259 | end |
---|
260 | ProjModeList=get(handles.ProjMode,'String'); |
---|
261 | menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj)); |
---|
262 | if isempty(menu_index) |
---|
263 | menu_index=1;% |
---|
264 | end |
---|
265 | set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length |
---|
266 | set(handles.ProjMode,'String',menu_proj) |
---|
267 | ProjMode_Callback(hObject, eventdata, handles) |
---|
268 | |
---|
269 | %------------------------------------------------------------------------ |
---|
270 | % --- Executes on selection change in ProjMode. |
---|
271 | function ProjMode_Callback(hObject, eventdata, handles) |
---|
272 | menu=get(handles.ProjMode,'String'); |
---|
273 | value=get(handles.ProjMode,'Value'); |
---|
274 | ProjMode=menu{value}; |
---|
275 | menu=get(handles.Type,'String'); |
---|
276 | value=get(handles.Type,'Value'); |
---|
277 | ObjectStyle=menu{value}; |
---|
278 | %%%%%%%%% TODO |
---|
279 | test3D=0; %TODO: update test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case |
---|
280 | %%%%%%%%% |
---|
281 | %default setting |
---|
282 | set(handles.num_Angle_1,'Visible','off') |
---|
283 | set(handles.num_Angle_2,'Visible','off') |
---|
284 | set(handles.num_Angle_3,'Visible','off') |
---|
285 | set(handles.num_RangeX_1,'Visible','off') |
---|
286 | set(handles.num_RangeX_2,'Visible','off') |
---|
287 | set(handles.num_RangeY_1,'Visible','off') |
---|
288 | if isequal(ProjMode,'interp') |
---|
289 | set(handles.num_RangeY_2,'Visible','off') |
---|
290 | else |
---|
291 | set(handles.num_RangeY_2,'Visible','on') |
---|
292 | end |
---|
293 | if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse') |
---|
294 | set(handles.num_RangeX_2,'Visible','on') |
---|
295 | else |
---|
296 | set(handles.num_RangeX_2,'Visible','off') |
---|
297 | end |
---|
298 | set(handles.num_RangeZ_1,'Visible','off') |
---|
299 | set(handles.num_RangeZ_2,'Visible','off') |
---|
300 | set(handles.num_DX,'Visible','off') |
---|
301 | set(handles.num_DY,'Visible','off') |
---|
302 | set(handles.num_DZ,'Visible','off') |
---|
303 | |
---|
304 | switch ObjectStyle |
---|
305 | case 'points' |
---|
306 | set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point') |
---|
307 | % set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points') |
---|
308 | % set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points') |
---|
309 | % set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points') |
---|
310 | case {'line','polyline','polygon'} |
---|
311 | set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line') |
---|
312 | set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line') |
---|
313 | % set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line') |
---|
314 | % set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line') |
---|
315 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
316 | set(handles.num_DX,'Visible','on') |
---|
317 | set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line') |
---|
318 | end |
---|
319 | case {'rectangle','ellipse'} |
---|
320 | set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle]) |
---|
321 | set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle]) |
---|
322 | % set(handles.XObject,'TooltipString',['XObject: x coordinate of the ' Type ' centre']) |
---|
323 | % set(handles.YObject,'TooltipString',['YObject: y coordinate of the ' Type ' centre']) |
---|
324 | case {'plane'} |
---|
325 | set(handles.num_Angle_3,'Visible','on') |
---|
326 | set(handles.num_RangeX_1,'Visible','on') |
---|
327 | set(handles.num_RangeX_2,'Visible','on') |
---|
328 | set(handles.num_RangeY_1,'Visible','on') |
---|
329 | set(handles.num_RangeY_2,'Visible','on') |
---|
330 | % set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' Type]) |
---|
331 | % set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' Type]) |
---|
332 | set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane') |
---|
333 | if test3D |
---|
334 | set(handles.num_Angle_2,'Visible','on') |
---|
335 | set(handles.num_Angle_1,'Visible','on') |
---|
336 | set(handles.num_RangeZ_2,'Visible','on') |
---|
337 | end |
---|
338 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
339 | set(handles.num_DX,'Visible','on') |
---|
340 | set(handles.num_DY,'Visible','on') |
---|
341 | else |
---|
342 | set(handles.num_DX,'Visible','off') |
---|
343 | set(handles.num_DY,'Visible','off') |
---|
344 | end |
---|
345 | if isequal(ProjMode,'interp') |
---|
346 | set(handles.num_DZ,'Visible','on') |
---|
347 | end |
---|
348 | case {'volume'} |
---|
349 | set(handles.num_RangeX_1,'Visible','on') |
---|
350 | set(handles.num_RangeX_2,'Visible','on') |
---|
351 | set(handles.num_RangeY_1,'Visible','on') |
---|
352 | set(handles.num_RangeY_2,'Visible','on') |
---|
353 | set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' ObjectStyle]) |
---|
354 | set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' ObjectStyle]) |
---|
355 | set(handles.num_Angle_1,'Visible','on') |
---|
356 | set(handles.num_Angle_2,'Visible','on') |
---|
357 | set(handles.num_Angle_3,'Visible','on') |
---|
358 | set(handles.num_RangeZ_1,'Visible','on') |
---|
359 | set(handles.num_RangeZ_2,'Visible','on') |
---|
360 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
361 | set(handles.num_DX,'Visible','on') |
---|
362 | set(handles.num_DY,'Visible','on') |
---|
363 | set(handles.num_DZ,'Visible','on') |
---|
364 | else |
---|
365 | set(handles.num_DX,'Visible','off') |
---|
366 | set(handles.num_DY,'Visible','off') |
---|
367 | set(handles.num_DZ,'Visible','off') |
---|
368 | end |
---|
369 | end |
---|
370 | %------------------------------------------------------------------------ |
---|
371 | |
---|
372 | %------------------------------------------------------------------------ |
---|
373 | function num_Angle_1_Callback(hObject, eventdata, handles) |
---|
374 | update_slider(hObject, eventdata,handles) |
---|
375 | %------------------------------------------------------------------------ |
---|
376 | %------------------------------------------------------------------------ |
---|
377 | function num_Angle_2_Callback(hObject, eventdata, handles) |
---|
378 | update_slider(hObject, eventdata,handles) |
---|
379 | %------------------------------------------------------------------------ |
---|
380 | function update_slider(hObject, eventdata,handles) |
---|
381 | %rotation angles |
---|
382 | PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first angle in degrees |
---|
383 | PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second angle in degrees |
---|
384 | PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second angle in degrees |
---|
385 | om=norm(PlaneAngle);%norm of rotation angle in radians |
---|
386 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis |
---|
387 | cos_om=cos(pi*om/180); |
---|
388 | sin_om=sin(pi*om/180); |
---|
389 | coeff=OmAxis(3)*(1-cos_om); |
---|
390 | %components of the unity vector norm_plane normal to the projection plane |
---|
391 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; |
---|
392 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; |
---|
393 | norm_plane(3)=OmAxis(3)*coeff+cos_om; |
---|
394 | huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle |
---|
395 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
396 | if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z') |
---|
397 | Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z); |
---|
398 | set(handles.z_slider,'Min',min(Z)) |
---|
399 | set(handles.z_slider,'Max',max(Z)) |
---|
400 | ZMax_Callback(hObject, eventdata, handles) |
---|
401 | end |
---|
402 | %------------------------------------------------------------------------ |
---|
403 | function num_DX_Callback(hObject, eventdata, handles) |
---|
404 | %------------------------------------------------------------------------ |
---|
405 | %------------------------------------------------------------------------ |
---|
406 | function num_DY_Callback(hObject, eventdata, handles) |
---|
407 | %------------------------------------------------------------------------ |
---|
408 | %------------------------------------------------------------------------ |
---|
409 | function num_DZ_Callback(hObject, eventdata, handles) |
---|
410 | %------------------------------------------------------------------------ |
---|
411 | |
---|
412 | |
---|
413 | %------------------------------------------------------------------------ |
---|
414 | % --- Executes on button press in PLOT: PLOT the defined object and its projected field |
---|
415 | function PLOT_Callback(hObject, eventdata, handles) |
---|
416 | |
---|
417 | %% read the object parameters in the GUI set_object |
---|
418 | ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object |
---|
419 | if iscell(ObjectData.Coord)%check for empty line |
---|
420 | ObjectData.Coord=[0 0 0]; |
---|
421 | hhset_object=guidata(handles.set_object); |
---|
422 | set(hhset_object.Coord,'Data',ObjectData.Coord) |
---|
423 | end |
---|
424 | checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines |
---|
425 | if ~isempty(checknan) |
---|
426 | ObjectData.Coord(checknan,:)=[];%remove the NaN lines |
---|
427 | end |
---|
428 | ObjectName=ObjectData.Name;%name of the current object defined in set_object |
---|
429 | if isempty(ObjectName) |
---|
430 | ObjectName=ObjectData.Type; |
---|
431 | end |
---|
432 | |
---|
433 | %% read the object selection in the GUI uvmat |
---|
434 | huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle |
---|
435 | UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat |
---|
436 | hhuvmat=guidata(huvmat);%handles of the objects children of the GUI uvmat |
---|
437 | ListObject=get(hhuvmat.ListObject_1,'String');% list of objects displayed in uvmat |
---|
438 | IndexObj(1)=get(hhuvmat.ListObject_1,'Value');% index of the selected object for display in uvmat |
---|
439 | if get(hhuvmat.ViewObject,'Value') && get(hhuvmat.edit_object,'Value') |
---|
440 | IndexObj(2)=get(hhuvmat.ListObject,'Value');% index of the object, possibly selected for display in view_field |
---|
441 | end |
---|
442 | if ~get(hhuvmat.edit_object,'Value') %new object is being created |
---|
443 | detectname=1; |
---|
444 | ObjectNameNew=ObjectName; |
---|
445 | vers=0;% index of the name |
---|
446 | while detectname==1 |
---|
447 | detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list |
---|
448 | if detectname% if the object name already exists |
---|
449 | indstr=regexp(ObjectNameNew,'\D'); |
---|
450 | if indstr(end)<length(ObjectNameNew) %object name ends by a number |
---|
451 | vers=str2double(ObjectNameNew(indstr(end)+1:end))+1; |
---|
452 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)]; |
---|
453 | else |
---|
454 | vers=vers+1; |
---|
455 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]; |
---|
456 | end |
---|
457 | end |
---|
458 | end |
---|
459 | ObjectName=ObjectNameNew; |
---|
460 | set(handles.Name,'String',ObjectName)% display the default name in set_object |
---|
461 | IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat |
---|
462 | set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list |
---|
463 | set(hhuvmat.ListObject_1,'String',[ListObject;{ObjectName}]);%complement the object list |
---|
464 | set(hhuvmat.ListObject,'Value',IndexObj(2)) |
---|
465 | UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet) |
---|
466 | end |
---|
467 | |
---|
468 | %% naming the object |
---|
469 | % ListObject{IndexObj(end),1}=ObjectName; |
---|
470 | % set(hhuvmat.ListObject,'String',ListObject) |
---|
471 | % set(hhuvmat.ListObject_1,'String',ListObject) |
---|
472 | |
---|
473 | %% update the object plot |
---|
474 | if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles |
---|
475 | ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat; |
---|
476 | else |
---|
477 | ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input |
---|
478 | end |
---|
479 | if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles |
---|
480 | ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field; |
---|
481 | else |
---|
482 | ObjectData.DisplayHandle_view_field=[]; |
---|
483 | end |
---|
484 | UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties |
---|
485 | if numel(IndexObj)==2 |
---|
486 | UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2)); |
---|
487 | end |
---|
488 | set(huvmat,'UserData',UvData) |
---|
489 | |
---|
490 | %% plot the field projected on the object |
---|
491 | if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none') |
---|
492 | PlotType='text'; |
---|
493 | else |
---|
494 | [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData |
---|
495 | if ~isempty(errormsg) |
---|
496 | msgbox_uvmat('ERROR', errormsg) |
---|
497 | return |
---|
498 | end |
---|
499 | if numel(IndexObj)==1 % if only one object is selected, the projection is in uvmat |
---|
500 | % plotaxes=hhuvmat.axes3;%handle of axes3 in view_field |
---|
501 | PlotType=plot_field(ProjData,hhuvmat.axes3,read_GUI(get(hhuvmat.axes3,'parent')));%update the current uvmat plot |
---|
502 | else % if a second object is selected, the projection is in view_field, and this second object is selected |
---|
503 | hview_field=findobj(allchild(0),'tag','view_field'); |
---|
504 | if isempty(hview_field) |
---|
505 | PlotType=view_field(ProjData); %open the view_field GUI for plot |
---|
506 | % hview_field=view_field;%open the GUI view_field if it is not found |
---|
507 | else |
---|
508 | hhview_field=guidata(hview_field); |
---|
509 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.axes3,read_GUI(hview_field));%update an existing plot in view_field |
---|
510 | write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object |
---|
511 | end |
---|
512 | % PlotHandles=guidata(hview_field); |
---|
513 | % plotaxes=PlotHandles.axes3;%handle of axes3 in view_field |
---|
514 | end |
---|
515 | % fighandle=get(plotaxes,'parent'); |
---|
516 | % PlotParam=read_GUI(fighandle); |
---|
517 | % PlotType=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot |
---|
518 | end |
---|
519 | if strcmp(PlotType,'text') |
---|
520 | hview_field=findobj(allchild(0),'tag','view_field'); %case of no projection (pure object display) |
---|
521 | if ~isempty(hview_field) |
---|
522 | delete(hview_field) |
---|
523 | end |
---|
524 | end |
---|
525 | |
---|
526 | %% update the GUI uvmat |
---|
527 | hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI |
---|
528 | set(hhuvmat.MenuEditObject,'enable','on') |
---|
529 | set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update |
---|
530 | set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow |
---|
531 | |
---|
532 | %------------------------------------------------------------------------ |
---|
533 | % --- Executes on button press in MenuCoord. |
---|
534 | function MenuCoord_Callback(hObject, eventdata, handles) |
---|
535 | %------------------------------------------------------------------------ |
---|
536 | %---------------------------------------------------- |
---|
537 | function num_RangeY_1_Callback(hObject, eventdata, handles) |
---|
538 | %------------------------------------------------------------------------ |
---|
539 | |
---|
540 | function num_RangeZ_1_Callback(hObject, eventdata, handles) |
---|
541 | %------------------------------------------------------------------------ |
---|
542 | |
---|
543 | function num_RangeZ_2_Callback(hObject, eventdata, handles) |
---|
544 | DZ=str2num(get(handles.num_RangeZ_2,'String')); |
---|
545 | ZMin=get(handles.z_slider,'Min'); |
---|
546 | ZMax=get(handles.z_slider,'Max'); |
---|
547 | if ~isequal(ZMax-ZMin,0) |
---|
548 | rel_step(1)=DZ/(ZMax-ZMin); |
---|
549 | rel_step(2)=0.2; |
---|
550 | set(handles.z_slider,'SliderStep',rel_step) |
---|
551 | end |
---|
552 | %------------------------------------------------------------------------ |
---|
553 | function num_RangeY_2_Callback(hObject, eventdata, handles) |
---|
554 | %------------------------------------------------------------------------ |
---|
555 | |
---|
556 | function num_RangeX_1_Callback(hObject, eventdata, handles) |
---|
557 | %------------------------------------------------------------------------ |
---|
558 | |
---|
559 | function num_RangeX_2_Callback(hObject, eventdata, handles) |
---|
560 | %------------------------------------------------------------------------ |
---|
561 | %------------------------------------------------------------------------ |
---|
562 | function SAVE_Callback(hObject, eventdata, handles) |
---|
563 | % ------------------------------------------------------ |
---|
564 | %Object=read_set_object(handles); |
---|
565 | Object=read_GUI(handles.set_object); |
---|
566 | huvmat=findobj('Tag','uvmat'); |
---|
567 | % UvData=get(huvmat,'UserData'); |
---|
568 | if isempty(huvmat) |
---|
569 | huvmat=findobj(allchild(0),'Name','series'); |
---|
570 | end |
---|
571 | hchild=get(huvmat,'Children'); |
---|
572 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
573 | if isempty(hrootpath) |
---|
574 | RootPath=''; |
---|
575 | else |
---|
576 | RootPath=get(hrootpath,'String'); |
---|
577 | if iscell(RootPath) |
---|
578 | RootPath=RootPath{1}; |
---|
579 | end |
---|
580 | end |
---|
581 | title={'object name'}; |
---|
582 | dir_save=uigetdir(RootPath); |
---|
583 | ObjectName=get(handles.Name,'String'); |
---|
584 | if ~isempty(ObjectName)&&~strcmp(ObjectName,'') |
---|
585 | def={fullfile(dir_save,[ObjectName '.xml'])}; |
---|
586 | else |
---|
587 | def={fullfile(dir_save,[Object.Style '.xml'])}; |
---|
588 | end |
---|
589 | displ_txt='save object as an .xml file';%default display |
---|
590 | menu=get(handles.ProjMode,'String'); |
---|
591 | value=get(handles.ProjMode,'Value'); |
---|
592 | ProjMode=menu{value}; |
---|
593 | if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside') |
---|
594 | displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)'; |
---|
595 | end |
---|
596 | answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def); |
---|
597 | if ~isempty(answer) |
---|
598 | t=struct2xml(Object); |
---|
599 | save(t,answer{1}) |
---|
600 | end |
---|
601 | msgbox_uvmat('CONFIRMATION',[answer{1} ' saved']) |
---|
602 | |
---|
603 | %------------------------------------------------------------------------ |
---|
604 | % --- Executes on slider movement. |
---|
605 | function z_slider_Callback(hObject, eventdata, handles) |
---|
606 | %--------------------------------------------------------- |
---|
607 | Z_value=get(handles.z_slider,'Value'); |
---|
608 | %rotation angles |
---|
609 | PlaneAngle=[0 0 0]; |
---|
610 | norm_plane=[0 0 1]; |
---|
611 | cos_om=1; |
---|
612 | sin_om=0; |
---|
613 | |
---|
614 | PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first angle in degrees |
---|
615 | PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second angle in degrees |
---|
616 | PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second angle in degrees |
---|
617 | PlaneAngle=(pi/180)*PlaneAngle; |
---|
618 | om=norm(PlaneAngle);%norm of rotation angle in radians |
---|
619 | if isequal(om,0) |
---|
620 | norm_plane=[0 0 1]; |
---|
621 | else |
---|
622 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis |
---|
623 | cos_om=cos(om); |
---|
624 | sin_om=sin(om); |
---|
625 | coeff=OmAxis(3)*(1-cos_om); |
---|
626 | %components of the unity vector norm_plane normal to the projection plane |
---|
627 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; |
---|
628 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; |
---|
629 | norm_plane(3)=OmAxis(3)*coeff+cos_om; |
---|
630 | end |
---|
631 | |
---|
632 | % update graph |
---|
633 | PLOT_Callback(hObject, eventdata, handles) |
---|
634 | |
---|
635 | %------------------------------------------------------------------------ |
---|
636 | % --- Executes on button press in HELP. |
---|
637 | function HELP_Callback(hObject, eventdata, handles) |
---|
638 | %------------------------------------------------------------------------ |
---|
639 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
640 | pathelp=fileparts(path_to_uvmat); |
---|
641 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
642 | 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') |
---|
643 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
644 | web([helpfile '#set_object']) |
---|
645 | end |
---|
646 | %------------------------------------------------------------------------ |
---|
647 | |
---|
648 | function Name_Callback(hObject, eventdata, handles) |
---|
649 | % hObject handle to Name (see GCBO) |
---|
650 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
651 | % handles structure with handles and user data (see GUIDATA) |
---|
652 | |
---|
653 | % Hints: get(hObject,'String') returns contents of Name as text |
---|
654 | % str2double(get(hObject,'String')) returns contents of Name as a double |
---|
655 | |
---|
656 | %------------------------------------------------------------------------ |
---|
657 | % --- Executes when entered data in editable cell(s) in Coord. |
---|
658 | function Coord_CellEditCallback(hObject, eventdata, handles) |
---|
659 | %------------------------------------------------------------------------ |
---|
660 | ListType=get(handles.Type,'String'); |
---|
661 | Type=ListType{get(handles.Type,'Value')}; |
---|
662 | switch Type |
---|
663 | % add lines if multi line input needed |
---|
664 | case{'points','polyline','polygon'} |
---|
665 | Coord=get(handles.Coord,'Data'); |
---|
666 | if ~isnan(Coord(end,1)) |
---|
667 | if isequal(size(Coord,2),3) |
---|
668 | %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case) |
---|
669 | Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case) |
---|
670 | else |
---|
671 | Coord=[Coord;NaN NaN]; %add a line for edition (2D case) |
---|
672 | end |
---|
673 | set(handles.Coord,'Data',Coord) |
---|
674 | end |
---|
675 | end |
---|
676 | |
---|
677 | |
---|
678 | |
---|
679 | function num_Angle_3_Callback(hObject, eventdata, handles) |
---|
680 | % hObject handle to num_Angle_3 (see GCBO) |
---|
681 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
682 | % handles structure with handles and user data (see GUIDATA) |
---|
683 | |
---|
684 | % Hints: get(hObject,'String') returns contents of num_Angle_3 as text |
---|
685 | % str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double |
---|