1 | % By Philip Torr 2002 |
---|
2 | % copyright Microsoft Corp. |
---|
3 | |
---|
4 | function cal_param_out = c_menu(varargin) |
---|
5 | % C_MENU Application M-file for c_menu.fig |
---|
6 | % FIG = C_MENU launch c_menu GUI. |
---|
7 | % C_MENU('callback_name', ...) invoke the named callback. |
---|
8 | |
---|
9 | % Last Modified by GUIDE v2.0 16-May-2002 14:35:35 |
---|
10 | error(nargchk(0,4,nargin)) % function takes only 0 or 2 argument |
---|
11 | if nargin == 2 % LAUNCH GUI |
---|
12 | |
---|
13 | |
---|
14 | fig = openfig(mfilename,'reuse'); |
---|
15 | |
---|
16 | % Generate a structure of handles to pass to callbacks, and store it. |
---|
17 | handles = guihandles(fig); |
---|
18 | |
---|
19 | |
---|
20 | cal_param = varargin{1}; |
---|
21 | handles.focal_length = cal_param.focal_length; |
---|
22 | handles.aspect_ratio = cal_param.aspect_ratio; |
---|
23 | handles.ppx = cal_param.ppx; |
---|
24 | handles.ppy = cal_param.ppy; |
---|
25 | handles.m3 = cal_param.m3; |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | foc_string = strcat(num2str(handles.focal_length),', in pixels:',num2str(handles.focal_length * handles.m3)) |
---|
30 | set(handles.foc_button, 'String', foc_string); |
---|
31 | set(handles.ar_button, 'String', num2str(handles.aspect_ratio)); |
---|
32 | set(handles.ppx_button, 'String', num2str(handles.ppx)); |
---|
33 | set(handles.ppy_button, 'String', num2str(handles.ppy)); |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | guidata(fig, handles); |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | % Wait for callbacks to run and window to be dismissed: |
---|
44 | uiwait(fig); |
---|
45 | |
---|
46 | |
---|
47 | % UIWAIT might have returned because the window was deleted using |
---|
48 | % the close box - in that case, return 'cancel' as the answer, and |
---|
49 | % don't bother deleting the window! |
---|
50 | if ~ishandle(fig) |
---|
51 | disp('No changes made'); |
---|
52 | cal_param_out(1) = handles.focal_length; |
---|
53 | cal_param_out(2) = handles.aspect_ratio; |
---|
54 | cal_param_out(3) = handles.ppx; |
---|
55 | cal_param_out(4) = handles.ppy; |
---|
56 | else |
---|
57 | % otherwise, we got here because the user pushed one of the two buttons. |
---|
58 | % retrieve the latest copy of the 'handles' struct, and return the answer. |
---|
59 | % Also, we need to delete the window. |
---|
60 | |
---|
61 | handles = guidata(fig); |
---|
62 | cal_param_out(1) = handles.focal_length; |
---|
63 | cal_param_out(2) = handles.aspect_ratio; |
---|
64 | cal_param_out(3) = handles.ppx; |
---|
65 | cal_param_out(4) = handles.ppy; |
---|
66 | delete(fig); |
---|
67 | end |
---|
68 | |
---|
69 | |
---|
70 | elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK |
---|
71 | |
---|
72 | try |
---|
73 | [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard |
---|
74 | catch |
---|
75 | disp(lasterr); |
---|
76 | end |
---|
77 | |
---|
78 | end |
---|
79 | |
---|
80 | |
---|
81 | %| ABOUT CALLBACKS: |
---|
82 | %| GUIDE automatically appends subfunction prototypes to this file, and |
---|
83 | %| sets objects' callback properties to call them through the FEVAL |
---|
84 | %| switchyard above. This comment describes that mechanism. |
---|
85 | %| |
---|
86 | %| Each callback subfunction declaration has the following form: |
---|
87 | %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) |
---|
88 | %| |
---|
89 | %| The subfunction name is composed using the object's Tag and the |
---|
90 | %| callback type separated by '_', e.g. 'slider2_Callback', |
---|
91 | %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. |
---|
92 | %| |
---|
93 | %| H is the callback object's handle (obtained using GCBO). |
---|
94 | %| |
---|
95 | %| EVENTDATA is empty, but reserved for future use. |
---|
96 | %| |
---|
97 | %| HANDLES is a structure containing handles of components in GUI using |
---|
98 | %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This |
---|
99 | %| structure is created at GUI startup using GUIHANDLES and stored in |
---|
100 | %| the figure's application data using GUIDATA. A copy of the structure |
---|
101 | %| is passed to each callback. You can store additional information in |
---|
102 | %| this structure at GUI startup, and you can change the structure |
---|
103 | %| during callbacks. Call guidata(h, handles) after changing your |
---|
104 | %| copy to replace the stored original so that subsequent callbacks see |
---|
105 | %| the updates. Type "help guihandles" and "help guidata" for more |
---|
106 | %| information. |
---|
107 | %| |
---|
108 | %| VARARGIN contains any extra arguments you have passed to the |
---|
109 | %| callback. Specify the extra arguments by editing the callback |
---|
110 | %| property in the inspector. By default, GUIDE sets the property to: |
---|
111 | %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) |
---|
112 | %| Add any extra arguments after the last argument, before the final |
---|
113 | %| closing parenthesis. |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | % -------------------------------------------------------------------- |
---|
118 | function varargout = close_button_Callback(h, eventdata, handles, varargin) |
---|
119 | % Stub for Callback of the uicontrol handles.close_button. |
---|
120 | %Stub for Callback of the uicontrol handles.close_button. |
---|
121 | % |
---|
122 | % Obtaining the Figure Handle from Within a Callback. In general, dismissing a modal figure requires the handle |
---|
123 | % of the figure. Since most GUIs hide figure handles to prevent accidental access, the gcbf (get callback figure) |
---|
124 | % command provides the most effective method to get the figure handle from within a callback routine. |
---|
125 | % |
---|
126 | % gcbf returns the handle of the figure containing the object whose callback is executing. This enables you to use |
---|
127 | % gcbf in the callback of the component that will dismiss the dialog. For example, suppose your dialog includes a |
---|
128 | % push button (tagged pushbutton1) that closes the dialog. Its callback could include a call to delete at the end of |
---|
129 | % its callback subfunction. |
---|
130 | |
---|
131 | disp('closing'); |
---|
132 | % cal_param_out.max_disparity = handles.max_disparity; |
---|
133 | % cal_param_out.corner_sigma = handles.corner_sigma; |
---|
134 | % cal_param_out.match_half_size = handles.match_half_size; |
---|
135 | |
---|
136 | uiresume(handles.figure1); |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | % -------------------------------------------------------------------- |
---|
141 | function varargout = foc_button_Callback(h, eventdata, handles, varargin) |
---|
142 | |
---|
143 | nc = str2num(get(handles.foc_button, 'String')); |
---|
144 | |
---|
145 | minnc = 1; |
---|
146 | maxnc = 1000000; |
---|
147 | if (isempty(nc) | (nc < minnc) | (nc >maxnc)) |
---|
148 | nc = handles.focal_length; |
---|
149 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
150 | end; |
---|
151 | |
---|
152 | handles.focal_length = nc; |
---|
153 | foc_string = strcat(num2str(handles.focal_length),', in pixels:',num2str(handles.focal_length * handles.m3)) |
---|
154 | set(handles.foc_button, 'String', foc_string); |
---|
155 | |
---|
156 | %save data |
---|
157 | guidata(handles.figure1, handles); |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | % -------------------------------------------------------------------- |
---|
162 | function varargout = ar_button_Callback(h, eventdata, handles, varargin) |
---|
163 | |
---|
164 | |
---|
165 | nc = str2num(get(handles.ar_button, 'String')); |
---|
166 | |
---|
167 | minnc = 0; |
---|
168 | maxnc = 1000000; |
---|
169 | if (isempty(nc) | (nc < minnc) | (nc >maxnc)) |
---|
170 | nc = handles.aspect_ratio; |
---|
171 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
172 | end; |
---|
173 | |
---|
174 | handles.aspect_ratio = nc; |
---|
175 | set(handles.ar_button, 'String', num2str(handles.aspect_ratio)); |
---|
176 | |
---|
177 | %save data |
---|
178 | guidata(handles.figure1, handles); |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | % -------------------------------------------------------------------- |
---|
183 | function varargout = ppx_button_Callback(h, eventdata, handles, varargin) |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | nc = str2num(get(handles.ppx_button, 'String')); |
---|
188 | |
---|
189 | minnc = 0; |
---|
190 | maxnc = 1000000; |
---|
191 | if (isempty(nc) | (nc < minnc) | (nc >maxnc)) |
---|
192 | nc = handles.max_ppx; |
---|
193 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
194 | end; |
---|
195 | |
---|
196 | handles.ppx = nc; |
---|
197 | set(handles.ppx_button, 'String', num2str(handles.ppx)); |
---|
198 | |
---|
199 | %save data |
---|
200 | guidata(handles.figure1, handles); |
---|
201 | |
---|
202 | % -------------------------------------------------------------------- |
---|
203 | function varargout = ppy_button_Callback(h, eventdata, handles, varargin) |
---|
204 | |
---|
205 | |
---|
206 | nc = str2num(get(handles.ppy_button, 'String')); |
---|
207 | |
---|
208 | minnc = 0; |
---|
209 | maxnc = 1000000; |
---|
210 | if (isempty(nc) | (nc < minnc) | (nc >maxnc)) |
---|
211 | nc = handles.max_ppy; |
---|
212 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
213 | end; |
---|
214 | |
---|
215 | handles.ppy = nc; |
---|
216 | set(handles.ppy_button, 'String', num2str(handles.ppy)); |
---|
217 | |
---|
218 | %save data |
---|
219 | guidata(handles.figure1, handles); |
---|