source: trunk/src/set_object.m @ 1156

Last change on this file since 1156 was 1127, checked in by g7moreau, 11 months ago

Update Joel email

File size: 36.6 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%=======================================================================
21% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
22%   http://www.legi.grenoble-inp.fr
23%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
24%
25%     This file is part of the toolbox UVMAT.
26%
27%     UVMAT is free software; you can redistribute it and/or modify
28%     it under the terms of the GNU General Public License as published
29%     by the Free Software Foundation; either version 2 of the license,
30%     or (at your option) any later version.
31%
32%     UVMAT is distributed in the hope that it will be useful,
33%     but WITHOUT ANY WARRANTY; without even the implied warranty of
34%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35%     GNU General Public License (see LICENSE.txt) for more details.
36%=======================================================================
37
38function varargout = set_object(varargin)
39
40% Last Modified by GUIDE v2.5 01-Apr-2020 22:25:49
41
42% Begin initialization code - DO NOT REFRESH
43gui_Singleton = 1;
44gui_State = struct('gui_Name',       mfilename, ...
45                   'gui_Singleton',  gui_Singleton, ...
46                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
47                   'gui_OutputFcn',  @set_object_OutputFcn, ...
48                   'gui_LayoutFcn',  [] , ...
49                   'gui_Callback',   []);
50if nargin & ischar(varargin{1})
51    gui_State.gui_Callback = str2func(varargin{1});
52end
53
54if nargout
55    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
56else
57    gui_mainfcn(gui_State, varargin{:});
58end
59% End initialization code - DO NOT REFRESH
60%------------------------------------------------------------------------
61%------------------------------------------------------------------------
62% --- Executes just before set_object is made visible.
63%INPUT:
64% handles: handles of the set_object interface elements
65%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
66%        if =[] or absent: index still undefined (create mode in uvmat)
67%        if=0; no associated object (used for series), the button 'REFRESH' is  then unvisible
68%'data': read from an existing object selected in the interface
69%      .Name : class of object ('POINTS','LINE',....)
70%      .num_DX,num_DY,num_DZ; meshes for regular grids
71%      .Coord: object position coordinates
72%      .ParentButton: handle of the uicontrol object calling the interface
73% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
74%  if =[] or absent, no refresh (mask mode in uvmat)
75% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
76function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
77%-------------------------------------------------------------------
78% Choose default command line output for set_object
79handles.output = hObject;
80% Update handles structure
81guidata(hObject, handles);
82
83%% position
84set(0,'Unit','pixels')
85ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
86PosGUI=get(handles.set_object,'Position');% fig width in pixels
87Width=PosGUI(3);%width of the gui set_object in pixels
88Height=PosGUI(4);
89Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
90Bottom=ScreenSize(4)-Height-40; %put fig at top right
91set(handles.set_object,'Unit','pixels')
92set(handles.set_object,'Position',[Left Bottom Width Height])
93
94%default
95if ~exist('ZBounds','var')
96    ZBounds=0; %default
97end
98test3D=(ZBounds~=0); % =1 for 3D fleds
99set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
100set(hObject,'DeleteFcn',{@closefcn})
101
102% fill the interface as set in the input data:
103if exist('data','var')
104    if isfield(data,'Coord')
105        set(handles.Coord,'Data',data.Coord)
106        if size(data.Coord,2)==3
107            set(handles.z_slider,'Visible','on')
108        end
109    else
110        set(handles.z_slider,'Visible','off')
111    end
112    if isfield(data,'TypeMenu')
113        set(handles.Type,'String',data.TypeMenu)
114    end
115    if isfield(data,'ProjModeMenu')
116        set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
117    end
118    errormsg=fill_GUI(data,handles.set_object);
119    if ~isempty(errormsg)
120        msgbox_uvmat('ERROR','bad data input in set_object')
121        return
122    end
123    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type
124    set(handles.REFRESH,'BackgroundColor',[1 0 0])
125    if isfield(data,'RangeZ')
126        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
127        if length(ZBounds) >= 2
128            DZ=max(data.RangeZ);%slider step
129            if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
130                rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
131                rel_step(2)=0.1;
132                set(handles.z_slider,'Visible','on')
133                set(handles.z_slider,'Min',ZBounds(1))
134                set(handles.z_slider,'Max',ZBounds(2))
135                set(handles.z_slider,'SliderStep',rel_step)
136                set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
137            end
138        end
139    end
140    if isfield(data,'RangeX')
141        if ischar(data.RangeX)
142            data.RangeX=str2num(data.RangeX);
143        end
144        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
145        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
146    end
147    if isfield(data,'RangeY')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
148        if ischar(data.RangeY)
149            data.RangeY=str2num(data.RangeY);
150        end
151        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
152        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
153    end
154    if isfield(data,'RangeZ')%&& ~strcmp(data.Type,'plane_z')%TODO: generalise
155        if ischar(data.RangeZ)
156            data.RangeZ=str2num(data.RangeZ);
157        end
158        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
159        if numel(data.RangeZ)>=2
160            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
161        end
162    end
163    if ~(isfield(data,'Angle') && size(data.Angle,2)==3)
164        data.Angle=[0 0 0];
165    end
166    set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
167    set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
168    set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
169    if test3D
170        set(handles.num_Angle_1,'Visible','on')
171    set(handles.num_Angle_2,'Visible','on')
172    end
173end
174set(get(handles.set_object,'children'),'enable','off')
175set(handles.SAVE,'enable','on')
176
177
178%------------------------------------------------------------------------
179% --- Outputs from this function are returned to the command line.
180function varargout = set_object_OutputFcn(hObject, eventdata, handles)
181%------------------------------------------------------------------------
182% Get default command line output from handles structure
183varargout{1} = handles.output;
184varargout{2}=handles;
185
186%------------------------------------------------------------------------
187% executed when closing the GUI set_object
188function closefcn(gcbo,eventdata)
189%------------------------------------------------------------------------
190huvmat=findobj(allchild(0),'Tag','uvmat');%find the current uvmat interface handle
191if ~isempty(huvmat)
192    hhuvmat=guidata(huvmat);
193    set(hhuvmat.CheckViewObject,'value',0)%
194    set(hhuvmat.CheckEditObject,'Value',0)% desactivate the edit option
195    % deselect the object in ListObject when view_field is closed
196    if isempty(findobj(allchild(0),'Tag','view_field'))
197        ObjIndex=get(hhuvmat.ListObject,'Value');
198        ObjIndex=ObjIndex(1);%keep only the first object selected
199        set(hhuvmat.ListObject,'Value',ObjIndex)
200        % draw all object colors in blue (unselected) in uvmat
201        hother=[findobj(hhuvmat.PlotAxes,'Tag','proj_object');findobj(hhuvmat.PlotAxes,'Tag','DeformPoint')];%find all the proj object and deform point representations
202        for iobj=1:length(hother)
203            if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
204                set(hother(iobj),'EdgeColor','b')
205                if isequal(get(hother(iobj),'FaceColor'),'m')
206                    set(hother(iobj),'FaceColor','b')
207                end
208            elseif isequal(get(hother(iobj),'Type'),'image')
209                Acolor=get(hother(iobj),'CData');
210                Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
211                set(hother(iobj),'CData',Acolor);
212            else
213                set(hother(iobj),'Color','b')
214            end
215            set(hother(iobj),'Selected','off')
216        end
217    end
218end
219hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
220if ~isempty(hseries)
221    hhseries=guidata(hseries);
222    set(hhseries.EditObject,'Value',0)
223end
224
225
226%------------------------------------------------------------------------
227% --- Executes on selection change in Type.
228function Type_Callback(hObject, eventdata, handles)
229%------------------------------------------------------------------------
230
231ListType=get(handles.Type,'String');
232Type=ListType{get(handles.Type,'Value')};
233% make correspondance between different object styles
234Coord=get(handles.Coord,'Data');
235
236%% set the number of lines in the Coord table depending on object type
237switch Type
238    case {'line'}
239        if size(Coord,1)<2
240            if isequal(size(Coord,2),3)
241                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
242            else
243                Coord=[Coord; 0 0]; %add a line for edition (2D case)
244            end
245        else
246            Coord=Coord(1:2,:);
247        end
248    case {'rectangle','ellipse','plane','volume'}
249        if ~isempty(Coord)
250        Coord=Coord(1,:);
251        end
252end
253set(handles.Coord,'Data',Coord)
254
255%% set the projection menu and the corresponding options
256if isempty(get(handles.ProjMode,'UserData'))
257    switch Type
258        case 'polyline'
259            menu_proj={'interp_lin';'interp_tps';'none'};
260        case {'polygon','rectangle','ellipse'}
261            menu_proj={'inside';'outside';'mask_inside';'mask_outside';'interp_lin';'interp_tps';'none'};
262        case 'volume'
263            menu_proj={'interp_lin';'none'};
264        otherwise
265            menu_proj={'projection';'interp_lin';'interp_tps';'none'};%default
266    end
267else
268    menu_proj=get(handles.ProjMode,'UserData');
269end
270ProjModeList=get(handles.ProjMode,'String');
271menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj));
272if isempty(menu_index)
273    menu_index=1;%
274end
275set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length
276set(handles.ProjMode,'String',menu_proj)
277ProjMode_Callback(hObject, eventdata, handles)
278
279%------------------------------------------------------------------------
280% --- Executes on selection change in ProjMode.
281%------------------------------------------------------------------------
282function ProjMode_Callback(hObject, eventdata, handles)
283
284set(handles.REFRESH,'BackgroundColor',[1 0 1])
285menu=get(handles.ProjMode,'String');
286value=get(handles.ProjMode,'Value');
287ProjMode=menu{value};
288menu=get(handles.Type,'String');
289value=get(handles.Type,'Value');
290ObjectStyle=menu{value};
291
292%default setting
293% set(handles.num_Angle_1,'Visible','off')
294% set(handles.num_Angle_2,'Visible','off')
295% set(handles.num_Angle_3,'Visible','off')
296set(handles.num_RangeX_1,'Visible','off')
297set(handles.num_RangeY_1,'Visible','off')
298
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%default
305                set(handles.num_RangeX_2,'Visible','off')
306         set(handles.num_RangeY_2,'Visible','off')
307switch ObjectStyle
308    case 'points'
309        set(handles.num_RangeInterp,'TooltipString','num_RangeY_2: range of projection around each point')
310%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
311%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
312%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
313    case {'line','polyline','polygon'}
314        set(handles.num_RangeX_2,'Visible','off')
315         set(handles.num_RangeY_2,'Visible','off')
316        %set(handles.num_RangeY_2,'TooltipString','num_RangeY_2: range of projection around the line')
317         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
318%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
319%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
320        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
321            set(handles.num_DX,'Visible','on')
322            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
323            set(handles.num_RangeInterp,'Visible','on')
324        end       
325    case {'rectangle','ellipse'}
326                set(handles.num_RangeX_2,'Visible','on')
327         set(handles.num_RangeY_2,'Visible','on')
328        set(handles.num_RangeX_2,'TooltipString',['num_RangeX_2: half length of the ' ObjectStyle])
329        set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle])
330        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
331            set(handles.num_DX,'Visible','on')
332            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
333            set(handles.num_RangeInterp,'Visible','on')
334        end       
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.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
342%         if test3D
343%             set(handles.num_Angle_2,'Visible','on')
344%             set(handles.num_Angle_1,'Visible','on')
345%             %set(handles.num_Angle_1,'String','90')
346%             %set(handles.Coord,'Data',[0 0 0])
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            set(handles.num_RangeInterp,'Visible','on')
353        else
354            set(handles.num_DX,'Visible','off')
355            set(handles.num_DY,'Visible','off')
356        end
357%         if  isequal(ProjMode,'interp_lin')
358%             set(handles.num_DZ,'Visible','on') 
359%         end
360     case {'volume'} 
361        set(handles.num_RangeX_1,'Visible','on')
362        set(handles.num_RangeX_2,'Visible','on')
363        set(handles.num_RangeY_1,'Visible','on')
364        set(handles.num_RangeY_2,'Visible','on')
365%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
366%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
367        set(handles.num_Angle_1,'Visible','on')
368        set(handles.num_Angle_2,'Visible','on')
369        %set(handles.num_Angle_3,'Visible','on')
370        set(handles.num_RangeZ_1,'Visible','on')
371        set(handles.num_RangeZ_2,'Visible','on')
372        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
373            set(handles.num_DX,'Visible','on')
374            set(handles.num_DY,'Visible','on')
375            set(handles.num_DZ,'Visible','on')
376        else
377            set(handles.num_DX,'Visible','off')
378            set(handles.num_DY,'Visible','off')
379            set(handles.num_DZ,'Visible','off')
380        end
381end
382% set default values read in the plot of uvmat to initiate the mesh
383if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
384    huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
385    if ~isempty(huvmat)
386        UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
387        if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String')));
388            if  isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
389                set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh))
390                set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh))
391                set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin))
392                set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax))
393                set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin))
394                set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax))
395            end
396            if isempty(get(handles.CoordUnit,'String'))&& isfield(UvData.Field,'CoordUnit')
397                set(handles.CoordUnit,'String',UvData.Field.CoordUnit)
398            end
399        end
400    end
401    if isempty(str2num(get(handles.num_RangeInterp,'String'))) && isfield(UvData,'Field')
402        set(handles.num_RangeInterp,'String',num2str(3*UvData.Field.CoordMesh))% default interpolationlength= 3 meshes
403    end
404end
405
406%------------------------------------------------------------------------
407
408%------------------------------------------------------------------------
409function num_Angle_1_Callback(hObject, eventdata, handles)
410update_slider(hObject, eventdata,handles)
411%------------------------------------------------------------------------
412%------------------------------------------------------------------------
413function num_Angle_2_Callback(hObject, eventdata, handles)
414update_slider(hObject, eventdata,handles)
415%------------------------------------------------------------------------
416function update_slider(hObject, eventdata,handles)
417%rotation angles
418PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
419PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
420%PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
421% om=norm(PlaneAngle);%norm of rotation angle in radians
422% OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
423cos_om1=cos(pi*PlaneAngle(1)/180);
424sin_om1=sin(pi*PlaneAngle(1)/180);
425cos_om2=cos(pi*PlaneAngle(2)/180);
426sin_om2=sin(pi*PlaneAngle(2)/180);
427%components of the unity vector norm_plane normal to the projection plane
428% norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
429% norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
430% norm_plane(3)=OmAxis(3)*coeff+cos_om;
431huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
432UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
433if isfield(UvData,'X') && isfield(UvData,'Y') && isfield(UvData,'Z')
434    Z=sin_om2*(cos_om1*(UvData.X)+sin_om1*(UvData.Y))+cos_om2*(UvData.Z);
435    set(handles.z_slider,'Min',min(Z))
436    set(handles.z_slider,'Max',max(Z))
437    ZMax_Callback(hObject, eventdata, handles)
438end
439%------------------------------------------------------------------------
440function num_DX_Callback(hObject, eventdata, handles)
441%------------------------------------------------------------------------
442%------------------------------------------------------------------------
443function num_DY_Callback(hObject, eventdata, handles)
444%------------------------------------------------------------------------
445%------------------------------------------------------------------------
446function num_DZ_Callback(hObject, eventdata, handles)
447%------------------------------------------------------------------------
448
449
450%------------------------------------------------------------------------
451% --- Executes on button press in REFRESH: refresh the current object , refresh the object and its projected field
452%------------------------------------------------------------------------
453function REFRESH_Callback(hObject, eventdata, handles)
454
455set(handles.REFRESH,'BackgroundColor',[1 1 0])% indicate activation of REFRESH
456drawnow
457
458%% update the object in the GUI series if relevant
459if strcmp(get(handles.set_object,'Name'),'edit_object_series')
460    hseries=findobj(allchild(0),'Tag','series');
461    if ~isempty(hseries)
462        SeriesData=get(hseries,'UserData');
463    SeriesData.ProjObject=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
464    set(hseries,'UserData',SeriesData);
465    end
466    set(handles.REFRESH,'BackgroundColor',[1 0 0])
467    return
468end
469
470%% read the object parameters in the GUI set_object
471ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
472if isfield(ObjectData,'CoordLine')% remove CoordLine (not used as object feature)
473    ObjectData=rmfield(ObjectData,'CoordLine');
474end
475if iscell(ObjectData.Coord)%check for empty line
476    ObjectData.Coord=[0 0 0];
477    hhset_object=guidata(handles.set_object);
478    set(hhset_object.Coord,'Data',ObjectData.Coord)
479end
480checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
481if ~isempty(checknan)
482    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
483end
484ObjectName=ObjectData.Name;%name of the current object defined in set_object
485if isempty(ObjectName)
486     ObjectName=ObjectData.Type;% name the object by the object type type by default
487end
488
489%% read the current object selection in the GUI uvmat
490huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
491UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
492hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
493ListObject=get(hhuvmat.ListObject,'String');% list of objects displayed in uvmat
494
495if isequal(get(hhuvmat.CheckEditObject,'Value'),0) %we append a new object
496    ListObject=[ListObject;{''}];
497    IndexObj=length(ListObject);
498    set(hhuvmat.ListObject,'String',ListObject)
499    set(hhuvmat.ListObject,'Value',IndexObj)
500    UvData.ProjObject{IndexObj}=[]; %create a new empty object
501    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
502    UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
503else   
504    IndexObj=get(hhuvmat.ListObject,'Value');% index of the selected object for display in uvmat
505end
506
507%set or modify(edit mode) the name of the currently selected object
508detectname=1;
509ObjectNameNew=ObjectName;
510vers=0;% index of the name
511ListOther=ListObject;
512ListOther(IndexObj)=[];
513while ~isempty(detectname)
514    detectname=find(strcmp(ObjectNameNew,ListOther),1);%test the existence of the proposed name in the list
515    if detectname% if the object name already exists
516        indstr=regexp(ObjectNameNew,'\D');%indices of non number characters
517        if indstr(end)<length(ObjectNameNew) %object name ends by a number
518            vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
519            ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
520        else
521            vers=vers+1;
522            ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
523        end
524    end
525end
526ObjectName=ObjectNameNew;
527set(handles.Name,'String',ObjectName)% display the default name in set_object
528ListObject{IndexObj}=ObjectName;
529set(hhuvmat.ListObject,'String',ListObject);%complement the object list
530set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
531set(hhuvmat.CheckViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object
532check_handle=isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')...
533    && ~isempty(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat) && ishandle(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat);
534if check_handle
535    obj_handle=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
536end
537UvData.ProjObject{IndexObj}=ObjectData;%record the current object properties in uvmat
538if check_handle
539    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=obj_handle; %preserve the object plot handle if valid
540else
541    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; %axes taken as object display handle by defualt
542end
543
544%% refresh the field projected on the object
545hview_field=[];%default
546IndexObj_1=get(hhuvmat.ListObject_1,'Value');
547if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
548    PlotType='text';
549else
550    % create tps coeff if needed for ProjMode 'interp_tps'
551    if strcmp(ObjectData.ProjMode,'interp_tps')&&~isfield(UvData.Field,'Coord_tps')
552        %UvData.Field=calc_tps(UvData.Field,1);
553        [UvData.Field,errormsg]=tps_coeff_field(UvData.Field,1);
554        if ~isempty(errormsg)
555            msgbox_uvmat('ERROR', ['set_object/tps_coeff_field/' errormsg])
556            set(handles.REFRESH,'enable','on')
557            return
558        end
559    end
560    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
561    if ~isempty(errormsg)
562        msgbox_uvmat('ERROR', ['set_object/proj_field/' errormsg])
563        set(handles.REFRESH,'enable','on')
564        return
565    end
566    if isequal(IndexObj_1,IndexObj) % if  the projection is in uvmat
567        PlotType=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(get(hhuvmat.PlotAxes,'parent')));%update the current uvmat plot
568    else  % if the projection is in view_field
569        hview_field=findobj(allchild(0),'tag','view_field');
570        if isempty(hview_field)
571            hview_field=view_field(ProjData); %open the view_field GUI for plot
572        else
573            hhview_field=guidata(hview_field);
574            [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%update an existing  plot in view_field
575            errormsg=fill_GUI(PlotParam,hview_field);
576            if ~isempty(errormsg)
577                msgbox_uvmat('ERROR',errormsg)
578                return
579            end
580            %     write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
581        end
582        haxes=findobj(hview_field,'tag','axes3');
583        Data=get(hview_field,'UserData');
584        if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
585            h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
586            pos_table=get(h_TableDisplay,'Position');
587            pos=get(hview_field,'Position');
588            set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
589            drawnow
590            set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
591        else
592            set(hview_field,'Position',Data.GUISize)
593        end
594    end
595end
596
597%% update the object refresh
598%hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
599% if we are editing the object used for projection in uvmat
600if isequal(IndexObj_1,IndexObj)
601    %update the representation of the current object for projection field represented in view_field
602    for iobj=1:numel(UvData.ProjObject)
603        UvData.ProjObject{iobj}.DisplayHandle.uvmat=...
604            plot_object(UvData.ProjObject{iobj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{iobj}.DisplayHandle.uvmat,'b');
605    end
606else %  we are editing the object used for projection field represented in view_field
607    %update the representation of the current object in uvmat
608    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=...
609             plot_object(UvData.ProjObject{IndexObj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'m');
610    %indicate the object index in the user data of the object refresh (needed for further mouse editing)
611    ObjectInfo=get(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData');
612    ObjectInfo.IndexObj=IndexObj;
613    set(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData',ObjectInfo)
614    % update the representation of all objects in view_field
615    for iobj=1:numel(UvData.ProjObject)
616        if isfield(UvData.ProjObject{iobj},'DisplayHandle') && isfield(UvData.ProjObject{iobj}.DisplayHandle,'view_field')
617            UvData.ProjObject{iobj}.DisplayHandle.view_field=...
618                plot_object(UvData.ProjObject{iobj},UvData.ProjObject{iobj},UvData.ProjObject{iobj}.DisplayHandle.view_field,'b');
619        end
620    end
621end
622set(huvmat,'UserData',UvData)
623
624%% update the GUI uvmat
625set(hhuvmat.CheckEditObject,'Value',1) % set uvmat to object edit mode to allow further object update
626set(hhuvmat.CheckViewField,'Value',1)
627
628set(handles.REFRESH,'BackgroundColor',[1 0 0])
629set(handles.num_RangeY_2,'BackgroundColor',[1 1 1])
630
631% --- Executes on button press in DisplayCoord.
632function DisplayCoord_Callback(hObject, eventdata, handles)
633global Coord
634Coord=get(handles.Coord,'Data');
635evalin('base','global Coord')%make Coord global in the workspace
636display('object coordinates:')
637evalin('base','Coord') %display Coord in the workspace
638commandwindow; %brings the Matlab command window to the front
639
640%----------------------------------------------------
641function num_RangeY_1_Callback(hObject, eventdata, handles)
642%------------------------------------------------------------------------
643
644function num_RangeZ_1_Callback(hObject, eventdata, handles)
645%------------------------------------------------------------------------
646
647function num_RangeZ_2_Callback(hObject, eventdata, handles)
648DZ=str2num(get(handles.num_RangeZ_2,'String'));
649ZMin=get(handles.z_slider,'Min');
650ZMax=get(handles.z_slider,'Max');
651if ~isequal(ZMax-ZMin,0)
652    rel_step(1)=DZ/(ZMax-ZMin);
653    rel_step(2)=0.2;
654    set(handles.z_slider,'SliderStep',rel_step)
655end
656%------------------------------------------------------------------------
657function num_RangeY_2_Callback(hObject, eventdata, handles)
658%------------------------------------------------------------------------
659
660function num_RangeX_1_Callback(hObject, eventdata, handles)
661%------------------------------------------------------------------------
662
663function num_RangeX_2_Callback(hObject, eventdata, handles)
664
665%------------------------------------------------------------------------
666%------------------------------------------------------------------------
667function SAVE_Callback(hObject, eventdata, handles)
668% ------------------------------------------------------
669Object=read_GUI(handles.set_object);
670if isfield(Object,'CoordLine')% remove CoordLine (not used as object feature)
671    Object=rmfield(Object,'CoordLine');
672end
673huvmat=findobj('Tag','uvmat');
674if isempty(huvmat)
675    huvmat=findobj(allchild(0),'Name','series');
676end
677hchild=get(huvmat,'Children');
678hrootpath=findobj(hchild,'Tag','RootPath');
679if isempty(hrootpath)
680    RootPath='';
681else
682    RootPath=get(hrootpath,'String');
683    if iscell(RootPath)
684        RootPath=RootPath{1};
685    end
686end
687title={'object name'};
688dir_save=uigetfile_uvmat('select the folder for the new xml object file:',RootPath,'uigetdir');
689if ~isempty(dir_save)
690    ObjectName=get(handles.Name,'String');
691    if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
692        def=[ObjectName '.xml'];
693    else
694        def=[Object.Style '.xml'];
695    end
696    displ_txt={['save object in' dir_save]; 'with file name (.xml):'};%default display
697    menu=get(handles.ProjMode,'String');
698    value=get(handles.ProjMode,'Value');
699    ProjMode=menu{value};
700    if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
701        displ_txt=[displ_txt; '(note: to create a mask image, use ''Tools/make mask'' on the upper bar menu of uvmat)'];
702    end
703    answer=msgbox_uvmat('INPUT_TXT',displ_txt,def);
704    if ischar(answer)
705        FullName=fullfile(dir_save,answer);
706        t=struct2xml(Object);
707        t=set(t,1,'name','ProjObject');
708        try
709            save(t,FullName)
710            msgbox_uvmat('CONFIRMATION',[FullName  ' saved'])
711        catch ME
712            msgbox_uvmat('ERROR',ME.message)
713        end
714    end
715end
716
717%------------------------------------------------------------------------
718% --- Executes on slider movement.
719function z_slider_Callback(hObject, eventdata, handles)
720%---------------------------------------------------------
721Z_value=get(handles.z_slider,'Value');
722%rotation angles
723PlaneAngle=[0 0];
724norm_plane=[0 0 1];
725cos_om=1;
726sin_om=0;
727
728PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
729PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
730%PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
731PlaneAngle=(pi/180)*PlaneAngle;
732M2=[cos(PlaneAngle(2)) sin(PlaneAngle(2)) 0;-sin(PlaneAngle(2)) cos(PlaneAngle(2)) 0;0 0 1];
733M1=[1 0 0;0 cos(PlaneAngle(1)) sin(PlaneAngle(1));0 -sin(PlaneAngle(1)) cos(PlaneAngle(1))];
734M=M1*M2;
735norm_plane=M*[0 0 1]';
736
737% om=norm(PlaneAngle);%norm of rotation angle in radians
738% if isequal(om,0)
739%     norm_plane=[0 0 1];
740% else
741%     OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
742%     cos_om=cos(om);
743%     sin_om=sin(om);
744%     coeff=OmAxis(3)*(1-cos_om);
745%     %components of the unity vector norm_plane normal to the projection plane
746%     norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
747%     norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
748%     norm_plane(3)=OmAxis(3)*coeff+cos_om;
749% end
750Coord=get(handles.Coord,'Data');
751Coord(3)=Z_value;
752set(handles.Coord,'Data',Coord)
753
754% update graph
755REFRESH_Callback(hObject, eventdata, handles)
756
757%------------------------------------------------------------------------
758% --- Executes on button press in HELP.
759function HELP_Callback(hObject, eventdata, handles)
760%------------------------------------------------------------------------
761web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#ProjObject')
762
763%------------------------------------------------------------------------
764% --- Executes when selected cell(s) is changed in ListCoord.
765%------------------------------------------------------------------------
766function Coord_CellSelectionCallback(hObject, eventdata, handles)
767if ~isempty(eventdata.Indices)
768    iline=eventdata.Indices(1);% selected line number
769    set(handles.CoordLine,'String',num2str(iline))
770end
771
772
773% function num_Angle_3_Callback(hObject, eventdata, handles)
774%
775% %------------------------------------------------------------------------
776% % --- Executes on key press with selection of a uicontrol
777% %------------------------------------------------------------------------
778% function KeyPressFcn(hObject, eventdata, handles)
779% set(handles.REFRESH,'BackgroundColor',[1 0 1])% se REFRESH to magenta color, indicates that refresh needs to be done
780% if strcmp(get(hObject,'Tag'),'num_Angle_3')
781%     set(handles.num_RangeX_1,'String','')
782%     set(handles.num_RangeX_2,'String','')
783%         set(handles.num_RangeY_1,'String','')
784%     set(handles.num_RangeY_2,'String','')
785% end
786
787%------------------------------------------------------------------------
788% --- Executes on key press with focus on Coord and none of its controls.
789%------------------------------------------------------------------------
790function Coord_KeyPressFcn(hObject, eventdata, handles)
791
792set(handles.REFRESH,'BackgroundColor',[1 0 1])
793xx=double(get(handles.set_object,'CurrentCharacter')); %get the keyboard character
794if ismember(xx,[127 31])% delete, or downward
795    Coord=get(handles.Coord,'Data');
796    iline=str2double(get(handles.CoordLine,'String'));
797            if isequal(xx, 31)
798                if isequal(iline,size(Coord,1))% arrow downward
799                Coord=[Coord;zeros(1,size(Coord,2))];
800                end
801            else
802    Coord(iline,:)=[];% suppress the current line
803            end
804    set(handles.Coord,'Data',Coord);
805end
806
807%------------------------------------------------------------------------
808% --- Executes on button press in clear_line.
809%------------------------------------------------------------------------
810function clear_line_Callback(hObject, eventdata, handles)
811
812Coord=get(handles.Coord,'Data');
813iline=str2double(get(handles.CoordLine,'String'));
814if isempty(iline)
815    msgbox_uvmat('WARNING','no line suppressed, select a line in the table')
816else
817    Coord(iline,:)=[];
818    set(handles.REFRESH,'BackgroundColor',[1 0 1])
819    set(handles.Coord,'Data',Coord);
820    set(handles.CoordLine,'String','')
821    REFRESH_Callback(hObject,eventdata,handles)
822end
823
824
825function num_RangeInterp_Callback(hObject, eventdata, handles)
826
827
828% --- Executes on key press with focus on num_RangeX_2 and none of its controls.
829function suggest_refresh(hObject, eventdata, handles)
830set(handles.REFRESH,'BackgroundColor',[1 0 1])
831
832
833function num_Angle_3_Callback(hObject, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.