source: trunk/src/set_object.m @ 410

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

projection on object improved: two menus for object projection dispalyed in uvmat and in view_field

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