source: trunk/src/set_object.m @ 146

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

bugs corrected for projection objects

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