source: trunk/src/set_object.m @ 1061

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