source: trunk/src/create_grid.m @ 257

Last change on this file since 257 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
RevLine 
[38]1%'create_grid': called by the GUI geometry_calib to create a physical grid
[89]2%------------------------------------------------------------------------
[38]3% coord=create_grid(input_grid)
[37]4%
5% OUTPUT:
[38]6% coord: matrix (nbpoint, 3) of coordinates for grid points, with columns x,y,z
[37]7%
[89]8% INPUT:
[38]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)
[37]11
12function varargout = create_grid(varargin)
13
[156]14% Last Modified by GUIDE v2.5 16-Dec-2010 00:17:20
[37]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.
[88]37function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid,name)
[37]38%------------------------------------------------------------------------
39% This function has no output args, see OutputFcn.
40
41% Choose default command line output for create_grid
42handles.output = 'Cancel';
43
[88]44if exist('name','var') && ischar(name)
45    set(hObject,'name',name)
[156]46    if strcmp(name,'detect_grid')
47        set(handles.white,'Visible','on')
48        set(handles.black,'Visible','on')
49    end
[88]50end
[37]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')
[60]101        set(handles.y_0,'String',num2str(input_grid.y_0));
[37]102   end
103   if isfield(input_grid,'y_1')
[60]104        set(handles.y_1,'String',num2str(input_grid.y_1));
[37]105   end
106   if isfield(input_grid,'Dy')
[60]107        set(handles.Dy,'String',num2str(input_grid.Dy));
[37]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')
[60]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];
[37]133    [yarray,xarray]=meshgrid(yarray,xarray);
134    xarray=reshape(xarray,numel(xarray),1);
135    yarray=reshape(yarray,numel(yarray),1);
[60]136    T.z_0=str2num(get(handles.z_0,'String'));
137    if isempty(T.z_0)
138        T.z_0=0;
[37]139    end
[60]140    zarray=T.z_0*ones(size(yarray));
[37]141    varargout{1}=[xarray yarray zarray];
[109]142    varargout{2}=T;
[156]143    varargout{3}=get(handles.white,'Value')
[37]144end
[109]145
[37]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
[156]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)
[37]207
[156]208% Hint: get(hObject,'Value') returns toggle state of white
[37]209
210
[156]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.