source: trunk/src/set_object.m @ 40

Last change on this file since 40 was 40, checked in by sommeria, 11 years ago

-relabel_i_j added to the svn (relabel an image series with two indices)
-Menu projection Object added to uvmat, rationalizes the call of projection objects (to improve yet)
-get_plot_handles: modified in relationwith the Menu projection object
-mouse_down: corrected in relation with previous change in field transforms
-transform_field functions added to the svn
-set_object and keyboard_callback: cleaning

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