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