Skip to content

Commit a85021d

Browse files
committed
update contours when scrolling through the volumnes
1 parent d43a9de commit a85021d

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

pymirc/viewer/threeaxisviewer.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def __init__(self, vols,
277277
self.l2x.append(self.axes[3*i + 2].axvline(self.sl_y, color = 'r',ls = ls))
278278
self.l2y.append(self.axes[3*i + 2].axhline(self.shape[self.iz] - self.sl_z, color = 'r',ls = ls))
279279

280+
# list for contour definitions
281+
self.contour_configs = []
282+
280283
#------------------------------------------------------------------------
281284
def update_colorbars(self):
282285
for i in range(self.n_vols):
@@ -350,6 +353,17 @@ def redraw(self):
350353
self.redraw_coronal()
351354
self.redraw_sagittal()
352355

356+
# draw all contour lines
357+
if len(self.contour_configs) > 0:
358+
for cfg in self.contour_configs:
359+
for i in range(3):
360+
# remove drawn contour lines first
361+
while(len(self.ax[cfg[1],i].collections) > 0):
362+
for col in self.ax[cfg[1],i].collections:
363+
col.remove()
364+
365+
self.ax[cfg[1],i].contour(self.imgs[cfg[0]][i].get_array(), cfg[2], **cfg[3])
366+
self.fig.canvas.draw()
353367
#------------------------------------------------------------------------
354368
def recalculate_slices(self):
355369
if self.ndim == 3:
@@ -372,21 +386,21 @@ def recalculate_slices(self):
372386
self.fstr = ', ' + str(self.sl_t)
373387

374388
#------------------------------------------------------------------------
375-
def add_contour(self, N = 3, source = 0, target = 1, cmap = py.cm.autumn):
376-
for i in range(3):
377-
self.ax[target,i].contour(self.imgs[source][i].get_array(), N, cmap = cmap)
378-
self.fig.canvas.draw()
389+
def add_contour(self, source, target, levels, contour_kwargs):
390+
self.contour_configs.append([source, target, levels, contour_kwargs])
391+
self.redraw()
379392

380393
#------------------------------------------------------------------------
381-
def remove_contour(self, target):
382-
for i in range(3):
383-
for col in self.ax[target,i].collections:
384-
col.remove()
385-
# a 2nd loop is needed to remove the last element (not clear why)
386-
for col in self.ax[target,i].collections:
387-
col.remove()
388-
389-
self.fig.canvas.draw()
394+
def remove_contour(self, k):
395+
if k < len(self.contour_configs):
396+
cfg = self.contour_configs[k]
397+
for i in range(3):
398+
# remove drawn contour lines first
399+
while(len(self.ax[cfg[1],i].collections) > 0):
400+
for col in self.ax[cfg[1],i].collections:
401+
col.remove()
402+
self.contour_configs.pop(k)
403+
self.redraw()
390404

391405
#------------------------------------------------------------------------
392406
def onkeypress(self,event):

0 commit comments

Comments
 (0)