source: trunk/src/set_object.m @ 627

Last change on this file since 627 was 627, checked in by sommeria, 11 years ago

a few bugs repaired, display of the local mouse indication in a separate window

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