source: trunk/src/set_object.m @ 967

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

3D cuts improved

File size: 37.1 KB
RevLine 
[204]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%
[445]9% INPUT:u
[204]10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
[379]14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
[204]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)
[809]19
20%=======================================================================
[924]21% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]22%   http://www.legi.grenoble-inp.fr
23%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
[204]24%
25%     This file is part of the toolbox UVMAT.
[809]26%
[204]27%     UVMAT is free software; you can redistribute it and/or modify
[809]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%
[204]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
[809]35%     GNU General Public License (see LICENSE.txt) for more details.
36%=======================================================================
[204]37
38function varargout = set_object(varargin)
39
[966]40% Last Modified by GUIDE v2.5 09-Jul-2016 20:25:37
[204]41
[680]42% Begin initialization code - DO NOT REFRESH
[204]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
[680]59% End initialization code - DO NOT REFRESH
[204]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)
[680]67%        if=0; no associated object (used for series), the button 'REFRESH' is  then unvisible
[204]68%'data': read from an existing object selected in the interface
[379]69%      .Name : class of object ('POINTS','LINE',....)
70%      .num_DX,num_DY,num_DZ; meshes for regular grids
[204]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:
[680]74%  if =[] or absent, no refresh (mask mode in uvmat)
[204]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
[613]83%% position
[657]84set(0,'Unit','pixels')
[613]85ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
[705]86PosGUI=get(handles.set_object,'Position');% fig width in pixels
87Width=PosGUI(3);%width of the gui set_object in pixels
88Height=PosGUI(4);
[613]89Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
90Bottom=ScreenSize(4)-Height-40; %put fig at top right
[657]91set(handles.set_object,'Unit','pixels')
[613]92set(handles.set_object,'Position',[Left Bottom Width Height])
93
[204]94%default
[206]95if ~exist('ZBounds','var')
96    ZBounds=0; %default
[204]97end
[309]98set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
[402]99set(hObject,'DeleteFcn',{@closefcn})
[204]100
101% fill the interface as set in the input data:
102if exist('data','var')
[967]103    if isfield(data,'Coord')
104        set(handles.Coord,'Data',data.Coord)
105        if size(data.Coord,2)==3
[379]106        set(handles.z_slider,'Visible','on')
[967]107        end
[379]108    else
[204]109        set(handles.z_slider,'Visible','off')
110    end
[387]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)
[954]116    end     
[591]117    errormsg=fill_GUI(data,handles.set_object);
[410]118    if ~isempty(errormsg)
119        msgbox_uvmat('ERROR','bad data input in set_object')
120        return
121    end
[387]122    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
[681]123    set(handles.REFRESH,'BackgroundColor',[1 0 0])
[955]124    if isfield(data,'RangeZ')
[379]125        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[955]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
[204]137        end
138    end
[954]139    if isfield(data,'RangeX')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
[204]140        if ischar(data.RangeX)
141            data.RangeX=str2num(data.RangeX);
142        end
[379]143        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
144        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
[204]145    end
[954]146    if isfield(data,'RangeY')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
[204]147        if ischar(data.RangeY)
148            data.RangeY=str2num(data.RangeY);
149        end
[379]150        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
151        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
[204]152    end
[954]153    if isfield(data,'RangeZ')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
[204]154        if ischar(data.RangeZ)
155            data.RangeZ=str2num(data.RangeZ);
156        end
[379]157        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
[204]158        if numel(data.RangeZ)>=2
[379]159            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
[204]160        end
161    end 
[625]162    if ~isfield(data,'Angle')
[965]163        data.Angle=[0 0];
[625]164    end
165%     if isfield(data,'Angle') && isequal(numel(data.Angle),3)
[379]166         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
167         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
[961]168%         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
[625]169%     end
[204]170end
[625]171set(get(handles.set_object,'children'),'enable','off')
172set(handles.SAVE,'enable','on')
[680]173% set(handles.REFRESH,'enable','off')
[204]174
[625]175
[204]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%------------------------------------------------------------------------
[402]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);
[650]191    set(hhuvmat.CheckViewObject,'value',0)%
192    set(hhuvmat.CheckEditObject,'Value',0)% desactivate the edit option
[402]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
[511]199        hother=[findobj(hhuvmat.PlotAxes,'Tag','proj_object');findobj(hhuvmat.PlotAxes,'Tag','DeformPoint')];%find all the proj object and deform point representations
[402]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);
[667]220    set(hhseries.EditObject,'Value',0)
[402]221end
222
223
224%------------------------------------------------------------------------
[379]225% --- Executes on selection change in Type.
226function Type_Callback(hObject, eventdata, handles)
[204]227%------------------------------------------------------------------------
[681]228
[379]229ListType=get(handles.Type,'String');
230Type=ListType{get(handles.Type,'Value')};
[204]231% make correspondance between different object styles
[379]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,:);
[204]248end
[379]249set(handles.Coord,'Data',Coord)
[204]250
[379]251%% set the projection menu and the corresponding options
[387]252if isempty(get(handles.ProjMode,'UserData'))
253    switch Type
[648]254        case 'polyline'
255            menu_proj={'interp_lin';'interp_tps';'none'};
[387]256        case {'polygon','rectangle','ellipse'}
[648]257            menu_proj={'inside';'outside';'mask_inside';'mask_outside';'interp_lin';'interp_tps';'none'};
[387]258        case 'volume'
[581]259            menu_proj={'interp_lin';'none'};
[387]260        otherwise
[581]261            menu_proj={'projection';'interp_lin';'interp_tps';'none'};%default
[387]262    end
263else
264    menu_proj=get(handles.ProjMode,'UserData');
265end
[410]266ProjModeList=get(handles.ProjMode,'String');
267menu_index=find(strcmp(ProjModeList{get(handles.ProjMode,'Value')},menu_proj));
268if isempty(menu_index)
269    menu_index=1;%
[204]270end
[410]271set(handles.ProjMode,'Value',menu_index);% value index must not exceed the menu length
[204]272set(handles.ProjMode,'String',menu_proj)
273ProjMode_Callback(hObject, eventdata, handles)
[379]274
[204]275%------------------------------------------------------------------------
276% --- Executes on selection change in ProjMode.
[675]277%------------------------------------------------------------------------
[681]278function ProjMode_Callback(hObject, eventdata, handles)
[675]279
[681]280set(handles.REFRESH,'BackgroundColor',[1 0 1])
[204]281menu=get(handles.ProjMode,'String');
282value=get(handles.ProjMode,'Value');
283ProjMode=menu{value};
[379]284menu=get(handles.Type,'String');
285value=get(handles.Type,'Value');
[204]286ObjectStyle=menu{value};
[379]287%%%%%%%%% TODO
[955]288test3D=strcmp(ObjectStyle,'plane_z'); %TODO: generalize
[379]289%%%%%%%%%
[204]290%default setting
[379]291set(handles.num_Angle_1,'Visible','off')
292set(handles.num_Angle_2,'Visible','off')
[961]293%set(handles.num_Angle_3,'Visible','off')
[379]294set(handles.num_RangeX_1,'Visible','off')
295set(handles.num_RangeX_2,'Visible','off')
296set(handles.num_RangeY_1,'Visible','off')
[589]297if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]298    set(handles.num_RangeY_2,'Visible','off')
[204]299else
[379]300    set(handles.num_RangeY_2,'Visible','on')
[204]301end
302if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
[379]303    set(handles.num_RangeX_2,'Visible','on')
[204]304else
[379]305   set(handles.num_RangeX_2,'Visible','off')
[204]306end
[379]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')
[912]312set(handles.num_RangeInterp,'Visible','off')
[204]313
314switch ObjectStyle
315    case 'points'
[675]316        set(handles.num_RangeY_2,'TooltipString','num_RangeY_2: range of projection around each point')
[379]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')
[204]320    case {'line','polyline','polygon'}
[675]321        set(handles.num_RangeY_2,'TooltipString','num_RangeY_2: range of projection around the line')
[379]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')
[581]325        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]326            set(handles.num_DX,'Visible','on')
327            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
[912]328            set(handles.num_RangeInterp,'Visible','on')
[204]329        end       
330    case {'rectangle','ellipse'}
[675]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])
[954]333    case {'plane','plane_z'} 
[961]334%        set(handles.num_Angle_3,'Visible','on')
[379]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')
[204]340        if test3D
[379]341            set(handles.num_Angle_2,'Visible','on')
342            set(handles.num_Angle_1,'Visible','on')
[961]343            set(handles.num_Angle_1,'String','90')
[967]344            %set(handles.Coord,'Data',[0 0 0])
[379]345            set(handles.num_RangeZ_2,'Visible','on')
[204]346        end
[581]347        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]348            set(handles.num_DX,'Visible','on')
349            set(handles.num_DY,'Visible','on')
[912]350            set(handles.num_RangeInterp,'Visible','on')
[204]351        else
[379]352            set(handles.num_DX,'Visible','off')
353            set(handles.num_DY,'Visible','off')
[204]354        end
[912]355%         if  isequal(ProjMode,'interp_lin')
356%             set(handles.num_DZ,'Visible','on') 
357%         end
[204]358     case {'volume'} 
[379]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')
[204]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])
[379]365        set(handles.num_Angle_1,'Visible','on')
366        set(handles.num_Angle_2,'Visible','on')
[965]367        %set(handles.num_Angle_3,'Visible','on')
[379]368        set(handles.num_RangeZ_1,'Visible','on')
369        set(handles.num_RangeZ_2,'Visible','on')
[581]370        if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[379]371            set(handles.num_DX,'Visible','on')
372            set(handles.num_DY,'Visible','on')
373            set(handles.num_DZ,'Visible','on')
[204]374        else
[379]375            set(handles.num_DX,'Visible','off')
376            set(handles.num_DY,'Visible','off')
377            set(handles.num_DZ,'Visible','off')
[204]378        end
379end
[864]380% set default values read in the plot of uvmat to initiate the mesh
381if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps')
[912]382            huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
383        UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
[864]384    if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String')));     
[912]385%         Field=UvData.Field;
[864]386        if  isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
387            set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh))
388            set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh))
389            set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin))
390            set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax))
391            set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin))
392            set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax))
393        end
[954]394        if isempty(get(handles.CoordUnit,'String'))&& isfield(UvData.Field,'CoordUnit')
395            set(handles.CoordUnit,'String',UvData.Field.CoordUnit)
[864]396        end       
397    end
[922]398    if isempty(str2num(get(handles.num_RangeInterp,'String'))) && isfield(UvData,'Field')
[912]399     set(handles.num_RangeInterp,'String',num2str(3*UvData.Field.CoordMesh))% default interpolationlength= 3 meshes
400    end
[864]401end
402
[204]403%------------------------------------------------------------------------
404
405%------------------------------------------------------------------------
[379]406function num_Angle_1_Callback(hObject, eventdata, handles)
[204]407update_slider(hObject, eventdata,handles)
408%------------------------------------------------------------------------
409%------------------------------------------------------------------------
[379]410function num_Angle_2_Callback(hObject, eventdata, handles)
[204]411update_slider(hObject, eventdata,handles)
412%------------------------------------------------------------------------
413function update_slider(hObject, eventdata,handles)
414%rotation angles
[379]415PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
416PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
[965]417%PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
[212]418om=norm(PlaneAngle);%norm of rotation angle in radians
419OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
420cos_om=cos(pi*om/180);
421sin_om=sin(pi*om/180);
422coeff=OmAxis(3)*(1-cos_om);
423%components of the unity vector norm_plane normal to the projection plane
424norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
425norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
426norm_plane(3)=OmAxis(3)*coeff+cos_om;
[204]427huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
428UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
[912]429if isfield(UvData,'X') && isfield(UvData,'Y') && isfield(UvData,'Z')
[212]430    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
[204]431    set(handles.z_slider,'Min',min(Z))
432    set(handles.z_slider,'Max',max(Z))
433    ZMax_Callback(hObject, eventdata, handles)
434end
435%------------------------------------------------------------------------
[379]436function num_DX_Callback(hObject, eventdata, handles)
[204]437%------------------------------------------------------------------------
438%------------------------------------------------------------------------
[379]439function num_DY_Callback(hObject, eventdata, handles)
[204]440%------------------------------------------------------------------------
441%------------------------------------------------------------------------
[379]442function num_DZ_Callback(hObject, eventdata, handles)
[204]443%------------------------------------------------------------------------
444
445
446%------------------------------------------------------------------------
[680]447% --- Executes on button press in REFRESH: refresh the current object , refresh the object and its projected field
448%------------------------------------------------------------------------
449function REFRESH_Callback(hObject, eventdata, handles)
[204]450
[681]451set(handles.REFRESH,'BackgroundColor',[1 1 0])% indicate activation of REFRESH
[508]452drawnow
453
[630]454%% update the object in the GUI series if relevant
455if strcmp(get(handles.set_object,'Name'),'edit_object_series')
456    hseries=findobj(allchild(0),'Tag','series');
457    if ~isempty(hseries)
458        SeriesData=get(hseries,'UserData');
459    SeriesData.ProjObject=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
460    set(hseries,'UserData',SeriesData);
461    end
[680]462    set(handles.REFRESH,'BackgroundColor',[1 0 0])
[630]463    return
464end
465
[410]466%% read the object parameters in the GUI set_object
[388]467ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
[871]468if isfield(ObjectData,'CoordLine')% remove CoordLine (not used as object feature)
469    ObjectData=rmfield(ObjectData,'CoordLine');
470end
[397]471if iscell(ObjectData.Coord)%check for empty line
472    ObjectData.Coord=[0 0 0];
473    hhset_object=guidata(handles.set_object);
474    set(hhset_object.Coord,'Data',ObjectData.Coord)
475end
[388]476checknan=isnan(sum(ObjectData.Coord,2));%check for NaN lines
477if ~isempty(checknan)
478    ObjectData.Coord(checknan,:)=[];%remove the NaN lines
479end
[402]480ObjectName=ObjectData.Name;%name of the current object defined in set_object
[309]481if isempty(ObjectName)
[432]482     ObjectName=ObjectData.Type;% name the object by the object type type by default
[204]483end
[413]484
[432]485%% read the current object selection in the GUI uvmat
[413]486huvmat=findobj('tag','uvmat');%find the current uvmat GUI handle
487UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
488hhuvmat=guidata(huvmat);%handles of the objects children of the  GUI uvmat
[432]489ListObject=get(hhuvmat.ListObject,'String');% list of objects displayed in uvmat
[625]490
[650]491if isequal(get(hhuvmat.CheckEditObject,'Value'),0) %we append a new object
[625]492    ListObject=[ListObject;{''}];
493    IndexObj=length(ListObject);
494    set(hhuvmat.ListObject,'String',ListObject)
495    set(hhuvmat.ListObject,'Value',IndexObj)
496    UvData.ProjObject{IndexObj}=[]; %create a new empty object
497    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
498    UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
[630]499else   
[625]500    IndexObj=get(hhuvmat.ListObject,'Value');% index of the selected object for display in uvmat
501end
502
[630]503%set or modify(edit mode) the name of the currently selected object
[445]504detectname=1;
505ObjectNameNew=ObjectName;
506vers=0;% index of the name
507ListOther=ListObject;
508ListOther(IndexObj)=[];
509while ~isempty(detectname)
510    detectname=find(strcmp(ObjectNameNew,ListOther),1);%test the existence of the proposed name in the list
511    if detectname% if the object name already exists
512        indstr=regexp(ObjectNameNew,'\D');%indices of non number characters
513        if indstr(end)<length(ObjectNameNew) %object name ends by a number
514            vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
515            ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
516        else
517            vers=vers+1;
518            ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
[204]519        end
520    end
[445]521end
522ObjectName=ObjectNameNew;
523set(handles.Name,'String',ObjectName)% display the default name in set_object
524ListObject{IndexObj}=ObjectName;
525set(hhuvmat.ListObject,'String',ListObject);%complement the object list
[625]526set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
[650]527set(hhuvmat.CheckViewObject,'Value',1)% indicate that the currently selected objected is viewed on set_object
[622]528check_handle=isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')...
529    && ~isempty(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat) && ishandle(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat);
[445]530if check_handle
[622]531    obj_handle=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
[445]532end
[622]533UvData.ProjObject{IndexObj}=ObjectData;%record the current object properties in uvmat
[445]534if check_handle
[622]535    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=obj_handle; %preserve the object plot handle if valid
[445]536else
[622]537    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; %axes taken as object display handle by defualt
[204]538end
[309]539
[680]540%% refresh the field projected on the object
[432]541hview_field=[];%default
[445]542IndexObj_1=get(hhuvmat.ListObject_1,'Value');
[388]543if strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')||strcmp(ObjectData.ProjMode,'none')
544    PlotType='text';
545else
[581]546    % create tps coeff if needed for ProjMode 'interp_tps'
[586]547    if strcmp(ObjectData.ProjMode,'interp_tps')&&~isfield(UvData.Field,'Coord_tps')
548        %UvData.Field=calc_tps(UvData.Field,1);
549        [UvData.Field,errormsg]=tps_coeff_field(UvData.Field,1);
550        if ~isempty(errormsg)
551            msgbox_uvmat('ERROR', ['set_object/tps_coeff_field/' errormsg])
[680]552            set(handles.REFRESH,'enable','on')
[586]553            return
554        end
[508]555    end
[388]556    [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
557    if ~isempty(errormsg)
[586]558        msgbox_uvmat('ERROR', ['set_object/proj_field/' errormsg])
[680]559        set(handles.REFRESH,'enable','on')
[388]560        return
[586]561    end
[445]562    if isequal(IndexObj_1,IndexObj) % if  the projection is in uvmat
[586]563        PlotType=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(get(hhuvmat.PlotAxes,'parent')));%update the current uvmat plot
[491]564    else  % if the projection is in view_field
[413]565        hview_field=findobj(allchild(0),'tag','view_field');
566        if isempty(hview_field)
[429]567            hview_field=view_field(ProjData); %open the view_field GUI for plot
[413]568        else
569            hhview_field=guidata(hview_field);
[511]570            [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%update an existing  plot in view_field
[591]571            errormsg=fill_GUI(PlotParam,hview_field);
[569]572            if ~isempty(errormsg)
573                msgbox_uvmat('ERROR',errormsg)
574                return
575            end
[586]576            %     write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
[413]577        end
[429]578        haxes=findobj(hview_field,'tag','axes3');
579        Data=get(hview_field,'UserData');
580        if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
581            h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
582            pos_table=get(h_TableDisplay,'Position');
583            pos=get(hview_field,'Position');
584            set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
585            drawnow
586            set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
587        else
588            set(hview_field,'Position',Data.GUISize)
589        end
[388]590    end
[227]591end
[429]592
[680]593%% update the object refresh
[622]594hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
[445]595% if we are editing the object used for projection in uvmat
596if isequal(IndexObj_1,IndexObj)
597    %update the representation of the current object for projection field represented in view_field
[622]598    for iobj=1:numel(UvData.ProjObject)
599        UvData.ProjObject{iobj}.DisplayHandle.uvmat=...
600            plot_object(UvData.ProjObject{iobj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{iobj}.DisplayHandle.uvmat,'b');
[432]601    end
[445]602else %  we are editing the object used for projection field represented in view_field
603    %update the representation of the current object in uvmat
[622]604    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=...
605             plot_object(UvData.ProjObject{IndexObj},UvData.ProjObject{IndexObj_1},UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'m');
[680]606    %indicate the object index in the user data of the object refresh (needed for further mouse editing)
[622]607    ObjectInfo=get(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData');
[445]608    ObjectInfo.IndexObj=IndexObj;
[622]609    set(UvData.ProjObject{IndexObj}.DisplayHandle.uvmat,'UserData',ObjectInfo)
[445]610    % update the representation of all objects in view_field
[622]611    for iobj=1:numel(UvData.ProjObject)
[729]612        if isfield(UvData.ProjObject{iobj},'DisplayHandle') && isfield(UvData.ProjObject{iobj}.DisplayHandle,'view_field')
[622]613            UvData.ProjObject{iobj}.DisplayHandle.view_field=...
614                plot_object(UvData.ProjObject{iobj},UvData.ProjObject{iobj},UvData.ProjObject{iobj}.DisplayHandle.view_field,'b');
[445]615        end
[432]616    end
617end
618set(huvmat,'UserData',UvData)
619
[204]620%% update the GUI uvmat
[650]621set(hhuvmat.CheckEditObject,'Value',1) % set uvmat to object edit mode to allow further object update
622set(hhuvmat.CheckViewField,'Value',1)
[681]623
[680]624set(handles.REFRESH,'BackgroundColor',[1 0 0])
[681]625set(handles.num_RangeY_2,'BackgroundColor',[1 1 1])
626
[772]627% --- Executes on button press in DisplayCoord.
628function DisplayCoord_Callback(hObject, eventdata, handles)
[738]629global Coord
630Coord=get(handles.Coord,'Data');
631evalin('base','global Coord')%make Coord global in the workspace
632display('object coordinates:')
633evalin('base','Coord') %display Coord in the workspace
634commandwindow; %brings the Matlab command window to the front
635
[204]636%----------------------------------------------------
[379]637function num_RangeY_1_Callback(hObject, eventdata, handles)
[204]638%------------------------------------------------------------------------
639
[379]640function num_RangeZ_1_Callback(hObject, eventdata, handles)
[204]641%------------------------------------------------------------------------
642
[379]643function num_RangeZ_2_Callback(hObject, eventdata, handles)
644DZ=str2num(get(handles.num_RangeZ_2,'String'));
[204]645ZMin=get(handles.z_slider,'Min');
646ZMax=get(handles.z_slider,'Max');
647if ~isequal(ZMax-ZMin,0)
648    rel_step(1)=DZ/(ZMax-ZMin);
649    rel_step(2)=0.2;
650    set(handles.z_slider,'SliderStep',rel_step)
651end
652%------------------------------------------------------------------------
[379]653function num_RangeY_2_Callback(hObject, eventdata, handles)
[204]654%------------------------------------------------------------------------
655
[379]656function num_RangeX_1_Callback(hObject, eventdata, handles)
[204]657%------------------------------------------------------------------------
658
[379]659function num_RangeX_2_Callback(hObject, eventdata, handles)
[681]660
[204]661%------------------------------------------------------------------------
662%------------------------------------------------------------------------
663function SAVE_Callback(hObject, eventdata, handles)
664% ------------------------------------------------------
[379]665Object=read_GUI(handles.set_object);
[871]666if isfield(Object,'CoordLine')% remove CoordLine (not used as object feature)
667    Object=rmfield(Object,'CoordLine');
668end
[204]669huvmat=findobj('Tag','uvmat');
670if isempty(huvmat)
671    huvmat=findobj(allchild(0),'Name','series');
672end
673hchild=get(huvmat,'Children');
674hrootpath=findobj(hchild,'Tag','RootPath');
675if isempty(hrootpath)
676    RootPath='';
677else
678    RootPath=get(hrootpath,'String');
679    if iscell(RootPath)
680        RootPath=RootPath{1};
681    end
682end
683title={'object name'};
[667]684dir_save=uigetfile_uvmat('select the folder for the new xml object file:',RootPath,'uigetdir');
685if ~isempty(dir_save)
686    ObjectName=get(handles.Name,'String');
687    if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
[675]688        def=[ObjectName '.xml'];
[667]689    else
[675]690        def=[Object.Style '.xml'];
[667]691    end
[705]692    displ_txt={['save object in' dir_save]; 'with file name (.xml):'};%default display
[667]693    menu=get(handles.ProjMode,'String');
694    value=get(handles.ProjMode,'Value');
695    ProjMode=menu{value};
696    if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
[745]697        displ_txt=[displ_txt; '(note: to create a mask image, use ''Tools/make mask'' on the upper bar menu of uvmat)'];
[667]698    end
[675]699    answer=msgbox_uvmat('INPUT_TXT',displ_txt,def);
[705]700    if ischar(answer)
701        FullName=fullfile(dir_save,answer);
[667]702        t=struct2xml(Object);
703        t=set(t,1,'name','ProjObject');
[912]704        try
705            save(t,FullName)
706            msgbox_uvmat('CONFIRMATION',[FullName  ' saved'])
707        catch ME
708            msgbox_uvmat('ERROR',ME.message)
709        end
[667]710    end
[204]711end
[227]712
[204]713%------------------------------------------------------------------------
714% --- Executes on slider movement.
715function z_slider_Callback(hObject, eventdata, handles)
716%---------------------------------------------------------
717Z_value=get(handles.z_slider,'Value');
718%rotation angles
[965]719PlaneAngle=[0 0];
[227]720norm_plane=[0 0 1];
721cos_om=1;
722sin_om=0;
723
[379]724PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
725PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
[964]726%PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
[227]727PlaneAngle=(pi/180)*PlaneAngle;
[964]728M2=[cos(PlaneAngle(2)) sin(PlaneAngle(2)) 0;-sin(PlaneAngle(2)) cos(PlaneAngle(2)) 0;0 0 1];
729M1=[1 0 0;0 cos(PlaneAngle(1)) sin(PlaneAngle(1));0 -sin(PlaneAngle(1)) cos(PlaneAngle(1))];
730M=M1*M2;
731norm_plane=M*[0 0 1]';
732
733% om=norm(PlaneAngle);%norm of rotation angle in radians
734% if isequal(om,0)
735%     norm_plane=[0 0 1];
736% else
737%     OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
738%     cos_om=cos(om);
739%     sin_om=sin(om);
740%     coeff=OmAxis(3)*(1-cos_om);
741%     %components of the unity vector norm_plane normal to the projection plane
742%     norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
743%     norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
744%     norm_plane(3)=OmAxis(3)*coeff+cos_om;
745% end
[747]746Coord=get(handles.Coord,'Data');
747Coord(3)=Z_value;
748set(handles.Coord,'Data',Coord)
[204]749
[388]750% update graph
[680]751REFRESH_Callback(hObject, eventdata, handles)
[227]752
[204]753%------------------------------------------------------------------------
754% --- Executes on button press in HELP.
755function HELP_Callback(hObject, eventdata, handles)
[227]756%------------------------------------------------------------------------
[773]757web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#ProjObject')
[204]758
[850]759%------------------------------------------------------------------------
[674]760% --- Executes when selected cell(s) is changed in ListCoord.
[850]761%------------------------------------------------------------------------
[674]762function Coord_CellSelectionCallback(hObject, eventdata, handles)
763if ~isempty(eventdata.Indices)
764    iline=eventdata.Indices(1);% selected line number
[850]765    set(handles.CoordLine,'String',num2str(iline))
[674]766end
[379]767
[681]768
[965]769% function num_Angle_3_Callback(hObject, eventdata, handles)
770%
771% %------------------------------------------------------------------------
772% % --- Executes on key press with selection of a uicontrol
773% %------------------------------------------------------------------------
774% function KeyPressFcn(hObject, eventdata, handles)
775% set(handles.REFRESH,'BackgroundColor',[1 0 1])% se REFRESH to magenta color, indicates that refresh needs to be done
776% if strcmp(get(hObject,'Tag'),'num_Angle_3')
777%     set(handles.num_RangeX_1,'String','')
778%     set(handles.num_RangeX_2,'String','')
779%         set(handles.num_RangeY_1,'String','')
780%     set(handles.num_RangeY_2,'String','')
781% end
[681]782
[674]783%------------------------------------------------------------------------
[681]784% --- Executes on key press with focus on Coord and none of its controls.
785%------------------------------------------------------------------------
786function Coord_KeyPressFcn(hObject, eventdata, handles)
787
788set(handles.REFRESH,'BackgroundColor',[1 0 1])
[674]789xx=double(get(handles.set_object,'CurrentCharacter')); %get the keyboard character
[680]790if ismember(xx,[127 31])% delete, or downward
[674]791    Coord=get(handles.Coord,'Data');
[850]792    iline=str2double(get(handles.CoordLine,'String'));
[674]793            if isequal(xx, 31)
794                if isequal(iline,size(Coord,1))% arrow downward
795                Coord=[Coord;zeros(1,size(Coord,2))];
796                end
797            else
798    Coord(iline,:)=[];% suppress the current line
799            end
800    set(handles.Coord,'Data',Coord);
801end
[850]802
803%------------------------------------------------------------------------
804% --- Executes on button press in clear_line.
805%------------------------------------------------------------------------
806function clear_line_Callback(hObject, eventdata, handles)
807
808Coord=get(handles.Coord,'Data');
809iline=str2double(get(handles.CoordLine,'String'));
810if isempty(iline)
811    msgbox_uvmat('WARNING','no line suppressed, select a line in the table')
812else
813    Coord(iline,:)=[];
814    set(handles.REFRESH,'BackgroundColor',[1 0 1])
815    set(handles.Coord,'Data',Coord);
816    set(handles.CoordLine,'String','')
817    REFRESH_Callback(hObject,eventdata,handles)
818end
[911]819
820
821
822function num_RangeInterp_Callback(hObject, eventdata, handles)
[966]823
824
825% --- Executes on key press with focus on num_Angle_1 and none of its controls.
826function num_Angle_1_KeyPressFcn(hObject, eventdata, handles)
827% hObject    handle to num_Angle_1 (see GCBO)
828% eventdata  structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
829%       Key: name of the key that was pressed, in lower case
830%       Character: character interpretation of the key(s) that was pressed
831%       Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
832% handles    structure with handles and user data (see GUIDATA)
833
834
835% --- Executes on key press with focus on num_Angle_2 and none of its controls.
836function num_Angle_2_KeyPressFcn(hObject, eventdata, handles)
837% hObject    handle to num_Angle_2 (see GCBO)
838% eventdata  structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
839%       Key: name of the key that was pressed, in lower case
840%       Character: character interpretation of the key(s) that was pressed
841%       Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
842% handles    structure with handles and user data (see GUIDATA)
Note: See TracBrowser for help on using the repository browser.