Skip to content

Commit 6c82823

Browse files
authored
Merge pull request #253 from larsoner/annot
FIX: annotations and bgcolor
2 parents 55bfb4e + 41f1e48 commit 6c82823

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

surfer/viz.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,12 +1267,13 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
12671267
self._to_borders(labels, hemi, borders)
12681268

12691269
# Handle null labels properly
1270-
# (tksurfer doesn't use the alpha channel, so sometimes this
1271-
# is set weirdly. For our purposes, it should always be 0.
1272-
# Unless this sometimes causes problems?
1273-
cmap[np.where(cmap[:, 4] == 0), 3] = 0
1274-
if np.any(labels == 0) and not np.any(cmap[:, -1] == 0):
1275-
cmap = np.vstack((cmap, np.zeros(5, int)))
1270+
cmap[:, 3] = 255
1271+
bgcolor = self._brain_color
1272+
bgcolor[-1] = 0
1273+
cmap[cmap[:, 4] < 0, 4] += 2 ** 24 # wrap to positive
1274+
cmap[cmap[:, 4] <= 0, :4] = bgcolor
1275+
if np.any(labels == 0) and not np.any(cmap[:, -1] <= 0):
1276+
cmap = np.vstack((cmap, np.concatenate([bgcolor, [0]])))
12761277

12771278
# Set label ids sensibly
12781279
order = np.argsort(cmap[:, -1])
@@ -1885,6 +1886,21 @@ def set_surf(self, surf):
18851886
if brain._f.scene is not None:
18861887
brain._f.scene.reset_zoom()
18871888

1889+
@property
1890+
def _brain_color(self):
1891+
geo_actor = self._brain_list[0]['brain']._geo_surf.actor
1892+
if self._brain_list[0]['brain']._using_lut:
1893+
bgcolor = np.mean(
1894+
self._brain_list[0]['brain']._geo_surf.module_manager
1895+
.scalar_lut_manager.lut.table.to_array(), axis=0)
1896+
else:
1897+
bgcolor = geo_actor.property.color
1898+
if len(bgcolor) == 3:
1899+
bgcolor = bgcolor + (1,)
1900+
bgcolor = 255 * np.array(bgcolor)
1901+
bgcolor[-1] *= geo_actor.property.opacity
1902+
return bgcolor
1903+
18881904
@verbose
18891905
def scale_data_colormap(self, fmin, fmid, fmax, transparent,
18901906
center=None, alpha=1.0, verbose=None):
@@ -1942,17 +1958,7 @@ def scale_data_colormap(self, fmin, fmid, fmax, transparent,
19421958
center, alpha)
19431959

19441960
# Get the effective background color as 255-based 4-element array
1945-
geo_actor = self._brain_list[0]['brain']._geo_surf.actor
1946-
if self._brain_list[0]['brain']._using_lut:
1947-
bgcolor = np.mean(
1948-
self._brain_list[0]['brain']._geo_surf.module_manager
1949-
.scalar_lut_manager.lut.table.to_array(), axis=0)
1950-
else:
1951-
bgcolor = geo_actor.property.color
1952-
if len(bgcolor) == 3:
1953-
bgcolor = bgcolor + (1,)
1954-
bgcolor = 255 * np.array(bgcolor)
1955-
bgcolor[-1] *= geo_actor.property.opacity
1961+
bgcolor = self._brain_color
19561962

19571963
views = self._toggle_render(False)
19581964
# Use the new colormap

0 commit comments

Comments
 (0)