%'set_object': GUI to edit a projection object %------------------------------------------------------------------------ % function hset_object= set_object(data, PlotHandles,ZBounds) % associated with the GUI set_object.fig % % OUTPUT: % hset_object: handle of the GUI figure % % INPUT: % data: structure describing the object properties % .Style=... % .ProjMode % .CoordType: 'phys' or 'px' % .num_DX,.num_DY,.num_DZ : mesh along each dirction % .RangeX, RangeY % .Coord(j,i), i=1, 2, 3, components x, y, z of j=1...n position(s) characterizing the object components % PlotHandles: handles for projection plots NO MORE USED % Zbounds: bounds on Z ( 3D case) % %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA % This file is part of the toolbox UVMAT. % % UVMAT is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % UVMAT is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License (file UVMAT/COPYING.txt) for more details. %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA function varargout = set_object(varargin) % Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47 % Begin initialization code - DO NOT PLOT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @set_object_OpeningFcn, ... 'gui_OutputFcn', @set_object_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin & ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT PLOT %------------------------------------------------------------------------ %------------------------------------------------------------------------ % --- Executes just before set_object is made visible. %INPUT: % handles: handles of the set_object interface elements %'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify % if =[] or absent: index still undefined (create mode in uvmat) % if=0; no associated object (used for series), the button 'PLOT' is then unvisible %'data': read from an existing object selected in the interface % .Name : class of object ('POINTS','LINE',....) % .num_DX,num_DY,num_DZ; meshes for regular grids % .Coord: object position coordinates % .ParentButton: handle of the uicontrol object calling the interface % PlotHandles: set of handles of the elements contolling the plotting of the projected field: % if =[] or absent, no plot (mask mode in uvmat) % parameters on the uvmat interface (obtained by 'get_plot_handle.m') function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds) %------------------------------------------------------------------- % Choose default command line output for set_object handles.output = hObject; % Update handles structure guidata(hObject, handles); %default if ~exist('ZBounds','var') ZBounds=0; %default end set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front) set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function enable_plot=0;%default: does not allow plot of object and projection % fill the interface as set in the input data: if exist('data','var') if isfield(data,'enable_plot') enable_plot=data.enable_plot;%test to desable button PLOT (display mode) end if isfield(data,'Coord') &&size(data.Coord,2)==3 set(handles.z_slider,'Visible','on') else set(handles.z_slider,'Visible','off') end errormsg=fill_GUI(data,handles); % if isfield(data,'StyleMenu') % set(handles.Type,'String',data.StyleMenu); % end % if isfield(data,'Type') % menu=get(handles.Type,'String'); % for iline=1:length(menu) % if isequal(menu{iline},data.Style) % set(handles.Type,'Value',iline) % break % end % end % end Type_Callback(hObject, eventdata, handles) % if isfield(data,'ProjMenu') % set(handles.ProjMode,'String',data.ProjMenu);%overset the standard menu % end % if isfield(data,'ProjMode') % menu=get(handles.ProjMode,'String'); % for iline=1:length(menu) % if isequal(menu{iline},data.ProjMode) % set(handles.ProjMode,'Value',iline) % break % end % end % end % ProjMode_Callback(hObject, eventdata, handles) % if isfield(data,'Coord') % if ischar(data.Coord) % data.Coord=str2num(data.Coord); % elseif iscell(data.Coord) % CoordCell=data.Coord; % data.Coord=zeros(numel(CoordCell),3); % data.Coord(:,3)=zeros(numel(CoordCell),1); % z component set to 0 by default % for iline=1:numel(CoordCell) % line_vec=str2num(CoordCell{iline}); % if numel(line_vec)==2 % data.Coord(iline,1:2)=str2num(CoordCell{iline}); % else % data.Coord(iline,:)=str2num(CoordCell{iline}); % end % end % end % if size(data.Coord,2)>=2 % sizcoord=size(data.Coord); % for i=1:sizcoord(1) % XObject{i}=num2str(data.Coord(i,1),4); % YObject{i}=num2str(data.Coord(i,2),4); % end % % set(handles.XObject,'String',XObject) % % set(handles.YObject,'String',YObject) % if sizcoord(2)>3 % for i=1:sizcoord(1) % ZObject{i}=num2str(data.Coord(i,3),4); % end % set(handles.ZObject,'String',ZObject) % end % end % end % if isfield(data,'DX') % if ~ischar(handles.num_DX) % data.DX=num2str(data.DX,3); % end % set(handles.num_DX,'String',data.DX) % end % if isfield(data,'DY') % if ~ischar(handles.num_DY) % data.DY=num2str(data.DY,3); % end % set(handles.num_DY,'String',data.DX) % end if isfield(data,'RangeZ') && length(ZBounds) >= 2 set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3)) DZ=max(data.RangeZ);%slider step if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1) rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1 rel_step(2)=0.1; set(handles.z_slider,'Visible','on') set(handles.z_slider,'Min',ZBounds(1)) set(handles.z_slider,'Max',ZBounds(2)) set(handles.z_slider,'SliderStep',rel_step) set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2) end end if isfield(data,'RangeX') if ischar(data.RangeX) data.RangeX=str2num(data.RangeX); end set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3)) set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3)) end if isfield(data,'RangeY') if ischar(data.RangeY) data.RangeY=str2num(data.RangeY); end set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3)) set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3)) end if isfield(data,'RangeZ') if ischar(data.RangeZ) data.RangeZ=str2num(data.RangeZ); end set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3)) if numel(data.RangeZ)>=2 set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3)) end end if isfield(data,'Angle') && isequal(numel(data.Angle),3) set(handles.num_Angle_1,'String',num2str(data.Angle(1))) set(handles.num_Angle_2,'String',num2str(data.Angle(2))) set(handles.num_Angle_3,'String',num2str(data.Angle(3))) end % if isfield(data,'DZ') % if ~ischar(handles.num_DZ) % data.DY=num2str(data.DZ,3); % end % set(handles.num_DZ,'String',data.DZ) % end % if isfield(data,'CoordUnit') % set(handles.CoordUnit,'String',data.CoordUnit) % end end if enable_plot set(handles.PLOT,'enable','on') else set(handles.PLOT,'enable','off') end huvmat=findobj(allchild(0),'tag','uvmat'); UvData=get(huvmat,'UserData'); pos_uvmat=get(huvmat,'Position'); %position the set_object GUI with respect to uvmat if isfield(UvData,'SetObjectOrigin') pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2); pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); set(hObject,'Position',pos_set_object) end %------------------------------------------------------------------------ % --- Outputs from this function are returned to the command line. function varargout = set_object_OutputFcn(hObject, eventdata, handles) %------------------------------------------------------------------------ % Get default command line output from handles structure varargout{1} = handles.output; varargout{2}=handles; %------------------------------------------------------------------------ % --- Executes on selection change in Type. function Type_Callback(hObject, eventdata, handles) %------------------------------------------------------------------------ %style_prev=get(handles.Type,'UserData');%previous object style ListType=get(handles.Type,'String'); Type=ListType{get(handles.Type,'Value')}; % make correspondance between different object styles Coord=get(handles.Coord,'Data'); % % Xcolumn=get(handles.XObject,'String'); % Ycolumn=get(handles.YObject,'String'); % if ischar(Xcolumn) % sizchar=size(Xcolumn); % for icol=1:sizchar(1) % Xcolumn_cell{icol}=Xcolumn(icol,:); % end % Xcolumn=Xcolumn_cell; % end % if ischar(Ycolumn) % sizchar=size(Ycolumn); % for icol=1:sizchar(1) % Ycolumn_cell{icol}=Ycolumn(icol,:); % end % Ycolumn=Ycolumn_cell; % end % Zcolumn={};%default % z_new={}; % if isequal(get(handles.ZObject,'Visible'),'on') % %data.NbDim=3; %test 3D object % Zcolumn=get(handles.ZObject,'String'); % if ischar(Zcolumn) % Zcolumn={Zcolumn}; % end % end % x_new{1}=Xcolumn{1}; % y_new{1}=Ycolumn{1}; % x_new{1}=Coord(1,1); % y_new{1}=Coord(1,2); % z_new{1}=Coord(1,3); % if ~isempty(Zcolumn) % z_new{1}=Zcolumn{1}; % end % if isequal(style,'line') % if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse') % num_RangeX_2=get(handles.num_RangeX_2,'String'); % num_RangeY_2=get(handles.num_RangeY_2,'String'); % x_new{2}=num2str(num_RangeX_2,4); % y_new{2}=num2str(num_RangeY_2,4); % set(handles.XObject,'String',x_new) % set(handles.YObject,'String',y_new) % set(handles.ZObject,'String',z_new) % end % elseif isequal(style,'polyline') % elseif strcmp(style,'rectangle')|| strcmp(style,'ellipse') % set(handles.XObject,'String',x_new) % set(handles.YObject,'String',y_new) % set(handles.ZObject,'String',z_new) % end %% set the number of lines in the Coord table depending on object type switch Type case{'line'} if size(Coord,1)<2 if isequal(size(Coord,2),3) Coord=[Coord; 0 0 0];%add a line for edition (3D case) else Coord=[Coord; 0 0]; %add a line for edition (2D case) end else Coord=Coord(1:2,:); end case{'rectangle','ellipse','plane','volume'} Coord=Coord(1,:); end set(handles.Coord,'Data',Coord) %% set the projection menu and the corresponding options switch Type case {'points','line','polyline','plane'} menu_proj={'projection';'interp';'filter';'none'}; case {'polygon','rectangle','ellipse'} menu_proj={'inside';'outside';'mask_inside';'mask_outside'}; case 'volume' menu_proj={'interp';'none'}; otherwise menu_proj={'projection';'interp';'filter';'none'};%default end proj_index=get(handles.ProjMode,'Value'); if proj_index