source: trunk/src/set_object.m @ 622

Last change on this file since 622 was 622, checked in by sommeria, 8 years ago

mouse system for uvmat imrpoved

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