source: trunk/src/set_object.m @ 418

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

various bugs corrected and improvement in civ1_TEST

File size: 30.1 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})
88
89% fill the interface as set in the input data:
90if exist('data','var')
91    if isfield(data,'Coord') &&size(data.Coord,2)==3
92        set(handles.z_slider,'Visible','on')
93    else
94        set(handles.z_slider,'Visible','off')
95    end
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
102    errormsg=fill_GUI(data,handles);
103    if ~isempty(errormsg)
104        msgbox_uvmat('ERROR','bad data input in set_object')
105        return
106    end
107    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
108
109    if isfield(data,'RangeZ') && length(ZBounds) >= 2
110        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
111        DZ=max(data.RangeZ);%slider step
112        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
113            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
114            rel_step(2)=0.1;
115            set(handles.z_slider,'Visible','on')
116            set(handles.z_slider,'Min',ZBounds(1))
117            set(handles.z_slider,'Max',ZBounds(2))
118            set(handles.z_slider,'SliderStep',rel_step)
119            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
120        end
121    end
122    if isfield(data,'RangeX')
123        if ischar(data.RangeX)
124            data.RangeX=str2num(data.RangeX);
125        end
126        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
127        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
128    end
129    if isfield(data,'RangeY')
130        if ischar(data.RangeY)
131            data.RangeY=str2num(data.RangeY);
132        end
133        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
134        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
135    end
136    if isfield(data,'RangeZ')
137        if ischar(data.RangeZ)
138            data.RangeZ=str2num(data.RangeZ);
139        end
140        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
141        if numel(data.RangeZ)>=2
142            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
143        end
144    end 
145    if isfield(data,'Angle') && isequal(numel(data.Angle),3)
146         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
147         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
148         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
149    end
150end
151% if enable_plot
152%    set(handles.PLOT,'enable','on')
153% else
154% enable the PLOT (REFRESH) button by default
155   set(handles.PLOT,'enable','off')
156% end
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%------------------------------------------------------------------------
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);
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
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%------------------------------------------------------------------------
219% --- Executes on selection change in Type.
220function Type_Callback(hObject, eventdata, handles)
221%------------------------------------------------------------------------
222%style_prev=get(handles.Type,'UserData');%previous object style
223ListType=get(handles.Type,'String');
224Type=ListType{get(handles.Type,'Value')};
225% make correspondance between different object styles
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,:);
242end
243set(handles.Coord,'Data',Coord)
244
245%% set the projection menu and the corresponding options
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
260ProjModeList=get(handles.ProjMode,'String');
261menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj));
262if isempty(menu_index)
263    menu_index=1;%
264end
265set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length
266set(handles.ProjMode,'String',menu_proj)
267ProjMode_Callback(hObject, eventdata, handles)
268
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};
275menu=get(handles.Type,'String');
276value=get(handles.Type,'Value');
277ObjectStyle=menu{value};
278%%%%%%%%% TODO
279test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
280%%%%%%%%%
281%default setting
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')
288if isequal(ProjMode,'interp')
289    set(handles.num_RangeY_2,'Visible','off')
290else
291    set(handles.num_RangeY_2,'Visible','on')
292end
293if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
294    set(handles.num_RangeX_2,'Visible','on')
295else
296   set(handles.num_RangeX_2,'Visible','off')
297end
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')
303
304switch ObjectStyle
305    case 'points'
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')
310    case {'line','polyline','polygon'}
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')
315        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
316            set(handles.num_DX,'Visible','on')
317            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
318        end       
319    case {'rectangle','ellipse'}
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'])
324    case {'plane'} 
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')
333        if test3D
334            set(handles.num_Angle_2,'Visible','on')
335            set(handles.num_Angle_1,'Visible','on')
336            set(handles.num_RangeZ_2,'Visible','on')
337        end
338        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
339            set(handles.num_DX,'Visible','on')
340            set(handles.num_DY,'Visible','on')
341        else
342            set(handles.num_DX,'Visible','off')
343            set(handles.num_DY,'Visible','off')
344        end
345        if  isequal(ProjMode,'interp')
346            set(handles.num_DZ,'Visible','on') 
347        end
348     case {'volume'} 
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')
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])
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')
360        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
361            set(handles.num_DX,'Visible','on')
362            set(handles.num_DY,'Visible','on')
363            set(handles.num_DZ,'Visible','on')
364        else
365            set(handles.num_DX,'Visible','off')
366            set(handles.num_DY,'Visible','off')
367            set(handles.num_DZ,'Visible','off')
368        end
369end
370%------------------------------------------------------------------------
371
372%------------------------------------------------------------------------
373function num_Angle_1_Callback(hObject, eventdata, handles)
374update_slider(hObject, eventdata,handles)
375%------------------------------------------------------------------------
376%------------------------------------------------------------------------
377function num_Angle_2_Callback(hObject, eventdata, handles)
378update_slider(hObject, eventdata,handles)
379%------------------------------------------------------------------------
380function update_slider(hObject, eventdata,handles)
381%rotation angles
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
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;
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')
397    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
398    set(handles.z_slider,'Min',min(Z))
399    set(handles.z_slider,'Max',max(Z))
400    ZMax_Callback(hObject, eventdata, handles)
401end
402%------------------------------------------------------------------------
403function num_DX_Callback(hObject, eventdata, handles)
404%------------------------------------------------------------------------
405%------------------------------------------------------------------------
406function num_DY_Callback(hObject, eventdata, handles)
407%------------------------------------------------------------------------
408%------------------------------------------------------------------------
409function num_DZ_Callback(hObject, eventdata, handles)
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
417%% read the object parameters in the GUI set_object
418ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
419if iscell(ObjectData.Coord)%check for empty line
420    ObjectData.Coord=[0 0 0];
421    hhset_object=guidata(handles.set_object);
422    set(hhset_object.Coord,'Data',ObjectData.Coord)
423end
424checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
425if ~isempty(checknan)
426    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
427end
428ObjectName=ObjectData.Name;%name of the current object defined in set_object
429if isempty(ObjectName)
430     ObjectName=ObjectData.Type;
431end
432
433%% read the object selection in the GUI uvmat
434huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
435UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
436hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
437ListObject=get(hhuvmat.ListObject_1,'String');% list of objects displayed in uvmat
438IndexObj(1)=get(hhuvmat.ListObject_1,'Value');% index of the selected object for display in uvmat
439if get(hhuvmat.ViewObject,'Value') && get(hhuvmat.edit_object,'Value')
440    IndexObj(2)=get(hhuvmat.ListObject,'Value');% index of the object, possibly selected for display in view_field
441end
442if ~get(hhuvmat.edit_object,'Value') %new object is being created
443    detectname=1;
444    ObjectNameNew=ObjectName;
445    vers=0;% index of the name
446    while detectname==1
447        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
448        if detectname% if the object name already exists
449            indstr=regexp(ObjectNameNew,'\D');
450            if indstr(end)<length(ObjectNameNew) %object name ends by a number
451                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
452                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
453            else
454                vers=vers+1;
455                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
456            end
457        end
458    end
459    ObjectName=ObjectNameNew;
460    set(handles.Name,'String',ObjectName)% display the default name in set_object
461    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
462    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
463    set(hhuvmat.ListObject_1,'String',[ListObject;{ObjectName}]);%complement the object list
464    set(hhuvmat.ListObject,'Value',IndexObj(2))
465    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
466end
467
468%% naming the object
469% ListObject{IndexObj(end),1}=ObjectName;
470% set(hhuvmat.ListObject,'String',ListObject)
471% set(hhuvmat.ListObject_1,'String',ListObject)
472
473%% update the object plot
474if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
475    ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
476else
477    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
478end
479if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
480    ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
481else
482    ObjectData.DisplayHandle_view_field=[];
483end
484UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
485if numel(IndexObj)==2
486    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
487end
488set(huvmat,'UserData',UvData)
489
490%% plot the field projected on the object
491if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
492    PlotType='text';
493else
494    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
495    if ~isempty(errormsg)
496        msgbox_uvmat('ERROR', errormsg)
497        return
498    end   
499    if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
500%         plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
501        PlotType=plot_field(ProjData,hhuvmat.axes3,read_GUI(get(hhuvmat.axes3,'parent')));%update the current uvmat plot
502    else  % if a second object is selected, the projection is in view_field, and this second object is selected
503        hview_field=findobj(allchild(0),'tag','view_field');
504        if isempty(hview_field)
505            PlotType=view_field(ProjData); %open the view_field GUI for plot
506          %  hview_field=view_field;%open the GUI view_field if it is not found
507        else
508            hhview_field=guidata(hview_field);
509            [PlotType,PlotParam]=plot_field(ProjData,hhview_field.axes3,read_GUI(hview_field));%update an existing  plot in view_field
510            write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
511        end
512%         PlotHandles=guidata(hview_field);
513%         plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
514    end
515%     fighandle=get(plotaxes,'parent');
516%     PlotParam=read_GUI(fighandle);
517   % PlotType=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
518end
519if strcmp(PlotType,'text')
520    hview_field=findobj(allchild(0),'tag','view_field'); %case of no projection (pure object display)
521    if ~isempty(hview_field)
522        delete(hview_field)
523    end
524end
525   
526%% update the GUI uvmat
527hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
528set(hhuvmat.MenuEditObject,'enable','on')
529set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
530set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
531
532%------------------------------------------------------------------------
533% --- Executes on button press in MenuCoord.
534function MenuCoord_Callback(hObject, eventdata, handles)
535%------------------------------------------------------------------------
536%----------------------------------------------------
537function num_RangeY_1_Callback(hObject, eventdata, handles)
538%------------------------------------------------------------------------
539
540function num_RangeZ_1_Callback(hObject, eventdata, handles)
541%------------------------------------------------------------------------
542
543function num_RangeZ_2_Callback(hObject, eventdata, handles)
544DZ=str2num(get(handles.num_RangeZ_2,'String'));
545ZMin=get(handles.z_slider,'Min');
546ZMax=get(handles.z_slider,'Max');
547if ~isequal(ZMax-ZMin,0)
548    rel_step(1)=DZ/(ZMax-ZMin);
549    rel_step(2)=0.2;
550    set(handles.z_slider,'SliderStep',rel_step)
551end
552%------------------------------------------------------------------------
553function num_RangeY_2_Callback(hObject, eventdata, handles)
554%------------------------------------------------------------------------
555
556function num_RangeX_1_Callback(hObject, eventdata, handles)
557%------------------------------------------------------------------------
558
559function num_RangeX_2_Callback(hObject, eventdata, handles)
560%------------------------------------------------------------------------
561%------------------------------------------------------------------------
562function SAVE_Callback(hObject, eventdata, handles)
563% ------------------------------------------------------
564%Object=read_set_object(handles);
565Object=read_GUI(handles.set_object);
566huvmat=findobj('Tag','uvmat');
567% UvData=get(huvmat,'UserData');
568if isempty(huvmat)
569    huvmat=findobj(allchild(0),'Name','series');
570end
571hchild=get(huvmat,'Children');
572hrootpath=findobj(hchild,'Tag','RootPath');
573if isempty(hrootpath)
574    RootPath='';
575else
576    RootPath=get(hrootpath,'String');
577    if iscell(RootPath)
578        RootPath=RootPath{1};
579    end
580end
581title={'object name'};
582dir_save=uigetdir(RootPath);
583ObjectName=get(handles.Name,'String');
584if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
585    def={fullfile(dir_save,[ObjectName '.xml'])};
586else
587    def={fullfile(dir_save,[Object.Style '.xml'])};
588end
589displ_txt='save object as an .xml file';%default display
590menu=get(handles.ProjMode,'String');
591value=get(handles.ProjMode,'Value');
592ProjMode=menu{value};
593if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
594    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
595end
596answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
597if ~isempty(answer)
598    t=struct2xml(Object);
599    save(t,answer{1})
600end
601msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
602
603%------------------------------------------------------------------------
604% --- Executes on slider movement.
605function z_slider_Callback(hObject, eventdata, handles)
606%---------------------------------------------------------
607Z_value=get(handles.z_slider,'Value');
608%rotation angles
609PlaneAngle=[0 0 0];
610norm_plane=[0 0 1];
611cos_om=1;
612sin_om=0;
613
614PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
615PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
616PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
617PlaneAngle=(pi/180)*PlaneAngle;
618om=norm(PlaneAngle);%norm of rotation angle in radians
619if isequal(om,0)
620    norm_plane=[0 0 1];
621else
622    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
623    cos_om=cos(om);
624    sin_om=sin(om);
625    coeff=OmAxis(3)*(1-cos_om);
626    %components of the unity vector norm_plane normal to the projection plane
627    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
628    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
629    norm_plane(3)=OmAxis(3)*coeff+cos_om;
630end
631
632% update graph
633PLOT_Callback(hObject, eventdata, handles)
634
635%------------------------------------------------------------------------
636% --- Executes on button press in HELP.
637function HELP_Callback(hObject, eventdata, handles)
638%------------------------------------------------------------------------
639path_to_uvmat=which ('uvmat');% check the path of uvmat
640pathelp=fileparts(path_to_uvmat);
641helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
642if ~isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
643    addpath (fullfile(pathelp,'uvmat_doc'))
644    web([helpfile '#set_object'])
645end
646%------------------------------------------------------------------------
647
648function Name_Callback(hObject, eventdata, handles)
649% hObject    handle to Name (see GCBO)
650% eventdata  reserved - to be defined in a future version of MATLAB
651% handles    structure with handles and user data (see GUIDATA)
652
653% Hints: get(hObject,'String') returns contents of Name as text
654%        str2double(get(hObject,'String')) returns contents of Name as a double
655
656%------------------------------------------------------------------------
657% --- Executes when entered data in editable cell(s) in Coord.
658function Coord_CellEditCallback(hObject, eventdata, handles)
659%------------------------------------------------------------------------
660ListType=get(handles.Type,'String');
661Type=ListType{get(handles.Type,'Value')};
662switch Type
663    % add lines if multi line input needed
664    case{'points','polyline','polygon'}
665        Coord=get(handles.Coord,'Data');
666        if ~isnan(Coord(end,1))
667            if isequal(size(Coord,2),3)
668                %Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
669                Coord=[Coord;NaN NaN NaN]; %add a line for edition (3D case)
670            else
671                Coord=[Coord;NaN NaN]; %add a line for edition (2D case)
672            end
673            set(handles.Coord,'Data',Coord)
674        end
675end
676
677
678
679function num_Angle_3_Callback(hObject, eventdata, handles)
680% hObject    handle to num_Angle_3 (see GCBO)
681% eventdata  reserved - to be defined in a future version of MATLAB
682% handles    structure with handles and user data (see GUIDATA)
683
684% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
685%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.