source: trunk/src/set_object.m @ 35

Last change on this file since 35 was 2, checked in by gostiaux, 15 years ago
  • Initial import
  • Add .m files in src
  • Add .fig files in src
  • Add .xml config files
File size: 30.6 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');
516% if isempty(huvmat)
517%     huvmat=findobj(allchild(0),'Name','series');
518% end
519hchild=get(huvmat,'Children');
520hrootpath=findobj(hchild,'Tag','RootPath');
521if ~isempty(hrootpath)
522    oldfile=get(hrootpath,'String');
523    if iscell(oldfile)
524        oldfile=oldfile{1};
525    end
526end
527%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
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    errordlg('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
552title=set_title(s.Style,s.ProjMode);%update the title
553if ~isempty(huvmat)
554    hhuvmat=guidata(huvmat);
555%     set(hhuvmat.POINTS,'Value',0)
556%     set(hhuvmat.POINTS,'BackgroundColor',[0 1 0])%put unactivated buttons to green
557%     set(hhuvmat.LINE,'Value',0)
558%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
559%     set(hhuvmat.PATCH,'Value',0)
560%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
561%     set(hhuvmat.PLANE,'Value',0)
562%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
563%     set(hhuvmat.VOLUME,'Value',0)
564%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
565%     if ~isequal(title,'MASK')
566%         eval(['set(hhuvmat.' title ',''Value'',1)'])
567%         eval(['set(hhuvmat.' title ',''BackgroundColor'',[1 1 0])'])
568%     end
569end
570menu=get(handles.TITLE,'String');
571for iline=1:length(menu)
572     if isequal(menu{iline},title)
573         set(handles.TITLE,'Value',iline)
574         break
575     end
576end
577TITLE_Callback(hObject, eventdata, handles)
578teststyle=0;
579% if isfield(s,'Style')
580menu=get(handles.ObjectStyle,'String');
581for iline=1:length(menu)
582    if isequal(menu{iline},s.Style)
583        set(handles.ObjectStyle,'Value',iline)
584        teststyle=1;
585        break
586    end
587end
588testmode=0;
589menu=get(handles.ProjMode,'String');
590for iline=1:length(menu)
591    if isequal(menu{iline},s.ProjMode)
592        set(handles.ProjMode,'Value',iline)
593        testmode=1;
594        break
595    end
596end
597
598ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
599if isfield(s,'CoordType')
600    if isequal(s.CoordType,'phys')
601        set(handles.MenuCoord,'Value',1)
602    elseif isequal(s.CoordType,'px')
603        set(handles.MenuCoord,'Value',2)
604    else
605        warndlg('unknown CoordType (px or phys) in set_object.m')
606    end
607end
608if isfield(s,'XMax')
609    set(handles.XMax,'String',s.XMax)
610end
611if isfield(s,'XMin')
612    set(handles.XMin,'String',s.XMin)
613end
614if isfield(s,'YMax')
615    set(handles.YMax,'String',s.YMax)
616end
617if isfield(s,'YMin')
618    set(handles.YMin,'String',s.YMin)
619end
620Range=0;
621if isfield(s,'Range')
622    if ischar(s.Range)
623        Range=str2num(s.Range);
624    else
625        Range(1,:)=str2num(s.Range{1});
626        Range(2,:)=str2num(s.Range{2});
627    end
628end
629if size(Range,2)>=3
630    if size(Range,1)>=2
631       set(handles.ZMin,'String',num2str(Range(2,3),3))
632    end
633    if size(Range,1)>=2
634       set(handles.ZMax,'String',num2str(Range(1,3),3))
635    end
636end
637if size(Range,2)>=2
638    if size(Range,1)>=2
639       set(handles.YMin,'String',num2str(Range(2,2),3))
640    end
641    if size(Range,1)>=2
642       set(handles.YMax,'String',num2str(Range(1,2),3))
643    end
644end
645if size(Range,2)>=1
646    if size(Range,1)>=2
647       set(handles.XMin,'String',num2str(Range(2,1),3))
648    end
649    if size(Range,1)>=2
650       set(handles.XMax,'String',num2str(Range(1,1),3))
651    end
652end
653if isfield(s,'RangeX') & ischar(s.RangeX)
654     RangeX=str2num(s.RangeX);
655    set(handles.XMax,'String',num2str(max(RangeX),3))
656    set(handles.XMin,'String',num2str(min(RangeX),3))
657end
658
659if isfield(s,'RangeY')
660    if ischar(s.RangeY)
661        RangeY=str2num(s.RangeY);
662        set(handles.YMax,'String',num2str(max(RangeY),3))
663        set(handles.YMin,'String',num2str(min(RangeY),3))
664    end
665end
666if isfield(s,'RangeZ')
667    if ischar(s.RangeZ)
668        RangeZ=str2num(s.RangeZ);
669        set(handles.ZMax,'String',num2str(max(RangeZ),3))
670        set(handles.ZMin,'String',num2str(min(RangeZ),3))
671    end
672end
673if isfield(s,'Phi')
674    set(handles.Phi,'String',s.Phi)
675end
676if isfield(s,'Theta')
677    set(handles.Theta,'String',s.Theta)
678end
679if isfield(s,'Psi')
680    set(handles.Psi,'String',s.Psi)
681end
682
683if isfield(s,'DX')
684    set(handles.DX,'String',s.DX)
685end
686if isfield(s,'DY')
687    set(handles.DY,'String',s.DY)
688end
689if ~isfield(s,'Coord')
690    XObject='0';%default
691    YObject='0';
692elseif ischar(s.Coord)
693    line=str2num(s.Coord);
694    XObject=num2str(line(1),4);
695    YObject=num2str(line(2),4);
696else
697    for i=1:length(s.Coord)
698        line=str2num(s.Coord{i});
699        XObject{i}=num2str(line(1),4);
700        YObject{i}=num2str(line(2),4);
701    end
702end
703set(handles.XObject,'String',XObject)
704set(handles.YObject,'String',YObject)
705%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
706
707%----------------------------------------------------
708% executed when closing: set the parent interface button to value 0
709function closefcn(gcbo,eventdata,parent_button)
710
711huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
712if ~isempty(huvmat)
713    hhuvmat=guidata(huvmat);
714    set(hhuvmat.create,'Value',0)
715    set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
716%     set(hhuvmat.LINE,'Value',0)
717%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
718%     set(hhuvmat.PATCH,'Value',0)
719%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
720%     set(hhuvmat.PLANE,'Value',0)
721%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
722%     set(hhuvmat.VOLUME,'Value',0)
723%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
724    set(hhuvmat.edit,'Value',0)
725    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
726end
727hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
728if ~isempty(hseries)
729    hhseries=guidata(hseries);
730    set(hhseries.GetObject,'Value',0)
731    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
732end
733
734%-----------------------------------------------------------------------
735% --- Executes on button press in PLOT: PLOT the defined object and its projected field
736function PLOT_Callback(hObject, eventdata, handles)
737
738hsetobject=get(handles.PLOT,'parent');
739SetData=get(hsetobject,'UserData');%get the hidden interface data
740huvmat=findobj('Name','uvmat');%find the current uvmat interface handle
741hlist_object=findobj(huvmat,'Tag','list_object');%handles of the object list in the GUI uvmat
742IndexObj=get(hlist_object,'Value');%position in the objet list
743UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
744ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
745ObjectData.HandlesDisplay=[]; % new object plot by default
746if length(UvData.Object) >= IndexObj && isfield(UvData.Object{IndexObj},'HandlesDisplay')
747    hdisplay=UvData.Object{IndexObj}.HandlesDisplay;
748    if isequal(UvData.Object{IndexObj}.Style, ObjectData.Style) && isequal(UvData.Object{IndexObj}.ProjMode, ObjectData.ProjMode)
749        ObjectData.HandlesDisplay=UvData.Object{IndexObj}.HandlesDisplay;
750    else  % for a new object styl, delete the existing object plots
751        for ih=1:length(hdisplay)
752            PlotData=get(hdisplay(ih),'UserData');
753            if isfield(PlotData,'SubObject') & ishandle(PlotData.SubObject)
754                    delete(PlotData.SubObject);
755            end
756            if isfield(PlotData,'DeformPoint') & ishandle(PlotData.DeformPoint)
757                   delete(PlotData.DeformPoint);
758            end
759            if ~isequal(hdisplay(ih),0)
760                delete(hdisplay(ih));
761            end
762        end
763        if isfield(ObjectData,'plotaxes') && ishandle(ObjectData.plotaxes)
764            delete(ObjectData.plotaxes)%delete the axes for plotting the current projection result
765        end
766    end     
767end
768
769% update the object plot and projection field
770UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
771
772set(huvmat,'UserData',UvData)%update the data in the uvmat interface
773list_str=get(hlist_object,'String');
774TITLE=set_title(ObjectData.Style,ObjectData.ProjMode);
775list_str{IndexObj}=[num2str(IndexObj) '-' TITLE];
776if isequal(length(list_str),IndexObj)
777    list_str{IndexObj+1}='more...';
778end
779set(hlist_object,'String',list_str)
780set(hlist_object,'Value',IndexObj)
781
782%update create buttons on the GUI uvmat: set to object edit mode after object plotting
783hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
784%desactivate all create buttons in mode edit
785% if isequal(get(hhuvmat.edit,'Value'),0)
786    set(hhuvmat.create,'Value',0)
787    set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
788%     set(hhuvmat.LINE,'Value',0)
789%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
790%     set(hhuvmat.PATCH,'Value',0)
791%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
792%     set(hhuvmat.PLANE,'Value',0)
793%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
794%     set(hhuvmat.VOLUME,'Value',0)
795%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
796% end
797set(hhuvmat.edit,'Value',1)
798set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
799set(hhuvmat.edit,'Value',1);%
800UvData.MouseAction='edit_object'; % set the edit button to 'on'
801set(huvmat,'UserData',UvData)
802
803% --- Executes on button press in MenuCoord.
804function MenuCoord_Callback(hObject, eventdata, handles)
805
806%----------------------------------------------------
807function YMin_Callback(hObject, eventdata, handles)
808
809
810function ZMin_Callback(hObject, eventdata, handles)
811
812
813function ZMax_Callback(hObject, eventdata, handles)
814DZ=str2num(get(handles.ZMax,'String'));
815ZMin=get(handles.z_slider,'Min');
816ZMax=get(handles.z_slider,'Max');
817if ~isequal(ZMax-ZMin,0)
818    rel_step(1)=DZ/(ZMax-ZMin);
819    rel_step(2)=0.2;
820    set(handles.z_slider,'SliderStep',rel_step)
821end
822
823function YMax_Callback(hObject, eventdata, handles)
824
825
826function XMin_Callback(hObject, eventdata, handles)
827
828
829function XMax_Callback(hObject, eventdata, handles)
830
831
832% ------------------------------------------------------
833function SAVE_Callback(hObject, eventdata, handles)
834% ------------------------------------------------------
835Object=read_set_object(handles);
836huvmat=findobj('Tag','uvmat');
837% UvData=get(huvmat,'UserData');
838if isempty(huvmat)
839    huvmat=findobj(allchild(0),'Name','series');
840end
841hchild=get(huvmat,'Children');
842hrootpath=findobj(hchild,'Tag','RootPath');
843if isempty(hrootpath)
844    RootPath='';
845else
846    RootPath=get(hrootpath,'String');
847    if iscell(RootPath)
848        RootPath=RootPath{1};
849    end
850end
851title={'object name'};
852dir_save=uigetdir(RootPath);
853def={fullfile(dir_save,['Object' Object.CoordType '.xml'])};
854options.Resize='on';
855displ_txt='save object as an .xml file';%default display
856menu=get(handles.ProjMode,'String');
857value=get(handles.ProjMode,'Value');
858ProjMode=menu{value};
859if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
860    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
861end
862answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
863%answer=inputdlg('','save object in a new .xml file',1,def,'on');
864if ~isempty(answer)
865    t=struct2xml(Object);
866    save(t,answer{1})
867end
868msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
869%---------------------------------------------------------
870% --- Executes on slider movement.
871function z_slider_Callback(hObject, eventdata, handles)
872%---------------------------------------------------------
873%A ADAPTER
874Z_value=get(handles.z_slider,'Value');
875
876%rotation angles
877Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
878Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
879
880%components of the unity vector normal to the projection plane
881NormVec_X=-sin(Phi)*sin(Theta);
882NormVec_Y=cos(Phi)*sin(Theta);
883NormVec_Z=cos(Theta);
884
885%set new plane position and update graph
886set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
887set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
888set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
889PLOT_Callback(hObject, eventdata, handles)
890
891
892
893function XObject_Callback(hObject, eventdata, handles)
894
895
896function YObject_Callback(hObject, eventdata, handles)
897
898
899
900
901function ZObject_Callback(hObject, eventdata, handles)
902
903
904% --- Executes on button press in HELP.
905function HELP_Callback(hObject, eventdata, handles)
906path_to_uvmat=which ('uvmat');% check the path of uvmat
907pathelp=fileparts(path_to_uvmat);
908helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
909if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
910else
911    web([helpfile '#set_object'])   
912end
913
914
915
916
Note: See TracBrowser for help on using the repository browser.