source: trunk/src/create_grid.m @ 782

Last change on this file since 782 was 694, checked in by sommeria, 11 years ago

create_grid now remember white or black marks
bug repaired for transform fct in series

File size: 7.8 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 
112   if isfield(input_grid,'CheckWhite')
113       if input_grid.CheckWhite
114        set(handles.white,'Value',1)
115        set(handles.black,'Value',0)
116       else
117          set(handles.white,'Value',0)
118          set(handles.black,'Value',1)
119       end
120   end
121end
122
123set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
124% UIWAIT makes create_grid wait for user response (see UIRESUME)
125uiwait(handles.figure1);
126
127%------------------------------------------------------------------------
128% --- Outputs from this function are returned to the command line.
129function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
130%------------------------------------------------------------------------
131% Get default command line output from handles structure
132varargout{1}=[0 0 0];%default
133if ~isequal(handles.output,'Cancel')
134    T.x_0=str2num(get(handles.x_0,'String'));
135    T.Dx=str2num(get(handles.Dx,'String'));
136    T.x_1=str2num(get(handles.x_1,'String'));
137    xarray=[T.x_0:T.Dx:T.x_1];
138    T.y_0=str2num(get(handles.y_0,'String'));
139    T.Dy=str2num(get(handles.Dy,'String'));
140    T.y_1=str2num(get(handles.y_1,'String'));
141    yarray=[T.y_0:T.Dy:T.y_1];
142    [yarray,xarray]=meshgrid(yarray,xarray);
143    xarray=reshape(xarray,numel(xarray),1);
144    yarray=reshape(yarray,numel(yarray),1);
145    T.z_0=str2num(get(handles.z_0,'String'));
146    if isempty(T.z_0)
147        T.z_0=0;
148    end
149    zarray=T.z_0*ones(size(yarray));
150    varargout{1}=[xarray yarray zarray];
151    varargout{2}=T;
152    varargout{3}=get(handles.white,'Value');
153end
154
155% The figure can be deleted now
156delete(handles.figure1);
157
158%------------------------------------------------------------------------
159% --- Executes on button press in OK.
160function OK_Callback(hObject, eventdata, handles)
161%------------------------------------------------------------------------
162handles.output = get(hObject,'String');
163guidata(hObject, handles);% Update handles structure
164uiresume(handles.figure1);
165
166%------------------------------------------------------------------------
167% --- Executes on button press in Cancel.
168function Cancel_Callback(hObject, eventdata, handles)
169%------------------------------------------------------------------------
170handles.output = get(hObject,'String');
171guidata(hObject, handles); % Update handles structure
172uiresume(handles.figure1);
173
174%------------------------------------------------------------------------
175% --- Executes when user attempts to close figure1.
176function figure1_CloseRequestFcn(hObject, eventdata, handles)
177%------------------------------------------------------------------------
178if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
179    % The GUI is still in UIWAIT, us UIRESUME
180    uiresume(handles.figure1);
181else
182    % The GUI is no longer waiting, just close it
183    delete(handles.figure1);
184end
185
186%------------------------------------------------------------------------
187% --- Executes on key press over figure1 with no controls selected.
188function figure1_KeyPressFcn(hObject, eventdata, handles)
189%------------------------------------------------------------------------
190% Check for "enter" or "escape"
191if isequal(get(hObject,'CurrentKey'),'escape')
192    % User said no by hitting escape
193    handles.output = 'Cancel';
194   
195    % Update handles structure
196    guidata(hObject, handles);
197   
198    uiresume(handles.figure1);
199end
200if isequal(get(hObject,'CurrentKey'),'return')
201    uiresume(handles.figure1);
202end   
203
204
205% --- Executes on button press in white.
206function white_Callback(hObject, eventdata, handles)
207val=get(handles.white,'Value');
208if val
209    set(handles.black,'Value',0)
210else
211    set(handles.black,'Value',1)
212end
213% hObject    handle to white (see GCBO)
214% eventdata  reserved - to be defined in a future version of MATLAB
215% handles    structure with handles and user data (see GUIDATA)
216
217% Hint: get(hObject,'Value') returns toggle state of white
218
219
220% --- Executes on button press in black.
221function black_Callback(hObject, eventdata, handles)
222val=get(handles.black,'Value');
223if val
224    set(handles.white,'Value',0)
225else
226    set(handles.white,'Value',1)
227end
228
Note: See TracBrowser for help on using the repository browser.