source: trunk/src/set_object.m @ 397

Last change on this file since 397 was 397, checked in by sommeria, 12 years ago

civ_matlab and patch improved, changes in the management of interpolation (still in progress).
adapatation to movies (use of VideoReader?)

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%------------------------------------------------------------------------
224% --- Executes on selection change in ProjMode.
225function ProjMode_Callback(hObject, eventdata, handles)
226menu=get(handles.ProjMode,'String');
227value=get(handles.ProjMode,'Value');
228ProjMode=menu{value};
229menu=get(handles.Type,'String');
230value=get(handles.Type,'Value');
231ObjectStyle=menu{value};
232%%%%%%%%% TODO
233test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
234%%%%%%%%%
235%default setting
236set(handles.num_Angle_1,'Visible','off')
237set(handles.num_Angle_2,'Visible','off')
238set(handles.num_Angle_3,'Visible','off')
239set(handles.num_RangeX_1,'Visible','off')
240set(handles.num_RangeX_2,'Visible','off')
241set(handles.num_RangeY_1,'Visible','off')
242if isequal(ProjMode,'interp')
243    set(handles.num_RangeY_2,'Visible','off')
244else
245    set(handles.num_RangeY_2,'Visible','on')
246end
247if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
248    set(handles.num_RangeX_2,'Visible','on')
249else
250   set(handles.num_RangeX_2,'Visible','off')
251end
252set(handles.num_RangeZ_1,'Visible','off')
253set(handles.num_RangeZ_2,'Visible','off')
254set(handles.num_DX,'Visible','off')
255set(handles.num_DY,'Visible','off')
256set(handles.num_DZ,'Visible','off')
257
258switch ObjectStyle
259    case 'points'
260        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point')
261%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
262%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
263%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
264    case {'line','polyline','polygon'}
265        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line')
266         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
267%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
268%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
269        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
270            set(handles.num_DX,'Visible','on')
271            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
272        end       
273    case {'rectangle','ellipse'}
274        set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle])
275        set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle])
276%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' Type ' centre'])
277%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' Type ' centre'])
278    case {'plane'} 
279        set(handles.num_Angle_3,'Visible','on')
280        set(handles.num_RangeX_1,'Visible','on')
281        set(handles.num_RangeX_2,'Visible','on')
282        set(handles.num_RangeY_1,'Visible','on')
283        set(handles.num_RangeY_2,'Visible','on')
284%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' Type])
285%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' Type])
286        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
287        if test3D
288            set(handles.num_Angle_2,'Visible','on')
289            set(handles.num_Angle_1,'Visible','on')
290            set(handles.num_RangeZ_2,'Visible','on')
291        end
292        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
293            set(handles.num_DX,'Visible','on')
294            set(handles.num_DY,'Visible','on')
295        else
296            set(handles.num_DX,'Visible','off')
297            set(handles.num_DY,'Visible','off')
298        end
299        if  isequal(ProjMode,'interp')
300            set(handles.num_DZ,'Visible','on') 
301        end
302     case {'volume'} 
303        set(handles.num_RangeX_1,'Visible','on')
304        set(handles.num_RangeX_2,'Visible','on')
305        set(handles.num_RangeY_1,'Visible','on')
306        set(handles.num_RangeY_2,'Visible','on')
307        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
308        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
309        set(handles.num_Angle_1,'Visible','on')
310        set(handles.num_Angle_2,'Visible','on')
311        set(handles.num_Angle_3,'Visible','on')
312        set(handles.num_RangeZ_1,'Visible','on')
313        set(handles.num_RangeZ_2,'Visible','on')
314        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
315            set(handles.num_DX,'Visible','on')
316            set(handles.num_DY,'Visible','on')
317            set(handles.num_DZ,'Visible','on')
318        else
319            set(handles.num_DX,'Visible','off')
320            set(handles.num_DY,'Visible','off')
321            set(handles.num_DZ,'Visible','off')
322        end
323end
324%------------------------------------------------------------------------
325
326%------------------------------------------------------------------------
327function num_Angle_1_Callback(hObject, eventdata, handles)
328update_slider(hObject, eventdata,handles)
329%------------------------------------------------------------------------
330%------------------------------------------------------------------------
331function num_Angle_2_Callback(hObject, eventdata, handles)
332update_slider(hObject, eventdata,handles)
333%------------------------------------------------------------------------
334function update_slider(hObject, eventdata,handles)
335%rotation angles
336PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
337PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
338PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
339om=norm(PlaneAngle);%norm of rotation angle in radians
340OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
341cos_om=cos(pi*om/180);
342sin_om=sin(pi*om/180);
343coeff=OmAxis(3)*(1-cos_om);
344%components of the unity vector norm_plane normal to the projection plane
345norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
346norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
347norm_plane(3)=OmAxis(3)*coeff+cos_om;
348huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
349UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
350if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
351    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
352    set(handles.z_slider,'Min',min(Z))
353    set(handles.z_slider,'Max',max(Z))
354    ZMax_Callback(hObject, eventdata, handles)
355end
356%------------------------------------------------------------------------
357function num_DX_Callback(hObject, eventdata, handles)
358%------------------------------------------------------------------------
359%------------------------------------------------------------------------
360function num_DY_Callback(hObject, eventdata, handles)
361%------------------------------------------------------------------------
362%------------------------------------------------------------------------
363function num_DZ_Callback(hObject, eventdata, handles)
364%------------------------------------------------------------------------
365
366%------------------------------------------------------------------------
367%------------------------------------------------------------------------
368%----------------------------------------------------
369% executed when closing: set the parent interface button to value 0
370function closefcn(gcbo,eventdata,parent_button)
371huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
372if ~isempty(huvmat)
373    hhuvmat=guidata(huvmat);
374    set(hhuvmat.edit,'Value',0)
375    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
376end
377hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
378if ~isempty(hseries)
379    hhseries=guidata(hseries);
380    set(hhseries.GetObject,'Value',0)
381    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
382end
383
384%------------------------------------------------------------------------
385% --- Executes on button press in PLOT: PLOT the defined object and its projected field
386function PLOT_Callback(hObject, eventdata, handles)
387
388%% reading the object parameters on the GUI uvmat
389huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
390UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
391hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
392ListObject=get(hhuvmat.ListObject,'String');% list of objects displyed in uvmat
393IndexObj=get(hhuvmat.ListObject,'Value');% index(indices) of the selected object(s) in uvmat
394                                        % (the first one is plotted in uvmat axis, the second one in view_field)
395
396%% read the object on the GUI set_object
397ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
398ObjectName=ObjectData.Name;%name of the current object defined in set_object
399if iscell(ObjectData.Coord)%check for empty line
400    ObjectData.Coord=[0 0 0];
401    hhset_object=guidata(handles.set_object);
402    set(hhset_object.Coord,'Data',ObjectData.Coord)
403end
404checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
405if ~isempty(checknan)
406    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
407end
408if isempty(ObjectName)
409    if get(hhuvmat.edit_object,'Value')% edit mode
410        if isempty(ListObject)
411            ObjectName='Plane';
412        else
413        ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item
414        end
415    else %new object
416        StyleList=get(handles.Type,'String');
417        StyleVal=get(handles.Type,'Value');
418        ObjectName=StyleList{StyleVal};
419    end
420end
421if ~get(hhuvmat.edit_object,'Value') %new object is being created
422    detectname=1;
423    ObjectNameNew=ObjectName;
424    vers=0;
425    while detectname==1
426        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
427        if detectname% if the object name already exists
428            indstr=regexp(ObjectNameNew,'\D');
429            if indstr(end)<length(ObjectNameNew) %object name ends by a number
430                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
431                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
432            else
433                vers=vers+1;
434                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
435            end
436        end
437    end
438    ObjectName=ObjectNameNew;
439    set(handles.Name,'String',ObjectName)% display the default name in set_object
440    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
441    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
442    set(hhuvmat.ListObject,'Value',IndexObj)
443    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
444end
445testnew=0;
446if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
447    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
448else  % if a second object is selected, the projection is in view_field, and this second object is selected
449    hview_field=findobj(allchild(0),'tag','view_field');
450    if isempty(hview_field)
451        hview_field=view_field;%open the GUI view_field if it is not found
452    end
453    PlotHandles=guidata(hview_field);
454    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
455end
456
457%% naming the object
458ListObject{IndexObj(end),1}=ObjectName;
459set(hhuvmat.ListObject,'String',ListObject)
460
461%% update the object plot
462if testnew
463    set(hhuvmat.ListObject,'Value',IndexObj)
464    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
465    ObjectData.DisplayHandle_view_field=[];
466else
467    if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
468        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
469    else
470        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
471    end
472    if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
473        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
474    else
475        ObjectData.DisplayHandle_view_field=[];
476    end
477end
478UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
479if numel(IndexObj)==2
480    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
481end
482set(huvmat,'UserData',UvData)
483
484%% plot the field projected on the object and store in the corresponding figue
485if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
486    PlotType='text';
487   
488else
489    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
490    if ~isempty(errormsg)
491        msgbox_uvmat('ERROR', errormsg)
492        return
493    end
494    fighandle=get(plotaxes,'parent');
495    PlotParam=read_GUI(fighandle);
496    PlotType=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
497end
498if strcmp(PlotType,'text')
499    hview_field=findobj(allchild(0),'tag','view_field'); %case of no projection (pure object display)
500    if ~isempty(hview_field)
501        delete(hview_field)
502    end
503end
504   
505%% update the GUI uvmat
506hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
507set(hhuvmat.MenuEditObject,'enable','on')
508set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
509set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
510
511%------------------------------------------------------------------------
512% --- Executes on button press in MenuCoord.
513function MenuCoord_Callback(hObject, eventdata, handles)
514%------------------------------------------------------------------------
515%----------------------------------------------------
516function num_RangeY_1_Callback(hObject, eventdata, handles)
517%------------------------------------------------------------------------
518
519function num_RangeZ_1_Callback(hObject, eventdata, handles)
520%------------------------------------------------------------------------
521
522function num_RangeZ_2_Callback(hObject, eventdata, handles)
523DZ=str2num(get(handles.num_RangeZ_2,'String'));
524ZMin=get(handles.z_slider,'Min');
525ZMax=get(handles.z_slider,'Max');
526if ~isequal(ZMax-ZMin,0)
527    rel_step(1)=DZ/(ZMax-ZMin);
528    rel_step(2)=0.2;
529    set(handles.z_slider,'SliderStep',rel_step)
530end
531%------------------------------------------------------------------------
532function num_RangeY_2_Callback(hObject, eventdata, handles)
533%------------------------------------------------------------------------
534
535function num_RangeX_1_Callback(hObject, eventdata, handles)
536%------------------------------------------------------------------------
537
538function num_RangeX_2_Callback(hObject, eventdata, handles)
539%------------------------------------------------------------------------
540%------------------------------------------------------------------------
541function SAVE_Callback(hObject, eventdata, handles)
542% ------------------------------------------------------
543%Object=read_set_object(handles);
544Object=read_GUI(handles.set_object);
545huvmat=findobj('Tag','uvmat');
546% UvData=get(huvmat,'UserData');
547if isempty(huvmat)
548    huvmat=findobj(allchild(0),'Name','series');
549end
550hchild=get(huvmat,'Children');
551hrootpath=findobj(hchild,'Tag','RootPath');
552if isempty(hrootpath)
553    RootPath='';
554else
555    RootPath=get(hrootpath,'String');
556    if iscell(RootPath)
557        RootPath=RootPath{1};
558    end
559end
560title={'object name'};
561dir_save=uigetdir(RootPath);
562ObjectName=get(handles.Name,'String');
563if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
564    def={fullfile(dir_save,[ObjectName '.xml'])};
565else
566    def={fullfile(dir_save,[Object.Style '.xml'])};
567end
568displ_txt='save object as an .xml file';%default display
569menu=get(handles.ProjMode,'String');
570value=get(handles.ProjMode,'Value');
571ProjMode=menu{value};
572if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
573    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
574end
575answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
576if ~isempty(answer)
577    t=struct2xml(Object);
578    save(t,answer{1})
579end
580msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
581
582%------------------------------------------------------------------------
583% --- Executes on slider movement.
584function z_slider_Callback(hObject, eventdata, handles)
585%---------------------------------------------------------
586Z_value=get(handles.z_slider,'Value');
587%rotation angles
588PlaneAngle=[0 0 0];
589norm_plane=[0 0 1];
590cos_om=1;
591sin_om=0;
592
593PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
594PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
595PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
596PlaneAngle=(pi/180)*PlaneAngle;
597om=norm(PlaneAngle);%norm of rotation angle in radians
598if isequal(om,0)
599    norm_plane=[0 0 1];
600else
601    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
602    cos_om=cos(om);
603    sin_om=sin(om);
604    coeff=OmAxis(3)*(1-cos_om);
605    %components of the unity vector norm_plane normal to the projection plane
606    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
607    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
608    norm_plane(3)=OmAxis(3)*coeff+cos_om;
609end
610
611% update graph
612PLOT_Callback(hObject, eventdata, handles)
613
614%------------------------------------------------------------------------
615% --- Executes on button press in HELP.
616function HELP_Callback(hObject, eventdata, handles)
617%------------------------------------------------------------------------
618path_to_uvmat=which ('uvmat');% check the path of uvmat
619pathelp=fileparts(path_to_uvmat);
620helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
621if ~isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
622    addpath (fullfile(pathelp,'uvmat_doc'))
623    web([helpfile '#set_object'])
624end
625%------------------------------------------------------------------------
626
627function Name_Callback(hObject, eventdata, handles)
628% hObject    handle to Name (see GCBO)
629% eventdata  reserved - to be defined in a future version of MATLAB
630% handles    structure with handles and user data (see GUIDATA)
631
632% Hints: get(hObject,'String') returns contents of Name as text
633%        str2double(get(hObject,'String')) returns contents of Name as a double
634
635%------------------------------------------------------------------------
636% --- Executes when entered data in editable cell(s) in Coord.
637function Coord_CellEditCallback(hObject, eventdata, handles)
638%------------------------------------------------------------------------
639ListType=get(handles.Type,'String');
640Type=ListType{get(handles.Type,'Value')};
641switch Type
642    % add lines if multi line input needed
643    case{'points','polyline','polygon'}
644        Coord=get(handles.Coord,'Data');
645        if ~isnan(Coord(end,1))
646            if isequal(size(Coord,2),3)
647                %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
648                Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case)
649            else
650                Coord=[Coord;NaN NaN]; %add a line for edition (2D case)
651            end
652            set(handles.Coord,'Data',Coord)
653        end
654end
655
656
657
658function num_Angle_3_Callback(hObject, eventdata, handles)
659% hObject    handle to num_Angle_3 (see GCBO)
660% eventdata  reserved - to be defined in a future version of MATLAB
661% handles    structure with handles and user data (see GUIDATA)
662
663% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
664%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.