source: trunk/src/set_object.m @ 342

Last change on this file since 342 was 342, checked in by sommeria, 13 years ago

various bugs corrected

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