source: trunk/src/create_grid.m @ 72

Last change on this file since 72 was 60, checked in by sommeria, 14 years ago

-plot projections on a new specific GUI view_field, to avoid the multiplication of active figures
-introduce a ruler in uvmat (in menu/Tools), to measure distances and angles
-insert automatic detection of points for geometric calibration: tool 'detect_grid'. Four points, deliminating the grid to determine, must be marked with the mouse, as well as the physical grid. Then the points inside are automatically detected.
-reading plane positions in ImaDoc? improved to deal with volume scans

File size: 6.6 KB
Line 
1%'create_grid': called by the GUI geometry_calib to create a physical grid
2% coord=create_grid(input_grid)
3%
4% OUTPUT:
5% coord: matrix (nbpoint, 3) of coordinates for grid points, with columns x,y,z
6%
7%INPUT:
8% input_grid (optional): structure to initiate the GUI with fields .x_0,.Dx,.x_1
9% (defining x coordinates), .y_0,.Dy,.y_1 (defining y coordinates)
10
11function varargout = create_grid(varargin)
12
13% Last Modified by GUIDE v2.5 05-Mar-2010 21:57:44
14
15% Begin initialization code - DO NOT EDIT
16gui_Singleton = 1;
17gui_State = struct('gui_Name',       mfilename, ...
18                   'gui_Singleton',  gui_Singleton, ...
19                   'gui_OpeningFcn', @create_grid_OpeningFcn, ...
20                   'gui_OutputFcn',  @create_grid_OutputFcn, ...
21                   'gui_LayoutFcn',  [] , ...
22                   'gui_Callback',   []);
23if nargin && ischar(varargin{1})
24    gui_State.gui_Callback = str2func(varargin{1});
25end
26
27if nargout
28    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
29else
30    gui_mainfcn(gui_State, varargin{:});
31end
32% End initialization code - DO NOT EDIT
33
34%------------------------------------------------------------------------
35% --- Executes just before create_grid is made visible.
36function create_grid_OpeningFcn(hObject, eventdata, handles,input_grid)
37%------------------------------------------------------------------------
38% This function has no output args, see OutputFcn.
39
40% Choose default command line output for create_grid
41handles.output = 'Cancel';
42
43% Update handles structure
44guidata(hObject, handles);
45testNo=0;
46testCancel=1;
47testinputstring=0;
48icontype='quest';%default question icon (text input asked)
49
50% Determine the position of the dialog - centered on the screen
51FigPos=get(0,'DefaultFigurePosition');
52OldUnits = get(hObject, 'Units');
53set(hObject, 'Units', 'pixels');
54OldPos = get(hObject,'Position');
55FigWidth = OldPos(3);
56FigHeight = OldPos(4);
57ScreenUnits=get(0,'Units');
58set(0,'Units','pixels');
59ScreenSize=get(0,'ScreenSize');
60set(0,'Units',ScreenUnits);
61
62FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
63FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
64FigPos(3:4)=[FigWidth FigHeight];
65set(hObject, 'Position', FigPos);
66set(hObject, 'Units', OldUnits);
67
68% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
69load dialogicons.mat
70eval(['IconData=' icontype 'IconData;'])
71eval(['IconCMap=' icontype 'IconMap;'])
72questIconMap(256,:) = get(handles.figure1, 'Color');
73Img=image(IconData, 'Parent', handles.axes1);
74set(handles.figure1, 'Colormap', IconCMap);
75set(handles.axes1, ...
76    'Visible', 'off', ...
77    'YDir'   , 'reverse'       , ...
78    'XLim'   , get(Img,'XData'), ...
79    'YLim'   , get(Img,'YData')  ...
80    );
81
82if exist('input_grid','var') && ~isempty(input_grid)
83   if isfield(input_grid,'x_0')
84        set(handles.x_0,'String',num2str(input_grid.x_0));
85   end
86   if isfield(input_grid,'x_1')
87        set(handles.x_1,'String',num2str(input_grid.x_1));
88   end
89   if isfield(input_grid,'Dx')
90        set(handles.Dx,'String',num2str(input_grid.Dx));
91   end
92   if isfield(input_grid,'y_0')
93        set(handles.y_0,'String',num2str(input_grid.y_0));
94   end
95   if isfield(input_grid,'y_1')
96        set(handles.y_1,'String',num2str(input_grid.y_1));
97   end
98   if isfield(input_grid,'Dy')
99        set(handles.Dy,'String',num2str(input_grid.Dy));
100   end
101   if isfield(input_grid,'z')
102        set(handles.z,'String',num2str(input_grid.z));
103   end 
104end
105
106set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
107% UIWAIT makes create_grid wait for user response (see UIRESUME)
108uiwait(handles.figure1);
109
110%------------------------------------------------------------------------
111% --- Outputs from this function are returned to the command line.
112function varargout = create_grid_OutputFcn(hObject, eventdata, handles)
113%------------------------------------------------------------------------
114% Get default command line output from handles structure
115varargout{1}=[0 0 0];%default
116if ~isequal(handles.output,'Cancel')
117    T.x_0=str2num(get(handles.x_0,'String'));
118    T.Dx=str2num(get(handles.Dx,'String'));
119    T.x_1=str2num(get(handles.x_1,'String'));
120    xarray=[T.x_0:T.Dx:T.x_1];
121    T.y_0=str2num(get(handles.y_0,'String'));
122    T.Dy=str2num(get(handles.Dy,'String'));
123    T.y_1=str2num(get(handles.y_1,'String'));
124    yarray=[T.y_0:T.Dy:T.y_1];
125    [yarray,xarray]=meshgrid(yarray,xarray);
126    xarray=reshape(xarray,numel(xarray),1);
127    yarray=reshape(yarray,numel(yarray),1);
128    T.z_0=str2num(get(handles.z_0,'String'));
129    if isempty(T.z_0)
130        T.z_0=0;
131    end
132    zarray=T.z_0*ones(size(yarray));
133    varargout{1}=[xarray yarray zarray];
134end
135varargout{2}=T;
136% The figure can be deleted now
137delete(handles.figure1);
138
139%------------------------------------------------------------------------
140% --- Executes on button press in OK.
141function OK_Callback(hObject, eventdata, handles)
142%------------------------------------------------------------------------
143handles.output = get(hObject,'String');
144guidata(hObject, handles);% Update handles structure
145uiresume(handles.figure1);
146
147%------------------------------------------------------------------------
148% --- Executes on button press in Cancel.
149function Cancel_Callback(hObject, eventdata, handles)
150%------------------------------------------------------------------------
151handles.output = get(hObject,'String');
152guidata(hObject, handles); % Update handles structure
153uiresume(handles.figure1);
154
155%------------------------------------------------------------------------
156% --- Executes when user attempts to close figure1.
157function figure1_CloseRequestFcn(hObject, eventdata, handles)
158%------------------------------------------------------------------------
159if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
160    % The GUI is still in UIWAIT, us UIRESUME
161    uiresume(handles.figure1);
162else
163    % The GUI is no longer waiting, just close it
164    delete(handles.figure1);
165end
166
167%------------------------------------------------------------------------
168% --- Executes on key press over figure1 with no controls selected.
169function figure1_KeyPressFcn(hObject, eventdata, handles)
170%------------------------------------------------------------------------
171% Check for "enter" or "escape"
172if isequal(get(hObject,'CurrentKey'),'escape')
173    % User said no by hitting escape
174    handles.output = 'Cancel';
175   
176    % Update handles structure
177    guidata(hObject, handles);
178   
179    uiresume(handles.figure1);
180end
181if isequal(get(hObject,'CurrentKey'),'return')
182    uiresume(handles.figure1);
183end   
184
185
186
187
188
Note: See TracBrowser for help on using the repository browser.