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