forked from fieldtrip/fieldtrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_plot_crosshair.m
135 lines (122 loc) · 3.97 KB
/
ft_plot_crosshair.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function h = ft_plot_crosshair(pos, varargin)
% FT_PLOT_CROSSHAIR plots a crosshair at a specified position in two [x, y] or three
% [x, y, z] dimensions.
%
% Use as
% h = ft_plot_crosshair(pos, ...)
% where pos is the desired position of the crosshair. The handles of the lines are
% returned.
%
% Optional input arguments should be specified in key-value pairs and can include
% 'color' = [r g b] value or string, see PLOT
% 'parent' = handle of the parent axes
% 'handle' = handle of the existing line objects to be updated
%
% You can specify the handles of existing line objects which will be then updated,
% rather than creating a new set of lines. If both parent and handle ar specified,
% the handle option prevail.
%
% Example
% ft_plot_crosshair([0.5 0.5], 'color', 'r')
%
% See also FT_PLOT_BOX, FT_PLOT_LINE, TEXT, LINE
% Copyright (C) 2003-2017, Robert Oostenveld
%
% This file is part of FieldTrip, see http://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://www.gnu.org/licenses/>.
%
% $Id$
% get the optional input arguments
color = ft_getopt(varargin, 'color');
parent = ft_getopt(varargin, 'parent');
h = ft_getopt(varargin, 'handle');
if ~isempty(h)
% the parent to the first handle is set as the current axes
set(gcf, 'currentaxes', get(h(1),'parent'));
elseif ~isempty(parent)
% the parent is set as the current axes
set(gcf, 'currentaxes', parent);
else
% the current axes stay as they are
end
% color management
if ~isempty(color)
if ischar(color) && exist([color '.m'], 'file')
color = eval(color);
end
varargin = ft_setopt(varargin, 'color', color);
end
% determine the size of the figure
border = [get(gca, 'xlim') get(gca, 'ylim') get(gca, 'zlim')];
switch numel(pos)
case 2
x = [ border(1) pos(1)
border(2) pos(1) ];
y = [ pos(2) border(3)
pos(2) border(4) ];
if isempty(h) && (~ishold)
hold on
h = line(x, y, varargin{:});
hold off
elseif isempty(h)
h = line(x, y, varargin{:});
else
set(h(1), 'xdata', x(:,1)');
set(h(1), 'ydata', y(:,1)');
set(h(2), 'xdata', x(:,2)');
set(h(2), 'ydata', y(:,2)');
end
if ~isempty(color)
set(h(1), 'color', color);
set(h(2), 'color', color);
else
% ensure they have the same color
set(h(2), 'color', get(h(1), 'color'));
end
case 3
x = [ border(1) pos(1) pos(1)
border(2) pos(1) pos(1)];
y = [ pos(2) border(3) pos(2)
pos(2) border(4) pos(2)];
z = [ pos(3) pos(3) border(5)
pos(3) pos(3) border(6)];
if isempty(h) && (~ishold)
hold on
h = line(x, y, z, varargin{:});
hold off
elseif isempty(h)
h = line(x, y, z, varargin{:});
else
set(h(1), 'xdata', x(:,1)');
set(h(1), 'ydata', y(:,1)');
set(h(1), 'zdata', z(:,1)');
set(h(2), 'xdata', x(:,2)');
set(h(2), 'ydata', y(:,2)');
set(h(2), 'zdata', z(:,2)');
set(h(3), 'xdata', x(:,3)');
set(h(3), 'ydata', y(:,3)');
set(h(3), 'zdata', z(:,3)');
end
if ~isempty(color)
set(h(1), 'color', color);
set(h(2), 'color', color);
set(h(3), 'color', color);
else
% ensure they have the same color
set(h(2), 'color', get(h(1), 'color'));
set(h(3), 'color', get(h(1), 'color'));
end
end % switch