source: trunk/src/set_object.m @ 71

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

civ3D updated: introduction of image size
imadoc2struct: reding of image size from the xml file
set_object, view_field and related functions: improvement of projection object editing
mouse: possibility of adjusting the calibrations points with the mouse

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