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 | function varargout = create_grid(varargin)
|
---|
13 |
|
---|
14 | % Last Modified by GUIDE v2.5 16-Dec-2010 00:17:20
|
---|
15 |
|
---|
16 | % Begin initialization code - DO NOT EDIT
|
---|
17 | gui_Singleton = 1;
|
---|
18 | gui_State = struct('gui_Name', mfilename, ...
|
---|
19 | 'gui_Singleton', gui_Singleton, ...
|
---|
20 | 'gui_OpeningFcn', @create_grid_OpeningFcn, ...
|
---|
21 | 'gui_OutputFcn', @create_grid_OutputFcn, ...
|
---|
22 | 'gui_LayoutFcn', [] , ...
|
---|
23 | 'gui_Callback', []);
|
---|
24 | if nargin && ischar(varargin{1})
|
---|
25 | gui_State.gui_Callback = str2func(varargin{1});
|
---|
26 | end
|
---|
27 |
|
---|
28 | if nargout
|
---|
29 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
---|
30 | else
|
---|
31 | gui_mainfcn(gui_State, varargin{:});
|
---|
32 | end
|
---|
33 | % End initialization code - DO NOT EDIT
|
---|
34 |
|
---|
35 | %------------------------------------------------------------------------
|
---|
36 | % --- Executes just before create_grid is made visible.
|
---|
37 | function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid,name)
|
---|
38 | %------------------------------------------------------------------------
|
---|
39 | % This function has no output args, see OutputFcn.
|
---|
40 |
|
---|
41 | % Choose default command line output for create_grid
|
---|
42 | handles.output = 'Cancel';
|
---|
43 |
|
---|
44 | if exist('name','var') && ischar(name)
|
---|
45 | set(hObject,'name',name)
|
---|
46 | if strcmp(name,'detect_grid')
|
---|
47 | set(handles.white,'Visible','on')
|
---|
48 | set(handles.black,'Visible','on')
|
---|
49 | end
|
---|
50 | end
|
---|
51 | % Update handles structure
|
---|
52 | guidata(hObject, handles);
|
---|
53 | testNo=0;
|
---|
54 | testCancel=1;
|
---|
55 | testinputstring=0;
|
---|
56 | icontype='quest';%default question icon (text input asked)
|
---|
57 |
|
---|
58 | % Determine the position of the dialog - centered on the screen
|
---|
59 | FigPos=get(0,'DefaultFigurePosition');
|
---|
60 | OldUnits = get(hObject, 'Units');
|
---|
61 | set(hObject, 'Units', 'pixels');
|
---|
62 | OldPos = get(hObject,'Position');
|
---|
63 | FigWidth = OldPos(3);
|
---|
64 | FigHeight = OldPos(4);
|
---|
65 | ScreenUnits=get(0,'Units');
|
---|
66 | set(0,'Units','pixels');
|
---|
67 | ScreenSize=get(0,'ScreenSize');
|
---|
68 | set(0,'Units',ScreenUnits);
|
---|
69 |
|
---|
70 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
|
---|
71 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
|
---|
72 | FigPos(3:4)=[FigWidth FigHeight];
|
---|
73 | set(hObject, 'Position', FigPos);
|
---|
74 | set(hObject, 'Units', OldUnits);
|
---|
75 |
|
---|
76 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
77 | load dialogicons.mat
|
---|
78 | eval(['IconData=' icontype 'IconData;'])
|
---|
79 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
80 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
81 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
82 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
83 | set(handles.axes1, ...
|
---|
84 | 'Visible', 'off', ...
|
---|
85 | 'YDir' , 'reverse' , ...
|
---|
86 | 'XLim' , get(Img,'XData'), ...
|
---|
87 | 'YLim' , get(Img,'YData') ...
|
---|
88 | );
|
---|
89 |
|
---|
90 | if exist('input_grid','var') && ~isempty(input_grid)
|
---|
91 | if isfield(input_grid,'x_0')
|
---|
92 | set(handles.x_0,'String',num2str(input_grid.x_0));
|
---|
93 | end
|
---|
94 | if isfield(input_grid,'x_1')
|
---|
95 | set(handles.x_1,'String',num2str(input_grid.x_1));
|
---|
96 | end
|
---|
97 | if isfield(input_grid,'Dx')
|
---|
98 | set(handles.Dx,'String',num2str(input_grid.Dx));
|
---|
99 | end
|
---|
100 | if isfield(input_grid,'y_0')
|
---|
101 | set(handles.y_0,'String',num2str(input_grid.y_0));
|
---|
102 | end
|
---|
103 | if isfield(input_grid,'y_1')
|
---|
104 | set(handles.y_1,'String',num2str(input_grid.y_1));
|
---|
105 | end
|
---|
106 | if isfield(input_grid,'Dy')
|
---|
107 | set(handles.Dy,'String',num2str(input_grid.Dy));
|
---|
108 | end
|
---|
109 | if isfield(input_grid,'z')
|
---|
110 | set(handles.z,'String',num2str(input_grid.z));
|
---|
111 | end
|
---|
112 | end
|
---|
113 |
|
---|
114 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
115 | % UIWAIT makes create_grid wait for user response (see UIRESUME)
|
---|
116 | uiwait(handles.figure1);
|
---|
117 |
|
---|
118 | %------------------------------------------------------------------------
|
---|
119 | % --- Outputs from this function are returned to the command line.
|
---|
120 | function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
|
---|
121 | %------------------------------------------------------------------------
|
---|
122 | % Get default command line output from handles structure
|
---|
123 | varargout{1}=[0 0 0];%default
|
---|
124 | if ~isequal(handles.output,'Cancel')
|
---|
125 | T.x_0=str2num(get(handles.x_0,'String'));
|
---|
126 | T.Dx=str2num(get(handles.Dx,'String'));
|
---|
127 | T.x_1=str2num(get(handles.x_1,'String'));
|
---|
128 | xarray=[T.x_0:T.Dx:T.x_1];
|
---|
129 | T.y_0=str2num(get(handles.y_0,'String'));
|
---|
130 | T.Dy=str2num(get(handles.Dy,'String'));
|
---|
131 | T.y_1=str2num(get(handles.y_1,'String'));
|
---|
132 | yarray=[T.y_0:T.Dy:T.y_1];
|
---|
133 | [yarray,xarray]=meshgrid(yarray,xarray);
|
---|
134 | xarray=reshape(xarray,numel(xarray),1);
|
---|
135 | yarray=reshape(yarray,numel(yarray),1);
|
---|
136 | T.z_0=str2num(get(handles.z_0,'String'));
|
---|
137 | if isempty(T.z_0)
|
---|
138 | T.z_0=0;
|
---|
139 | end
|
---|
140 | zarray=T.z_0*ones(size(yarray));
|
---|
141 | varargout{1}=[xarray yarray zarray];
|
---|
142 | varargout{2}=T;
|
---|
143 | varargout{3}=get(handles.white,'Value')
|
---|
144 | end
|
---|
145 |
|
---|
146 | % The figure can be deleted now
|
---|
147 | delete(handles.figure1);
|
---|
148 |
|
---|
149 | %------------------------------------------------------------------------
|
---|
150 | % --- Executes on button press in OK.
|
---|
151 | function OK_Callback(hObject, eventdata, handles)
|
---|
152 | %------------------------------------------------------------------------
|
---|
153 | handles.output = get(hObject,'String');
|
---|
154 | guidata(hObject, handles);% Update handles structure
|
---|
155 | uiresume(handles.figure1);
|
---|
156 |
|
---|
157 | %------------------------------------------------------------------------
|
---|
158 | % --- Executes on button press in Cancel.
|
---|
159 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
160 | %------------------------------------------------------------------------
|
---|
161 | handles.output = get(hObject,'String');
|
---|
162 | guidata(hObject, handles); % Update handles structure
|
---|
163 | uiresume(handles.figure1);
|
---|
164 |
|
---|
165 | %------------------------------------------------------------------------
|
---|
166 | % --- Executes when user attempts to close figure1.
|
---|
167 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
168 | %------------------------------------------------------------------------
|
---|
169 | if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
170 | % The GUI is still in UIWAIT, us UIRESUME
|
---|
171 | uiresume(handles.figure1);
|
---|
172 | else
|
---|
173 | % The GUI is no longer waiting, just close it
|
---|
174 | delete(handles.figure1);
|
---|
175 | end
|
---|
176 |
|
---|
177 | %------------------------------------------------------------------------
|
---|
178 | % --- Executes on key press over figure1 with no controls selected.
|
---|
179 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
180 | %------------------------------------------------------------------------
|
---|
181 | % Check for "enter" or "escape"
|
---|
182 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
183 | % User said no by hitting escape
|
---|
184 | handles.output = 'Cancel';
|
---|
185 |
|
---|
186 | % Update handles structure
|
---|
187 | guidata(hObject, handles);
|
---|
188 |
|
---|
189 | uiresume(handles.figure1);
|
---|
190 | end
|
---|
191 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
192 | uiresume(handles.figure1);
|
---|
193 | end
|
---|
194 |
|
---|
195 |
|
---|
196 | % --- Executes on button press in white.
|
---|
197 | function white_Callback(hObject, eventdata, handles)
|
---|
198 | val=get(handles.white,'Value');
|
---|
199 | if val
|
---|
200 | set(handles.black,'Value',0)
|
---|
201 | else
|
---|
202 | set(handles.black,'Value',1)
|
---|
203 | end
|
---|
204 | % hObject handle to white (see GCBO)
|
---|
205 | % eventdata reserved - to be defined in a future version of MATLAB
|
---|
206 | % handles structure with handles and user data (see GUIDATA)
|
---|
207 |
|
---|
208 | % Hint: get(hObject,'Value') returns toggle state of white
|
---|
209 |
|
---|
210 |
|
---|
211 | % --- Executes on button press in black.
|
---|
212 | function black_Callback(hObject, eventdata, handles)
|
---|
213 | val=get(handles.black,'Value');
|
---|
214 | if val
|
---|
215 | set(handles.white,'Value',0)
|
---|
216 | else
|
---|
217 | set(handles.white,'Value',1)
|
---|
218 | end
|
---|
219 |
|
---|