source: trunk/src/set_object.m @ 379

Last change on this file since 379 was 379, checked in by sommeria, 12 years ago

several bugs corrected
set_object.fig rationalized so that read_set_object is replaced by the rgeneral fct read_GUI.

File size: 32.2 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:
10% data: structure describing the object properties
11%    .Style=...
12%    .ProjMode
13%    .CoordType: 'phys' or 'px'
14%    .num_DX,.num_DY,.num_DZ : mesh along each dirction
15%    .RangeX, RangeY
16%    .Coord(j,i), i=1, 2, 3,  components x, y, z of j=1...n position(s) characterizing the object components
17% PlotHandles: handles for projection plots NO MORE USED
18% Zbounds: bounds on Z ( 3D case)
19%
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23%     This file is part of the toolbox UVMAT.
24%
25%     UVMAT is free software; you can redistribute it and/or modify
26%     it under the terms of the GNU General Public License as published by
27%     the Free Software Foundation; either version 2 of the License, or
28%     (at your option) any later version.
29%
30%     UVMAT is distributed in the hope that it will be useful,
31%     but WITHOUT ANY WARRANTY; without even the implied warranty of
32%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
34%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35
36function varargout = set_object(varargin)
37
38% Last Modified by GUIDE v2.5 26-Jan-2012 22:00:47
39
40% Begin initialization code - DO NOT PLOT
41gui_Singleton = 1;
42gui_State = struct('gui_Name',       mfilename, ...
43                   'gui_Singleton',  gui_Singleton, ...
44                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
45                   'gui_OutputFcn',  @set_object_OutputFcn, ...
46                   'gui_LayoutFcn',  [] , ...
47                   'gui_Callback',   []);
48if nargin & ischar(varargin{1})
49    gui_State.gui_Callback = str2func(varargin{1});
50end
51
52if nargout
53    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
54else
55    gui_mainfcn(gui_State, varargin{:});
56end
57% End initialization code - DO NOT PLOT
58%------------------------------------------------------------------------
59%------------------------------------------------------------------------
60% --- Executes just before set_object is made visible.
61%INPUT:
62% handles: handles of the set_object interface elements
63%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
64%        if =[] or absent: index still undefined (create mode in uvmat)
65%        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
66%'data': read from an existing object selected in the interface
67%      .Name : class of object ('POINTS','LINE',....)
68%      .num_DX,num_DY,num_DZ; meshes for regular grids
69%      .Coord: object position coordinates
70%      .ParentButton: handle of the uicontrol object calling the interface
71% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
72%  if =[] or absent, no plot (mask mode in uvmat)
73% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
74function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
75%-------------------------------------------------------------------
76% Choose default command line output for set_object
77handles.output = hObject;
78% Update handles structure
79guidata(hObject, handles);
80
81%default
82if ~exist('ZBounds','var')
83    ZBounds=0; %default
84end
85set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
86set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
87enable_plot=0;%default: does not allow plot of object and projection
88
89% fill the interface as set in the input data:
90if exist('data','var')
91    if isfield(data,'enable_plot')
92        enable_plot=data.enable_plot;%test to desable button PLOT (display mode)
93    end
94    if isfield(data,'Coord') &&size(data.Coord,2)==3
95        set(handles.z_slider,'Visible','on')
96    else
97        set(handles.z_slider,'Visible','off')
98    end
99    errormsg=fill_GUI(data,handles);
100%     if isfield(data,'StyleMenu')
101%         set(handles.Type,'String',data.StyleMenu);
102%     end
103%     if isfield(data,'Type')
104%         menu=get(handles.Type,'String');
105%         for iline=1:length(menu)
106%             if isequal(menu{iline},data.Style)
107%                 set(handles.Type,'Value',iline)
108%                 break
109%             end
110%         end
111%     end
112    Type_Callback(hObject, eventdata, handles)
113%     if isfield(data,'ProjMenu')
114%         set(handles.ProjMode,'String',data.ProjMenu);%overset the standard menu
115%     end
116%     if isfield(data,'ProjMode')
117%         menu=get(handles.ProjMode,'String');
118%         for iline=1:length(menu)
119%             if isequal(menu{iline},data.ProjMode)
120%                 set(handles.ProjMode,'Value',iline)
121%                 break
122%             end
123%         end
124%     end
125%    ProjMode_Callback(hObject, eventdata, handles)
126%     if isfield(data,'Coord')
127%         if ischar(data.Coord)
128%             data.Coord=str2num(data.Coord);
129%         elseif iscell(data.Coord)
130%             CoordCell=data.Coord;
131%             data.Coord=zeros(numel(CoordCell),3);
132%             data.Coord(:,3)=zeros(numel(CoordCell),1); % z component set to 0 by default
133%             for iline=1:numel(CoordCell)
134%                 line_vec=str2num(CoordCell{iline});
135%                 if numel(line_vec)==2
136%                     data.Coord(iline,1:2)=str2num(CoordCell{iline});
137%                 else
138%                     data.Coord(iline,:)=str2num(CoordCell{iline});
139%                 end
140%             end
141%         end
142%         if size(data.Coord,2)>=2
143%             sizcoord=size(data.Coord);
144%             for i=1:sizcoord(1)
145%                 XObject{i}=num2str(data.Coord(i,1),4);
146%                 YObject{i}=num2str(data.Coord(i,2),4);
147%             end
148% %             set(handles.XObject,'String',XObject)
149% %             set(handles.YObject,'String',YObject)
150%             if sizcoord(2)>3
151%                 for i=1:sizcoord(1)
152%                     ZObject{i}=num2str(data.Coord(i,3),4);
153%                 end
154%                 set(handles.ZObject,'String',ZObject)
155%             end
156%         end
157%     end
158%     if isfield(data,'DX')
159%         if ~ischar(handles.num_DX)
160%             data.DX=num2str(data.DX,3);
161%         end
162%         set(handles.num_DX,'String',data.DX)
163%     end
164%     if isfield(data,'DY')
165%         if ~ischar(handles.num_DY)
166%             data.DY=num2str(data.DY,3);
167%         end
168%         set(handles.num_DY,'String',data.DX)
169%     end
170    if isfield(data,'RangeZ') && length(ZBounds) >= 2
171        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
172        DZ=max(data.RangeZ);%slider step
173        if ~isnan(ZBounds(1)) && ZBounds(2)~=ZBounds(1)
174            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
175            rel_step(2)=0.1;
176            set(handles.z_slider,'Visible','on')
177            set(handles.z_slider,'Min',ZBounds(1))
178            set(handles.z_slider,'Max',ZBounds(2))
179            set(handles.z_slider,'SliderStep',rel_step)
180            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
181        end
182    end
183    if isfield(data,'RangeX')
184        if ischar(data.RangeX)
185            data.RangeX=str2num(data.RangeX);
186        end
187        set(handles.num_RangeX_2,'String',num2str(max(data.RangeX),3))
188        set(handles.num_RangeX_1,'String',num2str(min(data.RangeX),3))
189    end
190    if isfield(data,'RangeY')
191        if ischar(data.RangeY)
192            data.RangeY=str2num(data.RangeY);
193        end
194        set(handles.num_RangeY_2,'String',num2str(max(data.RangeY),3))
195        set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
196    end
197    if isfield(data,'RangeZ')
198        if ischar(data.RangeZ)
199            data.RangeZ=str2num(data.RangeZ);
200        end
201        set(handles.num_RangeZ_2,'String',num2str(max(data.RangeZ),3))
202        if numel(data.RangeZ)>=2
203            set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
204        end
205    end 
206    if isfield(data,'Angle') && isequal(numel(data.Angle),3)
207         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
208         set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
209         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
210    end
211%     if isfield(data,'DZ')
212%         if ~ischar(handles.num_DZ)
213%             data.DY=num2str(data.DZ,3);
214%         end
215%         set(handles.num_DZ,'String',data.DZ)
216%     end
217%     if isfield(data,'CoordUnit')
218%         set(handles.CoordUnit,'String',data.CoordUnit)
219%     end
220end
221if enable_plot
222   set(handles.PLOT,'enable','on')
223else
224   set(handles.PLOT,'enable','off')
225end
226huvmat=findobj(allchild(0),'tag','uvmat');
227UvData=get(huvmat,'UserData');
228pos_uvmat=get(huvmat,'Position');
229%position the set_object GUI with respect to uvmat
230if isfield(UvData,'SetObjectOrigin')
231    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
232    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
233    set(hObject,'Position',pos_set_object)
234end
235
236
237%------------------------------------------------------------------------
238% --- Outputs from this function are returned to the command line.
239function varargout = set_object_OutputFcn(hObject, eventdata, handles)
240%------------------------------------------------------------------------
241% Get default command line output from handles structure
242varargout{1} = handles.output;
243varargout{2}=handles;
244
245%------------------------------------------------------------------------
246% --- Executes on selection change in Type.
247function Type_Callback(hObject, eventdata, handles)
248%------------------------------------------------------------------------
249%style_prev=get(handles.Type,'UserData');%previous object style
250ListType=get(handles.Type,'String');
251Type=ListType{get(handles.Type,'Value')};
252% make correspondance between different object styles
253Coord=get(handles.Coord,'Data');
254%
255% Xcolumn=get(handles.XObject,'String');
256% Ycolumn=get(handles.YObject,'String');
257% if ischar(Xcolumn)
258%     sizchar=size(Xcolumn);
259%     for icol=1:sizchar(1)
260%         Xcolumn_cell{icol}=Xcolumn(icol,:);
261%     end
262%     Xcolumn=Xcolumn_cell;
263% end
264% if ischar(Ycolumn)
265%     sizchar=size(Ycolumn);
266%     for icol=1:sizchar(1)
267%         Ycolumn_cell{icol}=Ycolumn(icol,:);
268%     end
269%     Ycolumn=Ycolumn_cell;
270% end
271% Zcolumn={};%default
272% z_new={};
273% if isequal(get(handles.ZObject,'Visible'),'on')
274%     %data.NbDim=3; %test 3D object
275%     Zcolumn=get(handles.ZObject,'String');
276%     if ischar(Zcolumn)
277%         Zcolumn={Zcolumn};
278%     end
279% end
280% x_new{1}=Xcolumn{1};
281% y_new{1}=Ycolumn{1};
282% x_new{1}=Coord(1,1);
283% y_new{1}=Coord(1,2);
284% z_new{1}=Coord(1,3);
285% if ~isempty(Zcolumn)
286%     z_new{1}=Zcolumn{1};
287% end
288% if isequal(style,'line')
289%     if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse')
290%         num_RangeX_2=get(handles.num_RangeX_2,'String');
291%         num_RangeY_2=get(handles.num_RangeY_2,'String');
292%         x_new{2}=num2str(num_RangeX_2,4);
293%         y_new{2}=num2str(num_RangeY_2,4);
294%         set(handles.XObject,'String',x_new)
295%         set(handles.YObject,'String',y_new)
296%         set(handles.ZObject,'String',z_new)
297%     end
298% elseif isequal(style,'polyline')
299% elseif strcmp(style,'rectangle')|| strcmp(style,'ellipse')
300%      set(handles.XObject,'String',x_new)
301%      set(handles.YObject,'String',y_new)
302%      set(handles.ZObject,'String',z_new)
303% end
304
305%% set the number of lines in the Coord table depending on object type
306switch Type
307    case{'line'}
308        if size(Coord,1)<2
309            if isequal(size(Coord,2),3)
310                Coord=[Coord; 0 0 0];%add a line for edition (3D case)
311            else
312                Coord=[Coord; 0 0]; %add a line for edition (2D case)
313            end
314        else
315            Coord=Coord(1:2,:);
316        end
317    case{'rectangle','ellipse','plane','volume'}
318        Coord=Coord(1,:);
319end
320set(handles.Coord,'Data',Coord)
321
322%% set the projection menu and the corresponding options
323switch Type
324    case {'points','line','polyline','plane'}
325        menu_proj={'projection';'interp';'filter';'none'};
326    case {'polygon','rectangle','ellipse'}
327        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
328    case 'volume'
329        menu_proj={'interp';'none'};
330    otherwise
331        menu_proj={'projection';'interp';'filter';'none'};%default
332end   
333proj_index=get(handles.ProjMode,'Value');
334if proj_index<numel(menu_proj)
335    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
336end
337set(handles.ProjMode,'String',menu_proj)
338ProjMode_Callback(hObject, eventdata, handles)
339
340%store the current option
341% str=get(handles.Type,'String');
342% val=get(handles.Type,'Value');
343% set(handles.Type,'UserData',style)
344
345%------------------------------------------------------------------------
346function xObject_Callback(hObject, eventdata, handles)
347
348%------------------------------------------------------------------------
349function yObject_Callback(hObject, eventdata, handles)
350
351%------------------------------------------------------------------------
352% --- Executes on selection change in zObject.
353function zObject_Callback(hObject, eventdata, handles)
354%------------------------------------------------------------------------
355
356%------------------------------------------------------------------------
357% --- Executes on selection change in ProjMode.
358function ProjMode_Callback(hObject, eventdata, handles)
359menu=get(handles.ProjMode,'String');
360value=get(handles.ProjMode,'Value');
361ProjMode=menu{value};
362menu=get(handles.Type,'String');
363value=get(handles.Type,'Value');
364ObjectStyle=menu{value};
365%%%%%%%%% TODO
366test3D=0; %TODO: update  test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
367%%%%%%%%%
368%default setting
369set(handles.num_Angle_1,'Visible','off')
370set(handles.num_Angle_2,'Visible','off')
371set(handles.num_Angle_3,'Visible','off')
372set(handles.num_RangeX_1,'Visible','off')
373set(handles.num_RangeX_2,'Visible','off')
374set(handles.num_RangeY_1,'Visible','off')
375if isequal(ProjMode,'interp')
376    set(handles.num_RangeY_2,'Visible','off')
377else
378    set(handles.num_RangeY_2,'Visible','on')
379end
380if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
381    set(handles.num_RangeX_2,'Visible','on')
382else
383   set(handles.num_RangeX_2,'Visible','off')
384end
385set(handles.num_RangeZ_1,'Visible','off')
386set(handles.num_RangeZ_2,'Visible','off')
387set(handles.num_DX,'Visible','off')
388set(handles.num_DY,'Visible','off')
389set(handles.num_DZ,'Visible','off')
390
391switch ObjectStyle
392    case 'points'
393        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around each point')
394%         set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
395%         set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
396%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
397    case {'line','polyline','polygon'}
398        set(handles.num_RangeY_2,'TooltipString','num_YMax: range of projection around the line')
399         set(handles.Coord,'TooltipString','Coord: table of x,y, z coordinates defining the line')
400%         set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
401%         set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
402        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
403            set(handles.num_DX,'Visible','on')
404            set(handles.num_DX,'TooltipString','num_DX: mesh for the interpolated field along the line')
405        end       
406    case {'rectangle','ellipse'}
407        set(handles.num_RangeX_2,'TooltipString',['num_XMax: half length of the ' ObjectStyle])
408        set(handles.num_RangeY_2,'TooltipString',['num_YMax: half width of the ' ObjectStyle])
409%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' Type ' centre'])
410%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' Type ' centre'])
411    case {'plane'} 
412        set(handles.num_Angle_3,'Visible','on')
413        set(handles.num_RangeX_1,'Visible','on')
414        set(handles.num_RangeX_2,'Visible','on')
415        set(handles.num_RangeY_1,'Visible','on')
416        set(handles.num_RangeY_2,'Visible','on')
417%         set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' Type])
418%         set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' Type])
419        set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane')
420        if test3D
421            set(handles.num_Angle_2,'Visible','on')
422            set(handles.num_Angle_1,'Visible','on')
423            set(handles.num_RangeZ_2,'Visible','on')
424        end
425        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
426            set(handles.num_DX,'Visible','on')
427            set(handles.num_DY,'Visible','on')
428        else
429            set(handles.num_DX,'Visible','off')
430            set(handles.num_DY,'Visible','off')
431        end
432        if  isequal(ProjMode,'interp')
433            set(handles.num_DZ,'Visible','on') 
434        end
435     case {'volume'} 
436        set(handles.num_RangeX_1,'Visible','on')
437        set(handles.num_RangeX_2,'Visible','on')
438        set(handles.num_RangeY_1,'Visible','on')
439        set(handles.num_RangeY_2,'Visible','on')
440        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
441        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
442        set(handles.num_Angle_1,'Visible','on')
443        set(handles.num_Angle_2,'Visible','on')
444        set(handles.num_Angle_3,'Visible','on')
445        set(handles.num_RangeZ_1,'Visible','on')
446        set(handles.num_RangeZ_2,'Visible','on')
447        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
448            set(handles.num_DX,'Visible','on')
449            set(handles.num_DY,'Visible','on')
450            set(handles.num_DZ,'Visible','on')
451        else
452            set(handles.num_DX,'Visible','off')
453            set(handles.num_DY,'Visible','off')
454            set(handles.num_DZ,'Visible','off')
455        end
456end
457%------------------------------------------------------------------------
458
459%------------------------------------------------------------------------
460function num_Angle_1_Callback(hObject, eventdata, handles)
461update_slider(hObject, eventdata,handles)
462%------------------------------------------------------------------------
463%------------------------------------------------------------------------
464function num_Angle_2_Callback(hObject, eventdata, handles)
465update_slider(hObject, eventdata,handles)
466%------------------------------------------------------------------------
467function update_slider(hObject, eventdata,handles)
468%rotation angles
469PlaneAngle(1)=str2num(get(handles.num_Angle_1,'String'));%first  angle in degrees
470PlaneAngle(2)=str2num(get(handles.num_Angle_2,'String'));%second  angle in degrees
471PlaneAngle(3)=str2num(get(handles.num_Angle_3,'String'));%second  angle in degrees
472om=norm(PlaneAngle);%norm of rotation angle in radians
473OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
474cos_om=cos(pi*om/180);
475sin_om=sin(pi*om/180);
476coeff=OmAxis(3)*(1-cos_om);
477%components of the unity vector norm_plane normal to the projection plane
478norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
479norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
480norm_plane(3)=OmAxis(3)*coeff+cos_om;
481huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
482UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
483if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
484    Z=norm_plane(1)*(UvData.X)+norm_plane(2)*(UvData.Y)+norm_plane(3)*(UvData.Z);
485    set(handles.z_slider,'Min',min(Z))
486    set(handles.z_slider,'Max',max(Z))
487    ZMax_Callback(hObject, eventdata, handles)
488end
489%------------------------------------------------------------------------
490function num_DX_Callback(hObject, eventdata, handles)
491%------------------------------------------------------------------------
492%------------------------------------------------------------------------
493function num_DY_Callback(hObject, eventdata, handles)
494%------------------------------------------------------------------------
495%------------------------------------------------------------------------
496function num_DZ_Callback(hObject, eventdata, handles)
497%------------------------------------------------------------------------
498
499%------------------------------------------------------------------------
500%------------------------------------------------------------------------
501%----------------------------------------------------
502% executed when closing: set the parent interface button to value 0
503function closefcn(gcbo,eventdata,parent_button)
504huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
505if ~isempty(huvmat)
506    hhuvmat=guidata(huvmat);
507    set(hhuvmat.edit,'Value',0)
508    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
509end
510hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
511if ~isempty(hseries)
512    hhseries=guidata(hseries);
513    set(hhseries.GetObject,'Value',0)
514    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
515end
516
517%------------------------------------------------------------------------
518% --- Executes on button press in PLOT: PLOT the defined object and its projected field
519function PLOT_Callback(hObject, eventdata, handles)
520
521%% reading the object parameters on the GUI uvmat
522huvmat=findobj('tag','uvmat');%find the current uvmat interface handle
523UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat
524hhuvmat=guidata(huvmat);%handles in the uvmat GUI
525ListObject=get(hhuvmat.ListObject,'String');%position in the objet list
526IndexObj=get(hhuvmat.ListObject,'Value');
527
528%% read the object on the GUI set_object
529%ObjectData=read_set_object(handles.set_object);%read the input parameters defining the object in the GUI set_object
530ObjectData=read_GUI(handles.set_object);%read the input parameters defining the object in the GUI set_object
531%ObjectData.Coord=cell2mat(ObjectData.Coord);
532ObjectName=ObjectData.Name;%name of the current object defiend in set_object
533if isempty(ObjectName)
534    if get(hhuvmat.edit_object,'Value')% edit mode
535        ObjectName=ListObject{IndexObj(end)};%take the name of the last (second) selected item
536    else %new object
537        StyleList=get(handles.Type,'String');
538        StyleVal=get(handles.Type,'Value');
539        ObjectName=StyleList{StyleVal};
540    end
541end
542if ~get(hhuvmat.edit_object,'Value') %new object is being created
543    detectname=1;
544    ObjectNameNew=ObjectName;
545    vers=0;
546    while detectname==1
547        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
548        if detectname% if the object name already exists
549            indstr=regexp(ObjectNameNew,'\D');
550            if indstr(end)<length(ObjectNameNew) %object name ends by a number
551                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
552                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
553            else
554                vers=vers+1;
555                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
556            end
557        end
558    end
559    ObjectName=ObjectNameNew;
560    set(handles.Name,'String',ObjectName)% display the default name in set_object
561    IndexObj(2)=numel(ListObject)+1;% append an object to the list in uvmat
562    set(hhuvmat.ListObject,'String',[ListObject;{ObjectName}]);%complement the object list
563    set(hhuvmat.ListObject,'Value',IndexObj)
564    UvData.Object{IndexObj(2)}=[];%initiate a new object (empty yet)
565end
566testnew=0;
567if numel(IndexObj)==1   % if only one object is selected, the projection is in uvmat
568 %       PlotHandles=hhuvmat;
569    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
570else  % if a second object is selected, the projection is in view_field, and this second object is selected
571    hview_field=findobj(allchild(0),'tag','view_field');
572    if isempty(hview_field)
573        hview_field=view_field;
574    end
575    PlotHandles=guidata(hview_field);
576    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
577end
578
579%% naming the object
580ListObject{IndexObj(end),1}=ObjectName;
581set(hhuvmat.ListObject,'String',ListObject)
582
583%% update the object plot and projection field
584if testnew
585    set(hhuvmat.ListObject,'Value',IndexObj)
586    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
587    ObjectData.DisplayHandle_view_field=[];
588else
589    if IndexObj(end)<=length(UvData.Object) && isfield(UvData.Object{IndexObj(end)},'DisplayHandle_uvmat')% save the previous object graph handles
590        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj(end)}.DisplayHandle_uvmat;
591    else
592        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
593    end
594    if isfield(UvData.Object{IndexObj(end)},'DisplayHandle_view_field')% save the previous object graph handles
595        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj(end)}.DisplayHandle_view_field;
596    else
597        ObjectData.DisplayHandle_view_field=[];
598    end
599end
600UvData.Object{IndexObj(end)}=ObjectData;%update the current object properties
601if numel(IndexObj)==2
602    UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
603end
604set(huvmat,'UserData',UvData)
605
606%% plot the field projected on the object and store in the corresponding figue
607[ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
608if ~isempty(errormsg)
609    msgbox_uvmat('ERROR', errormsg)
610    return
611end
612fighandle=get(plotaxes,'parent');
613PlotParam=read_GUI(fighandle);
614[PlotType,Object_out{IndexObj(end)}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
615
616%% update the GUI uvmat
617hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
618set(hhuvmat.MenuEditObject,'enable','on')
619set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
620set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
621
622%------------------------------------------------------------------------
623% --- Executes on button press in MenuCoord.
624function MenuCoord_Callback(hObject, eventdata, handles)
625%------------------------------------------------------------------------
626%----------------------------------------------------
627function num_RangeY_1_Callback(hObject, eventdata, handles)
628%------------------------------------------------------------------------
629
630function num_RangeZ_1_Callback(hObject, eventdata, handles)
631%------------------------------------------------------------------------
632
633function num_RangeZ_2_Callback(hObject, eventdata, handles)
634DZ=str2num(get(handles.num_RangeZ_2,'String'));
635ZMin=get(handles.z_slider,'Min');
636ZMax=get(handles.z_slider,'Max');
637if ~isequal(ZMax-ZMin,0)
638    rel_step(1)=DZ/(ZMax-ZMin);
639    rel_step(2)=0.2;
640    set(handles.z_slider,'SliderStep',rel_step)
641end
642%------------------------------------------------------------------------
643function num_RangeY_2_Callback(hObject, eventdata, handles)
644%------------------------------------------------------------------------
645
646function num_RangeX_1_Callback(hObject, eventdata, handles)
647%------------------------------------------------------------------------
648
649function num_RangeX_2_Callback(hObject, eventdata, handles)
650%------------------------------------------------------------------------
651%------------------------------------------------------------------------
652function SAVE_Callback(hObject, eventdata, handles)
653% ------------------------------------------------------
654%Object=read_set_object(handles);
655Object=read_GUI(handles.set_object);
656huvmat=findobj('Tag','uvmat');
657% UvData=get(huvmat,'UserData');
658if isempty(huvmat)
659    huvmat=findobj(allchild(0),'Name','series');
660end
661hchild=get(huvmat,'Children');
662hrootpath=findobj(hchild,'Tag','RootPath');
663if isempty(hrootpath)
664    RootPath='';
665else
666    RootPath=get(hrootpath,'String');
667    if iscell(RootPath)
668        RootPath=RootPath{1};
669    end
670end
671title={'object name'};
672dir_save=uigetdir(RootPath);
673ObjectName=get(handles.Name,'String');
674if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
675    def={fullfile(dir_save,[ObjectName '.xml'])};
676else
677    def={fullfile(dir_save,[Object.Style '.xml'])};
678end
679displ_txt='save object as an .xml file';%default display
680menu=get(handles.ProjMode,'String');
681value=get(handles.ProjMode,'Value');
682ProjMode=menu{value};
683if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
684    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
685end
686answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
687if ~isempty(answer)
688    t=struct2xml(Object);
689    save(t,answer{1})
690end
691msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
692
693%------------------------------------------------------------------------
694% --- Executes on slider movement.
695function z_slider_Callback(hObject, eventdata, handles)
696%---------------------------------------------------------
697Z_value=get(handles.z_slider,'Value');
698%rotation angles
699PlaneAngle=[0 0 0];
700norm_plane=[0 0 1];
701cos_om=1;
702sin_om=0;
703
704PlaneAngle(1)=str2double(get(handles.num_Angle_1,'String'));%first  angle in degrees
705PlaneAngle(2)=str2double(get(handles.num_Angle_2,'String'));%second  angle in degrees
706PlaneAngle(3)=str2double(get(handles.num_Angle_3,'String'));%second  angle in degrees
707PlaneAngle=(pi/180)*PlaneAngle;
708om=norm(PlaneAngle);%norm of rotation angle in radians
709if isequal(om,0)
710    norm_plane=[0 0 1];
711else
712    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
713    cos_om=cos(om);
714    sin_om=sin(om);
715    coeff=OmAxis(3)*(1-cos_om);
716    %components of the unity vector norm_plane normal to the projection plane
717    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
718    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
719    norm_plane(3)=OmAxis(3)*coeff+cos_om;
720end
721
722%set new plane position and update graph
723% set(handles.XObject,'String',num2str(norm_plane(1)*Z_value,4))
724% set(handles.YObject,'String',num2str(norm_plane(2)*Z_value,4))
725% set(handles.ZObject,'String',num2str(norm_plane(3)*Z_value,4))
726PLOT_Callback(hObject, eventdata, handles)
727
728%------------------------------------------------------------------------
729% --- Executes on button press in HELP.
730function HELP_Callback(hObject, eventdata, handles)
731%------------------------------------------------------------------------
732path_to_uvmat=which ('uvmat');% check the path of uvmat
733pathelp=fileparts(path_to_uvmat);
734helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
735if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
736else
737    addpath (fullfile(pathelp,'uvmat_doc'))
738    web([helpfile '#set_object'])
739end
740%------------------------------------------------------------------------
741
742function Name_Callback(hObject, eventdata, handles)
743% hObject    handle to Name (see GCBO)
744% eventdata  reserved - to be defined in a future version of MATLAB
745% handles    structure with handles and user data (see GUIDATA)
746
747% Hints: get(hObject,'String') returns contents of Name as text
748%        str2double(get(hObject,'String')) returns contents of Name as a double
749
750%------------------------------------------------------------------------
751% --- Executes when entered data in editable cell(s) in Coord.
752function Coord_CellEditCallback(hObject, eventdata, handles)
753%------------------------------------------------------------------------
754ListType=get(handles.Type,'String');
755Type=ListType{get(handles.Type,'Value')};
756switch Type
757    % add lines if multi line input needed
758    case{'points','polyline','polygon'}
759        Coord=get(handles.Coord,'Data');
760        if isequal(size(Coord,2),3)
761            Coord=[Coord;{[]} {[]} {[]}];%add a line for edition (3D case)
762        else
763            Coord=[Coord;{[]} {[]}]; %add a line for edition (2D case)
764        end
765        set(handles.Coord,'Data',Coord)
766end
767
768
769
770function num_Angle_3_Callback(hObject, eventdata, handles)
771% hObject    handle to num_Angle_3 (see GCBO)
772% eventdata  reserved - to be defined in a future version of MATLAB
773% handles    structure with handles and user data (see GUIDATA)
774
775% Hints: get(hObject,'String') returns contents of num_Angle_3 as text
776%        str2double(get(hObject,'String')) returns contents of num_Angle_3 as a double
Note: See TracBrowser for help on using the repository browser.