@@ -30,6 +30,10 @@ class VolumeSlicer:
30
30
scene_id (str): the scene that this slicer is part of. Slicers
31
31
that have the same scene-id show each-other's positions with
32
32
line indicators. By default this is derived from ``id(volume)``.
33
+ thumbnail (int or bool): linear size of low-resolution data to be
34
+ uploaded to the client. If ``False``, the full-resolution data are
35
+ uploaded client-side. If ``True`` (default), a default value of 32 is
36
+ used.
33
37
34
38
This is a placeholder object, not a Dash component. The components
35
39
that make up the slicer can be accessed as attributes. These must all
@@ -73,6 +77,7 @@ def __init__(
73
77
axis = 0 ,
74
78
reverse_y = True ,
75
79
scene_id = None ,
80
+ thumbnail = True ,
76
81
):
77
82
78
83
if not isinstance (app , Dash ):
@@ -97,6 +102,16 @@ def __init__(
97
102
self ._other_axii = [0 , 1 , 2 ]
98
103
self ._other_axii .pop (self ._axis )
99
104
105
+ # Check and store thumbnail
106
+ if not (isinstance (thumbnail , (int , bool ))):
107
+ raise ValueError ("thumbnail must be a boolean or an integer." )
108
+ # No thumbnail if thumbnail size is larger than image size
109
+ if isinstance (thumbnail , int ) and thumbnail > np .max (volume .shape ):
110
+ thumbnail = False
111
+ if thumbnail is True :
112
+ thumbnail = 32 # default size
113
+ self ._thumbnail = thumbnail
114
+
100
115
# Check and store scene id, and generate
101
116
if scene_id is None :
102
117
n = len (_assigned_scene_ids )
@@ -120,7 +135,8 @@ def __init__(
120
135
121
136
# Build the slicer
122
137
self ._create_dash_components ()
123
- self ._create_server_callbacks ()
138
+ if thumbnail :
139
+ self ._create_server_callbacks ()
124
140
self ._create_client_callbacks ()
125
141
126
142
# Note(AK): we could make some stores public, but let's do this only when actual use-cases arise?
@@ -260,12 +276,18 @@ def _create_dash_components(self):
260
276
info = self ._slice_info
261
277
262
278
# Prep low-res slices
263
- thumbnail_size = get_thumbnail_size (info ["size" ][:2 ], (32 , 32 ))
279
+ if self ._thumbnail is False :
280
+ thumbnail_size = None
281
+ info ["lowres_size" ] = info ["size" ]
282
+ else :
283
+ thumbnail_size = get_thumbnail_size (
284
+ info ["size" ][:2 ], (self ._thumbnail , self ._thumbnail )
285
+ )
286
+ info ["lowres_size" ] = thumbnail_size
264
287
thumbnails = [
265
288
img_array_to_uri (self ._slice (i ), thumbnail_size )
266
289
for i in range (info ["size" ][2 ])
267
290
]
268
- info ["lowres_size" ] = thumbnail_size
269
291
270
292
# Create the figure object - can be accessed by user via slicer.graph.figure
271
293
self ._fig = fig = Figure (data = [])
@@ -324,7 +346,9 @@ def _create_dash_components(self):
324
346
self ._overlay_data = Store (id = self ._subid ("overlay" ), data = [])
325
347
326
348
# Slice data provided by the server
327
- self ._server_data = Store (id = self ._subid ("server-data" ), data = "" )
349
+ self ._server_data = Store (
350
+ id = self ._subid ("server-data" ), data = {"index" : - 1 , "slice" : None }
351
+ )
328
352
329
353
# Store image traces for the slicer.
330
354
self ._img_traces = Store (id = self ._subid ("img-traces" ), data = [])
0 commit comments