source: trunk/src/set_object.m @ 55

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

-use of a single parameter file PARAM.xml (instead of PARAM_WIN and PARAM_LINUX).
-correction of a bug for opening an existing projection object
-manual editing of vectors made available with the builtin netcdf tool.
-bug fix for reading netcdf files with the builtin netcdf tool.

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