-
Notifications
You must be signed in to change notification settings - Fork 714
/
ft_select_voxel.m
82 lines (75 loc) · 2.8 KB
/
ft_select_voxel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function ft_select_voxel(handle, eventdata, varargin)
% FT_SELECT_VOXEL is a helper function that can be used as callback function
% in a figure. It allows the user to select a voxel from a (resliced) 3-D volume.
%
% Use as
% voxel = ft_select_voxel(h, eventdata, ...)
% The first two arguments are automatically passed by MATLAB to any
% callback function.
%
% Additional options should be specified in key-value pairs and can be
% 'callback' = function handle to be executed after channels have been selected
%
% You can pass additional arguments to the callback function in a cell-array
% like {@function_handle,arg1,arg2}
%
% Example
% % create a figure with a random 3-D volume
% mri = rand(128,128,128);
% ft_plot_slice(mri, 'location', [64 64 64], 'orientation', [1 1 1]);
% view(120,30)
% xlabel('x'); ylabel('y'); zlabel('z'); grid on
% axis([0 128 0 128 0 128])
% axis equal; axis vis3d
% axis([0 128 0 128 0 128])
%
% % add this function as the callback to make a single selection
% set(gcf, 'WindowButtonDownFcn', {@ft_select_voxel, 'callback', @disp})
%
% Subsequently you can click in the figure and you'll see that the disp
% function is executed as callback and that it displays the selected
% voxel.
%
% See also FT_SELECT_BOX, FT_SELECT_CHANNEL, FT_SELECT_POINT, FT_SELECT_POINT3D, FT_SELECT_RANGE
% Copyright (C) 2010, Robert Oostenveld
%
% This file is part of FieldTrip, see http:https://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http:https://www.gnu.org/licenses/>.
%
% $Id$
% get optional input arguments
callback = ft_getopt(varargin, 'callback');
% get the clicked position from the figure
% voxel = get(gca, 'CurrentPoint');
% the select3d function also takes care of projections
[p, v, vi, face, facei] = select3d(gca);
voxel = p';
if isempty(voxel)
return
end
% execute the original callback with the selected channel as input argument
if ~isempty(callback)
if isa(callback, 'cell')
% the callback specifies a function and additional arguments
funhandle = callback{1};
funargs = callback(2:end);
feval(funhandle, voxel, funargs{:});
else
% the callback only specifies a function
funhandle = callback;
feval(funhandle, voxel);
end
end