source: trunk/src/set_object.m @ 74

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

rotate_points: used for geometry_calib was forgotten. It is now added
plot_field now does not consider black the vectors with either vec_F=0 or vec_F=1 (vec_F=0 in the 3D3C software instead of vec_F=1)
set_object and uvmat: improvements for projection plane in volume vel data

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