source: trunk/src/set_object.m @ 77

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

introduction of volume projection on a regular grid (mode 'interp') using griddata3. It works but very slow.
minor bug corrections
todo: problem with 3D projection when the same field is read twice (e;g. w used for vector color)

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