source: trunk/src/set_object.m @ 307

Last change on this file since 307 was 307, checked in by sommeria, 9 years ago

bug fixed in the browser of civ + bug fix for the plot of objects

File size: 33.8 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_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)
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%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
647%------------------------------------------------------------------------
648%----------------------------------------------------
649% executed when closing: set the parent interface button to value 0
650function closefcn(gcbo,eventdata,parent_button)
651
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
673ObjectName=get(handles.TITLE,'String');%name of the current object
674ListObject=get(hhuvmat.ListObject,'String');%position in the objet list
675IndexObj=get(hhuvmat.ListObject,'Value');
676IndexObj_1=IndexObj(1);
677% if isequal(get(hhuvmat.list_object_2,'Visible'),'on')
678%     IndexObj_2=get(hhuvmat.list_object_2,'Value');
679%     List2=get(hhuvmat.list_object_2,'String');
680if numel(IndexObj)==2
681    IndexObj_2=IndexObj(2);
682else
683    IndexObj_2=[];
684end
685testnew=0;
686ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
687if ~isempty(ListObject) && strcmp(ListObject{IndexObj_1},ObjectName)% we are editing the object whose projection is viewed in the uvmat frame
688    IndexObj=IndexObj_1;
689    projview='uvmat';
690elseif ~isempty(IndexObj_2) && IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field 
691    IndexObj=IndexObj_2;
692    projview='view_field';
693else %new object
694    testnew=1;
695    IndexObj=numel(ListObject)+1;
696    projview='view_field';
697end
698if strcmp(projview,'view_field')
699    hview_field=findobj(allchild(0),'tag','view_field');
700    if isempty(hview_field)
701        hview_field=view_field;
702    end
703    PlotHandles=guidata(hview_field);
704    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
705else
706    PlotHandles=hhuvmat;
707    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
708
709end   
710
711%% naming the object
712if length(ObjectName)<1% name of object not defined in set_object
713    ObjectName=[num2str(IndexObj) '-' ObjectData.Style];%default name
714elseif ~get(hhuvmat.edit_object,'Value')%not in edit mode (new object created)
715    detectname=1;
716    ObjectNameNew=ObjectName;
717    vers=0;
718    while detectname==1
719        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
720        if detectname% if the object name already exists
721            indstr=regexp(ObjectNameNew,'\D');
722            if indstr(end)<length(ObjectNameNew) %object name ends by a number
723                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
724                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
725            else
726                vers=vers+1;
727                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];     
728            end
729        end
730    end
731    ObjectName=ObjectNameNew;
732end
733ListObject{IndexObj,1}=ObjectName;
734set(hhuvmat.ListObject,'String',ListObject)
735% set(hhuvmat.list_object_2,'String',ListObject)
736
737%% update the object plot and projection field
738if testnew
739   set(hhuvmat.ListObject,'Value',IndexObj)
740%     set(hhuvmat.list_object_2,'Value',IndexObj)
741    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
742    ObjectData.DisplayHandle_view_field=[];
743else
744    IndexObj
745    UvData.Object{IndexObj}
746    if IndexObj<=length(UvData.Object) && isfield(UvData.Object{IndexObj},'DisplayHandle_uvmat')% save the previous object graph handles
747        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj}.DisplayHandle_uvmat;
748    else
749        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
750    end
751    if isfield(UvData.Object{IndexObj},'DisplayHandle_view_field')% save the previous object graph handles
752        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj}.DisplayHandle_view_field;
753    else
754        ObjectData.DisplayHandle_view_field=[];
755    end
756end
757UvData.Object{IndexObj}=ObjectData;%update the current object properties
758UvData.Object=update_obj(UvData,IndexObj_1,IndexObj_2);
759set(huvmat,'UserData',UvData)
760
761%% plot the field projected on the object and store in the corresponding figue
762[ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
763if ~isempty(errormsg)
764    msgbox_uvmat('ERROR', errormsg)
765    return
766end
767%PlotParam=read_plot_param(PlotHandles);
768fighandle=get(plotaxes,'parent');
769PlotParam=read_GUI(fighandle);
770[PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
771
772%% update the GUI uvmat
773hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
774set(hhuvmat.MenuEditObject,'enable','on')
775set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
776set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
777%UvData.MouseAction='edit_object'; % set the edit button to 'on'
778
779%------------------------------------------------------------------------
780% --- Executes on button press in MenuCoord.
781function MenuCoord_Callback(hObject, eventdata, handles)
782%------------------------------------------------------------------------
783%----------------------------------------------------
784function YMin_Callback(hObject, eventdata, handles)
785%------------------------------------------------------------------------
786
787function ZMin_Callback(hObject, eventdata, handles)
788%------------------------------------------------------------------------
789
790function ZMax_Callback(hObject, eventdata, handles)
791DZ=str2num(get(handles.ZMax,'String'));
792ZMin=get(handles.z_slider,'Min');
793ZMax=get(handles.z_slider,'Max');
794if ~isequal(ZMax-ZMin,0)
795    rel_step(1)=DZ/(ZMax-ZMin);
796    rel_step(2)=0.2;
797    set(handles.z_slider,'SliderStep',rel_step)
798end
799%------------------------------------------------------------------------
800function YMax_Callback(hObject, eventdata, handles)
801%------------------------------------------------------------------------
802
803function XMin_Callback(hObject, eventdata, handles)
804%------------------------------------------------------------------------
805
806function XMax_Callback(hObject, eventdata, handles)
807%------------------------------------------------------------------------
808%------------------------------------------------------------------------
809function SAVE_Callback(hObject, eventdata, handles)
810% ------------------------------------------------------
811Object=read_set_object(handles);
812huvmat=findobj('Tag','uvmat');
813% UvData=get(huvmat,'UserData');
814if isempty(huvmat)
815    huvmat=findobj(allchild(0),'Name','series');
816end
817hchild=get(huvmat,'Children');
818hrootpath=findobj(hchild,'Tag','RootPath');
819if isempty(hrootpath)
820    RootPath='';
821else
822    RootPath=get(hrootpath,'String');
823    if iscell(RootPath)
824        RootPath=RootPath{1};
825    end
826end
827title={'object name'};
828dir_save=uigetdir(RootPath);
829ObjectName=get(handles.TITLE,'String');
830if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
831    def={fullfile(dir_save,[ObjectName '.xml'])};
832else
833    def={fullfile(dir_save,[Object.Style '.xml'])};
834end
835displ_txt='save object as an .xml file';%default display
836menu=get(handles.ProjMode,'String');
837value=get(handles.ProjMode,'Value');
838ProjMode=menu{value};
839if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
840    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
841end
842answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
843if ~isempty(answer)
844    t=struct2xml(Object);
845    save(t,answer{1})
846end
847msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
848
849%------------------------------------------------------------------------
850% --- Executes on slider movement.
851function z_slider_Callback(hObject, eventdata, handles)
852%---------------------------------------------------------
853Z_value=get(handles.z_slider,'Value');
854%rotation angles
855PlaneAngle=[0 0 0];
856norm_plane=[0 0 1];
857cos_om=1;
858sin_om=0;
859
860PlaneAngle(1)=str2double(get(handles.Phi,'String'));%first  angle in degrees
861PlaneAngle(2)=str2double(get(handles.Theta,'String'));%second  angle in degrees
862PlaneAngle(3)=str2double(get(handles.Psi,'String'));%second  angle in degrees
863PlaneAngle=(pi/180)*PlaneAngle;
864om=norm(PlaneAngle);%norm of rotation angle in radians
865if isequal(om,0)
866    norm_plane=[0 0 1];
867else
868    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
869    cos_om=cos(om);
870    sin_om=sin(om);
871    coeff=OmAxis(3)*(1-cos_om);
872    %components of the unity vector norm_plane normal to the projection plane
873    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
874    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
875    norm_plane(3)=OmAxis(3)*coeff+cos_om;
876end
877
878%set new plane position and update graph
879set(handles.XObject,'String',num2str(norm_plane(1)*Z_value,4))
880set(handles.YObject,'String',num2str(norm_plane(2)*Z_value,4))
881set(handles.ZObject,'String',num2str(norm_plane(3)*Z_value,4))
882PLOT_Callback(hObject, eventdata, handles)
883
884%------------------------------------------------------------------------
885% --- Executes on button press in HELP.
886function HELP_Callback(hObject, eventdata, handles)
887%------------------------------------------------------------------------
888path_to_uvmat=which ('uvmat');% check the path of uvmat
889pathelp=fileparts(path_to_uvmat);
890helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
891if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
892else
893    addpath (fullfile(pathelp,'uvmat_doc'))
894    web([helpfile '#set_object'])
895end
896%------------------------------------------------------------------------
897
898
Note: See TracBrowser for help on using the repository browser.