source: trunk/src/set_object.m @ 72

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

ima2vol: write image volumes in 16 bits (test for civ_3D)
plot-text removed: put as a sub-function of plot_field
uvmat: movie stops in case of error in reding files
bug fixes for reading 3D vel fields

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