Skip to content

Commit 0808ff3

Browse files
committed
ENH: Add label border parameter
1 parent 7d2ef99 commit 0808ff3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

surfer/viz.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,10 @@ def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
10101010
threshold the label ids using this value in the label
10111011
file's scalar field (i.e. label only vertices with
10121012
scalar >= thresh)
1013-
borders : bool
1014-
show only label borders
1013+
borders : bool | int
1014+
Show only label borders. If int, specify the number of steps
1015+
along the cortical mesh to include in the border definition
1016+
(higher numbers create thicker borders).
10151017
hemi : str | None
10161018
If None, it is assumed to belong to the hemipshere being
10171019
shown. If two hemispheres are being shown, an error will
@@ -1093,12 +1095,22 @@ def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
10931095
i += 1
10941096
label_name = name % i
10951097

1098+
if not isinstance(borders, (bool, int)) or borders < 0:
1099+
raise TypeError('borders must be a bool or int')
10961100
if borders:
10971101
n_vertices = label.size
10981102
edges = utils.mesh_edges(self.geo[hemi].faces)
10991103
border_edges = label[edges.row] != label[edges.col]
11001104
show = np.zeros(n_vertices, dtype=np.int)
1101-
show[np.unique(edges.row[border_edges])] = 1
1105+
keep_idx = np.unique(edges.row[border_edges])
1106+
if isinstance(borders, int):
1107+
for _ in range(borders):
1108+
keep_idx = np.in1d(self.geo[hemi].faces.ravel(), keep_idx)
1109+
keep_idx.shape = self.geo[hemi].faces.shape
1110+
keep_idx = self.geo[hemi].faces[np.any(keep_idx,
1111+
axis=1)].ravel()
1112+
keep_idx = keep_idx[np.in1d(keep_idx, ids)]
1113+
show[keep_idx] = 1
11021114
label *= show
11031115

11041116
# make a list of all the plotted labels

0 commit comments

Comments
 (0)