source: trunk/src/create_grid.m @ 881

Last change on this file since 881 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 8.7 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
12%=======================================================================
13% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
14%   http://www.legi.grenoble-inp.fr
15%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
16%
17%     This file is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published
21%     by the Free Software Foundation; either version 2 of the license,
22%     or (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (see LICENSE.txt) for more details.
28%=======================================================================
29
30function varargout = create_grid(varargin)
31
32% Last Modified by GUIDE v2.5 16-Dec-2010 00:17:20
33
34% Begin initialization code - DO NOT EDIT
35gui_Singleton = 1;
36gui_State = struct('gui_Name',       mfilename, ...
37                   'gui_Singleton',  gui_Singleton, ...
38                   'gui_OpeningFcn', @create_grid_OpeningFcn, ...
39                   'gui_OutputFcn',  @create_grid_OutputFcn, ...
40                   'gui_LayoutFcn',  [] , ...
41                   'gui_Callback',   []);
42if nargin && ischar(varargin{1})
43    gui_State.gui_Callback = str2func(varargin{1});
44end
45
46if nargout
47    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
48else
49    gui_mainfcn(gui_State, varargin{:});
50end
51% End initialization code - DO NOT EDIT
52
53%------------------------------------------------------------------------
54% --- Executes just before create_grid is made visible.
55function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid,name)
56%------------------------------------------------------------------------
57% This function has no output args, see OutputFcn.
58
59% Choose default command line output for create_grid
60handles.output = 'Cancel';
61
62if exist('name','var') && ischar(name)
63    set(hObject,'name',name)
64    if strcmp(name,'detect_grid')
65        set(handles.white,'Visible','on')
66        set(handles.black,'Visible','on')
67    end
68end
69% Update handles structure
70guidata(hObject, handles);
71testNo=0;
72testCancel=1;
73testinputstring=0;
74icontype='quest';%default question icon (text input asked)
75
76% Determine the position of the dialog - centered on the screen
77FigPos=get(0,'DefaultFigurePosition');
78OldUnits = get(hObject, 'Units');
79set(hObject, 'Units', 'pixels');
80OldPos = get(hObject,'Position');
81FigWidth = OldPos(3);
82FigHeight = OldPos(4);
83ScreenUnits=get(0,'Units');
84set(0,'Units','pixels');
85ScreenSize=get(0,'ScreenSize');
86set(0,'Units',ScreenUnits);
87
88FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
89FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
90FigPos(3:4)=[FigWidth FigHeight];
91set(hObject, 'Position', FigPos);
92set(hObject, 'Units', OldUnits);
93
94% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
95load dialogicons.mat
96eval(['IconData=' icontype 'IconData;'])
97eval(['IconCMap=' icontype 'IconMap;'])
98questIconMap(256,:) = get(handles.figure1, 'Color');
99Img=image(IconData, 'Parent', handles.axes1);
100set(handles.figure1, 'Colormap', IconCMap);
101set(handles.axes1, ...
102    'Visible', 'off', ...
103    'YDir'   , 'reverse'       , ...
104    'XLim'   , get(Img,'XData'), ...
105    'YLim'   , get(Img,'YData')  ...
106    );
107
108if exist('input_grid','var') && ~isempty(input_grid)
109   if isfield(input_grid,'x_0')
110        set(handles.x_0,'String',num2str(input_grid.x_0));
111   end
112   if isfield(input_grid,'x_1')
113        set(handles.x_1,'String',num2str(input_grid.x_1));
114   end
115   if isfield(input_grid,'Dx')
116        set(handles.Dx,'String',num2str(input_grid.Dx));
117   end
118   if isfield(input_grid,'y_0')
119        set(handles.y_0,'String',num2str(input_grid.y_0));
120   end
121   if isfield(input_grid,'y_1')
122        set(handles.y_1,'String',num2str(input_grid.y_1));
123   end
124   if isfield(input_grid,'Dy')
125        set(handles.Dy,'String',num2str(input_grid.Dy));
126   end
127   if isfield(input_grid,'z')
128        set(handles.z,'String',num2str(input_grid.z));
129   end 
130   if isfield(input_grid,'CheckWhite')
131       if input_grid.CheckWhite
132        set(handles.white,'Value',1)
133        set(handles.black,'Value',0)
134       else
135          set(handles.white,'Value',0)
136          set(handles.black,'Value',1)
137       end
138   end
139end
140
141set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
142% UIWAIT makes create_grid wait for user response (see UIRESUME)
143uiwait(handles.figure1);
144
145%------------------------------------------------------------------------
146% --- Outputs from this function are returned to the command line.
147function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
148%------------------------------------------------------------------------
149% Get default command line output from handles structure
150varargout{1}=[0 0 0];%default
151if ~isequal(handles.output,'Cancel')
152    T.x_0=str2num(get(handles.x_0,'String'));
153    T.Dx=str2num(get(handles.Dx,'String'));
154    T.x_1=str2num(get(handles.x_1,'String'));
155    xarray=[T.x_0:T.Dx:T.x_1];
156    T.y_0=str2num(get(handles.y_0,'String'));
157    T.Dy=str2num(get(handles.Dy,'String'));
158    T.y_1=str2num(get(handles.y_1,'String'));
159    yarray=[T.y_0:T.Dy:T.y_1];
160    [yarray,xarray]=meshgrid(yarray,xarray);
161    xarray=reshape(xarray,numel(xarray),1);
162    yarray=reshape(yarray,numel(yarray),1);
163    T.z_0=str2num(get(handles.z_0,'String'));
164    if isempty(T.z_0)
165        T.z_0=0;
166    end
167    zarray=T.z_0*ones(size(yarray));
168    varargout{1}=[xarray yarray zarray];
169    varargout{2}=T;
170    varargout{3}=get(handles.white,'Value');
171end
172
173% The figure can be deleted now
174delete(handles.figure1);
175
176%------------------------------------------------------------------------
177% --- Executes on button press in OK.
178function OK_Callback(hObject, eventdata, handles)
179%------------------------------------------------------------------------
180handles.output = get(hObject,'String');
181guidata(hObject, handles);% Update handles structure
182uiresume(handles.figure1);
183
184%------------------------------------------------------------------------
185% --- Executes on button press in Cancel.
186function Cancel_Callback(hObject, eventdata, handles)
187%------------------------------------------------------------------------
188handles.output = get(hObject,'String');
189guidata(hObject, handles); % Update handles structure
190uiresume(handles.figure1);
191
192%------------------------------------------------------------------------
193% --- Executes when user attempts to close figure1.
194function figure1_CloseRequestFcn(hObject, eventdata, handles)
195%------------------------------------------------------------------------
196if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
197    % The GUI is still in UIWAIT, us UIRESUME
198    uiresume(handles.figure1);
199else
200    % The GUI is no longer waiting, just close it
201    delete(handles.figure1);
202end
203
204%------------------------------------------------------------------------
205% --- Executes on key press over figure1 with no controls selected.
206function figure1_KeyPressFcn(hObject, eventdata, handles)
207%------------------------------------------------------------------------
208% Check for "enter" or "escape"
209if isequal(get(hObject,'CurrentKey'),'escape')
210    % User said no by hitting escape
211    handles.output = 'Cancel';
212   
213    % Update handles structure
214    guidata(hObject, handles);
215   
216    uiresume(handles.figure1);
217end
218if isequal(get(hObject,'CurrentKey'),'return')
219    uiresume(handles.figure1);
220end   
221
222
223% --- Executes on button press in white.
224function white_Callback(hObject, eventdata, handles)
225val=get(handles.white,'Value');
226if val
227    set(handles.black,'Value',0)
228else
229    set(handles.black,'Value',1)
230end
231% hObject    handle to white (see GCBO)
232% eventdata  reserved - to be defined in a future version of MATLAB
233% handles    structure with handles and user data (see GUIDATA)
234
235% Hint: get(hObject,'Value') returns toggle state of white
236
237
238% --- Executes on button press in black.
239function black_Callback(hObject, eventdata, handles)
240val=get(handles.black,'Value');
241if val
242    set(handles.white,'Value',0)
243else
244    set(handles.white,'Value',1)
245end
246
Note: See TracBrowser for help on using the repository browser.