source: trunk/src/set_object.m @ 41

Last change on this file since 41 was 41, checked in by sommeria, 11 years ago

-relabel_i_j: improve the question dlg box for image transform
-aver_stat,time_series,merge_proj: include modification of field transform and call of set_object.
-series: introduce a browser for set_object
-ima2vol: create volume images (png images of a slice concacened along y) for PIV 3D
-set_object: suppress TITLE, introduce Tooltip helps for parameters
-civ: fixed bug on BATCH sequences

File size: 30.9 KB
Line 
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% INTPUT:
10% data: structure describing the object properties
11%  PlotHandles: handles for projection plots
12% Zbounds: bounds on Z ( 3D case)
13%
14%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
15%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%     This file is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published by
21%     the Free Software Foundation; either version 2 of the License, or
22%     (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
28%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
29
30function varargout = set_object(varargin)
31
32% Last Modified by GUIDE v2.5 24-Nov-2008 14:29:06
33
34% Begin initialization code - DO NOT PLOT
35gui_Singleton = 1;
36gui_State = struct('gui_Name',       mfilename, ...
37                   'gui_Singleton',  gui_Singleton, ...
38                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
39                   'gui_OutputFcn',  @set_object_OutputFcn, ...
40                   'gui_LayoutFcn',  [] , ...
41                   'gui_Callback',   []);
42if nargin & isstr(varargin{1})
43    gui_State.gui_Callback = str2func(varargin{1});
44end
45
46if nargout
47    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
48else
49    gui_mainfcn(gui_State, varargin{:});
50end
51% End initialization code - DO NOT PLOT
52
53%-------------------------------------------------------------------
54% --- Executes just before set_object is made visible.
55%INPUT:
56% handles: handles of the set_object interface elements
57%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
58%        if =[] or absent: index still undefined (create mode in uvmat)
59%        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
60%'data': read from an existing object selected in the interface
61%      .TITLE : class of object ('POINTS','LINE',....)
62%      .DX,DY,DZ; meshes for regular grids
63%      .Coord: object position coordinates
64%      .ParentButton: handle of the uicontrol object calling the interface
65% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
66%  if =[] or absent, no plot (mask mode in uvmat)
67% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
68function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
69%-------------------------------------------------------------------
70% Choose default command line output for set_object
71handles.output = hObject;
72
73% Update handles structure
74guidata(hObject, handles);
75
76%default
77if ~exist('ZBound','var')
78    ZBound=0; %default
79end
80set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
81set(handles.MenuCoord,'ListboxTop',1)
82if ~exist('PlotHandles','var')
83     PlotHandles=[];
84end
85desable_open=0;%default: allow reading of object from xml file
86desable_plot=0;%default
87SetData.PlotHandles=PlotHandles;
88if exist('data','var') & isfield(data,'ParentButton')
89        SetData.ParentButton=data.ParentButton;
90        set(hObject,'DeleteFcn',{@closefcn,SetData.ParentButton})%
91end
92set(hObject,'UserData',SetData)
93
94% fill the interface as set in the input data:
95if exist('data','var')
96%     if isfield(data,'desable_open')
97%         desable_open=data.desable_open;%test to desable button OPEN (edit or display mode)
98%     end
99    if isfield(data,'desable_plot')
100        desable_plot=data.desable_plot;%test to desable button PLOT (display mode)
101    end
102    if ~isfield(data,'NbDim')|~isequal(data.NbDim,3)%2D case
103        set(handles.ZObject,'Visible','off')
104        set(handles.z_slider,'Visible','off')
105    else
106        set(handles.ZObject,'Visible','on')
107        set(handles.z_slider,'Visible','on')
108        if isfield(data,'Coord') && size(data.Coord,2)==3
109            set(handles.ZObject,'String',num2str(data.Coord(1,3),4))
110        end
111    end
112%     if isfield(data,'ProjMode') && isfield(data,'Style')
113%         data.TITLE=set_title(data.Style,data.ProjMode);% define TITLE in set_object (POINTS, LINE, PATCH,...)
114%     end
115%     if isfield(data,'TITLE')
116%         menutitle=get(handles.TITLE,'String');
117%         for iline=1:length(menutitle)
118%             strmenu=menutitle{iline};
119%             if isequal(data.TITLE,strmenu)
120%                 set(handles.TITLE,'Value',iline)
121%                 break
122%             end
123%         end
124%         TITLE_Callback(hObject, eventdata, handles)% enable edit boxes depending on TITLE
125%     end
126%     if isfield(data,'fixedtitle')&isequal(data.fixedtitle,1)
127%         set(handles.TITLE,'enable','off')
128%     end
129    if isfield(data,'Style')
130        menu=get(handles.ObjectStyle,'String');
131        for iline=1:length(menu)
132            if isequal(menu{iline},data.Style)
133                set(handles.ObjectStyle,'Value',iline)
134                break
135            end
136        end
137    end
138    ObjectStyle_Callback(hObject, eventdata, handles)
139    if isfield(data,'ProjMode')
140        menu=get(handles.ProjMode,'String');
141        for iline=1:length(menu)
142            if isequal(menu{iline},data.ProjMode)
143                set(handles.ProjMode,'Value',iline)
144                break
145            end
146        end
147    end
148    ProjMode_Callback(hObject, eventdata, handles)
149    if isfield(data,'Coord') & size(data.Coord,2)>=2
150        sizcoord=size(data.Coord);
151        for i=1:sizcoord(1)
152            XObject{i}=num2str(data.Coord(i,1),4);
153            YObject{i}=num2str(data.Coord(i,2),4);
154        end
155        set(handles.XObject,'String',XObject)
156        set(handles.YObject,'String',YObject)
157        %set(handles.XObject,'String',mat2cell(data.Coord(:,1),sizcoord(1)))
158        %set(handles.YObject,'String',mat2cell(data.Coord(:,2),sizcoord(1)))
159        if sizcoord(2)>3
160            for i=1:sizcoord(1)
161                ZObject{i}=num2str(data.Coord(i,3),4);
162            end
163            set(handles.ZObject,'String',ZObject)
164        end
165    end
166    if isfield(data,'DX')
167        set(handles.DX,'String',num2str(data.DX,3))
168    end
169    if isfield(data,'DY')
170         set(handles.DY,'String',num2str(data.DY,3))
171    end
172    %OBSOLETE (replaced by Range)
173%     if isfield(data,'XMin')
174%          set(handles.XMin,'String',num2str(data.XMin,3))
175%     end
176%     if isfield(data,'XMax')
177%          set(handles.XMax,'String',num2str(data.XMax,3))
178%     end
179%     if isfield(data,'YMin')
180%          set(handles.YMin,'String',num2str(data.YMin,3))
181%     end
182%     if isfield(data,'YMax')
183%          set(handles.YMax,'String',num2str(data.YMax,3))
184%     end
185    if isfield(data,'RangeZ') && length(ZBounds) >= 2
186        set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
187        DZ=max(data.RangeZ);%slider step
188        if ZBounds(2)~=ZBounds(1)
189            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
190            rel_step(2)=0.1;
191            set(handles.z_slider,'Visible','on')
192            set(handles.z_slider,'Min',ZBounds(1))
193            set(handles.z_slider,'Max',ZBounds(2))
194            set(handles.z_slider,'SliderStep',rel_step)
195            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
196        end
197    end
198    if isfield(data,'RangeX')
199            set(handles.XMax,'String',num2str(max(data.RangeX),3))
200            set(handles.XMin,'String',num2str(min(data.RangeX),3))
201    end
202    if isfield(data,'RangeY')
203            set(handles.YMax,'String',num2str(max(data.RangeY),3))
204            set(handles.YMin,'String',num2str(min(data.RangeY),3))
205    end
206    if isfield(data,'RangeZ')
207            set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
208            set(handles.ZMin,'String',num2str(min(data.RangeZ),3))
209    end 
210    if isfield(data,'Phi')
211         set(handles.Phi,'String',num2str(data.Phi,3))
212    end
213    if isfield(data,'Theta')
214         set(handles.Theta,'String',num2str(data.Theta,3))
215    end
216    if isfield(data,'Psi')
217         set(handles.Psi,'String',num2str(data.Psi,3))
218    end 
219    if isfield(data,'DZ')
220        set(handles.DZ,'String',num2str(data.DZ,3))
221    end
222    if isfield(data,'CoordType')
223        if isequal(data.CoordType,'phys')
224            set(handles.MenuCoord,'Value',1)
225        elseif isequal(data.CoordType,'px')
226             set(handles.MenuCoord,'Value',2)
227        end
228    end
229end
230% if desable_open
231%     set(handles.OPEN,'Visible','off')
232% else
233%     set(handles.OPEN,'Visible','on')
234% end
235if desable_plot
236   set(handles.PLOT,'Visible','off')
237else
238   set(handles.PLOT,'Visible','on')
239end
240
241
242% --- Outputs from this function are returned to the command line.
243function varargout = set_object_OutputFcn(hObject, eventdata, handles)
244% varargout  cell array for returning output args (see VARARGOUT);
245% hObject    handle to figure
246% eventdata  reserved - to be defined in a future version of MATLAB
247% handles    structure with handles and user data (see GUIDATA)
248
249% Get default command line output from handles structure
250varargout{1} = handles.output;
251varargout{2}=handles;
252
253%-----------------------------------------------
254% --- Executes on selection change in ObjectStyle.
255function ObjectStyle_Callback(hObject, eventdata, handles)
256style_prev=get(handles.ObjectStyle,'UserData');%previous object style
257str=get(handles.ObjectStyle,'String');
258val=get(handles.ObjectStyle,'Value');
259style=str{val};
260% make correspondance between different object styles
261% if ~isequal(str{val},style_prev)
262Xcolumn=get(handles.XObject,'String');
263Ycolumn=get(handles.YObject,'String');
264if ischar(Xcolumn)
265    sizchar=size(Xcolumn);
266    for icol=1:sizchar(1)
267        Xcolumn_cell{icol}=Xcolumn(icol,:);
268    end
269    Xcolumn=Xcolumn_cell;
270end
271if ischar(Ycolumn)
272    sizchar=size(Ycolumn);
273    for icol=1:sizchar(1)
274        Ycolumn_cell{icol}=Ycolumn(icol,:);
275    end
276    Ycolumn=Ycolumn_cell;
277end
278Zcolumn={};%default
279z_new={};
280if isequal(get(handles.ZObject,'Visible'),'on')
281    data.NbDim=3; %test 3D object
282    Zcolumn=get(handles.ZObject,'String');
283    if ischar(Zcolumn)
284        Zcolumn={Zcolumn};
285    end
286end
287x_new{1}=Xcolumn{1};
288y_new{1}=Ycolumn{1};
289if ~isempty(Zcolumn)
290    z_new{1}=Zcolumn{1};
291end
292if isequal(style,'line')
293    if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse')
294        XMax=get(handles.XMax,'String');
295        YMax=get(handles.YMax,'String');
296        x_new{2}=num2str(XMax,4);
297        y_new{2}=num2str(YMax,4);
298        set(handles.XObject,'String',x_new)
299        set(handles.YObject,'String',y_new)
300        set(handles.ZObject,'String',z_new)
301    end
302elseif isequal(style,'polyline')
303elseif isequal(style,'rectangle')| isequal(style,'ellipse')
304     set(handles.XObject,'String',x_new)
305     set(handles.YObject,'String',y_new)
306     set(handles.ZObject,'String',z_new)
307end
308% end
309switch style
310    case {'points','line','polyline','plane'}
311        menu_proj={'projection';'interp';'filter';'none'};
312    case {'polygon','rectangle','ellipse'}
313        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
314    case 'volume'
315        menu_proj={'none'};
316end   
317proj_index=get(handles.ProjMode,'Value');
318if proj_index<numel(menu_proj)
319    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
320end
321set(handles.ProjMode,'String',menu_proj)
322ProjMode_Callback(hObject, eventdata, handles)
323%store the current option
324str=get(handles.ObjectStyle,'String');
325val=get(handles.ObjectStyle,'Value');
326set(handles.ObjectStyle,'UserData',style)
327
328%----------------------------------------------
329function xObject_Callback(hObject, eventdata, handles)
330
331
332function yObject_Callback(hObject, eventdata, handles)
333
334
335% --- Executes on selection change in zObject.
336function zObject_Callback(hObject, eventdata, handles)
337
338
339
340% --- Executes on selection change in ProjMode.
341function ProjMode_Callback(hObject, eventdata, handles)
342menu=get(handles.ProjMode,'String');
343value=get(handles.ProjMode,'Value');
344ProjMode=menu{value};
345menu=get(handles.ObjectStyle,'String');
346value=get(handles.ObjectStyle,'Value');
347ObjectStyle=menu{value};
348test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
349
350%default setting
351set(handles.Phi,'Visible','off')
352set(handles.Theta,'Visible','off')
353set(handles.Psi,'Visible','off')
354set(handles.XMin,'Visible','off')
355set(handles.XMax,'Visible','off')
356set(handles.YMin,'Visible','off')
357if isequal(ProjMode,'interp')
358    set(handles.YMax,'Visible','off')
359else
360    set(handles.YMax,'Visible','on')
361end
362if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
363    set(handles.XMax,'Visible','on')
364else
365   set(handles.XMax,'Visible','off')
366end
367set(handles.ZMin,'Visible','off')
368set(handles.ZMax,'Visible','off')
369set(handles.DX,'Visible','off')
370set(handles.DY,'Visible','off')
371set(handles.DZ,'Visible','off')
372
373switch ObjectStyle
374    case 'points'
375        set(handles.YMax,'TooltipString','YMax: range of averaging around each point')
376        set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
377        set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
378        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
379    case {'line','polyline','polygon'}
380        set(handles.YMax,'TooltipString','YMax: range of averaging around the line')
381        set(handles.XObject,'TooltipString','XObject: set of x coordinates defining the line')
382        set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
383        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
384        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
385            set(handles.DX,'Visible','on')
386            set(handles.DX,'TooltipString','DX: mesh for the interpolated field along the line')
387        end       
388    case {'rectangle','ellipse'}
389        set(handles.XMax,'TooltipString',['XMax: half length of the ' ObjectStyle])
390        set(handles.YMax,'TooltipString',['YMax: half width of the ' ObjectStyle])
391        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' ObjectStyle ' centre'])
392        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' ObjectStyle ' centre'])
393    case {'plane','volume'} 
394        set(handles.Phi,'Visible','on')
395        set(handles.XMin,'Visible','on')
396        set(handles.XMax,'Visible','on')
397        set(handles.YMin,'Visible','on')
398        set(handles.YMax,'Visible','on')
399        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
400        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
401        if test3D
402            set(handles.Theta,'Visible','on')
403            set(handles.Psi,'Visible','on')
404            set(handles.ZMin,'Visible','on')
405            set(handles.ZMax,'Visible','on')
406        end
407        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
408            set(handles.DX,'Visible','on')
409            set(handles.DY,'Visible','on')
410        else
411            set(handles.DX,'Visible','off')
412            set(handles.DY,'Visible','off')
413        end
414        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
415            set(handles.DZ,'Visible','on') 
416        end
417end
418%
419% %---------------------------------------------
420% % --- Executes on selection change in TITLE.
421% function TITLE_Callback(style, handles)
422% %---------------------------------------------
423% switch style
424%     case {'points','line','polyline','plane'}
425%         menu_proj={'projection';'interp';'filter';'none'};
426%     case {'polygon','rectangle','ellipse'}
427%         menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
428%     case 'volume'
429%         menu_proj={'none'};
430% end
431%
432%
433% old_menu=get(handles.ObjectStyle,'String');
434% value=get(handles.ObjectStyle,'Value');
435% old_style=old_menu{value};
436% teststyle=0;
437% for iline=1:length(menu_style)
438%     if isequal(menu_style{iline},old_style)
439%         styleval=iline;
440%         teststyle=1;
441%         break
442%     end
443% end
444% if ~teststyle
445%     new_style=[];%default
446%     switch old_style
447%         case 'polyline'
448%             new_style='polygon';
449%         case 'polygon'
450%             new_style='polyline';
451%     end
452%     if ~isempty(new_style)
453%         for iline=1:length(menu_style)
454%             if isequal(menu_style{iline},new_style)
455%                 styleval=iline;
456%                 teststyle=1;
457%                 break
458%             end
459%         end
460%     end
461% end
462% if ~teststyle
463%     styleval=1;
464% end
465% set(handles.ObjectStyle,'String',menu_style)
466% set(handles.ObjectStyle,'Value',styleval)
467% set(handles.ProjMode,'String',menu_proj)
468% set(handles.ProjMode,'Value',1)
469% ObjectStyle_Callback(hObject, eventdata, handles) 
470
471%---------------------------------------------
472function Phi_Callback(hObject, eventdata, handles)
473update_slider(hObject, eventdata,handles)
474%---------------------------------------------
475
476function Theta_Callback(hObject, eventdata, handles)
477update_slider(hObject, eventdata,handles)
478
479function update_slider(hObject, eventdata,handles)
480%rotation angles
481Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
482Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
483
484%components of the unitiy vector normal to the projection plane
485NormVec_X=-sin(Phi)*sin(Theta);
486NormVec_Y=cos(Phi)*sin(Theta);
487NormVec_Z=cos(Theta);
488huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
489UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
490if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
491    Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
492    set(handles.z_slider,'Min',min(Z))
493    set(handles.z_slider,'Max',max(Z))
494    ZMax_Callback(hObject, eventdata, handles)
495end
496
497function DX_Callback(hObject, eventdata, handles)
498
499
500function DY_Callback(hObject, eventdata, handles)
501
502
503function DZ_Callback(hObject, eventdata, handles)
504
505
506
507%-----------------------------------------------------
508% --- Executes on button press in OPEN.
509function OPEN_Callback(hObject, eventdata, handles)
510%get the object file
511oldfile=' ';
512huvmat=findobj('Tag','uvmat');
513hchild=get(huvmat,'Children');
514hrootpath=findobj(hchild,'Tag','RootPath');
515if ~isempty(hrootpath)
516    oldfile=get(hrootpath,'String');
517    if iscell(oldfile)
518        oldfile=oldfile{1};
519    end
520end
521[FileName, PathName, filterindex] = uigetfile( ...
522       {'*.xml;*.mat', ' (*.xml,*.mat)';
523       '*.xml',  '.xml files '; ...
524        '*.mat',  '.mat matlab files '}, ...
525        'Pick a file',oldfile);
526fileinput=[PathName FileName];%complete file name
527testblank=findstr(fileinput,' ');%look for blanks
528if ~isempty(testblank)
529    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
530    return
531end
532sizf=size(fileinput);
533if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
534
535%read the file
536 t=xmltree(fileinput);
537 s=convert(t);
538 if ~isfield(s,'Style')
539     s.Style='points';
540 end
541 if ~isfield(s,'ProjMode')
542     s.ProjMode='none';
543 end
544%Display title
545% title=set_title(s.Style,s.ProjMode);%update the title
546% if ~isempty(huvmat)
547%     hhuvmat=guidata(huvmat);
548% end
549% menu=get(handles.TITLE,'String');
550% for iline=1:length(menu)
551%      if isequal(menu{iline},title)
552%          set(handles.TITLE,'Value',iline)
553%          break
554%      end
555% end
556%TITLE_Callback(hObject, eventdata, handles)
557teststyle=0;
558
559switch s.Style
560    case {'points','line','polyline','plane'}
561        menu_proj={'projection';'interp';'filter';'none'};
562    case {'polygon','rectangle','ellipse'}
563        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
564    case 'volume'
565        menu_proj={'none'};
566end
567set(handles.ObjectStyle,'String',menu_proj)
568menu=get(handles.ObjectStyle,'String');
569for iline=1:length(menu)
570    if isequal(menu{iline},s.Style)
571        set(handles.ObjectStyle,'Value',iline)
572        teststyle=1;
573        break
574    end
575end
576testmode=0;
577%menu=get(handles.ProjMode,'String');
578for iline=1:length(menu_proj)
579    if isequal(menu_proj{iline},s.ProjMode)
580        set(handles.ProjMode,'Value',iline)
581        testmode=1;
582        break
583    end
584end
585
586ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
587if isfield(s,'CoordType')
588    if isequal(s.CoordType,'phys')
589        set(handles.MenuCoord,'Value',1)
590    elseif isequal(s.CoordType,'px')
591        set(handles.MenuCoord,'Value',2)
592    else
593        warndlg('unknown CoordType (px or phys) in set_object.m')
594    end
595end
596if isfield(s,'XMax')
597    set(handles.XMax,'String',s.XMax)
598end
599if isfield(s,'XMin')
600    set(handles.XMin,'String',s.XMin)
601end
602if isfield(s,'YMax')
603    set(handles.YMax,'String',s.YMax)
604end
605if isfield(s,'YMin')
606    set(handles.YMin,'String',s.YMin)
607end
608Range=0;
609if isfield(s,'Range')
610    if ischar(s.Range)
611        Range=str2num(s.Range);
612    else
613        Range(1,:)=str2num(s.Range{1});
614        Range(2,:)=str2num(s.Range{2});
615    end
616end
617if size(Range,2)>=3
618    if size(Range,1)>=2
619       set(handles.ZMin,'String',num2str(Range(2,3),3))
620    end
621    if size(Range,1)>=2
622       set(handles.ZMax,'String',num2str(Range(1,3),3))
623    end
624end
625if size(Range,2)>=2
626    if size(Range,1)>=2
627       set(handles.YMin,'String',num2str(Range(2,2),3))
628    end
629    if size(Range,1)>=2
630       set(handles.YMax,'String',num2str(Range(1,2),3))
631    end
632end
633if size(Range,2)>=1
634    if size(Range,1)>=2
635       set(handles.XMin,'String',num2str(Range(2,1),3))
636    end
637    if size(Range,1)>=2
638       set(handles.XMax,'String',num2str(Range(1,1),3))
639    end
640end
641if isfield(s,'RangeX') & ischar(s.RangeX)
642     RangeX=str2num(s.RangeX);
643    set(handles.XMax,'String',num2str(max(RangeX),3))
644    set(handles.XMin,'String',num2str(min(RangeX),3))
645end
646
647if isfield(s,'RangeY')
648    if ischar(s.RangeY)
649        RangeY=str2num(s.RangeY);
650        set(handles.YMax,'String',num2str(max(RangeY),3))
651        set(handles.YMin,'String',num2str(min(RangeY),3))
652    end
653end
654if isfield(s,'RangeZ')
655    if ischar(s.RangeZ)
656        RangeZ=str2num(s.RangeZ);
657        set(handles.ZMax,'String',num2str(max(RangeZ),3))
658        set(handles.ZMin,'String',num2str(min(RangeZ),3))
659    end
660end
661if isfield(s,'Phi')
662    set(handles.Phi,'String',s.Phi)
663end
664if isfield(s,'Theta')
665    set(handles.Theta,'String',s.Theta)
666end
667if isfield(s,'Psi')
668    set(handles.Psi,'String',s.Psi)
669end
670
671if isfield(s,'DX')
672    set(handles.DX,'String',s.DX)
673end
674if isfield(s,'DY')
675    set(handles.DY,'String',s.DY)
676end
677if ~isfield(s,'Coord')
678    XObject='0';%default
679    YObject='0';
680elseif ischar(s.Coord)
681    line=str2num(s.Coord);
682    XObject=num2str(line(1),4);
683    YObject=num2str(line(2),4);
684else
685    for i=1:length(s.Coord)
686        line=str2num(s.Coord{i});
687        XObject{i}=num2str(line(1),4);
688        YObject{i}=num2str(line(2),4);
689    end
690end
691set(handles.XObject,'String',XObject)
692set(handles.YObject,'String',YObject)
693%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
694
695%----------------------------------------------------
696% executed when closing: set the parent interface button to value 0
697function closefcn(gcbo,eventdata,parent_button)
698
699huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
700if ~isempty(huvmat)
701    hhuvmat=guidata(huvmat);
702    set(hhuvmat.create,'Value',0)
703    set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
704%     set(hhuvmat.LINE,'Value',0)
705%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
706%     set(hhuvmat.PATCH,'Value',0)
707%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
708%     set(hhuvmat.PLANE,'Value',0)
709%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
710%     set(hhuvmat.VOLUME,'Value',0)
711%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
712    set(hhuvmat.edit,'Value',0)
713    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
714end
715hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
716if ~isempty(hseries)
717    hhseries=guidata(hseries);
718    set(hhseries.GetObject,'Value',0)
719    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
720end
721
722%-----------------------------------------------------------------------
723% --- Executes on button press in PLOT: PLOT the defined object and its projected field
724function PLOT_Callback(hObject, eventdata, handles)
725
726hsetobject=get(handles.PLOT,'parent');
727SetData=get(hsetobject,'UserData');%get the hidden interface data
728huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
729hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object list in the GUI uvmat
730IndexObj=get(hlist_object,'Value');%position in the objet list
731UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
732ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
733ObjectData.HandlesDisplay=[]; % new object plot by default
734if length(UvData.Object) >= IndexObj && isfield(UvData.Object{IndexObj},'HandlesDisplay')
735    hdisplay=UvData.Object{IndexObj}.HandlesDisplay;
736    if isequal(UvData.Object{IndexObj}.Style, ObjectData.Style) && isequal(UvData.Object{IndexObj}.ProjMode, ObjectData.ProjMode)
737        ObjectData.HandlesDisplay=UvData.Object{IndexObj}.HandlesDisplay;
738    else  % for a new object styl, delete the existing object plots
739        for ih=1:length(hdisplay)
740            PlotData=get(hdisplay(ih),'UserData');
741            if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject)
742                    delete(PlotData.SubObject);
743            end
744            if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint)
745                   delete(PlotData.DeformPoint);
746            end
747            if ~isequal(hdisplay(ih),0)
748                delete(hdisplay(ih));
749            end
750        end
751        if isfield(ObjectData,'plotaxes') && ishandle(ObjectData.plotaxes)
752            delete(ObjectData.plotaxes)%delete the axes for plotting the current projection result
753        end
754    end     
755end
756
757% update the object plot and projection field
758UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
759
760set(huvmat,'UserData',UvData)%update the data in the uvmat interface
761list_str=get(hlist_object,'String');
762% TITLE=set_title(ObjectData.Style,ObjectData.ProjMode);
763% list_str{IndexObj}=[num2str(IndexObj) '-' TITLE];
764list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
765if isequal(length(list_str),IndexObj)
766    list_str{IndexObj+1}='more...';
767end
768set(hlist_object,'String',list_str)
769set(hlist_object,'Value',IndexObj)
770
771%update create buttons on the GUI uvmat: set to object edit mode after object plotting
772hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
773%desactivate all create buttons in mode edit
774% if isequal(get(hhuvmat.edit,'Value'),0)
775    set(hhuvmat.create,'Value',0)
776    set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
777%     set(hhuvmat.LINE,'Value',0)
778%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
779%     set(hhuvmat.PATCH,'Value',0)
780%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
781%     set(hhuvmat.PLANE,'Value',0)
782%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
783%     set(hhuvmat.VOLUME,'Value',0)
784%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
785% end
786set(hhuvmat.edit,'Value',1)
787set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
788set(hhuvmat.edit,'Value',1);%
789UvData.MouseAction='edit_object'; % set the edit button to 'on'
790set(huvmat,'UserData',UvData)
791
792% --- Executes on button press in MenuCoord.
793function MenuCoord_Callback(hObject, eventdata, handles)
794
795%----------------------------------------------------
796function YMin_Callback(hObject, eventdata, handles)
797
798
799function ZMin_Callback(hObject, eventdata, handles)
800
801
802function ZMax_Callback(hObject, eventdata, handles)
803DZ=str2num(get(handles.ZMax,'String'));
804ZMin=get(handles.z_slider,'Min');
805ZMax=get(handles.z_slider,'Max');
806if ~isequal(ZMax-ZMin,0)
807    rel_step(1)=DZ/(ZMax-ZMin);
808    rel_step(2)=0.2;
809    set(handles.z_slider,'SliderStep',rel_step)
810end
811
812function YMax_Callback(hObject, eventdata, handles)
813
814
815function XMin_Callback(hObject, eventdata, handles)
816
817
818function XMax_Callback(hObject, eventdata, handles)
819
820
821% ------------------------------------------------------
822function SAVE_Callback(hObject, eventdata, handles)
823% ------------------------------------------------------
824Object=read_set_object(handles);
825huvmat=findobj('Tag','uvmat');
826% UvData=get(huvmat,'UserData');
827if isempty(huvmat)
828    huvmat=findobj(allchild(0),'Name','series');
829end
830hchild=get(huvmat,'Children');
831hrootpath=findobj(hchild,'Tag','RootPath');
832if isempty(hrootpath)
833    RootPath='';
834else
835    RootPath=get(hrootpath,'String');
836    if iscell(RootPath)
837        RootPath=RootPath{1};
838    end
839end
840title={'object name'};
841dir_save=uigetdir(RootPath);
842def={fullfile(dir_save,['Object' Object.CoordType '.xml'])};
843options.Resize='on';
844displ_txt='save object as an .xml file';%default display
845menu=get(handles.ProjMode,'String');
846value=get(handles.ProjMode,'Value');
847ProjMode=menu{value};
848if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
849    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
850end
851answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
852%answer=inputdlg('','save object in a new .xml file',1,def,'on');
853if ~isempty(answer)
854    t=struct2xml(Object);
855    save(t,answer{1})
856end
857msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
858
859%---------------------------------------------------------
860% --- Executes on slider movement.
861function z_slider_Callback(hObject, eventdata, handles)
862%---------------------------------------------------------
863%A ADAPTER
864Z_value=get(handles.z_slider,'Value');
865
866%rotation angles
867Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
868Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
869
870%components of the unity vector normal to the projection plane
871NormVec_X=-sin(Phi)*sin(Theta);
872NormVec_Y=cos(Phi)*sin(Theta);
873NormVec_Z=cos(Theta);
874
875%set new plane position and update graph
876set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
877set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
878set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
879PLOT_Callback(hObject, eventdata, handles)
880
881
882% --- Executes on button press in HELP.
883function HELP_Callback(hObject, eventdata, handles)
884path_to_uvmat=which ('uvmat');% check the path of uvmat
885pathelp=fileparts(path_to_uvmat);
886helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
887if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
888else
889    addpath (fullfile(pathelp,'uvmat_doc'))
890    web([helpfile '#set_object'])
891end
892
893
894
Note: See TracBrowser for help on using the repository browser.