source: trunk/src/set_object.m @ 81

Last change on this file since 81 was 81, checked in by sommeria, 14 years ago

several bug repairs:
option movie backward introduced for uvmat

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