source: trunk/src/create_grid.m @ 1060

Last change on this file since 1060 was 1027, checked in by g7moreau, 3 years ago
  • Update Copyright 2017 -> 2018
File size: 9.0 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-2018, LEGI UMR 5519 / CNRS UGA 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 02-Feb-2017 17:09:08
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');
171    varargout{4}=0;
172    if get(handles.CheckDots,'Value')
173    varargout{4}=str2num(get(handles.FilterWindow,'String'));
174    end
175end
176
177% The figure can be deleted now
178delete(handles.figure1);
179
180%------------------------------------------------------------------------
181% --- Executes on button press in OK.
182function OK_Callback(hObject, eventdata, handles)
183%------------------------------------------------------------------------
184handles.output = get(hObject,'String');
185guidata(hObject, handles);% Update handles structure
186uiresume(handles.figure1);
187
188%------------------------------------------------------------------------
189% --- Executes on button press in Cancel.
190function Cancel_Callback(hObject, eventdata, handles)
191%------------------------------------------------------------------------
192handles.output = get(hObject,'String');
193guidata(hObject, handles); % Update handles structure
194uiresume(handles.figure1);
195
196%------------------------------------------------------------------------
197% --- Executes when user attempts to close figure1.
198function figure1_CloseRequestFcn(hObject, eventdata, handles)
199%------------------------------------------------------------------------
200if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
201    % The GUI is still in UIWAIT, us UIRESUME
202    uiresume(handles.figure1);
203else
204    % The GUI is no longer waiting, just close it
205    delete(handles.figure1);
206end
207
208%------------------------------------------------------------------------
209% --- Executes on key press over figure1 with no controls selected.
210function figure1_KeyPressFcn(hObject, eventdata, handles)
211%------------------------------------------------------------------------
212% Check for "enter" or "escape"
213if isequal(get(hObject,'CurrentKey'),'escape')
214    % User said no by hitting escape
215    handles.output = 'Cancel';
216   
217    % Update handles structure
218    guidata(hObject, handles);
219   
220    uiresume(handles.figure1);
221end
222if isequal(get(hObject,'CurrentKey'),'return')
223    uiresume(handles.figure1);
224end   
225
226% --- Executes on button press in white.
227function white_Callback(hObject, eventdata, handles)
228val=get(handles.white,'Value');
229if val
230    set(handles.black,'Value',0)
231else
232    set(handles.black,'Value',1)
233end
234
235
236% --- Executes on button press in black.
237function black_Callback(hObject, eventdata, handles)
238val=get(handles.black,'Value');
239if val
240    set(handles.white,'Value',0)
241else
242    set(handles.white,'Value',1)
243end
244
245% --- Executes on button press in CheckDots.
246function CheckDots_Callback(hObject, eventdata, handles)
247val=get(handles.CheckDots,'Value');
248if val
249    set(handles.FilterWindow,'Visible','on')
250    set(handles.FilterWindow_txt,'Visible','on')
251else
252    set(handles.FilterWindow,'Visible','off')
253     set(handles.FilterWindow_txt,'Visible','off')
254end
255
Note: See TracBrowser for help on using the repository browser.