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:u |
---|
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 | %defaul settings |
---|
156 | set(get(handles.set_object,'children'),'enable','on') |
---|
157 | set(handles.PLOT,'enable','off') |
---|
158 | % end |
---|
159 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
160 | UvData=get(huvmat,'UserData'); |
---|
161 | pos_uvmat=get(huvmat,'Position'); |
---|
162 | %position the set_object GUI with respect to uvmat |
---|
163 | if isfield(UvData,'SetObjectOrigin') |
---|
164 | pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2); |
---|
165 | pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); |
---|
166 | set(hObject,'Position',pos_set_object) |
---|
167 | end |
---|
168 | |
---|
169 | %------------------------------------------------------------------------ |
---|
170 | % --- Outputs from this function are returned to the command line. |
---|
171 | function varargout = set_object_OutputFcn(hObject, eventdata, handles) |
---|
172 | %------------------------------------------------------------------------ |
---|
173 | % Get default command line output from handles structure |
---|
174 | varargout{1} = handles.output; |
---|
175 | varargout{2}=handles; |
---|
176 | |
---|
177 | %------------------------------------------------------------------------ |
---|
178 | % executed when closing the GUI set_object |
---|
179 | function closefcn(gcbo,eventdata) |
---|
180 | %------------------------------------------------------------------------ |
---|
181 | huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle |
---|
182 | if ~isempty(huvmat) |
---|
183 | hhuvmat=guidata(huvmat); |
---|
184 | % set(hhuvmat.ViewObject_1,'value',0)% desactivate the two view buttons |
---|
185 | set(hhuvmat.ViewObject,'value',0)% |
---|
186 | set(hhuvmat.edit_object,'Value',0)% desactivate the edit option |
---|
187 | set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree |
---|
188 | % deselect the object in ListObject when view_field is closed |
---|
189 | if isempty(findobj(allchild(0),'Tag','view_field')) |
---|
190 | ObjIndex=get(hhuvmat.ListObject,'Value'); |
---|
191 | ObjIndex=ObjIndex(1);%keep only the first object selected |
---|
192 | set(hhuvmat.ListObject,'Value',ObjIndex) |
---|
193 | % draw all object colors in blue (unselected) in uvmat |
---|
194 | hother=[findobj(hhuvmat.axes3,'Tag','proj_object');findobj(hhuvmat.axes3,'Tag','DeformPoint')];%find all the proj object and deform point representations |
---|
195 | for iobj=1:length(hother) |
---|
196 | if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch') |
---|
197 | set(hother(iobj),'EdgeColor','b') |
---|
198 | if isequal(get(hother(iobj),'FaceColor'),'m') |
---|
199 | set(hother(iobj),'FaceColor','b') |
---|
200 | end |
---|
201 | elseif isequal(get(hother(iobj),'Type'),'image') |
---|
202 | Acolor=get(hother(iobj),'CData'); |
---|
203 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
204 | set(hother(iobj),'CData',Acolor); |
---|
205 | else |
---|
206 | set(hother(iobj),'Color','b') |
---|
207 | end |
---|
208 | set(hother(iobj),'Selected','off') |
---|
209 | end |
---|
210 | end |
---|
211 | end |
---|
212 | hseries=findobj(allchild(0),'Name','series');%find the current series interface handle |
---|
213 | if ~isempty(hseries) |
---|
214 | hhseries=guidata(hseries); |
---|
215 | set(hhseries.GetObject,'Value',0) |
---|
216 | set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green |
---|
217 | end |
---|
218 | |
---|
219 | |
---|
220 | %------------------------------------------------------------------------ |
---|
221 | % --- Executes on selection change in Type. |
---|
222 | function Type_Callback(hObject, eventdata, handles) |
---|
223 | %------------------------------------------------------------------------ |
---|
224 | %style_prev=get(handles.Type,'UserData');%previous object style |
---|
225 | ListType=get(handles.Type,'String'); |
---|
226 | Type=ListType{get(handles.Type,'Value')}; |
---|
227 | % make correspondance between different object styles |
---|
228 | Coord=get(handles.Coord,'Data'); |
---|
229 | |
---|
230 | %% set the number of lines in the Coord table depending on object type |
---|
231 | switch Type |
---|
232 | case{'line'} |
---|
233 | if size(Coord,1)<2 |
---|
234 | if isequal(size(Coord,2),3) |
---|
235 | Coord=[Coord; 0 0 0];%add a line for edition (3D case) |
---|
236 | else |
---|
237 | Coord=[Coord; 0 0]; %add a line for edition (2D case) |
---|
238 | end |
---|
239 | else |
---|
240 | Coord=Coord(1:2,:); |
---|
241 | end |
---|
242 | case{'rectangle','ellipse','plane','volume'} |
---|
243 | Coord=Coord(1,:); |
---|
244 | end |
---|
245 | set(handles.Coord,'Data',Coord) |
---|
246 | |
---|
247 | %% set the projection menu and the corresponding options |
---|
248 | if isempty(get(handles.ProjMode,'UserData')) |
---|
249 | switch Type |
---|
250 | case {'points','line','polyline','plane'} |
---|
251 | menu_proj={'projection';'interp';'filter';'none'}; |
---|
252 | case {'polygon','rectangle','ellipse'} |
---|
253 | menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; |
---|
254 | case 'volume' |
---|
255 | menu_proj={'interp';'none'}; |
---|
256 | otherwise |
---|
257 | menu_proj={'projection';'interp';'filter';'none'};%default |
---|
258 | end |
---|
259 | else |
---|
260 | menu_proj=get(handles.ProjMode,'UserData'); |
---|
261 | end |
---|
262 | ProjModeList=get(handles.ProjMode,'String'); |
---|
263 | menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj)); |
---|
264 | if isempty(menu_index) |
---|
265 | menu_index=1;% |
---|
266 | end |
---|
267 | set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length |
---|
268 | set(handles.ProjMode,'String',menu_proj) |
---|
269 | ProjMode_Callback(hObject, eventdata, handles) |
---|
270 | |
---|
271 | %------------------------------------------------------------------------ |
---|
272 | % --- Executes on selection change in ProjMode. |
---|
273 | function ProjMode_Callback(hObject, eventdata, handles) |
---|
274 | menu=get(handles.ProjMode,'String'); |
---|
275 | value=get(handles.ProjMode,'Value'); |
---|
276 | ProjMode=menu{value}; |
---|
277 | menu=get(handles.Type,'String'); |
---|
278 | value=get(handles.Type,'Value'); |
---|
279 | ObjectStyle=menu{value}; |
---|
280 | %%%%%%%%% TODO |
---|
281 | test3D=0; %TODO: update test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case |
---|
282 | %%%%%%%%% |
---|
283 | %default setting |
---|
284 | set(handles.num_Angle_1,'Visible','off') |
---|
285 | set(handles.num_Angle_2,'Visible','off') |
---|
286 | set(handles.num_Angle_3,'Visible','off') |
---|
287 | set(handles.num_RangeX_1,'Visible','off') |
---|
288 | set(handles.num_RangeX_2,'Visible','off') |
---|
289 | set(handles.num_RangeY_1,'Visible','off') |
---|
290 | if isequal(ProjMode,'interp') |
---|
291 | set(handles.num_RangeY_2,'Visible','off') |
---|
292 | else |
---|
293 | set(handles.num_RangeY_2,'Visible','on') |
---|
294 | end |
---|
295 | if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse') |
---|
296 | set(handles.num_RangeX_2,'Visible','on') |
---|
297 | else |
---|
298 | set(handles.num_RangeX_2,'Visible','off') |
---|
299 | end |
---|
300 | set(handles.num_RangeZ_1,'Visible','off') |
---|
301 | set(handles.num_RangeZ_2,'Visible','off') |
---|
302 | set(handles.num_DX,'Visible','off') |
---|
303 | set(handles.num_DY,'Visible','off') |
---|
304 | set(handles.num_DZ,'Visible','off') |
---|
305 | |
---|
306 | switch ObjectStyle |
---|
307 | case 'points' |
---|
308 | set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point') |
---|
309 | % set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points') |
---|
310 | % set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points') |
---|
311 | % set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points') |
---|
312 | case {'line','polyline','polygon'} |
---|
313 | set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line') |
---|
314 | set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line') |
---|
315 | % set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line') |
---|
316 | % set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line') |
---|
317 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
318 | set(handles.num_DX,'Visible','on') |
---|
319 | set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line') |
---|
320 | end |
---|
321 | case {'rectangle','ellipse'} |
---|
322 | set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle]) |
---|
323 | set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle]) |
---|
324 | % set(handles.XObject,'TooltipString',['XObject: x coordinate of the ' Type ' centre']) |
---|
325 | % set(handles.YObject,'TooltipString',['YObject: y coordinate of the ' Type ' centre']) |
---|
326 | case {'plane'} |
---|
327 | set(handles.num_Angle_3,'Visible','on') |
---|
328 | set(handles.num_RangeX_1,'Visible','on') |
---|
329 | set(handles.num_RangeX_2,'Visible','on') |
---|
330 | set(handles.num_RangeY_1,'Visible','on') |
---|
331 | set(handles.num_RangeY_2,'Visible','on') |
---|
332 | % set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' Type]) |
---|
333 | % set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' Type]) |
---|
334 | set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane') |
---|
335 | if test3D |
---|
336 | set(handles.num_Angle_2,'Visible','on') |
---|
337 | set(handles.num_Angle_1,'Visible','on') |
---|
338 | set(handles.num_RangeZ_2,'Visible','on') |
---|
339 | end |
---|
340 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
341 | set(handles.num_DX,'Visible','on') |
---|
342 | set(handles.num_DY,'Visible','on') |
---|
343 | else |
---|
344 | set(handles.num_DX,'Visible','off') |
---|
345 | set(handles.num_DY,'Visible','off') |
---|
346 | end |
---|
347 | if isequal(ProjMode,'interp') |
---|
348 | set(handles.num_DZ,'Visible','on') |
---|
349 | end |
---|
350 | case {'volume'} |
---|
351 | set(handles.num_RangeX_1,'Visible','on') |
---|
352 | set(handles.num_RangeX_2,'Visible','on') |
---|
353 | set(handles.num_RangeY_1,'Visible','on') |
---|
354 | set(handles.num_RangeY_2,'Visible','on') |
---|
355 | set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' ObjectStyle]) |
---|
356 | set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' ObjectStyle]) |
---|
357 | set(handles.num_Angle_1,'Visible','on') |
---|
358 | set(handles.num_Angle_2,'Visible','on') |
---|
359 | set(handles.num_Angle_3,'Visible','on') |
---|
360 | set(handles.num_RangeZ_1,'Visible','on') |
---|
361 | set(handles.num_RangeZ_2,'Visible','on') |
---|
362 | if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter') |
---|
363 | set(handles.num_DX,'Visible','on') |
---|
364 | set(handles.num_DY,'Visible','on') |
---|
365 | set(handles.num_DZ,'Visible','on') |
---|
366 | else |
---|
367 | set(handles.num_DX,'Visible','off') |
---|
368 | set(handles.num_DY,'Visible','off') |
---|
369 | set(handles.num_DZ,'Visible','off') |
---|
370 | end |
---|
371 | end |
---|
372 | %------------------------------------------------------------------------ |
---|
373 | |
---|
374 | %------------------------------------------------------------------------ |
---|
375 | function num_Angle_1_Callback(hObject, eventdata, handles) |
---|
376 | update_slider(hObject, eventdata,handles) |
---|
377 | %------------------------------------------------------------------------ |
---|
378 | %------------------------------------------------------------------------ |
---|
379 | function num_Angle_2_Callback(hObject, eventdata, handles) |
---|
380 | update_slider(hObject, eventdata,handles) |
---|
381 | %------------------------------------------------------------------------ |
---|
382 | function update_slider(hObject, eventdata,handles) |
---|
383 | %rotation angles |
---|
384 | PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first angle in degrees |
---|
385 | PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second angle in degrees |
---|
386 | PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second angle in degrees |
---|
387 | om=norm(PlaneAngle);%norm of rotation angle in radians |
---|
388 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis |
---|
389 | cos_om=cos(pi*om/180); |
---|
390 | sin_om=sin(pi*om/180); |
---|
391 | coeff=OmAxis(3)*(1-cos_om); |
---|
392 | %components of the unity vector norm_plane normal to the projection plane |
---|
393 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; |
---|
394 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; |
---|
395 | norm_plane(3)=OmAxis(3)*coeff+cos_om; |
---|
396 | huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle |
---|
397 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
398 | if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z') |
---|
399 | Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z); |
---|
400 | set(handles.z_slider,'Min',min(Z)) |
---|
401 | set(handles.z_slider,'Max',max(Z)) |
---|
402 | ZMax_Callback(hObject, eventdata, handles) |
---|
403 | end |
---|
404 | %------------------------------------------------------------------------ |
---|
405 | function num_DX_Callback(hObject, eventdata, handles) |
---|
406 | %------------------------------------------------------------------------ |
---|
407 | %------------------------------------------------------------------------ |
---|
408 | function num_DY_Callback(hObject, eventdata, handles) |
---|
409 | %------------------------------------------------------------------------ |
---|
410 | %------------------------------------------------------------------------ |
---|
411 | function num_DZ_Callback(hObject, eventdata, handles) |
---|
412 | %------------------------------------------------------------------------ |
---|
413 | |
---|
414 | |
---|
415 | %------------------------------------------------------------------------ |
---|
416 | % --- Executes on button press in PLOT: refresh the current object , plot the object and its projected field |
---|
417 | function PLOT_Callback(hObject, eventdata, handles) |
---|
418 | |
---|
419 | %% read the object parameters in the GUI set_object |
---|
420 | ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object |
---|
421 | if iscell(ObjectData.Coord)%check for empty line |
---|
422 | ObjectData.Coord=[0 0 0]; |
---|
423 | hhset_object=guidata(handles.set_object); |
---|
424 | set(hhset_object.Coord,'Data',ObjectData.Coord) |
---|
425 | end |
---|
426 | checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines |
---|
427 | if ~isempty(checknan) |
---|
428 | ObjectData.Coord(checknan,:)=[];%remove the NaN lines |
---|
429 | end |
---|
430 | ObjectName=ObjectData.Name;%name of the current object defined in set_object |
---|
431 | if isempty(ObjectName) |
---|
432 | ObjectName=ObjectData.Type;% name the object by the object type type by default |
---|
433 | end |
---|
434 | |
---|
435 | %% read the current object selection in the GUI uvmat |
---|
436 | huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle |
---|
437 | UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat |
---|
438 | hhuvmat=guidata(huvmat);%handles of the objects children of the GUI uvmat |
---|
439 | ListObject=get(hhuvmat.ListObject,'String');% list of objects displayed in uvmat |
---|
440 | IndexObj=get(hhuvmat.ListObject,'Value');% index of the selected object for display in uvmat |
---|
441 | %set or modify(edit mode) the nameof the currently selected object |
---|
442 | detectname=1; |
---|
443 | ObjectNameNew=ObjectName; |
---|
444 | vers=0;% index of the name |
---|
445 | ListOther=ListObject; |
---|
446 | ListOther(IndexObj)=[]; |
---|
447 | while ~isempty(detectname) |
---|
448 | detectname=find(strcmp(ObjectNameNew,ListOther),1);%test the existence of the proposed name in the list |
---|
449 | if detectname% if the object name already exists |
---|
450 | indstr=regexp(ObjectNameNew,'\D');%indices of non number characters |
---|
451 | if indstr(end)<length(ObjectNameNew) %object name ends by a number |
---|
452 | vers=str2double(ObjectNameNew(indstr(end)+1:end))+1; |
---|
453 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)]; |
---|
454 | else |
---|
455 | vers=vers+1; |
---|
456 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]; |
---|
457 | end |
---|
458 | end |
---|
459 | end |
---|
460 | ObjectName=ObjectNameNew; |
---|
461 | set(handles.Name,'String',ObjectName)% display the default name in set_object |
---|
462 | ListObject{IndexObj}=ObjectName; |
---|
463 | set(hhuvmat.ListObject,'String',ListObject);%complement the object list |
---|
464 | set(hhuvmat.ViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object |
---|
465 | check_handle=isfield(UvData.Object{IndexObj},'DisplayHandle') && isfield(UvData.Object{IndexObj}.DisplayHandle,'uvmat')... |
---|
466 | && ~isempty(UvData.Object{IndexObj}.DisplayHandle.uvmat) && ishandle(UvData.Object{IndexObj}.DisplayHandle.uvmat); |
---|
467 | if check_handle |
---|
468 | obj_handle=UvData.Object{IndexObj}.DisplayHandle.uvmat; |
---|
469 | end |
---|
470 | UvData.Object{IndexObj}=ObjectData; |
---|
471 | if check_handle |
---|
472 | UvData.Object{IndexObj}.DisplayHandle.uvmat=obj_handle; %preserve the object plot handle if valid |
---|
473 | else |
---|
474 | UvData.Object{IndexObj}.DisplayHandle.uvmat=hhuvmat.axes3; %axes taken as object display handle by defualt |
---|
475 | end |
---|
476 | set(hhuvmat.edit_object,'Value',1)% set the current object to edit mode |
---|
477 | % %IndexObj=numel(ListObject)+1;% append an object to the list in uvmat |
---|
478 | % |
---|
479 | % set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list |
---|
480 | % set(hhuvmat.ListObject_1,'String',[ListObject;{ObjectName}]);%complement the object list |
---|
481 | % set(hhuvmat.ListObject,'Value',IndexObj) |
---|
482 | % set(hhuvmat.ViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object |
---|
483 | % UvData.Object{IndexObj}=[];%initiate a new object (empty yet) |
---|
484 | % UvData.Object{IndexObj}.DisplayHandle.uvmat=hhuvmat.axes3; %axes taken as object display handle by defualt |
---|
485 | % end |
---|
486 | |
---|
487 | %% plot the field projected on the object |
---|
488 | hview_field=[];%default |
---|
489 | IndexObj_1=get(hhuvmat.ListObject_1,'Value'); |
---|
490 | if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none') |
---|
491 | PlotType='text'; |
---|
492 | else |
---|
493 | [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData |
---|
494 | if ~isempty(errormsg) |
---|
495 | msgbox_uvmat('ERROR', errormsg) |
---|
496 | return |
---|
497 | end |
---|
498 | if isequal(IndexObj_1,IndexObj) % if the projection is in uvmat |
---|
499 | PlotType=plot_field(ProjData,hhuvmat.axes3,read_GUI(get(hhuvmat.axes3,'parent')));%update the current uvmat plot |
---|
500 | else % if the projection is in veiw_field |
---|
501 | hview_field=findobj(allchild(0),'tag','view_field'); |
---|
502 | if isempty(hview_field) |
---|
503 | hview_field=view_field(ProjData); %open the view_field GUI for plot |
---|
504 | else |
---|
505 | hhview_field=guidata(hview_field); |
---|
506 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.axes3,read_GUI(hview_field));%update an existing plot in view_field |
---|
507 | write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object |
---|
508 | end |
---|
509 | haxes=findobj(hview_field,'tag','axes3'); |
---|
510 | Data=get(hview_field,'UserData'); |
---|
511 | if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table) |
---|
512 | h_TableDisplay=findobj(hview_field,'tag','TableDisplay'); |
---|
513 | pos_table=get(h_TableDisplay,'Position'); |
---|
514 | pos=get(hview_field,'Position'); |
---|
515 | set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)]) |
---|
516 | drawnow |
---|
517 | set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing |
---|
518 | else |
---|
519 | set(hview_field,'Position',Data.GUISize) |
---|
520 | end |
---|
521 | set(hhuvmat.ViewField,'Value',1)% indicate that the field projection on the current object is plotted in view_field |
---|
522 | end |
---|
523 | end |
---|
524 | |
---|
525 | %% update the object plot |
---|
526 | hobject=UvData.Object{IndexObj}.DisplayHandle.uvmat; |
---|
527 | % if we are editing the object used for projection in uvmat |
---|
528 | if isequal(IndexObj_1,IndexObj) |
---|
529 | %update the representation of the current object for projection field represented in view_field |
---|
530 | % UvData.Object{iobj}.DisplayHandle.view_field=... |
---|
531 | % plot_object(UvData.Object{IndexObj},UvData.Object{IndexObj_1},UvData.Object{iobj}.DisplayHandle.uvmat,'m'); |
---|
532 | % update the representation of all objects in uvmat |
---|
533 | for iobj=1:numel(UvData.Object) |
---|
534 | UvData.Object{iobj}.DisplayHandle.uvmat=... |
---|
535 | plot_object(UvData.Object{iobj},UvData.Object{IndexObj_1},UvData.Object{iobj}.DisplayHandle.uvmat,'b'); |
---|
536 | end |
---|
537 | else % we are editing the object used for projection field represented in view_field |
---|
538 | %update the representation of the current object in uvmat |
---|
539 | UvData.Object{IndexObj}.DisplayHandle.uvmat=... |
---|
540 | plot_object(UvData.Object{IndexObj},UvData.Object{IndexObj_1},UvData.Object{IndexObj}.DisplayHandle.uvmat,'m'); |
---|
541 | %indicate the object index in the user data of the object plot (needed for further mouse editing) |
---|
542 | ObjectInfo=get(UvData.Object{IndexObj}.DisplayHandle.uvmat,'UserData'); |
---|
543 | ObjectInfo.IndexObj=IndexObj; |
---|
544 | set(UvData.Object{IndexObj}.DisplayHandle.uvmat,'UserData',ObjectInfo) |
---|
545 | % update the representation of all objects in view_field |
---|
546 | for iobj=1:numel(UvData.Object) |
---|
547 | if isfield(UvData.Object{iobj}.DisplayHandle,'view_field') |
---|
548 | UvData.Object{iobj}.DisplayHandle.view_field=... |
---|
549 | plot_object(UvData.Object{iobj},UvData.Object{iobj},UvData.Object{iobj}.DisplayHandle.view_field,'b'); |
---|
550 | end |
---|
551 | end |
---|
552 | end |
---|
553 | % UvData.Object{IndexObj}.DisplayHandle.uvmat=plot_object(ObjectData,UvData.Object{IndexObj_1},hobject,'m');%draw the object in uvmat |
---|
554 | % if ~isempty(hview_field) |
---|
555 | % if isfield(UvData.Object{IndexObj}.DisplayHandle,'view_field') |
---|
556 | % hobject=UvData.Object{IndexObj}.DisplayHandle.view_field; |
---|
557 | % end |
---|
558 | % if isempty(hobject) |
---|
559 | % hobject=haxes; |
---|
560 | % end |
---|
561 | % %draw the object in view_field |
---|
562 | % if ~isequal(IndexObj_1,IndexObj) % if the projection is in uvmat |
---|
563 | % UvData.Object{IndexObj}.DisplayHandle.view_field=plot_object(ObjectData,UvData.Object{IndexObj},hobject,'m'); |
---|
564 | % end |
---|
565 | % end |
---|
566 | set(huvmat,'UserData',UvData) |
---|
567 | |
---|
568 | %% update the GUI uvmat |
---|
569 | hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI |
---|
570 | set(hhuvmat.MenuEditObject,'enable','on') |
---|
571 | set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update |
---|
572 | set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow |
---|
573 | set(hhuvmat.ViewField,'Value',1) |
---|
574 | |
---|
575 | %------------------------------------------------------------------------ |
---|
576 | % --- Executes on button press in MenuCoord. |
---|
577 | function MenuCoord_Callback(hObject, eventdata, handles) |
---|
578 | %------------------------------------------------------------------------ |
---|
579 | %---------------------------------------------------- |
---|
580 | function num_RangeY_1_Callback(hObject, eventdata, handles) |
---|
581 | %------------------------------------------------------------------------ |
---|
582 | |
---|
583 | function num_RangeZ_1_Callback(hObject, eventdata, handles) |
---|
584 | %------------------------------------------------------------------------ |
---|
585 | |
---|
586 | function num_RangeZ_2_Callback(hObject, eventdata, handles) |
---|
587 | DZ=str2num(get(handles.num_RangeZ_2,'String')); |
---|
588 | ZMin=get(handles.z_slider,'Min'); |
---|
589 | ZMax=get(handles.z_slider,'Max'); |
---|
590 | if ~isequal(ZMax-ZMin,0) |
---|
591 | rel_step(1)=DZ/(ZMax-ZMin); |
---|
592 | rel_step(2)=0.2; |
---|
593 | set(handles.z_slider,'SliderStep',rel_step) |
---|
594 | end |
---|
595 | %------------------------------------------------------------------------ |
---|
596 | function num_RangeY_2_Callback(hObject, eventdata, handles) |
---|
597 | %------------------------------------------------------------------------ |
---|
598 | |
---|
599 | function num_RangeX_1_Callback(hObject, eventdata, handles) |
---|
600 | %------------------------------------------------------------------------ |
---|
601 | |
---|
602 | function num_RangeX_2_Callback(hObject, eventdata, handles) |
---|
603 | %------------------------------------------------------------------------ |
---|
604 | %------------------------------------------------------------------------ |
---|
605 | function SAVE_Callback(hObject, eventdata, handles) |
---|
606 | % ------------------------------------------------------ |
---|
607 | %Object=read_set_object(handles); |
---|
608 | Object=read_GUI(handles.set_object); |
---|
609 | huvmat=findobj('Tag','uvmat'); |
---|
610 | % UvData=get(huvmat,'UserData'); |
---|
611 | if isempty(huvmat) |
---|
612 | huvmat=findobj(allchild(0),'Name','series'); |
---|
613 | end |
---|
614 | hchild=get(huvmat,'Children'); |
---|
615 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
616 | if isempty(hrootpath) |
---|
617 | RootPath=''; |
---|
618 | else |
---|
619 | RootPath=get(hrootpath,'String'); |
---|
620 | if iscell(RootPath) |
---|
621 | RootPath=RootPath{1}; |
---|
622 | end |
---|
623 | end |
---|
624 | title={'object name'}; |
---|
625 | dir_save=uigetdir(RootPath); |
---|
626 | ObjectName=get(handles.Name,'String'); |
---|
627 | if ~isempty(ObjectName)&&~strcmp(ObjectName,'') |
---|
628 | def={fullfile(dir_save,[ObjectName '.xml'])}; |
---|
629 | else |
---|
630 | def={fullfile(dir_save,[Object.Style '.xml'])}; |
---|
631 | end |
---|
632 | displ_txt='save object as an .xml file';%default display |
---|
633 | menu=get(handles.ProjMode,'String'); |
---|
634 | value=get(handles.ProjMode,'Value'); |
---|
635 | ProjMode=menu{value}; |
---|
636 | if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside') |
---|
637 | displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)'; |
---|
638 | end |
---|
639 | answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def); |
---|
640 | if ~isempty(answer) |
---|
641 | t=struct2xml(Object); |
---|
642 | save(t,answer{1}) |
---|
643 | end |
---|
644 | msgbox_uvmat('CONFIRMATION',[answer{1} ' saved']) |
---|
645 | |
---|
646 | %------------------------------------------------------------------------ |
---|
647 | % --- Executes on slider movement. |
---|
648 | function z_slider_Callback(hObject, eventdata, handles) |
---|
649 | %--------------------------------------------------------- |
---|
650 | Z_value=get(handles.z_slider,'Value'); |
---|
651 | %rotation angles |
---|
652 | PlaneAngle=[0 0 0]; |
---|
653 | norm_plane=[0 0 1]; |
---|
654 | cos_om=1; |
---|
655 | sin_om=0; |
---|
656 | |
---|
657 | PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first angle in degrees |
---|
658 | PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second angle in degrees |
---|
659 | PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second angle in degrees |
---|
660 | PlaneAngle=(pi/180)*PlaneAngle; |
---|
661 | om=norm(PlaneAngle);%norm of rotation angle in radians |
---|
662 | if isequal(om,0) |
---|
663 | norm_plane=[0 0 1]; |
---|
664 | else |
---|
665 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis |
---|
666 | cos_om=cos(om); |
---|
667 | sin_om=sin(om); |
---|
668 | coeff=OmAxis(3)*(1-cos_om); |
---|
669 | %components of the unity vector norm_plane normal to the projection plane |
---|
670 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; |
---|
671 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; |
---|
672 | norm_plane(3)=OmAxis(3)*coeff+cos_om; |
---|
673 | end |
---|
674 | |
---|
675 | % update graph |
---|
676 | PLOT_Callback(hObject, eventdata, handles) |
---|
677 | |
---|
678 | %------------------------------------------------------------------------ |
---|
679 | % --- Executes on button press in HELP. |
---|
680 | function HELP_Callback(hObject, eventdata, handles) |
---|
681 | %------------------------------------------------------------------------ |
---|
682 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
683 | pathelp=fileparts(path_to_uvmat); |
---|
684 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
685 | 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') |
---|
686 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
687 | web([helpfile '#set_object']) |
---|
688 | end |
---|
689 | %------------------------------------------------------------------------ |
---|
690 | |
---|
691 | function Name_Callback(hObject, eventdata, handles) |
---|
692 | % hObject handle to Name (see GCBO) |
---|
693 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
694 | % handles structure with handles and user data (see GUIDATA) |
---|
695 | |
---|
696 | % Hints: get(hObject,'String') returns contents of Name as text |
---|
697 | % str2double(get(hObject,'String')) returns contents of Name as a double |
---|
698 | |
---|
699 | %------------------------------------------------------------------------ |
---|
700 | % --- Executes when entered data in editable cell(s) in Coord. |
---|
701 | function Coord_CellEditCallback(hObject, eventdata, handles) |
---|
702 | %------------------------------------------------------------------------ |
---|
703 | ListType=get(handles.Type,'String'); |
---|
704 | Type=ListType{get(handles.Type,'Value')}; |
---|
705 | switch Type |
---|
706 | % add lines if multi line input needed |
---|
707 | case{'points','polyline','polygon'} |
---|
708 | Coord=get(handles.Coord,'Data'); |
---|
709 | if ~isnan(Coord(end,1)) |
---|
710 | if isequal(size(Coord,2),3) |
---|
711 | %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case) |
---|
712 | Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case) |
---|
713 | else |
---|
714 | Coord=[Coord;NaN NaN]; %add a line for edition (2D case) |
---|
715 | end |
---|
716 | set(handles.Coord,'Data',Coord) |
---|
717 | end |
---|
718 | end |
---|
719 | |
---|
720 | |
---|
721 | |
---|
722 | function num_Angle_3_Callback(hObject, eventdata, handles) |
---|
723 | % hObject handle to num_Angle_3 (see GCBO) |
---|
724 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
725 | % handles structure with handles and user data (see GUIDATA) |
---|
726 | |
---|
727 | % Hints: get(hObject,'String') returns contents of num_Angle_3 as text |
---|
728 | % str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double |
---|