Home > . > set_object.m

set_object

PURPOSE ^

'set_object': GUI to edit a projection object

SYNOPSIS ^

function varargout = set_object(varargin)

DESCRIPTION ^

'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
 
 INTPUT:
 data: structure describing the object properties
  PlotHandles: handles for projection plots
 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %'set_object': GUI to edit a projection object
0002 %------------------------------------------------------------------------
0003 % function hset_object= set_object(data, PlotHandles,ZBounds)
0004 % associated with the GUI set_object.fig
0005 %
0006 % OUTPUT:
0007 % hset_object: handle of the GUI figure
0008 %
0009 % INTPUT:
0010 % data: structure describing the object properties
0011 %  PlotHandles: handles for projection plots
0012 % Zbounds: bounds on Z ( 3D case)
0013 %
0014 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0015 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
0016 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0017 %     This file is part of the toolbox UVMAT.
0018 %
0019 %     UVMAT is free software; you can redistribute it and/or modify
0020 %     it under the terms of the GNU General Public License as published by
0021 %     the Free Software Foundation; either version 2 of the License, or
0022 %     (at your option) any later version.
0023 %
0024 %     UVMAT is distributed in the hope that it will be useful,
0025 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
0028 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0029 
0030 function varargout = set_object(varargin)
0031 
0032 % Last Modified by GUIDE v2.5 24-Nov-2008 14:29:06
0033 
0034 % Begin initialization code - DO NOT PLOT
0035 gui_Singleton = 1;
0036 gui_State = struct('gui_Name',       mfilename, ...
0037                    'gui_Singleton',  gui_Singleton, ...
0038                    'gui_OpeningFcn', @set_object_OpeningFcn, ...
0039                    'gui_OutputFcn',  @set_object_OutputFcn, ...
0040                    'gui_LayoutFcn',  [] , ...
0041                    'gui_Callback',   []);
0042 if nargin & isstr(varargin{1})
0043     gui_State.gui_Callback = str2func(varargin{1});
0044 end
0045 
0046 if nargout
0047     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0048 else
0049     gui_mainfcn(gui_State, varargin{:});
0050 end
0051 % End initialization code - DO NOT PLOT
0052 
0053 %-------------------------------------------------------------------
0054 % --- Executes just before set_object is made visible.
0055 %INPUT:
0056 % handles: handles of the set_object interface elements
0057 %'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
0058 %        if =[] or absent: index still undefined (create mode in uvmat)
0059 %        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
0060 %'data': read from an existing object selected in the interface
0061 %      .TITLE : class of object ('POINTS','LINE',....)
0062 %      .DX,DY,DZ; meshes for regular grids
0063 %      .Coord: object position coordinates
0064 %      .ParentButton: handle of the uicontrol object calling the interface
0065 % PlotHandles: set of handles of the elements contolling the plotting of the projected field:
0066 %  if =[] or absent, no plot (mask mode in uvmat)
0067 % parameters on the uvmat interface (obtained by 'get_plot_handle.m')
0068 function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
0069 
0070 % Choose default command line output for set_object
0071 handles.output = hObject;
0072 
0073 % Update handles structure
0074 guidata(hObject, handles);
0075 
0076 %default
0077 if ~exist('ZBound','var')
0078     ZBound=0; %default
0079 end
0080 set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
0081 set(handles.MenuCoord,'ListboxTop',1)
0082 if ~exist('PlotHandles','var')
0083      PlotHandles=[];
0084 end
0085 desable_open=0;%default: allow reading of object from xml file
0086 desable_plot=0;%default
0087 SetData.PlotHandles=PlotHandles;
0088 if exist('data','var') & isfield(data,'ParentButton')
0089         SetData.ParentButton=data.ParentButton;
0090         set(hObject,'DeleteFcn',{@closefcn,SetData.ParentButton})%
0091 end
0092 set(hObject,'UserData',SetData)
0093 
0094 % fill the interface as set in the input data:
0095 if exist('data','var') 
0096     if isfield(data,'desable_open')
0097         desable_open=data.desable_open;%test to desable button OPEN (edit or display mode)
0098     end
0099     if isfield(data,'desable_plot')
0100         desable_plot=data.desable_plot;%test to desable button PLOT (display mode)
0101     end
0102     if ~isfield(data,'NbDim')|~isequal(data.NbDim,3)%2D case
0103         set(handles.ZObject,'Visible','off')
0104         set(handles.z_slider,'Visible','off')
0105     else
0106         set(handles.ZObject,'Visible','on')
0107         set(handles.z_slider,'Visible','on')
0108         if isfield(data,'Coord') && size(data.Coord,2)==3
0109             set(handles.ZObject,'String',num2str(data.Coord(1,3),4))
0110         end
0111     end
0112     if isfield(data,'ProjMode') && isfield(data,'Style')
0113         data.TITLE=set_title(data.Style,data.ProjMode);% define TITLE in set_object (POINTS, LINE, PATCH,...)
0114     end
0115     if isfield(data,'TITLE')
0116         menutitle=get(handles.TITLE,'String');
0117         for iline=1:length(menutitle)
0118             strmenu=menutitle{iline};
0119             if isequal(data.TITLE,strmenu)
0120                 set(handles.TITLE,'Value',iline)
0121                 break
0122             end
0123         end
0124         TITLE_Callback(hObject, eventdata, handles)% enable edit boxes depending on TITLE
0125     end
0126     if isfield(data,'fixedtitle')&isequal(data.fixedtitle,1)
0127         set(handles.TITLE,'enable','off')
0128     end
0129     if isfield(data,'Style')
0130         menu=get(handles.ObjectStyle,'String');
0131         for iline=1:length(menu)
0132             if isequal(menu{iline},data.Style)
0133                 set(handles.ObjectStyle,'Value',iline)
0134                 break
0135             end
0136         end
0137     end
0138     if isfield(data,'ProjMode')
0139         menu=get(handles.ProjMode,'String');
0140         for iline=1:length(menu)
0141             if isequal(menu{iline},data.ProjMode)
0142                 set(handles.ProjMode,'Value',iline)
0143                 break
0144             end
0145         end
0146     end
0147     if isfield(data,'Coord') & size(data.Coord,2)>=2
0148         sizcoord=size(data.Coord);
0149         for i=1:sizcoord(1)
0150             XObject{i}=num2str(data.Coord(i,1),4);
0151             YObject{i}=num2str(data.Coord(i,2),4);
0152         end
0153         set(handles.XObject,'String',XObject)
0154         set(handles.YObject,'String',YObject)
0155         %set(handles.XObject,'String',mat2cell(data.Coord(:,1),sizcoord(1)))
0156         %set(handles.YObject,'String',mat2cell(data.Coord(:,2),sizcoord(1)))
0157         if sizcoord(2)>3
0158             for i=1:sizcoord(1)
0159                 ZObject{i}=num2str(data.Coord(i,3),4);
0160             end
0161             set(handles.ZObject,'String',ZObject)
0162         end
0163     end
0164     if isfield(data,'DX')
0165         set(handles.DX,'String',num2str(data.DX,3))
0166     end
0167     if isfield(data,'DY')
0168          set(handles.DY,'String',num2str(data.DY,3))
0169     end
0170     %OBSOLETE (replaced by Range)
0171 %     if isfield(data,'XMin')
0172 %          set(handles.XMin,'String',num2str(data.XMin,3))
0173 %     end
0174 %     if isfield(data,'XMax')
0175 %          set(handles.XMax,'String',num2str(data.XMax,3))
0176 %     end
0177 %     if isfield(data,'YMin')
0178 %          set(handles.YMin,'String',num2str(data.YMin,3))
0179 %     end
0180 %     if isfield(data,'YMax')
0181 %          set(handles.YMax,'String',num2str(data.YMax,3))
0182 %     end
0183     if isfield(data,'RangeZ') && length(ZBounds) >= 2
0184         set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
0185         DZ=max(data.RangeZ);%slider step
0186         if ZBounds(2)~=ZBounds(1)
0187             rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
0188             rel_step(2)=0.1;
0189             set(handles.z_slider,'Visible','on')
0190             set(handles.z_slider,'Min',ZBounds(1))
0191             set(handles.z_slider,'Max',ZBounds(2))
0192             set(handles.z_slider,'SliderStep',rel_step)
0193             set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
0194         end
0195     end
0196     if isfield(data,'RangeX')
0197             set(handles.XMax,'String',num2str(max(data.RangeX),3))
0198             set(handles.XMin,'String',num2str(min(data.RangeX),3))
0199     end
0200     if isfield(data,'RangeY')
0201             set(handles.YMax,'String',num2str(max(data.RangeY),3))
0202             set(handles.YMin,'String',num2str(min(data.RangeY),3))
0203     end
0204     if isfield(data,'RangeZ')
0205             set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
0206             set(handles.ZMin,'String',num2str(min(data.RangeZ),3))
0207     end  
0208     if isfield(data,'Phi')
0209          set(handles.Phi,'String',num2str(data.Phi,3))
0210     end
0211     if isfield(data,'Theta')
0212          set(handles.Theta,'String',num2str(data.Theta,3))
0213     end
0214     if isfield(data,'Psi')
0215          set(handles.Psi,'String',num2str(data.Psi,3))
0216     end  
0217     if isfield(data,'DZ')
0218         set(handles.DZ,'String',num2str(data.DZ,3))
0219     end
0220     if isfield(data,'CoordType')
0221         if isequal(data.CoordType,'phys')
0222             set(handles.MenuCoord,'Value',1)
0223         elseif isequal(data.CoordType,'px')
0224              set(handles.MenuCoord,'Value',2)
0225         end
0226     end
0227 end
0228 if desable_open
0229     set(handles.OPEN,'Visible','off')
0230 else
0231     set(handles.OPEN,'Visible','on')
0232 end
0233 if desable_plot
0234    set(handles.PLOT,'Visible','off')
0235 else
0236    set(handles.PLOT,'Visible','on') 
0237 end
0238 
0239 
0240 % --- Outputs from this function are returned to the command line.
0241 function varargout = set_object_OutputFcn(hObject, eventdata, handles)
0242 % varargout  cell array for returning output args (see VARARGOUT);
0243 % hObject    handle to figure
0244 % eventdata  reserved - to be defined in a future version of MATLAB
0245 % handles    structure with handles and user data (see GUIDATA)
0246 
0247 % Get default command line output from handles structure
0248 varargout{1} = handles.output;
0249 varargout{2}=handles;
0250 
0251 %-----------------------------------------------
0252 % --- Executes on selection change in ObjectStyle.
0253 function ObjectStyle_Callback(hObject, eventdata, handles)
0254 style_prev=get(handles.ObjectStyle,'UserData');
0255 str=get(handles.ObjectStyle,'String');
0256 val=get(handles.ObjectStyle,'Value');
0257 % make correspondance between different object styles
0258 % if ~isequal(str{val},style_prev)
0259 Xcolumn=get(handles.XObject,'String');
0260 Ycolumn=get(handles.YObject,'String');
0261 if ischar(Xcolumn)
0262     sizchar=size(Xcolumn);
0263     for icol=1:sizchar(1)
0264         Xcolumn_cell{icol}=Xcolumn(icol,:);
0265     end
0266     Xcolumn=Xcolumn_cell;
0267 end
0268 if ischar(Ycolumn)
0269     sizchar=size(Ycolumn);
0270     for icol=1:sizchar(1)
0271         Ycolumn_cell{icol}=Ycolumn(icol,:);
0272     end
0273     Ycolumn=Ycolumn_cell;
0274 end
0275 Zcolumn={};%default
0276 z_new={};
0277 if isequal(get(handles.ZObject,'Visible'),'on')
0278     data.NbDim=3; %test 3D object
0279     Zcolumn=get(handles.ZObject,'String');
0280     if ischar(Zcolumn)
0281         Zcolumn={Zcolumn};
0282     end
0283 end
0284 x_new{1}=Xcolumn{1};
0285 y_new{1}=Ycolumn{1};
0286 if ~isempty(Zcolumn)
0287     z_new{1}=Zcolumn{1};
0288 end
0289 if isequal(str{val},'line')
0290     if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse')
0291         XMax=get(handles.XMax,'String');
0292         YMax=get(handles.YMax,'String');
0293         x_new{2}=num2str(XMax,4);
0294         y_new{2}=num2str(YMax,4);
0295         set(handles.XObject,'String',x_new)
0296         set(handles.YObject,'String',y_new)
0297         set(handles.ZObject,'String',z_new)
0298     end
0299 elseif isequal(str{val},'polyline')
0300 elseif isequal(str{val},'rectangle')| isequal(str{val},'ellipse')
0301      set(handles.XObject,'String',x_new)
0302      set(handles.YObject,'String',y_new)
0303      set(handles.ZObject,'String',z_new)
0304 end
0305 % end
0306             
0307             
0308 
0309 ProjMode_Callback(hObject, eventdata, handles)
0310 %store the current option
0311 str=get(handles.ObjectStyle,'String');
0312 val=get(handles.ObjectStyle,'Value');
0313 set(handles.ObjectStyle,'UserData',str{val})
0314 
0315 %----------------------------------------------
0316 function xObject_Callback(hObject, eventdata, handles)
0317 
0318 
0319 function yObject_Callback(hObject, eventdata, handles)
0320 
0321 
0322 % --- Executes on selection change in zObject.
0323 function zObject_Callback(hObject, eventdata, handles)
0324 
0325 
0326 
0327 % --- Executes on selection change in ProjMode.
0328 function ProjMode_Callback(hObject, eventdata, handles)
0329 menu=get(handles.ProjMode,'String');
0330 value=get(handles.ProjMode,'Value');
0331 ProjMode=menu{value};
0332 menu=get(handles.ObjectStyle,'String');
0333 value=get(handles.ObjectStyle,'Value');
0334 ObjectStyle=menu{value};
0335 test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
0336 if isequal(ObjectStyle,'plane')|isequal(ObjectStyle,'volume')
0337     set(handles.Phi,'Visible','on')
0338     if test3D%3D case
0339         set(handles.Theta,'Visible','on')
0340         set(handles.Psi,'Visible','on')
0341     end
0342     set(handles.XMin,'Visible','on')
0343     set(handles.XMax,'Visible','on')
0344     set(handles.YMin,'Visible','on')
0345     set(handles.YMax,'Visible','on')
0346     if test3D
0347         set(handles.Theta,'Visible','on')
0348         set(handles.Psi,'Visible','on')
0349         set(handles.ZMin,'Visible','on')
0350         set(handles.ZMax,'Visible','on')
0351     end
0352 else
0353     set(handles.Phi,'Visible','off')
0354     set(handles.Theta,'Visible','off')
0355     set(handles.Psi,'Visible','off')
0356     set(handles.XMin,'Visible','off')
0357     set(handles.XMax,'Visible','off')
0358     set(handles.YMin,'Visible','off')
0359     if isequal(ProjMode,'interp')
0360         set(handles.YMax,'Visible','off')
0361     else
0362         set(handles.YMax,'Visible','on')
0363     end
0364     if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
0365         set(handles.XMax,'Visible','on')
0366     else
0367        set(handles.XMax,'Visible','off')
0368     end
0369     set(handles.ZMin,'Visible','off')
0370     set(handles.ZMax,'Visible','off')
0371 end
0372 TITLE_list=get(handles.TITLE,'String');
0373 val=get(handles.TITLE,'Value');
0374 TITLE=TITLE_list{val};
0375 switch TITLE
0376     case {'POINTS','PATCH','MASK'}
0377         set(handles.DX,'Visible','off')
0378         set(handles.DY,'Visible','off')
0379         set(handles.DZ,'Visible','off')
0380     case {'LINE'}
0381         if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
0382             set(handles.DX,'Visible','on')
0383         else
0384             set(handles.DX,'Visible','off')
0385         end
0386     case {'PLANE'}  
0387         if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
0388             set(handles.DX,'Visible','on')
0389             set(handles.DY,'Visible','on')
0390         else
0391             set(handles.DX,'Visible','off')
0392             set(handles.DY,'Visible','off')
0393         end
0394     case {'VOLUME'} 
0395         if isequal(ProjMode,'interp')
0396             set(handles.DX,'Visible','on')
0397             set(handles.DY,'Visible','on')
0398             set(handles.DZ,'Visible','on')
0399         else
0400             set(handles.DX,'Visible','off')
0401             set(handles.DY,'Visible','off')
0402             set(handles.DZ,'Visible','off')   
0403         end
0404 end
0405 
0406 %---------------------------------------------
0407 % --- Executes on selection change in TITLE.
0408 function TITLE_Callback(hObject, eventdata, handles)
0409 %---------------------------------------------
0410 hsetobject=get(handles.TITLE,'parent');
0411 SetData=get(hsetobject,'UserData');%get the hidden interface data
0412 %      function named CALLBACK in UNTITLED.M with the given input arguments.
0413 menu=get(handles.TITLE,'String');
0414 value=get(handles.TITLE,'Value');
0415 titl=menu{value};
0416 if isequal(titl,'POINTS');
0417      menu_style={'points'};
0418      menu_proj={'projection';'interp';'filter';'none'};
0419 elseif isequal(titl,'LINE')
0420      menu_style={'line';'polyline';'rectangle';'polygon';'ellipse'};%'line' =default
0421      menu_proj={'projection';'interp';'filter';'none'};
0422 elseif isequal(titl,'PATCH')
0423      menu_style={'rectangle';'polygon';'ellipse'};%'line' =default
0424      menu_proj={'inside';'outside'};
0425 elseif isequal(titl,'MASK')
0426      menu_style={'polygon'};%'line' =default
0427      menu_proj={'mask_inside';'mask_outside'};
0428 elseif isequal(titl,'PLANE')
0429      menu_style={'plane'};
0430      menu_proj={'projection';'interp';'filter';'none'};
0431 elseif isequal(titl,'VOLUME')
0432      menu_style={'volume'};
0433      menu_proj={'none'};
0434   
0435 end
0436 old_menu=get(handles.ObjectStyle,'String');
0437 value=get(handles.ObjectStyle,'Value');
0438 old_style=old_menu{value};
0439 teststyle=0;
0440 for iline=1:length(menu_style)
0441     if isequal(menu_style{iline},old_style)
0442         styleval=iline;
0443         teststyle=1;
0444         break
0445     end
0446 end
0447 if ~teststyle
0448     new_style=[];%default
0449     switch old_style
0450         case 'polyline'
0451             new_style='polygon';
0452         case 'polygon'
0453             new_style='polyline';
0454     end
0455     if ~isempty(new_style)
0456         for iline=1:length(menu_style)
0457             if isequal(menu_style{iline},new_style)
0458                 styleval=iline;
0459                 teststyle=1;
0460                 break
0461             end
0462         end
0463     end
0464 end
0465 if ~teststyle
0466     styleval=1;
0467 end
0468 set(handles.ObjectStyle,'String',menu_style)
0469 set(handles.ObjectStyle,'Value',styleval)
0470 set(handles.ProjMode,'String',menu_proj)
0471 set(handles.ProjMode,'Value',1)
0472 ObjectStyle_Callback(hObject, eventdata, handles)  
0473 
0474 %---------------------------------------------
0475 function Phi_Callback(hObject, eventdata, handles)
0476 update_slider(hObject, eventdata,handles)
0477 %---------------------------------------------
0478 
0479 function Theta_Callback(hObject, eventdata, handles)
0480 update_slider(hObject, eventdata,handles)
0481 
0482 function update_slider(hObject, eventdata,handles)
0483 %rotation angles
0484 Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
0485 Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
0486 
0487 %components of the unitiy vector normal to the projection plane
0488 NormVec_X=-sin(Phi)*sin(Theta);
0489 NormVec_Y=cos(Phi)*sin(Theta);
0490 NormVec_Z=cos(Theta);
0491 huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
0492 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
0493 if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
0494     Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
0495     set(handles.z_slider,'Min',min(Z))
0496     set(handles.z_slider,'Max',max(Z))
0497     ZMax_Callback(hObject, eventdata, handles)
0498 end
0499 
0500 function DX_Callback(hObject, eventdata, handles)
0501 
0502 
0503 function DY_Callback(hObject, eventdata, handles)
0504 
0505 
0506 function DZ_Callback(hObject, eventdata, handles)
0507 
0508 
0509 
0510 %-----------------------------------------------------
0511 % --- Executes on button press in OPEN.
0512 function OPEN_Callback(hObject, eventdata, handles)
0513 %get the object file
0514 oldfile=' ';
0515 huvmat=findobj('Tag','uvmat');
0516 % if isempty(huvmat)
0517 %     huvmat=findobj(allchild(0),'Name','series');
0518 % end
0519 hchild=get(huvmat,'Children');
0520 hrootpath=findobj(hchild,'Tag','RootPath');
0521 if ~isempty(hrootpath)
0522     oldfile=get(hrootpath,'String');
0523     if iscell(oldfile)
0524         oldfile=oldfile{1};
0525     end
0526 end
0527 %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
0528 [FileName, PathName, filterindex] = uigetfile( ...
0529        {'*.xml;*.mat', ' (*.xml,*.mat)';
0530        '*.xml',  '.xml files '; ...
0531         '*.mat',  '.mat matlab files '}, ...
0532         'Pick a file',oldfile);
0533 fileinput=[PathName FileName];%complete file name
0534 testblank=findstr(fileinput,' ');%look for blanks
0535 if ~isempty(testblank)
0536     errordlg('forbidden input file name: contain blanks')
0537     return
0538 end
0539 sizf=size(fileinput);
0540 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0541 
0542 %read the file
0543  t=xmltree(fileinput);
0544  s=convert(t);
0545  if ~isfield(s,'Style')
0546      s.Style='points';
0547  end
0548  if ~isfield(s,'ProjMode')
0549      s.ProjMode='none';
0550  end
0551 %Display title
0552 title=set_title(s.Style,s.ProjMode);%update the title
0553 if ~isempty(huvmat)
0554     hhuvmat=guidata(huvmat);
0555 %     set(hhuvmat.POINTS,'Value',0)
0556 %     set(hhuvmat.POINTS,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0557 %     set(hhuvmat.LINE,'Value',0)
0558 %     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0559 %     set(hhuvmat.PATCH,'Value',0)
0560 %     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0561 %     set(hhuvmat.PLANE,'Value',0)
0562 %     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0563 %     set(hhuvmat.VOLUME,'Value',0)
0564 %     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0565 %     if ~isequal(title,'MASK')
0566 %         eval(['set(hhuvmat.' title ',''Value'',1)'])
0567 %         eval(['set(hhuvmat.' title ',''BackgroundColor'',[1 1 0])'])
0568 %     end
0569 end
0570 menu=get(handles.TITLE,'String');
0571 for iline=1:length(menu)
0572      if isequal(menu{iline},title)
0573          set(handles.TITLE,'Value',iline)
0574          break
0575      end
0576 end
0577 TITLE_Callback(hObject, eventdata, handles)
0578 teststyle=0;
0579 % if isfield(s,'Style')
0580 menu=get(handles.ObjectStyle,'String');
0581 for iline=1:length(menu)
0582     if isequal(menu{iline},s.Style)
0583         set(handles.ObjectStyle,'Value',iline)
0584         teststyle=1;
0585         break
0586     end
0587 end
0588 testmode=0;
0589 menu=get(handles.ProjMode,'String');
0590 for iline=1:length(menu)
0591     if isequal(menu{iline},s.ProjMode)
0592         set(handles.ProjMode,'Value',iline)
0593         testmode=1;
0594         break
0595     end
0596 end
0597 
0598 ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
0599 if isfield(s,'CoordType')
0600     if isequal(s.CoordType,'phys')
0601         set(handles.MenuCoord,'Value',1)
0602     elseif isequal(s.CoordType,'px')
0603         set(handles.MenuCoord,'Value',2)
0604     else
0605         warndlg('unknown CoordType (px or phys) in set_object.m')
0606     end
0607 end
0608 if isfield(s,'XMax')
0609     set(handles.XMax,'String',s.XMax)
0610 end
0611 if isfield(s,'XMin')
0612     set(handles.XMin,'String',s.XMin)
0613 end
0614 if isfield(s,'YMax')
0615     set(handles.YMax,'String',s.YMax)
0616 end
0617 if isfield(s,'YMin')
0618     set(handles.YMin,'String',s.YMin)
0619 end
0620 Range=0;
0621 if isfield(s,'Range')
0622     if ischar(s.Range)
0623         Range=str2num(s.Range);
0624     else
0625         Range(1,:)=str2num(s.Range{1});
0626         Range(2,:)=str2num(s.Range{2});
0627     end
0628 end
0629 if size(Range,2)>=3
0630     if size(Range,1)>=2
0631        set(handles.ZMin,'String',num2str(Range(2,3),3))
0632     end
0633     if size(Range,1)>=2
0634        set(handles.ZMax,'String',num2str(Range(1,3),3))
0635     end
0636 end
0637 if size(Range,2)>=2
0638     if size(Range,1)>=2
0639        set(handles.YMin,'String',num2str(Range(2,2),3))
0640     end
0641     if size(Range,1)>=2
0642        set(handles.YMax,'String',num2str(Range(1,2),3))
0643     end
0644 end
0645 if size(Range,2)>=1
0646     if size(Range,1)>=2
0647        set(handles.XMin,'String',num2str(Range(2,1),3))
0648     end
0649     if size(Range,1)>=2
0650        set(handles.XMax,'String',num2str(Range(1,1),3))
0651     end
0652 end
0653 if isfield(s,'RangeX') & ischar(s.RangeX)
0654      RangeX=str2num(s.RangeX);
0655     set(handles.XMax,'String',num2str(max(RangeX),3))
0656     set(handles.XMin,'String',num2str(min(RangeX),3))
0657 end
0658 
0659 if isfield(s,'RangeY')
0660     if ischar(s.RangeY)
0661         RangeY=str2num(s.RangeY);
0662         set(handles.YMax,'String',num2str(max(RangeY),3))
0663         set(handles.YMin,'String',num2str(min(RangeY),3))
0664     end
0665 end
0666 if isfield(s,'RangeZ')
0667     if ischar(s.RangeZ)
0668         RangeZ=str2num(s.RangeZ);
0669         set(handles.ZMax,'String',num2str(max(RangeZ),3))
0670         set(handles.ZMin,'String',num2str(min(RangeZ),3))
0671     end
0672 end
0673 if isfield(s,'Phi')
0674     set(handles.Phi,'String',s.Phi)
0675 end
0676 if isfield(s,'Theta')
0677     set(handles.Theta,'String',s.Theta)
0678 end
0679 if isfield(s,'Psi')
0680     set(handles.Psi,'String',s.Psi)
0681 end
0682 
0683 if isfield(s,'DX')
0684     set(handles.DX,'String',s.DX)
0685 end
0686 if isfield(s,'DY')
0687     set(handles.DY,'String',s.DY)
0688 end
0689 if ~isfield(s,'Coord')
0690     XObject='0';%default
0691     YObject='0';
0692 elseif ischar(s.Coord)
0693     line=str2num(s.Coord);
0694     XObject=num2str(line(1),4);
0695     YObject=num2str(line(2),4);
0696 else
0697     for i=1:length(s.Coord)
0698         line=str2num(s.Coord{i});
0699         XObject{i}=num2str(line(1),4);
0700         YObject{i}=num2str(line(2),4);
0701     end
0702 end
0703 set(handles.XObject,'String',XObject)
0704 set(handles.YObject,'String',YObject)
0705 %METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
0706 
0707 %----------------------------------------------------
0708 % executed when closing: set the parent interface button to value 0
0709 function closefcn(gcbo,eventdata,parent_button)
0710 
0711 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
0712 if ~isempty(huvmat)
0713     hhuvmat=guidata(huvmat);
0714     set(hhuvmat.create,'Value',0)
0715     set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0716 %     set(hhuvmat.LINE,'Value',0)
0717 %     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0718 %     set(hhuvmat.PATCH,'Value',0)
0719 %     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0720 %     set(hhuvmat.PLANE,'Value',0)
0721 %     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0722 %     set(hhuvmat.VOLUME,'Value',0)
0723 %     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0724     set(hhuvmat.edit,'Value',0)
0725     set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
0726 end
0727 hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
0728 if ~isempty(hseries)
0729     hhseries=guidata(hseries);
0730     set(hhseries.GetObject,'Value',0)
0731     set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0732 end
0733 
0734 %-----------------------------------------------------------------------
0735 % --- Executes on button press in PLOT: PLOT the defined object and its projected field
0736 function PLOT_Callback(hObject, eventdata, handles)
0737 
0738 hsetobject=get(handles.PLOT,'parent');
0739 SetData=get(hsetobject,'UserData');%get the hidden interface data
0740 huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
0741 hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object list in the GUI uvmat
0742 IndexObj=get(hlist_object,'Value');%position in the objet list
0743 UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
0744 ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
0745 ObjectData.HandlesDisplay=[]; % new object plot by default
0746 if length(UvData.Object) >= IndexObj && isfield(UvData.Object{IndexObj},'HandlesDisplay')
0747     hdisplay=UvData.Object{IndexObj}.HandlesDisplay;
0748     if isequal(UvData.Object{IndexObj}.Style, ObjectData.Style) && isequal(UvData.Object{IndexObj}.ProjMode, ObjectData.ProjMode)
0749         ObjectData.HandlesDisplay=UvData.Object{IndexObj}.HandlesDisplay;
0750     else  % for a new object styl, delete the existing object plots
0751         for ih=1:length(hdisplay)
0752             PlotData=get(hdisplay(ih),'UserData');
0753             if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject)
0754                     delete(PlotData.SubObject);
0755             end
0756             if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint)
0757                    delete(PlotData.DeformPoint);
0758             end
0759             if ~isequal(hdisplay(ih),0)
0760                 delete(hdisplay(ih));
0761             end
0762         end
0763         if isfield(ObjectData,'plotaxes') && ishandle(ObjectData.plotaxes)
0764             delete(ObjectData.plotaxes)%delete the axes for plotting the current projection result
0765         end
0766     end      
0767 end
0768 
0769 % update the object plot and projection field
0770 UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
0771 
0772 set(huvmat,'UserData',UvData)%update the data in the uvmat interface
0773 list_str=get(hlist_object,'String');
0774 TITLE=set_title(ObjectData.Style,ObjectData.ProjMode);
0775 list_str{IndexObj}=[num2str(IndexObj) '-' TITLE];
0776 if isequal(length(list_str),IndexObj)
0777     list_str{IndexObj+1}='more...';
0778 end
0779 set(hlist_object,'String',list_str)
0780 set(hlist_object,'Value',IndexObj)
0781 
0782 %update create buttons on the GUI uvmat: set to object edit mode after object plotting
0783 hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
0784 %desactivate all create buttons in mode edit
0785 % if isequal(get(hhuvmat.edit,'Value'),0)
0786     set(hhuvmat.create,'Value',0)
0787     set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0788 %     set(hhuvmat.LINE,'Value',0)
0789 %     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0790 %     set(hhuvmat.PATCH,'Value',0)
0791 %     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0792 %     set(hhuvmat.PLANE,'Value',0)
0793 %     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0794 %     set(hhuvmat.VOLUME,'Value',0)
0795 %     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
0796 % end
0797 set(hhuvmat.edit,'Value',1)
0798 set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
0799 set(hhuvmat.edit,'Value',1);%
0800 UvData.MouseAction='edit_object'; % set the edit button to 'on'
0801 set(huvmat,'UserData',UvData)
0802 
0803 % --- Executes on button press in MenuCoord.
0804 function MenuCoord_Callback(hObject, eventdata, handles)
0805 
0806 %----------------------------------------------------
0807 function YMin_Callback(hObject, eventdata, handles)
0808 
0809 
0810 function ZMin_Callback(hObject, eventdata, handles)
0811 
0812 
0813 function ZMax_Callback(hObject, eventdata, handles)
0814 DZ=str2num(get(handles.ZMax,'String'));
0815 ZMin=get(handles.z_slider,'Min');
0816 ZMax=get(handles.z_slider,'Max');
0817 if ~isequal(ZMax-ZMin,0)
0818     rel_step(1)=DZ/(ZMax-ZMin);
0819     rel_step(2)=0.2;
0820     set(handles.z_slider,'SliderStep',rel_step)
0821 end
0822 
0823 function YMax_Callback(hObject, eventdata, handles)
0824 
0825 
0826 function XMin_Callback(hObject, eventdata, handles)
0827 
0828 
0829 function XMax_Callback(hObject, eventdata, handles)
0830 
0831 
0832 % ------------------------------------------------------
0833 function SAVE_Callback(hObject, eventdata, handles)
0834 % ------------------------------------------------------
0835 Object=read_set_object(handles);
0836 huvmat=findobj('Tag','uvmat');
0837 % UvData=get(huvmat,'UserData');
0838 if isempty(huvmat)
0839     huvmat=findobj(allchild(0),'Name','series');
0840 end
0841 hchild=get(huvmat,'Children');
0842 hrootpath=findobj(hchild,'Tag','RootPath');
0843 if isempty(hrootpath)
0844     RootPath='';
0845 else
0846     RootPath=get(hrootpath,'String');
0847     if iscell(RootPath)
0848         RootPath=RootPath{1};
0849     end
0850 end
0851 title={'object name'};
0852 dir_save=uigetdir(RootPath);
0853 def={fullfile(dir_save,['Object' Object.CoordType '.xml'])};
0854 options.Resize='on';
0855 displ_txt='save object as an .xml file';%default display
0856 menu=get(handles.ProjMode,'String');
0857 value=get(handles.ProjMode,'Value');
0858 ProjMode=menu{value};
0859 if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
0860     displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
0861 end
0862 answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
0863 %answer=inputdlg('','save object in a new .xml file',1,def,'on');
0864 if ~isempty(answer)
0865     t=struct2xml(Object);
0866     save(t,answer{1})
0867 end
0868 msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
0869 %---------------------------------------------------------
0870 % --- Executes on slider movement.
0871 function z_slider_Callback(hObject, eventdata, handles)
0872 %---------------------------------------------------------
0873 %A ADAPTER
0874 Z_value=get(handles.z_slider,'Value');
0875 
0876 %rotation angles
0877 Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
0878 Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
0879 
0880 %components of the unity vector normal to the projection plane
0881 NormVec_X=-sin(Phi)*sin(Theta);
0882 NormVec_Y=cos(Phi)*sin(Theta);
0883 NormVec_Z=cos(Theta);
0884 
0885 %set new plane position and update graph
0886 set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
0887 set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
0888 set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
0889 PLOT_Callback(hObject, eventdata, handles)
0890 
0891 
0892 
0893 function XObject_Callback(hObject, eventdata, handles)
0894 
0895 
0896 function YObject_Callback(hObject, eventdata, handles)
0897 
0898 
0899 
0900 
0901 function ZObject_Callback(hObject, eventdata, handles)
0902 
0903 
0904 % --- Executes on button press in HELP.
0905 function HELP_Callback(hObject, eventdata, handles)
0906 path_to_uvmat=which ('uvmat');% check the path of uvmat
0907 pathelp=fileparts(path_to_uvmat);
0908 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
0909 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
0910 else
0911     web([helpfile '#set_object'])    
0912 end
0913 
0914 
0915 
0916

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003