@@ -277,6 +277,9 @@ def __init__(self, vols,
277
277
self .l2x .append (self .axes [3 * i + 2 ].axvline (self .sl_y , color = 'r' ,ls = ls ))
278
278
self .l2y .append (self .axes [3 * i + 2 ].axhline (self .shape [self .iz ] - self .sl_z , color = 'r' ,ls = ls ))
279
279
280
+ # list for contour definitions
281
+ self .contour_configs = []
282
+
280
283
#------------------------------------------------------------------------
281
284
def update_colorbars (self ):
282
285
for i in range (self .n_vols ):
@@ -350,6 +353,17 @@ def redraw(self):
350
353
self .redraw_coronal ()
351
354
self .redraw_sagittal ()
352
355
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 ()
353
367
#------------------------------------------------------------------------
354
368
def recalculate_slices (self ):
355
369
if self .ndim == 3 :
@@ -372,21 +386,21 @@ def recalculate_slices(self):
372
386
self .fstr = ', ' + str (self .sl_t )
373
387
374
388
#------------------------------------------------------------------------
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 ()
379
392
380
393
#------------------------------------------------------------------------
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 ()
390
404
391
405
#------------------------------------------------------------------------
392
406
def onkeypress (self ,event ):
0 commit comments