%'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' % .DX,.DY,.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 24-Nov-2008 14:29:06 % 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 % .TITLE : class of object ('POINTS','LINE',....) % .DX,DY,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,'Name') set(handles.TITLE,'String',data.Name) end if ~isfield(data,'NbDim')||~isequal(data.NbDim,3)%2D case set(handles.ZObject,'Visible','off') set(handles.z_slider,'Visible','off') else set(handles.ZObject,'Visible','on') set(handles.z_slider,'Visible','on') if isfield(data,'Coord') && size(data.Coord,2)==3 set(handles.ZObject,'String',num2str(data.Coord(1,3),4)) end end if isfield(data,'StyleMenu') set(handles.ObjectStyle,'String',data.StyleMenu); end if isfield(data,'Style') menu=get(handles.ObjectStyle,'String'); for iline=1:length(menu) if isequal(menu{iline},data.Style) set(handles.ObjectStyle,'Value',iline) break end end end ObjectStyle_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.DX) data.DX=num2str(data.DX,3); end set(handles.DX,'String',data.DX) end if isfield(data,'DY') if ~ischar(handles.DY) data.DY=num2str(data.DY,3); end set(handles.DY,'String',data.DX) end if isfield(data,'RangeZ') && length(ZBounds) >= 2 set(handles.ZMax,'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.XMax,'String',num2str(max(data.RangeX),3)) set(handles.XMin,'String',num2str(min(data.RangeX),3)) end if isfield(data,'RangeY') if ischar(data.RangeY) data.RangeY=str2num(data.RangeY); end set(handles.YMax,'String',num2str(max(data.RangeY),3)) set(handles.YMin,'String',num2str(min(data.RangeY),3)) end if isfield(data,'RangeZ') if ischar(data.RangeZ) data.RangeZ=str2num(data.RangeZ); end set(handles.ZMax,'String',num2str(max(data.RangeZ),3)) if numel(data.RangeZ)>=2 set(handles.ZMin,'String',num2str(min(data.RangeZ),3)) end end if isfield(data,'Angle') && isequal(numel(data.Angle),3) set(handles.Phi,'String',num2str(data.Angle(1))) set(handles.Theta,'String',num2str(data.Angle(2))) set(handles.Psi,'String',num2str(data.Angle(3))) end if isfield(data,'DZ') if ~ischar(handles.DZ) data.DY=num2str(data.DZ,3); end set(handles.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 ObjectStyle. function ObjectStyle_Callback(hObject, eventdata, handles) %------------------------------------------------------------------------ style_prev=get(handles.ObjectStyle,'UserData');%previous object style str=get(handles.ObjectStyle,'String'); val=get(handles.ObjectStyle,'Value'); style=str{val}; % make correspondance between different object styles 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}; if ~isempty(Zcolumn) z_new{1}=Zcolumn{1}; end if isequal(style,'line') if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse') XMax=get(handles.XMax,'String'); YMax=get(handles.YMax,'String'); x_new{2}=num2str(XMax,4); y_new{2}=num2str(YMax,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 switch style 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'}; end proj_index=get(handles.ProjMode,'Value'); if proj_index=3 if size(Range,1)>=2 set(handles.ZMin,'String',num2str(Range(2,3),3)) end if size(Range,1)>=2 set(handles.ZMax,'String',num2str(Range(1,3),3)) end end if size(Range,2)>=2 if size(Range,1)>=2 set(handles.YMin,'String',num2str(Range(2,2),3)) end if size(Range,1)>=2 set(handles.YMax,'String',num2str(Range(1,2),3)) end end if size(Range,2)>=1 if size(Range,1)>=2 set(handles.XMin,'String',num2str(Range(2,1),3)) end if size(Range,1)>=2 set(handles.XMax,'String',num2str(Range(1,1),3)) end end if isfield(s,'RangeX') & ischar(s.RangeX) RangeX=str2num(s.RangeX); set(handles.XMax,'String',num2str(max(RangeX),3)) set(handles.XMin,'String',num2str(min(RangeX),3)) end if isfield(s,'RangeY') if ischar(s.RangeY) RangeY=str2num(s.RangeY); set(handles.YMax,'String',num2str(max(RangeY),3)) set(handles.YMin,'String',num2str(min(RangeY),3)) end end if isfield(s,'RangeZ') if ischar(s.RangeZ) RangeZ=str2num(s.RangeZ); set(handles.ZMax,'String',num2str(max(RangeZ),3)) set(handles.ZMin,'String',num2str(min(RangeZ),3)) end end if isfield(s,'Phi') set(handles.Psi,'String',s.Phi)%old definition end if isfield(s,'Angle')&& isequal(numel(s.Angle),3) set(handles.Phi,'String',s.Angle(1)) set(handles.Theta,'String',s.Angle(2)) set(handles.Psi,'String',s.Angle(3)) end % if isfield(s,'Psi') % set(handles.Psi,'String',s.Psi) % end if isfield(s,'DX') set(handles.DX,'String',s.DX) end if isfield(s,'DY') set(handles.DY,'String',s.DY) end if ~isfield(s,'Coord') XObject='0';%default YObject='0'; elseif ischar(s.Coord) line=str2num(s.Coord); XObject=num2str(line(1),4); YObject=num2str(line(2),4); else for i=1:length(s.Coord) line=str2num(s.Coord{i}); XObject{i}=num2str(line(1),4); YObject{i}=num2str(line(2),4); end end set(handles.XObject,'String',XObject) set(handles.YObject,'String',YObject) %METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening %------------------------------------------------------------------------ %---------------------------------------------------- % executed when closing: set the parent interface button to value 0 function closefcn(gcbo,eventdata,parent_button) huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle if ~isempty(huvmat) hhuvmat=guidata(huvmat); set(hhuvmat.edit,'Value',0) set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree end hseries=findobj(allchild(0),'Name','series');%find the current series interface handle if ~isempty(hseries) hhseries=guidata(hseries); set(hhseries.GetObject,'Value',0) set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green end %------------------------------------------------------------------------ % --- Executes on button press in PLOT: PLOT the defined object and its projected field function PLOT_Callback(hObject, eventdata, handles) %% reading the object parameters on the GUI uvmat huvmat=findobj('tag','uvmat');%find the current uvmat interface handle UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat hhuvmat=guidata(huvmat);%handles in the uvmat GUI ListObject=get(hhuvmat.ListObject,'String');%position in the objet list IndexObj=get(hhuvmat.ListObject,'Value'); %% read the object on the GUI set_object ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object ObjectName=get(handles.TITLE,'String');%name of the current object defiend in set_object if isempty(ObjectName) if get(hhuvmat.edit_object,'Value')% edit mode ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item else %new object StyleList=get(handles.ObjectStyle,'String'); StyleVal=get(handles.ObjectStyle,'Value'); ObjectName=StyleList{StyleVal}; %ObjectName=[num2str(numel(ListObject)+1) '-' StyleList{StyleVal}];% take the object style as default name end end if ~get(hhuvmat.edit_object,'Value') %new object is being created detectname=1; ObjectNameNew=ObjectName; vers=0; while detectname==1 detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list if detectname% if the object name already exists indstr=regexp(ObjectNameNew,'\D'); if indstr(end)