source: trunk/src/set_object.m @ 388

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

several bugs corrected
file indexing, color images...

File size: 28.4 KB
RevLine 
[204]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'
[379]14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
[204]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
[379]38% Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47
[204]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
[379]67%      .Name : class of object ('POINTS','LINE',....)
68%      .num_DX,num_DY,num_DZ; meshes for regular grids
[204]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
[206]82if ~exist('ZBounds','var')
83    ZBounds=0; %default
[204]84end
85set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
[309]86set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
[204]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
[379]94    if isfield(data,'Coord') &&size(data.Coord,2)==3
95        set(handles.z_slider,'Visible','on')
96    else
[204]97        set(handles.z_slider,'Visible','off')
98    end
[387]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
[379]106    errormsg=fill_GUI(data,handles);
[387]107    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
108
[204]109    if isfield(data,'RangeZ') && length(ZBounds) >= 2
[379]110        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[204]111        DZ=max(data.RangeZ);%slider step
[206]112        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
[204]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
[379]126        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
127        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
[204]128    end
129    if isfield(data,'RangeY')
130        if ischar(data.RangeY)
131            data.RangeY=str2num(data.RangeY);
132        end
[379]133        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
134        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
[204]135    end
136    if isfield(data,'RangeZ')
137        if ischar(data.RangeZ)
138            data.RangeZ=str2num(data.RangeZ);
139        end
[379]140        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[204]141        if numel(data.RangeZ)>=2
[379]142            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
[204]143        end
144    end 
[212]145    if isfield(data,'Angle') && isequal(numel(data.Angle),3)
[379]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)))
[204]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%------------------------------------------------------------------------
[379]175% --- Executes on selection change in Type.
176function Type_Callback(hObject, eventdata, handles)
[204]177%------------------------------------------------------------------------
[379]178%style_prev=get(handles.Type,'UserData');%previous object style
179ListType=get(handles.Type,'String');
180Type=ListType{get(handles.Type,'Value')};
[204]181% make correspondance between different object styles
[379]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,:);
[204]198end
[379]199set(handles.Coord,'Data',Coord)
[204]200
[379]201%% set the projection menu and the corresponding options
[387]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
[204]216proj_index=get(handles.ProjMode,'Value');
[387]217if proj_index>numel(menu_proj)
[204]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)
[379]222
[204]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};
[379]229menu=get(handles.Type,'String');
230value=get(handles.Type,'Value');
[204]231ObjectStyle=menu{value};
[379]232%%%%%%%%% TODO
233test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
234%%%%%%%%%
[204]235%default setting
[379]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')
[204]242if isequal(ProjMode,'interp')
[379]243    set(handles.num_RangeY_2,'Visible','off')
[204]244else
[379]245    set(handles.num_RangeY_2,'Visible','on')
[204]246end
247if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
[379]248    set(handles.num_RangeX_2,'Visible','on')
[204]249else
[379]250   set(handles.num_RangeX_2,'Visible','off')
[204]251end
[379]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')
[204]257
258switch ObjectStyle
259    case 'points'
[379]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')
[204]264    case {'line','polyline','polygon'}
[379]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')
[204]269        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
[379]270            set(handles.num_DX,'Visible','on')
271            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
[204]272        end       
273    case {'rectangle','ellipse'}
[379]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'])
[204]278    case {'plane'} 
[379]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')
[204]287        if test3D
[379]288            set(handles.num_Angle_2,'Visible','on')
289            set(handles.num_Angle_1,'Visible','on')
290            set(handles.num_RangeZ_2,'Visible','on')
[204]291        end
292        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
[379]293            set(handles.num_DX,'Visible','on')
294            set(handles.num_DY,'Visible','on')
[204]295        else
[379]296            set(handles.num_DX,'Visible','off')
297            set(handles.num_DY,'Visible','off')
[204]298        end
[206]299        if  isequal(ProjMode,'interp')
[379]300            set(handles.num_DZ,'Visible','on') 
[204]301        end
302     case {'volume'} 
[379]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')
[204]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])
[379]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')
[204]314        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
[379]315            set(handles.num_DX,'Visible','on')
316            set(handles.num_DY,'Visible','on')
317            set(handles.num_DZ,'Visible','on')
[204]318        else
[379]319            set(handles.num_DX,'Visible','off')
320            set(handles.num_DY,'Visible','off')
321            set(handles.num_DZ,'Visible','off')
[204]322        end
323end
324%------------------------------------------------------------------------
325
326%------------------------------------------------------------------------
[379]327function num_Angle_1_Callback(hObject, eventdata, handles)
[204]328update_slider(hObject, eventdata,handles)
329%------------------------------------------------------------------------
330%------------------------------------------------------------------------
[379]331function num_Angle_2_Callback(hObject, eventdata, handles)
[204]332update_slider(hObject, eventdata,handles)
333%------------------------------------------------------------------------
334function update_slider(hObject, eventdata,handles)
335%rotation angles
[379]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
[212]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;
[204]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')
[212]351    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
[204]352    set(handles.z_slider,'Min',min(Z))
353    set(handles.z_slider,'Max',max(Z))
354    ZMax_Callback(hObject, eventdata, handles)
355end
356%------------------------------------------------------------------------
[379]357function num_DX_Callback(hObject, eventdata, handles)
[204]358%------------------------------------------------------------------------
359%------------------------------------------------------------------------
[379]360function num_DY_Callback(hObject, eventdata, handles)
[204]361%------------------------------------------------------------------------
362%------------------------------------------------------------------------
[379]363function num_DZ_Callback(hObject, eventdata, handles)
[204]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
[388]389huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
[204]390UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
[388]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)
[341]395
396%% read the object on the GUI set_object
[388]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
399checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
400if ~isempty(checknan)
401    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
402end
[309]403if isempty(ObjectName)
404    if get(hhuvmat.edit_object,'Value')% edit mode
405        ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item
[342]406    else %new object
[379]407        StyleList=get(handles.Type,'String');
408        StyleVal=get(handles.Type,'Value');
[342]409        ObjectName=StyleList{StyleVal};
[309]410    end
[204]411end
[309]412if ~get(hhuvmat.edit_object,'Value') %new object is being created
[204]413    detectname=1;
414    ObjectNameNew=ObjectName;
415    vers=0;
[309]416    while detectname==1
[204]417        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
418        if detectname% if the object name already exists
419            indstr=regexp(ObjectNameNew,'\D');
420            if indstr(end)<length(ObjectNameNew) %object name ends by a number
421                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
422                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
423            else
424                vers=vers+1;
[309]425                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
[204]426            end
427        end
428    end
429    ObjectName=ObjectNameNew;
[379]430    set(handles.Name,'String',ObjectName)% display the default name in set_object
[342]431    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
432    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
433    set(hhuvmat.ListObject,'Value',IndexObj)
434    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
[204]435end
[309]436testnew=0;
437if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
438    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
439else  % if a second object is selected, the projection is in view_field, and this second object is selected
440    hview_field=findobj(allchild(0),'tag','view_field');
441    if isempty(hview_field)
[388]442        hview_field=view_field;%open the GUI view_field if it is not found
[309]443    end
444    PlotHandles=guidata(hview_field);
445    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
446end
447
448%% naming the object
449ListObject{IndexObj(end),1}=ObjectName;
[307]450set(hhuvmat.ListObject,'String',ListObject)
[204]451
[388]452%% update the object plot
[309]453if testnew
454    set(hhuvmat.ListObject,'Value',IndexObj)
[204]455    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
456    ObjectData.DisplayHandle_view_field=[];
457else
[309]458    if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
459        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
[204]460    else
461        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
462    end
[309]463    if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
464        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
[204]465    else
466        ObjectData.DisplayHandle_view_field=[];
467    end
468end
[309]469UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
470if numel(IndexObj)==2
471    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
472end
[204]473set(huvmat,'UserData',UvData)
474
475%% plot the field projected on the object and store in the corresponding figue
[388]476if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
477    PlotType='text';
478   
479else
480    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
481    if ~isempty(errormsg)
482        msgbox_uvmat('ERROR', errormsg)
483        return
484    end
485    fighandle=get(plotaxes,'parent');
486    PlotParam=read_GUI(fighandle);
487    PlotType=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
[227]488end
[388]489if strcmp(PlotType,'text')
490    hview_field=findobj(allchild(0),'tag','view_field'); %case of no projection (pure object display)
491    if ~isempty(hview_field)
492        delete(hview_field)
493    end
494end
495   
[204]496%% update the GUI uvmat
497hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
498set(hhuvmat.MenuEditObject,'enable','on')
499set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
500set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
501
502%------------------------------------------------------------------------
503% --- Executes on button press in MenuCoord.
504function MenuCoord_Callback(hObject, eventdata, handles)
505%------------------------------------------------------------------------
506%----------------------------------------------------
[379]507function num_RangeY_1_Callback(hObject, eventdata, handles)
[204]508%------------------------------------------------------------------------
509
[379]510function num_RangeZ_1_Callback(hObject, eventdata, handles)
[204]511%------------------------------------------------------------------------
512
[379]513function num_RangeZ_2_Callback(hObject, eventdata, handles)
514DZ=str2num(get(handles.num_RangeZ_2,'String'));
[204]515ZMin=get(handles.z_slider,'Min');
516ZMax=get(handles.z_slider,'Max');
517if ~isequal(ZMax-ZMin,0)
518    rel_step(1)=DZ/(ZMax-ZMin);
519    rel_step(2)=0.2;
520    set(handles.z_slider,'SliderStep',rel_step)
521end
522%------------------------------------------------------------------------
[379]523function num_RangeY_2_Callback(hObject, eventdata, handles)
[204]524%------------------------------------------------------------------------
525
[379]526function num_RangeX_1_Callback(hObject, eventdata, handles)
[204]527%------------------------------------------------------------------------
528
[379]529function num_RangeX_2_Callback(hObject, eventdata, handles)
[204]530%------------------------------------------------------------------------
531%------------------------------------------------------------------------
532function SAVE_Callback(hObject, eventdata, handles)
533% ------------------------------------------------------
[379]534%Object=read_set_object(handles);
535Object=read_GUI(handles.set_object);
[204]536huvmat=findobj('Tag','uvmat');
537% UvData=get(huvmat,'UserData');
538if isempty(huvmat)
539    huvmat=findobj(allchild(0),'Name','series');
540end
541hchild=get(huvmat,'Children');
542hrootpath=findobj(hchild,'Tag','RootPath');
543if isempty(hrootpath)
544    RootPath='';
545else
546    RootPath=get(hrootpath,'String');
547    if iscell(RootPath)
548        RootPath=RootPath{1};
549    end
550end
551title={'object name'};
552dir_save=uigetdir(RootPath);
[379]553ObjectName=get(handles.Name,'String');
[204]554if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
555    def={fullfile(dir_save,[ObjectName '.xml'])};
556else
557    def={fullfile(dir_save,[Object.Style '.xml'])};
558end
559displ_txt='save object as an .xml file';%default display
560menu=get(handles.ProjMode,'String');
561value=get(handles.ProjMode,'Value');
562ProjMode=menu{value};
563if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
564    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
565end
566answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
567if ~isempty(answer)
568    t=struct2xml(Object);
569    save(t,answer{1})
570end
571msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
[227]572
[204]573%------------------------------------------------------------------------
574% --- Executes on slider movement.
575function z_slider_Callback(hObject, eventdata, handles)
576%---------------------------------------------------------
577Z_value=get(handles.z_slider,'Value');
578%rotation angles
[227]579PlaneAngle=[0 0 0];
580norm_plane=[0 0 1];
581cos_om=1;
582sin_om=0;
583
[379]584PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
585PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
586PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
[227]587PlaneAngle=(pi/180)*PlaneAngle;
[212]588om=norm(PlaneAngle);%norm of rotation angle in radians
[227]589if isequal(om,0)
590    norm_plane=[0 0 1];
591else
592    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
593    cos_om=cos(om);
594    sin_om=sin(om);
595    coeff=OmAxis(3)*(1-cos_om);
596    %components of the unity vector norm_plane normal to the projection plane
597    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
598    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
599    norm_plane(3)=OmAxis(3)*coeff+cos_om;
600end
[204]601
[388]602% update graph
[204]603PLOT_Callback(hObject, eventdata, handles)
[227]604
[204]605%------------------------------------------------------------------------
606% --- Executes on button press in HELP.
607function HELP_Callback(hObject, eventdata, handles)
[227]608%------------------------------------------------------------------------
[204]609path_to_uvmat=which ('uvmat');% check the path of uvmat
610pathelp=fileparts(path_to_uvmat);
611helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
[388]612if ~isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[204]613    addpath (fullfile(pathelp,'uvmat_doc'))
614    web([helpfile '#set_object'])
615end
616%------------------------------------------------------------------------
617
[379]618function Name_Callback(hObject, eventdata, handles)
619% hObject    handle to Name (see GCBO)
620% eventdata  reserved - to be defined in a future version of MATLAB
621% handles    structure with handles and user data (see GUIDATA)
[204]622
[379]623% Hints: get(hObject,'String') returns contents of Name as text
624%        str2double(get(hObject,'String')) returns contents of Name as a double
625
626%------------------------------------------------------------------------
627% --- Executes when entered data in editable cell(s) in Coord.
628function Coord_CellEditCallback(hObject, eventdata, handles)
629%------------------------------------------------------------------------
630ListType=get(handles.Type,'String');
631Type=ListType{get(handles.Type,'Value')};
632switch Type
633    % add lines if multi line input needed
634    case{'points','polyline','polygon'}
635        Coord=get(handles.Coord,'Data');
[388]636        if ~isnan(Coord(end,1))
637            if isequal(size(Coord,2),3)
638                %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
639                Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case)
640            else
641                Coord=[Coord;NaN NaN]; %add a line for edition (2D case)
642            end
643            set(handles.Coord,'Data',Coord)
[379]644        end
645end
646
647
648
649function num_Angle_3_Callback(hObject, eventdata, handles)
650% hObject    handle to num_Angle_3 (see GCBO)
651% eventdata  reserved - to be defined in a future version of MATLAB
652% handles    structure with handles and user data (see GUIDATA)
653
654% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
655%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.