source: trunk/src/set_object.m @ 402

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

bugs corrected and improved procedure for object projection

File size: 29.7 KB
Line 
1%'set_object': GUI to edit a projection object
2%------------------------------------------------------------------------
3% function hset_object= set_object(data, PlotHandles,ZBounds)
4% associated with the GUI set_object.fig
5%
6% OUTPUT:
7% hset_object: handle of the GUI figure
8%
9% 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
87set(hObject,'DeleteFcn',{@closefcn})
88enable_plot=0;%default: does not allow plot of object and projection
89
90% fill the interface as set in the input data:
91if exist('data','var')
92%     if isfield(data,'enable_plot')
93%         enable_plot=data.enable_plot;%test to desable button PLOT (display mode)
94%     end
95    if isfield(data,'Coord') &&size(data.Coord,2)==3
96        set(handles.z_slider,'Visible','on')
97    else
98        set(handles.z_slider,'Visible','off')
99    end
100    if isfield(data,'TypeMenu')
101        set(handles.Type,'String',data.TypeMenu)
102    end
103    if isfield(data,'ProjModeMenu')
104%         set(handles.ProjMode,'String',data.ProjModeMenu) % data.ProjModeMenu as projMode menu
105        set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
106    end
107    errormsg=fill_GUI(data,handles);
108    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
109
110    if isfield(data,'RangeZ') && length(ZBounds) >= 2
111        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
112        DZ=max(data.RangeZ);%slider step
113        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
114            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
115            rel_step(2)=0.1;
116            set(handles.z_slider,'Visible','on')
117            set(handles.z_slider,'Min',ZBounds(1))
118            set(handles.z_slider,'Max',ZBounds(2))
119            set(handles.z_slider,'SliderStep',rel_step)
120            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
121        end
122    end
123    if isfield(data,'RangeX')
124        if ischar(data.RangeX)
125            data.RangeX=str2num(data.RangeX);
126        end
127        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
128        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
129    end
130    if isfield(data,'RangeY')
131        if ischar(data.RangeY)
132            data.RangeY=str2num(data.RangeY);
133        end
134        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
135        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
136    end
137    if isfield(data,'RangeZ')
138        if ischar(data.RangeZ)
139            data.RangeZ=str2num(data.RangeZ);
140        end
141        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
142        if numel(data.RangeZ)>=2
143            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
144        end
145    end 
146    if isfield(data,'Angle') && isequal(numel(data.Angle),3)
147         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
148         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
149         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
150    end
151end
152% if enable_plot
153%    set(handles.PLOT,'enable','on')
154% else
155% enable the PLOT (REFRESH) button by default
156   set(handles.PLOT,'enable','off')
157% end
158huvmat=findobj(allchild(0),'tag','uvmat');
159UvData=get(huvmat,'UserData');
160pos_uvmat=get(huvmat,'Position');
161%position the set_object GUI with respect to uvmat
162if isfield(UvData,'SetObjectOrigin')
163    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
164    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
165    set(hObject,'Position',pos_set_object)
166end
167
168%------------------------------------------------------------------------
169% --- Outputs from this function are returned to the command line.
170function varargout = set_object_OutputFcn(hObject, eventdata, handles)
171%------------------------------------------------------------------------
172% Get default command line output from handles structure
173varargout{1} = handles.output;
174varargout{2}=handles;
175
176%------------------------------------------------------------------------
177% executed when closing the GUI set_object
178function closefcn(gcbo,eventdata)
179%------------------------------------------------------------------------
180huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle
181if ~isempty(huvmat)
182    hhuvmat=guidata(huvmat);
183    set(hhuvmat.edit_object,'Value',0)
184    set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
185    % deselect the object in ListObject when view_field is closed
186    if isempty(findobj(allchild(0),'Tag','view_field'))
187        ObjIndex=get(hhuvmat.ListObject,'Value');
188        ObjIndex=ObjIndex(1);%keep only the first object selected
189        set(hhuvmat.ListObject,'Value',ObjIndex)
190        % draw all object colors in blue (unselected) in uvmat
191        hother=[findobj(hhuvmat.axes3,'Tag','proj_object');findobj(hhuvmat.axes3,'Tag','DeformPoint')];%find all the proj object and deform point representations
192        for iobj=1:length(hother)
193            if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
194                set(hother(iobj),'EdgeColor','b')
195                if isequal(get(hother(iobj),'FaceColor'),'m')
196                    set(hother(iobj),'FaceColor','b')
197                end
198            elseif isequal(get(hother(iobj),'Type'),'image')
199                Acolor=get(hother(iobj),'CData');
200                Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
201                set(hother(iobj),'CData',Acolor);
202            else
203                set(hother(iobj),'Color','b')
204            end
205            set(hother(iobj),'Selected','off')
206        end
207    end
208end
209hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
210if ~isempty(hseries)
211    hhseries=guidata(hseries);
212    set(hhseries.GetObject,'Value',0)
213    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
214end
215
216
217%------------------------------------------------------------------------
218% --- Executes on selection change in Type.
219function Type_Callback(hObject, eventdata, handles)
220%------------------------------------------------------------------------
221%style_prev=get(handles.Type,'UserData');%previous object style
222ListType=get(handles.Type,'String');
223Type=ListType{get(handles.Type,'Value')};
224% make correspondance between different object styles
225Coord=get(handles.Coord,'Data');
226
227%% set the number of lines in the Coord table depending on object type
228switch Type
229    case{'line'}
230        if size(Coord,1)<2
231            if isequal(size(Coord,2),3)
232                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
233            else
234                Coord=[Coord; 0 0]; %add a line for edition (2D case)
235            end
236        else
237            Coord=Coord(1:2,:);
238        end
239    case{'rectangle','ellipse','plane','volume'}
240        Coord=Coord(1,:);
241end
242set(handles.Coord,'Data',Coord)
243
244%% set the projection menu and the corresponding options
245if isempty(get(handles.ProjMode,'UserData'))
246    switch Type
247        case {'points','line','polyline','plane'}
248            menu_proj={'projection';'interp';'filter';'none'};
249        case {'polygon','rectangle','ellipse'}
250            menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
251        case 'volume'
252            menu_proj={'interp';'none'};
253        otherwise
254            menu_proj={'projection';'interp';'filter';'none'};%default
255    end
256else
257    menu_proj=get(handles.ProjMode,'UserData');
258end
259proj_index=get(handles.ProjMode,'Value');
260if proj_index>numel(menu_proj)
261    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
262end
263set(handles.ProjMode,'String',menu_proj)
264ProjMode_Callback(hObject, eventdata, handles)
265
266%------------------------------------------------------------------------
267% --- Executes on selection change in ProjMode.
268function ProjMode_Callback(hObject, eventdata, handles)
269menu=get(handles.ProjMode,'String');
270value=get(handles.ProjMode,'Value');
271ProjMode=menu{value};
272menu=get(handles.Type,'String');
273value=get(handles.Type,'Value');
274ObjectStyle=menu{value};
275%%%%%%%%% TODO
276test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
277%%%%%%%%%
278%default setting
279set(handles.num_Angle_1,'Visible','off')
280set(handles.num_Angle_2,'Visible','off')
281set(handles.num_Angle_3,'Visible','off')
282set(handles.num_RangeX_1,'Visible','off')
283set(handles.num_RangeX_2,'Visible','off')
284set(handles.num_RangeY_1,'Visible','off')
285if isequal(ProjMode,'interp')
286    set(handles.num_RangeY_2,'Visible','off')
287else
288    set(handles.num_RangeY_2,'Visible','on')
289end
290if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
291    set(handles.num_RangeX_2,'Visible','on')
292else
293   set(handles.num_RangeX_2,'Visible','off')
294end
295set(handles.num_RangeZ_1,'Visible','off')
296set(handles.num_RangeZ_2,'Visible','off')
297set(handles.num_DX,'Visible','off')
298set(handles.num_DY,'Visible','off')
299set(handles.num_DZ,'Visible','off')
300
301switch ObjectStyle
302    case 'points'
303        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point')
304%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
305%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
306%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
307    case {'line','polyline','polygon'}
308        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line')
309         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
310%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
311%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
312        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
313            set(handles.num_DX,'Visible','on')
314            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
315        end       
316    case {'rectangle','ellipse'}
317        set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle])
318        set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle])
319%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' Type ' centre'])
320%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' Type ' centre'])
321    case {'plane'} 
322        set(handles.num_Angle_3,'Visible','on')
323        set(handles.num_RangeX_1,'Visible','on')
324        set(handles.num_RangeX_2,'Visible','on')
325        set(handles.num_RangeY_1,'Visible','on')
326        set(handles.num_RangeY_2,'Visible','on')
327%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' Type])
328%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' Type])
329        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
330        if test3D
331            set(handles.num_Angle_2,'Visible','on')
332            set(handles.num_Angle_1,'Visible','on')
333            set(handles.num_RangeZ_2,'Visible','on')
334        end
335        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
336            set(handles.num_DX,'Visible','on')
337            set(handles.num_DY,'Visible','on')
338        else
339            set(handles.num_DX,'Visible','off')
340            set(handles.num_DY,'Visible','off')
341        end
342        if  isequal(ProjMode,'interp')
343            set(handles.num_DZ,'Visible','on') 
344        end
345     case {'volume'} 
346        set(handles.num_RangeX_1,'Visible','on')
347        set(handles.num_RangeX_2,'Visible','on')
348        set(handles.num_RangeY_1,'Visible','on')
349        set(handles.num_RangeY_2,'Visible','on')
350        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
351        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
352        set(handles.num_Angle_1,'Visible','on')
353        set(handles.num_Angle_2,'Visible','on')
354        set(handles.num_Angle_3,'Visible','on')
355        set(handles.num_RangeZ_1,'Visible','on')
356        set(handles.num_RangeZ_2,'Visible','on')
357        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
358            set(handles.num_DX,'Visible','on')
359            set(handles.num_DY,'Visible','on')
360            set(handles.num_DZ,'Visible','on')
361        else
362            set(handles.num_DX,'Visible','off')
363            set(handles.num_DY,'Visible','off')
364            set(handles.num_DZ,'Visible','off')
365        end
366end
367%------------------------------------------------------------------------
368
369%------------------------------------------------------------------------
370function num_Angle_1_Callback(hObject, eventdata, handles)
371update_slider(hObject, eventdata,handles)
372%------------------------------------------------------------------------
373%------------------------------------------------------------------------
374function num_Angle_2_Callback(hObject, eventdata, handles)
375update_slider(hObject, eventdata,handles)
376%------------------------------------------------------------------------
377function update_slider(hObject, eventdata,handles)
378%rotation angles
379PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
380PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
381PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
382om=norm(PlaneAngle);%norm of rotation angle in radians
383OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
384cos_om=cos(pi*om/180);
385sin_om=sin(pi*om/180);
386coeff=OmAxis(3)*(1-cos_om);
387%components of the unity vector norm_plane normal to the projection plane
388norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
389norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
390norm_plane(3)=OmAxis(3)*coeff+cos_om;
391huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
392UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
393if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
394    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
395    set(handles.z_slider,'Min',min(Z))
396    set(handles.z_slider,'Max',max(Z))
397    ZMax_Callback(hObject, eventdata, handles)
398end
399%------------------------------------------------------------------------
400function num_DX_Callback(hObject, eventdata, handles)
401%------------------------------------------------------------------------
402%------------------------------------------------------------------------
403function num_DY_Callback(hObject, eventdata, handles)
404%------------------------------------------------------------------------
405%------------------------------------------------------------------------
406function num_DZ_Callback(hObject, eventdata, handles)
407%------------------------------------------------------------------------
408
409
410%------------------------------------------------------------------------
411% --- Executes on button press in PLOT: PLOT the defined object and its projected field
412function PLOT_Callback(hObject, eventdata, handles)
413
414%% reading the object parameters on the GUI uvmat
415huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
416UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
417hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
418ListObject=get(hhuvmat.ListObject,'String');% list of objects displyed in uvmat
419IndexObj=get(hhuvmat.ListObject,'Value');% index(indices) of the selected object(s) in uvmat
420                                        % (the first one is plotted in uvmat axis, the second one in view_field)
421
422%% read the object on the GUI set_object
423ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
424if iscell(ObjectData.Coord)%check for empty line
425    ObjectData.Coord=[0 0 0];
426    hhset_object=guidata(handles.set_object);
427    set(hhset_object.Coord,'Data',ObjectData.Coord)
428end
429checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
430if ~isempty(checknan)
431    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
432end
433ObjectName=ObjectData.Name;%name of the current object defined in set_object
434if isempty(ObjectName)
435    if get(hhuvmat.edit_object,'Value')% edit mode
436        if isempty(ListObject)
437            ObjectName='Plane';
438        else
439            ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item
440        end
441    else %new object
442        ObjectName=ObjectData.Type;
443    end
444end
445if ~get(hhuvmat.edit_object,'Value') %new object is being created
446    detectname=1;
447    ObjectNameNew=ObjectName;
448    vers=0;% index of the name
449    while detectname==1
450        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
451        if detectname% if the object name already exists
452            indstr=regexp(ObjectNameNew,'\D');
453            if indstr(end)<length(ObjectNameNew) %object name ends by a number
454                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
455                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
456            else
457                vers=vers+1;
458                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
459            end
460        end
461    end
462    ObjectName=ObjectNameNew;
463    set(handles.Name,'String',ObjectName)% display the default name in set_object
464    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
465    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
466    set(hhuvmat.ListObject,'Value',IndexObj)
467    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
468end
469testnew=0;
470if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
471    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
472else  % if a second object is selected, the projection is in view_field, and this second object is selected
473    hview_field=findobj(allchild(0),'tag','view_field');
474    if isempty(hview_field)
475        hview_field=view_field;%open the GUI view_field if it is not found
476    end
477    PlotHandles=guidata(hview_field);
478    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
479end
480
481%% naming the object
482ListObject{IndexObj(end),1}=ObjectName;
483set(hhuvmat.ListObject,'String',ListObject)
484
485%% update the object plot
486if testnew
487    set(hhuvmat.ListObject,'Value',IndexObj)
488    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
489    ObjectData.DisplayHandle_view_field=[];
490else
491    if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
492        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
493    else
494        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
495    end
496    if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
497        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
498    else
499        ObjectData.DisplayHandle_view_field=[];
500    end
501end
502UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
503if numel(IndexObj)==2
504    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
505end
506set(huvmat,'UserData',UvData)
507
508%% plot the field projected on the object and store in the corresponding figue
509if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
510    PlotType='text';
511   
512else
513    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
514    if ~isempty(errormsg)
515        msgbox_uvmat('ERROR', errormsg)
516        return
517    end
518    fighandle=get(plotaxes,'parent');
519    PlotParam=read_GUI(fighandle);
520    PlotType=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
521end
522if strcmp(PlotType,'text')
523    hview_field=findobj(allchild(0),'tag','view_field'); %case of no projection (pure object display)
524    if ~isempty(hview_field)
525        delete(hview_field)
526    end
527end
528   
529%% update the GUI uvmat
530hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
531set(hhuvmat.MenuEditObject,'enable','on')
532set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
533set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
534
535%------------------------------------------------------------------------
536% --- Executes on button press in MenuCoord.
537function MenuCoord_Callback(hObject, eventdata, handles)
538%------------------------------------------------------------------------
539%----------------------------------------------------
540function num_RangeY_1_Callback(hObject, eventdata, handles)
541%------------------------------------------------------------------------
542
543function num_RangeZ_1_Callback(hObject, eventdata, handles)
544%------------------------------------------------------------------------
545
546function num_RangeZ_2_Callback(hObject, eventdata, handles)
547DZ=str2num(get(handles.num_RangeZ_2,'String'));
548ZMin=get(handles.z_slider,'Min');
549ZMax=get(handles.z_slider,'Max');
550if ~isequal(ZMax-ZMin,0)
551    rel_step(1)=DZ/(ZMax-ZMin);
552    rel_step(2)=0.2;
553    set(handles.z_slider,'SliderStep',rel_step)
554end
555%------------------------------------------------------------------------
556function num_RangeY_2_Callback(hObject, eventdata, handles)
557%------------------------------------------------------------------------
558
559function num_RangeX_1_Callback(hObject, eventdata, handles)
560%------------------------------------------------------------------------
561
562function num_RangeX_2_Callback(hObject, eventdata, handles)
563%------------------------------------------------------------------------
564%------------------------------------------------------------------------
565function SAVE_Callback(hObject, eventdata, handles)
566% ------------------------------------------------------
567%Object=read_set_object(handles);
568Object=read_GUI(handles.set_object);
569huvmat=findobj('Tag','uvmat');
570% UvData=get(huvmat,'UserData');
571if isempty(huvmat)
572    huvmat=findobj(allchild(0),'Name','series');
573end
574hchild=get(huvmat,'Children');
575hrootpath=findobj(hchild,'Tag','RootPath');
576if isempty(hrootpath)
577    RootPath='';
578else
579    RootPath=get(hrootpath,'String');
580    if iscell(RootPath)
581        RootPath=RootPath{1};
582    end
583end
584title={'object name'};
585dir_save=uigetdir(RootPath);
586ObjectName=get(handles.Name,'String');
587if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
588    def={fullfile(dir_save,[ObjectName '.xml'])};
589else
590    def={fullfile(dir_save,[Object.Style '.xml'])};
591end
592displ_txt='save object as an .xml file';%default display
593menu=get(handles.ProjMode,'String');
594value=get(handles.ProjMode,'Value');
595ProjMode=menu{value};
596if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
597    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
598end
599answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
600if ~isempty(answer)
601    t=struct2xml(Object);
602    save(t,answer{1})
603end
604msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
605
606%------------------------------------------------------------------------
607% --- Executes on slider movement.
608function z_slider_Callback(hObject, eventdata, handles)
609%---------------------------------------------------------
610Z_value=get(handles.z_slider,'Value');
611%rotation angles
612PlaneAngle=[0 0 0];
613norm_plane=[0 0 1];
614cos_om=1;
615sin_om=0;
616
617PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
618PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
619PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
620PlaneAngle=(pi/180)*PlaneAngle;
621om=norm(PlaneAngle);%norm of rotation angle in radians
622if isequal(om,0)
623    norm_plane=[0 0 1];
624else
625    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
626    cos_om=cos(om);
627    sin_om=sin(om);
628    coeff=OmAxis(3)*(1-cos_om);
629    %components of the unity vector norm_plane normal to the projection plane
630    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
631    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
632    norm_plane(3)=OmAxis(3)*coeff+cos_om;
633end
634
635% update graph
636PLOT_Callback(hObject, eventdata, handles)
637
638%------------------------------------------------------------------------
639% --- Executes on button press in HELP.
640function HELP_Callback(hObject, eventdata, handles)
641%------------------------------------------------------------------------
642path_to_uvmat=which ('uvmat');% check the path of uvmat
643pathelp=fileparts(path_to_uvmat);
644helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
645if ~isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
646    addpath (fullfile(pathelp,'uvmat_doc'))
647    web([helpfile '#set_object'])
648end
649%------------------------------------------------------------------------
650
651function Name_Callback(hObject, eventdata, handles)
652% hObject    handle to Name (see GCBO)
653% eventdata  reserved - to be defined in a future version of MATLAB
654% handles    structure with handles and user data (see GUIDATA)
655
656% Hints: get(hObject,'String') returns contents of Name as text
657%        str2double(get(hObject,'String')) returns contents of Name as a double
658
659%------------------------------------------------------------------------
660% --- Executes when entered data in editable cell(s) in Coord.
661function Coord_CellEditCallback(hObject, eventdata, handles)
662%------------------------------------------------------------------------
663ListType=get(handles.Type,'String');
664Type=ListType{get(handles.Type,'Value')};
665switch Type
666    % add lines if multi line input needed
667    case{'points','polyline','polygon'}
668        Coord=get(handles.Coord,'Data');
669        if ~isnan(Coord(end,1))
670            if isequal(size(Coord,2),3)
671                %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
672                Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case)
673            else
674                Coord=[Coord;NaN NaN]; %add a line for edition (2D case)
675            end
676            set(handles.Coord,'Data',Coord)
677        end
678end
679
680
681
682function num_Angle_3_Callback(hObject, eventdata, handles)
683% hObject    handle to num_Angle_3 (see GCBO)
684% eventdata  reserved - to be defined in a future version of MATLAB
685% handles    structure with handles and user data (see GUIDATA)
686
687% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
688%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.