source: trunk/src/set_object.m @ 387

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

several bugs corrected: mask, color image...

File size: 28.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% INPUT:
10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
15%    .RangeX, RangeY
16%    .Coord(j,i), i=1, 2, 3,  components x, y, z of j=1...n position(s) characterizing the object components
17% PlotHandles: handles for projection plots NO MORE USED
18% Zbounds: bounds on Z ( 3D case)
19%
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23%     This file is part of the toolbox UVMAT.
24%
25%     UVMAT is free software; you can redistribute it and/or modify
26%     it under the terms of the GNU General Public License as published by
27%     the Free Software Foundation; either version 2 of the License, or
28%     (at your option) any later version.
29%
30%     UVMAT is distributed in the hope that it will be useful,
31%     but WITHOUT ANY WARRANTY; without even the implied warranty of
32%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
34%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35
36function varargout = set_object(varargin)
37
38% Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47
39
40% Begin initialization code - DO NOT PLOT
41gui_Singleton = 1;
42gui_State = struct('gui_Name',       mfilename, ...
43                   'gui_Singleton',  gui_Singleton, ...
44                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
45                   'gui_OutputFcn',  @set_object_OutputFcn, ...
46                   'gui_LayoutFcn',  [] , ...
47                   'gui_Callback',   []);
48if nargin & ischar(varargin{1})
49    gui_State.gui_Callback = str2func(varargin{1});
50end
51
52if nargout
53    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
54else
55    gui_mainfcn(gui_State, varargin{:});
56end
57% End initialization code - DO NOT PLOT
58%------------------------------------------------------------------------
59%------------------------------------------------------------------------
60% --- Executes just before set_object is made visible.
61%INPUT:
62% handles: handles of the set_object interface elements
63%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
64%        if =[] or absent: index still undefined (create mode in uvmat)
65%        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
66%'data': read from an existing object selected in the interface
67%      .Name : class of object ('POINTS','LINE',....)
68%      .num_DX,num_DY,num_DZ; meshes for regular grids
69%      .Coord: object position coordinates
70%      .ParentButton: handle of the uicontrol object calling the interface
71% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
72%  if =[] or absent, no plot (mask mode in uvmat)
73% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
74function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
75%-------------------------------------------------------------------
76% Choose default command line output for set_object
77handles.output = hObject;
78% Update handles structure
79guidata(hObject, handles);
80
81%default
82if ~exist('ZBounds','var')
83    ZBounds=0; %default
84end
85set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
86set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
87enable_plot=0;%default: does not allow plot of object and projection
88
89% fill the interface as set in the input data:
90if exist('data','var')
91    if isfield(data,'enable_plot')
92        enable_plot=data.enable_plot;%test to desable button PLOT (display mode)
93    end
94    if isfield(data,'Coord') &&size(data.Coord,2)==3
95        set(handles.z_slider,'Visible','on')
96    else
97        set(handles.z_slider,'Visible','off')
98    end
99    if isfield(data,'TypeMenu')
100        set(handles.Type,'String',data.TypeMenu)
101    end
102    if isfield(data,'ProjModeMenu')
103%         set(handles.ProjMode,'String',data.ProjModeMenu) % data.ProjModeMenu as projMode menu
104        set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
105    end
106    errormsg=fill_GUI(data,handles);
107    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
108
109    if isfield(data,'RangeZ') && length(ZBounds) >= 2
110        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
111        DZ=max(data.RangeZ);%slider step
112        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
113            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
114            rel_step(2)=0.1;
115            set(handles.z_slider,'Visible','on')
116            set(handles.z_slider,'Min',ZBounds(1))
117            set(handles.z_slider,'Max',ZBounds(2))
118            set(handles.z_slider,'SliderStep',rel_step)
119            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
120        end
121    end
122    if isfield(data,'RangeX')
123        if ischar(data.RangeX)
124            data.RangeX=str2num(data.RangeX);
125        end
126        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
127        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
128    end
129    if isfield(data,'RangeY')
130        if ischar(data.RangeY)
131            data.RangeY=str2num(data.RangeY);
132        end
133        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
134        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
135    end
136    if isfield(data,'RangeZ')
137        if ischar(data.RangeZ)
138            data.RangeZ=str2num(data.RangeZ);
139        end
140        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
141        if numel(data.RangeZ)>=2
142            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
143        end
144    end 
145    if isfield(data,'Angle') && isequal(numel(data.Angle),3)
146         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
147         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
148         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
149    end
150end
151if enable_plot
152   set(handles.PLOT,'enable','on')
153else
154   set(handles.PLOT,'enable','off')
155end
156huvmat=findobj(allchild(0),'tag','uvmat');
157UvData=get(huvmat,'UserData');
158pos_uvmat=get(huvmat,'Position');
159%position the set_object GUI with respect to uvmat
160if isfield(UvData,'SetObjectOrigin')
161    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
162    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
163    set(hObject,'Position',pos_set_object)
164end
165
166%------------------------------------------------------------------------
167% --- Outputs from this function are returned to the command line.
168function varargout = set_object_OutputFcn(hObject, eventdata, handles)
169%------------------------------------------------------------------------
170% Get default command line output from handles structure
171varargout{1} = handles.output;
172varargout{2}=handles;
173
174%------------------------------------------------------------------------
175% --- Executes on selection change in Type.
176function Type_Callback(hObject, eventdata, handles)
177%------------------------------------------------------------------------
178%style_prev=get(handles.Type,'UserData');%previous object style
179ListType=get(handles.Type,'String');
180Type=ListType{get(handles.Type,'Value')};
181% make correspondance between different object styles
182Coord=get(handles.Coord,'Data');
183
184%% set the number of lines in the Coord table depending on object type
185switch Type
186    case{'line'}
187        if size(Coord,1)<2
188            if isequal(size(Coord,2),3)
189                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
190            else
191                Coord=[Coord; 0 0]; %add a line for edition (2D case)
192            end
193        else
194            Coord=Coord(1:2,:);
195        end
196    case{'rectangle','ellipse','plane','volume'}
197        Coord=Coord(1,:);
198end
199set(handles.Coord,'Data',Coord)
200
201%% set the projection menu and the corresponding options
202if isempty(get(handles.ProjMode,'UserData'))
203    switch Type
204        case {'points','line','polyline','plane'}
205            menu_proj={'projection';'interp';'filter';'none'};
206        case {'polygon','rectangle','ellipse'}
207            menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
208        case 'volume'
209            menu_proj={'interp';'none'};
210        otherwise
211            menu_proj={'projection';'interp';'filter';'none'};%default
212    end
213else
214    menu_proj=get(handles.ProjMode,'UserData');
215end
216proj_index=get(handles.ProjMode,'Value');
217if proj_index>numel(menu_proj)
218    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
219end
220set(handles.ProjMode,'String',menu_proj)
221ProjMode_Callback(hObject, eventdata, handles)
222
223%store the current option
224% str=get(handles.Type,'String');
225% val=get(handles.Type,'Value');
226% set(handles.Type,'UserData',style)
227
228%------------------------------------------------------------------------
229function xObject_Callback(hObject, eventdata, handles)
230
231%------------------------------------------------------------------------
232function yObject_Callback(hObject, eventdata, handles)
233
234%------------------------------------------------------------------------
235% --- Executes on selection change in zObject.
236function zObject_Callback(hObject, eventdata, handles)
237%------------------------------------------------------------------------
238
239%------------------------------------------------------------------------
240% --- Executes on selection change in ProjMode.
241function ProjMode_Callback(hObject, eventdata, handles)
242menu=get(handles.ProjMode,'String');
243value=get(handles.ProjMode,'Value');
244ProjMode=menu{value};
245menu=get(handles.Type,'String');
246value=get(handles.Type,'Value');
247ObjectStyle=menu{value};
248%%%%%%%%% TODO
249test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
250%%%%%%%%%
251%default setting
252set(handles.num_Angle_1,'Visible','off')
253set(handles.num_Angle_2,'Visible','off')
254set(handles.num_Angle_3,'Visible','off')
255set(handles.num_RangeX_1,'Visible','off')
256set(handles.num_RangeX_2,'Visible','off')
257set(handles.num_RangeY_1,'Visible','off')
258if isequal(ProjMode,'interp')
259    set(handles.num_RangeY_2,'Visible','off')
260else
261    set(handles.num_RangeY_2,'Visible','on')
262end
263if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
264    set(handles.num_RangeX_2,'Visible','on')
265else
266   set(handles.num_RangeX_2,'Visible','off')
267end
268set(handles.num_RangeZ_1,'Visible','off')
269set(handles.num_RangeZ_2,'Visible','off')
270set(handles.num_DX,'Visible','off')
271set(handles.num_DY,'Visible','off')
272set(handles.num_DZ,'Visible','off')
273
274switch ObjectStyle
275    case 'points'
276        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point')
277%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
278%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
279%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
280    case {'line','polyline','polygon'}
281        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line')
282         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
283%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
284%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
285        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
286            set(handles.num_DX,'Visible','on')
287            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
288        end       
289    case {'rectangle','ellipse'}
290        set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle])
291        set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle])
292%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' Type ' centre'])
293%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' Type ' centre'])
294    case {'plane'} 
295        set(handles.num_Angle_3,'Visible','on')
296        set(handles.num_RangeX_1,'Visible','on')
297        set(handles.num_RangeX_2,'Visible','on')
298        set(handles.num_RangeY_1,'Visible','on')
299        set(handles.num_RangeY_2,'Visible','on')
300%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' Type])
301%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' Type])
302        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
303        if test3D
304            set(handles.num_Angle_2,'Visible','on')
305            set(handles.num_Angle_1,'Visible','on')
306            set(handles.num_RangeZ_2,'Visible','on')
307        end
308        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
309            set(handles.num_DX,'Visible','on')
310            set(handles.num_DY,'Visible','on')
311        else
312            set(handles.num_DX,'Visible','off')
313            set(handles.num_DY,'Visible','off')
314        end
315        if  isequal(ProjMode,'interp')
316            set(handles.num_DZ,'Visible','on') 
317        end
318     case {'volume'} 
319        set(handles.num_RangeX_1,'Visible','on')
320        set(handles.num_RangeX_2,'Visible','on')
321        set(handles.num_RangeY_1,'Visible','on')
322        set(handles.num_RangeY_2,'Visible','on')
323        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
324        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
325        set(handles.num_Angle_1,'Visible','on')
326        set(handles.num_Angle_2,'Visible','on')
327        set(handles.num_Angle_3,'Visible','on')
328        set(handles.num_RangeZ_1,'Visible','on')
329        set(handles.num_RangeZ_2,'Visible','on')
330        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
331            set(handles.num_DX,'Visible','on')
332            set(handles.num_DY,'Visible','on')
333            set(handles.num_DZ,'Visible','on')
334        else
335            set(handles.num_DX,'Visible','off')
336            set(handles.num_DY,'Visible','off')
337            set(handles.num_DZ,'Visible','off')
338        end
339end
340%------------------------------------------------------------------------
341
342%------------------------------------------------------------------------
343function num_Angle_1_Callback(hObject, eventdata, handles)
344update_slider(hObject, eventdata,handles)
345%------------------------------------------------------------------------
346%------------------------------------------------------------------------
347function num_Angle_2_Callback(hObject, eventdata, handles)
348update_slider(hObject, eventdata,handles)
349%------------------------------------------------------------------------
350function update_slider(hObject, eventdata,handles)
351%rotation angles
352PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
353PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
354PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
355om=norm(PlaneAngle);%norm of rotation angle in radians
356OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
357cos_om=cos(pi*om/180);
358sin_om=sin(pi*om/180);
359coeff=OmAxis(3)*(1-cos_om);
360%components of the unity vector norm_plane normal to the projection plane
361norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
362norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
363norm_plane(3)=OmAxis(3)*coeff+cos_om;
364huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
365UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
366if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
367    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
368    set(handles.z_slider,'Min',min(Z))
369    set(handles.z_slider,'Max',max(Z))
370    ZMax_Callback(hObject, eventdata, handles)
371end
372%------------------------------------------------------------------------
373function num_DX_Callback(hObject, eventdata, handles)
374%------------------------------------------------------------------------
375%------------------------------------------------------------------------
376function num_DY_Callback(hObject, eventdata, handles)
377%------------------------------------------------------------------------
378%------------------------------------------------------------------------
379function num_DZ_Callback(hObject, eventdata, handles)
380%------------------------------------------------------------------------
381
382%------------------------------------------------------------------------
383%------------------------------------------------------------------------
384%----------------------------------------------------
385% executed when closing: set the parent interface button to value 0
386function closefcn(gcbo,eventdata,parent_button)
387huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
388if ~isempty(huvmat)
389    hhuvmat=guidata(huvmat);
390    set(hhuvmat.edit,'Value',0)
391    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
392end
393hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
394if ~isempty(hseries)
395    hhseries=guidata(hseries);
396    set(hhseries.GetObject,'Value',0)
397    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
398end
399
400%------------------------------------------------------------------------
401% --- Executes on button press in PLOT: PLOT the defined object and its projected field
402function PLOT_Callback(hObject, eventdata, handles)
403
404%% reading the object parameters on the GUI uvmat
405huvmat=findobj('tag','uvmat');%find the current uvmat interface handle
406UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
407hhuvmat=guidata(huvmat);%handles in the uvmat GUI
408ListObject=get(hhuvmat.ListObject,'String');%position in the objet list
409IndexObj=get(hhuvmat.ListObject,'Value');
410
411%% read the object on the GUI set_object
412%ObjectData=read_set_object(handles.set_object);%read the input parameters defining the object in the GUI set_object
413ObjectData=read_GUI(handles.set_object);%read the input parameters defining the object in the GUI set_object
414%ObjectData.Coord=cell2mat(ObjectData.Coord);
415ObjectName=ObjectData.Name;%name of the current object defiend in set_object
416if isempty(ObjectName)
417    if get(hhuvmat.edit_object,'Value')% edit mode
418        ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item
419    else %new object
420        StyleList=get(handles.Type,'String');
421        StyleVal=get(handles.Type,'Value');
422        ObjectName=StyleList{StyleVal};
423    end
424end
425if ~get(hhuvmat.edit_object,'Value') %new object is being created
426    detectname=1;
427    ObjectNameNew=ObjectName;
428    vers=0;
429    while detectname==1
430        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
431        if detectname% if the object name already exists
432            indstr=regexp(ObjectNameNew,'\D');
433            if indstr(end)<length(ObjectNameNew) %object name ends by a number
434                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
435                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
436            else
437                vers=vers+1;
438                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
439            end
440        end
441    end
442    ObjectName=ObjectNameNew;
443    set(handles.Name,'String',ObjectName)% display the default name in set_object
444    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
445    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
446    set(hhuvmat.ListObject,'Value',IndexObj)
447    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
448end
449testnew=0;
450if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
451 %       PlotHandles=hhuvmat;
452    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
453else  % if a second object is selected, the projection is in view_field, and this second object is selected
454    hview_field=findobj(allchild(0),'tag','view_field');
455    if isempty(hview_field)
456        hview_field=view_field;
457    end
458    PlotHandles=guidata(hview_field);
459    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
460end
461
462%% naming the object
463ListObject{IndexObj(end),1}=ObjectName;
464set(hhuvmat.ListObject,'String',ListObject)
465
466%% update the object plot and projection field
467if testnew
468    set(hhuvmat.ListObject,'Value',IndexObj)
469    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
470    ObjectData.DisplayHandle_view_field=[];
471else
472    if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
473        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
474    else
475        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
476    end
477    if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
478        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
479    else
480        ObjectData.DisplayHandle_view_field=[];
481    end
482end
483UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
484if numel(IndexObj)==2
485    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
486end
487set(huvmat,'UserData',UvData)
488
489%% plot the field projected on the object and store in the corresponding figue
490[ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
491if ~isempty(errormsg)
492    msgbox_uvmat('ERROR', errormsg)
493    return
494end
495fighandle=get(plotaxes,'parent');
496PlotParam=read_GUI(fighandle);
497[PlotType,Object_out{IndexObj(end)}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
498
499%% update the GUI uvmat
500hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
501set(hhuvmat.MenuEditObject,'enable','on')
502set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
503set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
504
505%------------------------------------------------------------------------
506% --- Executes on button press in MenuCoord.
507function MenuCoord_Callback(hObject, eventdata, handles)
508%------------------------------------------------------------------------
509%----------------------------------------------------
510function num_RangeY_1_Callback(hObject, eventdata, handles)
511%------------------------------------------------------------------------
512
513function num_RangeZ_1_Callback(hObject, eventdata, handles)
514%------------------------------------------------------------------------
515
516function num_RangeZ_2_Callback(hObject, eventdata, handles)
517DZ=str2num(get(handles.num_RangeZ_2,'String'));
518ZMin=get(handles.z_slider,'Min');
519ZMax=get(handles.z_slider,'Max');
520if ~isequal(ZMax-ZMin,0)
521    rel_step(1)=DZ/(ZMax-ZMin);
522    rel_step(2)=0.2;
523    set(handles.z_slider,'SliderStep',rel_step)
524end
525%------------------------------------------------------------------------
526function num_RangeY_2_Callback(hObject, eventdata, handles)
527%------------------------------------------------------------------------
528
529function num_RangeX_1_Callback(hObject, eventdata, handles)
530%------------------------------------------------------------------------
531
532function num_RangeX_2_Callback(hObject, eventdata, handles)
533%------------------------------------------------------------------------
534%------------------------------------------------------------------------
535function SAVE_Callback(hObject, eventdata, handles)
536% ------------------------------------------------------
537%Object=read_set_object(handles);
538Object=read_GUI(handles.set_object);
539huvmat=findobj('Tag','uvmat');
540% UvData=get(huvmat,'UserData');
541if isempty(huvmat)
542    huvmat=findobj(allchild(0),'Name','series');
543end
544hchild=get(huvmat,'Children');
545hrootpath=findobj(hchild,'Tag','RootPath');
546if isempty(hrootpath)
547    RootPath='';
548else
549    RootPath=get(hrootpath,'String');
550    if iscell(RootPath)
551        RootPath=RootPath{1};
552    end
553end
554title={'object name'};
555dir_save=uigetdir(RootPath);
556ObjectName=get(handles.Name,'String');
557if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
558    def={fullfile(dir_save,[ObjectName '.xml'])};
559else
560    def={fullfile(dir_save,[Object.Style '.xml'])};
561end
562displ_txt='save object as an .xml file';%default display
563menu=get(handles.ProjMode,'String');
564value=get(handles.ProjMode,'Value');
565ProjMode=menu{value};
566if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
567    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
568end
569answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
570if ~isempty(answer)
571    t=struct2xml(Object);
572    save(t,answer{1})
573end
574msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
575
576%------------------------------------------------------------------------
577% --- Executes on slider movement.
578function z_slider_Callback(hObject, eventdata, handles)
579%---------------------------------------------------------
580Z_value=get(handles.z_slider,'Value');
581%rotation angles
582PlaneAngle=[0 0 0];
583norm_plane=[0 0 1];
584cos_om=1;
585sin_om=0;
586
587PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
588PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
589PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
590PlaneAngle=(pi/180)*PlaneAngle;
591om=norm(PlaneAngle);%norm of rotation angle in radians
592if isequal(om,0)
593    norm_plane=[0 0 1];
594else
595    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
596    cos_om=cos(om);
597    sin_om=sin(om);
598    coeff=OmAxis(3)*(1-cos_om);
599    %components of the unity vector norm_plane normal to the projection plane
600    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
601    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
602    norm_plane(3)=OmAxis(3)*coeff+cos_om;
603end
604
605%set new plane position and update graph
606% set(handles.XObject,'String',num2str(norm_plane(1)*Z_value,4))
607% set(handles.YObject,'String',num2str(norm_plane(2)*Z_value,4))
608% set(handles.ZObject,'String',num2str(norm_plane(3)*Z_value,4))
609PLOT_Callback(hObject, eventdata, handles)
610
611%------------------------------------------------------------------------
612% --- Executes on button press in HELP.
613function HELP_Callback(hObject, eventdata, handles)
614%------------------------------------------------------------------------
615path_to_uvmat=which ('uvmat');% check the path of uvmat
616pathelp=fileparts(path_to_uvmat);
617helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
618if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
619else
620    addpath (fullfile(pathelp,'uvmat_doc'))
621    web([helpfile '#set_object'])
622end
623%------------------------------------------------------------------------
624
625function Name_Callback(hObject, eventdata, handles)
626% hObject    handle to Name (see GCBO)
627% eventdata  reserved - to be defined in a future version of MATLAB
628% handles    structure with handles and user data (see GUIDATA)
629
630% Hints: get(hObject,'String') returns contents of Name as text
631%        str2double(get(hObject,'String')) returns contents of Name as a double
632
633%------------------------------------------------------------------------
634% --- Executes when entered data in editable cell(s) in Coord.
635function Coord_CellEditCallback(hObject, eventdata, handles)
636%------------------------------------------------------------------------
637ListType=get(handles.Type,'String');
638Type=ListType{get(handles.Type,'Value')};
639switch Type
640    % add lines if multi line input needed
641    case{'points','polyline','polygon'}
642        Coord=get(handles.Coord,'Data');
643        if isequal(size(Coord,2),3)
644            Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
645        else
646            Coord=[Coord;{[]} {[]}]; %add a line for edition (2D case)
647        end
648        set(handles.Coord,'Data',Coord)
649end
650
651
652
653function num_Angle_3_Callback(hObject, eventdata, handles)
654% hObject    handle to num_Angle_3 (see GCBO)
655% eventdata  reserved - to be defined in a future version of MATLAB
656% handles    structure with handles and user data (see GUIDATA)
657
658% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
659%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.