1 | %'create_grid': called by the GUI geometry_calib to create a physical grid
|
---|
2 | %------------------------------------------------------------------------
|
---|
3 | % coord=create_grid(input_grid)
|
---|
4 | %
|
---|
5 | % OUTPUT:
|
---|
6 | % coord: matrix (nbpoint, 3) of coordinates for grid points, with columns x,y,z
|
---|
7 | %
|
---|
8 | % INPUT:
|
---|
9 | % input_grid (optional): structure to initiate the GUI with fields .x_0,.Dx,.x_1
|
---|
10 | % (defining x coordinates), .y_0,.Dy,.y_1 (defining y coordinates)
|
---|
11 |
|
---|
12 | %=======================================================================
|
---|
13 | % Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
14 | % http://www.legi.grenoble-inp.fr
|
---|
15 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
16 | %
|
---|
17 | % This file is part of the toolbox UVMAT.
|
---|
18 | %
|
---|
19 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
20 | % it under the terms of the GNU General Public License as published
|
---|
21 | % by the Free Software Foundation; either version 2 of the license,
|
---|
22 | % or (at your option) any later version.
|
---|
23 | %
|
---|
24 | % UVMAT is distributed in the hope that it will be useful,
|
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
27 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
28 | %=======================================================================
|
---|
29 |
|
---|
30 | function varargout = create_grid(varargin)
|
---|
31 |
|
---|
32 | % Last Modified by GUIDE v2.5 02-Feb-2017 17:09:08
|
---|
33 |
|
---|
34 | % Begin initialization code - DO NOT EDIT
|
---|
35 | gui_Singleton = 1;
|
---|
36 | gui_State = struct('gui_Name', mfilename, ...
|
---|
37 | 'gui_Singleton', gui_Singleton, ...
|
---|
38 | 'gui_OpeningFcn', @create_grid_OpeningFcn, ...
|
---|
39 | 'gui_OutputFcn', @create_grid_OutputFcn, ...
|
---|
40 | 'gui_LayoutFcn', [] , ...
|
---|
41 | 'gui_Callback', []);
|
---|
42 | if nargin && ischar(varargin{1})
|
---|
43 | gui_State.gui_Callback = str2func(varargin{1});
|
---|
44 | end
|
---|
45 |
|
---|
46 | if nargout
|
---|
47 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
---|
48 | else
|
---|
49 | gui_mainfcn(gui_State, varargin{:});
|
---|
50 | end
|
---|
51 | % End initialization code - DO NOT EDIT
|
---|
52 |
|
---|
53 | %------------------------------------------------------------------------
|
---|
54 | % --- Executes just before create_grid is made visible.
|
---|
55 | function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid,name)
|
---|
56 | %------------------------------------------------------------------------
|
---|
57 | % This function has no output args, see OutputFcn.
|
---|
58 |
|
---|
59 | % Choose default command line output for create_grid
|
---|
60 | handles.output = 'Cancel';
|
---|
61 |
|
---|
62 | if exist('name','var') && ischar(name)
|
---|
63 | set(hObject,'name',name)
|
---|
64 | if strcmp(name,'detect_grid')
|
---|
65 | set(handles.white,'Visible','on')
|
---|
66 | set(handles.black,'Visible','on')
|
---|
67 | end
|
---|
68 | end
|
---|
69 | % Update handles structure
|
---|
70 | guidata(hObject, handles);
|
---|
71 | testNo=0;
|
---|
72 | testCancel=1;
|
---|
73 | testinputstring=0;
|
---|
74 | icontype='quest';%default question icon (text input asked)
|
---|
75 |
|
---|
76 | % Determine the position of the dialog - centered on the screen
|
---|
77 | FigPos=get(0,'DefaultFigurePosition');
|
---|
78 | OldUnits = get(hObject, 'Units');
|
---|
79 | set(hObject, 'Units', 'pixels');
|
---|
80 | OldPos = get(hObject,'Position');
|
---|
81 | FigWidth = OldPos(3);
|
---|
82 | FigHeight = OldPos(4);
|
---|
83 | ScreenUnits=get(0,'Units');
|
---|
84 | set(0,'Units','pixels');
|
---|
85 | ScreenSize=get(0,'ScreenSize');
|
---|
86 | set(0,'Units',ScreenUnits);
|
---|
87 |
|
---|
88 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
|
---|
89 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
|
---|
90 | FigPos(3:4)=[FigWidth FigHeight];
|
---|
91 | set(hObject, 'Position', FigPos);
|
---|
92 | set(hObject, 'Units', OldUnits);
|
---|
93 |
|
---|
94 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
95 | load dialogicons.mat
|
---|
96 | eval(['IconData=' icontype 'IconData;'])
|
---|
97 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
98 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
99 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
100 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
101 | set(handles.axes1, ...
|
---|
102 | 'Visible', 'off', ...
|
---|
103 | 'YDir' , 'reverse' , ...
|
---|
104 | 'XLim' , get(Img,'XData'), ...
|
---|
105 | 'YLim' , get(Img,'YData') ...
|
---|
106 | );
|
---|
107 |
|
---|
108 | if exist('input_grid','var') && ~isempty(input_grid)
|
---|
109 | if isfield(input_grid,'x_0')
|
---|
110 | set(handles.x_0,'String',num2str(input_grid.x_0));
|
---|
111 | end
|
---|
112 | if isfield(input_grid,'x_1')
|
---|
113 | set(handles.x_1,'String',num2str(input_grid.x_1));
|
---|
114 | end
|
---|
115 | if isfield(input_grid,'Dx')
|
---|
116 | set(handles.Dx,'String',num2str(input_grid.Dx));
|
---|
117 | end
|
---|
118 | if isfield(input_grid,'y_0')
|
---|
119 | set(handles.y_0,'String',num2str(input_grid.y_0));
|
---|
120 | end
|
---|
121 | if isfield(input_grid,'y_1')
|
---|
122 | set(handles.y_1,'String',num2str(input_grid.y_1));
|
---|
123 | end
|
---|
124 | if isfield(input_grid,'Dy')
|
---|
125 | set(handles.Dy,'String',num2str(input_grid.Dy));
|
---|
126 | end
|
---|
127 | if isfield(input_grid,'z')
|
---|
128 | set(handles.z,'String',num2str(input_grid.z));
|
---|
129 | end
|
---|
130 | if isfield(input_grid,'CheckWhite')
|
---|
131 | if input_grid.CheckWhite
|
---|
132 | set(handles.white,'Value',1)
|
---|
133 | set(handles.black,'Value',0)
|
---|
134 | else
|
---|
135 | set(handles.white,'Value',0)
|
---|
136 | set(handles.black,'Value',1)
|
---|
137 | end
|
---|
138 | end
|
---|
139 | end
|
---|
140 |
|
---|
141 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
142 | % UIWAIT makes create_grid wait for user response (see UIRESUME)
|
---|
143 | uiwait(handles.figure1);
|
---|
144 |
|
---|
145 | %------------------------------------------------------------------------
|
---|
146 | % --- Outputs from this function are returned to the command line.
|
---|
147 | function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
|
---|
148 | %------------------------------------------------------------------------
|
---|
149 | % Get default command line output from handles structure
|
---|
150 | varargout{1}=[0 0 0];%default
|
---|
151 | if ~isequal(handles.output,'Cancel')
|
---|
152 | T.x_0=str2num(get(handles.x_0,'String'));
|
---|
153 | T.Dx=str2num(get(handles.Dx,'String'));
|
---|
154 | T.x_1=str2num(get(handles.x_1,'String'));
|
---|
155 | xarray=[T.x_0:T.Dx:T.x_1];
|
---|
156 | T.y_0=str2num(get(handles.y_0,'String'));
|
---|
157 | T.Dy=str2num(get(handles.Dy,'String'));
|
---|
158 | T.y_1=str2num(get(handles.y_1,'String'));
|
---|
159 | yarray=[T.y_0:T.Dy:T.y_1];
|
---|
160 | [yarray,xarray]=meshgrid(yarray,xarray);
|
---|
161 | xarray=reshape(xarray,numel(xarray),1);
|
---|
162 | yarray=reshape(yarray,numel(yarray),1);
|
---|
163 | T.z_0=str2num(get(handles.z_0,'String'));
|
---|
164 | if isempty(T.z_0)
|
---|
165 | T.z_0=0;
|
---|
166 | end
|
---|
167 | zarray=T.z_0*ones(size(yarray));
|
---|
168 | varargout{1}=[xarray yarray zarray];
|
---|
169 | varargout{2}=T;
|
---|
170 | varargout{3}=get(handles.white,'Value');
|
---|
171 | varargout{4}=0;
|
---|
172 | if get(handles.CheckDots,'Value')
|
---|
173 | varargout{4}=str2num(get(handles.FilterWindow,'String'));
|
---|
174 | end
|
---|
175 | end
|
---|
176 |
|
---|
177 | % The figure can be deleted now
|
---|
178 | delete(handles.figure1);
|
---|
179 |
|
---|
180 | %------------------------------------------------------------------------
|
---|
181 | % --- Executes on button press in OK.
|
---|
182 | function OK_Callback(hObject, eventdata, handles)
|
---|
183 | %------------------------------------------------------------------------
|
---|
184 | handles.output = get(hObject,'String');
|
---|
185 | guidata(hObject, handles);% Update handles structure
|
---|
186 | uiresume(handles.figure1);
|
---|
187 |
|
---|
188 | %------------------------------------------------------------------------
|
---|
189 | % --- Executes on button press in Cancel.
|
---|
190 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
191 | %------------------------------------------------------------------------
|
---|
192 | handles.output = get(hObject,'String');
|
---|
193 | guidata(hObject, handles); % Update handles structure
|
---|
194 | uiresume(handles.figure1);
|
---|
195 |
|
---|
196 | %------------------------------------------------------------------------
|
---|
197 | % --- Executes when user attempts to close figure1.
|
---|
198 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
199 | %------------------------------------------------------------------------
|
---|
200 | if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
201 | % The GUI is still in UIWAIT, us UIRESUME
|
---|
202 | uiresume(handles.figure1);
|
---|
203 | else
|
---|
204 | % The GUI is no longer waiting, just close it
|
---|
205 | delete(handles.figure1);
|
---|
206 | end
|
---|
207 |
|
---|
208 | %------------------------------------------------------------------------
|
---|
209 | % --- Executes on key press over figure1 with no controls selected.
|
---|
210 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
211 | %------------------------------------------------------------------------
|
---|
212 | % Check for "enter" or "escape"
|
---|
213 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
214 | % User said no by hitting escape
|
---|
215 | handles.output = 'Cancel';
|
---|
216 |
|
---|
217 | % Update handles structure
|
---|
218 | guidata(hObject, handles);
|
---|
219 |
|
---|
220 | uiresume(handles.figure1);
|
---|
221 | end
|
---|
222 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
223 | uiresume(handles.figure1);
|
---|
224 | end
|
---|
225 |
|
---|
226 | % --- Executes on button press in white.
|
---|
227 | function white_Callback(hObject, eventdata, handles)
|
---|
228 | val=get(handles.white,'Value');
|
---|
229 | if val
|
---|
230 | set(handles.black,'Value',0)
|
---|
231 | else
|
---|
232 | set(handles.black,'Value',1)
|
---|
233 | end
|
---|
234 |
|
---|
235 |
|
---|
236 | % --- Executes on button press in black.
|
---|
237 | function black_Callback(hObject, eventdata, handles)
|
---|
238 | val=get(handles.black,'Value');
|
---|
239 | if val
|
---|
240 | set(handles.white,'Value',0)
|
---|
241 | else
|
---|
242 | set(handles.white,'Value',1)
|
---|
243 | end
|
---|
244 |
|
---|
245 | % --- Executes on button press in CheckDots.
|
---|
246 | function CheckDots_Callback(hObject, eventdata, handles)
|
---|
247 | val=get(handles.CheckDots,'Value');
|
---|
248 | if val
|
---|
249 | set(handles.FilterWindow,'Visible','on')
|
---|
250 | set(handles.FilterWindow_txt,'Visible','on')
|
---|
251 | else
|
---|
252 | set(handles.FilterWindow,'Visible','off')
|
---|
253 | set(handles.FilterWindow_txt,'Visible','off')
|
---|
254 | end
|
---|
255 |
|
---|