source: trunk/src/create_grid.m @ 659

Last change on this file since 659 was 156, checked in by sommeria, 14 years ago

many bug repairs and corrections for mouse action
create_grid: option for black marjkers for grid detection

File size: 7.6 KB
Line 
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
12function 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
17gui_Singleton = 1;
18gui_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',   []);
24if nargin && ischar(varargin{1})
25    gui_State.gui_Callback = str2func(varargin{1});
26end
27
28if nargout
29    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
30else
31    gui_mainfcn(gui_State, varargin{:});
32end
33% End initialization code - DO NOT EDIT
34
35%------------------------------------------------------------------------
36% --- Executes just before create_grid is made visible.
37function 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
42handles.output = 'Cancel';
43
44if 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
50end
51% Update handles structure
52guidata(hObject, handles);
53testNo=0;
54testCancel=1;
55testinputstring=0;
56icontype='quest';%default question icon (text input asked)
57
58% Determine the position of the dialog - centered on the screen
59FigPos=get(0,'DefaultFigurePosition');
60OldUnits = get(hObject, 'Units');
61set(hObject, 'Units', 'pixels');
62OldPos = get(hObject,'Position');
63FigWidth = OldPos(3);
64FigHeight = OldPos(4);
65ScreenUnits=get(0,'Units');
66set(0,'Units','pixels');
67ScreenSize=get(0,'ScreenSize');
68set(0,'Units',ScreenUnits);
69
70FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
71FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
72FigPos(3:4)=[FigWidth FigHeight];
73set(hObject, 'Position', FigPos);
74set(hObject, 'Units', OldUnits);
75
76% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
77load dialogicons.mat
78eval(['IconData=' icontype 'IconData;'])
79eval(['IconCMap=' icontype 'IconMap;'])
80questIconMap(256,:) = get(handles.figure1, 'Color');
81Img=image(IconData, 'Parent', handles.axes1);
82set(handles.figure1, 'Colormap', IconCMap);
83set(handles.axes1, ...
84    'Visible', 'off', ...
85    'YDir'   , 'reverse'       , ...
86    'XLim'   , get(Img,'XData'), ...
87    'YLim'   , get(Img,'YData')  ...
88    );
89
90if 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 
112end
113
114set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
115% UIWAIT makes create_grid wait for user response (see UIRESUME)
116uiwait(handles.figure1);
117
118%------------------------------------------------------------------------
119% --- Outputs from this function are returned to the command line.
120function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
121%------------------------------------------------------------------------
122% Get default command line output from handles structure
123varargout{1}=[0 0 0];%default
124if ~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')
144end
145
146% The figure can be deleted now
147delete(handles.figure1);
148
149%------------------------------------------------------------------------
150% --- Executes on button press in OK.
151function OK_Callback(hObject, eventdata, handles)
152%------------------------------------------------------------------------
153handles.output = get(hObject,'String');
154guidata(hObject, handles);% Update handles structure
155uiresume(handles.figure1);
156
157%------------------------------------------------------------------------
158% --- Executes on button press in Cancel.
159function Cancel_Callback(hObject, eventdata, handles)
160%------------------------------------------------------------------------
161handles.output = get(hObject,'String');
162guidata(hObject, handles); % Update handles structure
163uiresume(handles.figure1);
164
165%------------------------------------------------------------------------
166% --- Executes when user attempts to close figure1.
167function figure1_CloseRequestFcn(hObject, eventdata, handles)
168%------------------------------------------------------------------------
169if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
170    % The GUI is still in UIWAIT, us UIRESUME
171    uiresume(handles.figure1);
172else
173    % The GUI is no longer waiting, just close it
174    delete(handles.figure1);
175end
176
177%------------------------------------------------------------------------
178% --- Executes on key press over figure1 with no controls selected.
179function figure1_KeyPressFcn(hObject, eventdata, handles)
180%------------------------------------------------------------------------
181% Check for "enter" or "escape"
182if 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);
190end
191if isequal(get(hObject,'CurrentKey'),'return')
192    uiresume(handles.figure1);
193end   
194
195
196% --- Executes on button press in white.
197function white_Callback(hObject, eventdata, handles)
198val=get(handles.white,'Value');
199if val
200    set(handles.black,'Value',0)
201else
202    set(handles.black,'Value',1)
203end
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.
212function black_Callback(hObject, eventdata, handles)
213val=get(handles.black,'Value');
214if val
215    set(handles.white,'Value',0)
216else
217    set(handles.white,'Value',1)
218end
219
Note: See TracBrowser for help on using the repository browser.