-
Notifications
You must be signed in to change notification settings - Fork 8
add thumbnail_size property #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e480ddb
4b7d833
3637129
2669137
54e8663
f62aa09
82f2970
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ class VolumeSlicer: | |
scene_id (str): the scene that this slicer is part of. Slicers | ||
that have the same scene-id show each-other's positions with | ||
line indicators. By default this is derived from ``id(volume)``. | ||
thumbnail_size (int or None): linear size of low-resolution data to be | ||
uploaded to the client. If ``None``, the full-resolution data are | ||
uploaded client-side. | ||
|
||
This is a placeholder object, not a Dash component. The components | ||
that make up the slicer can be accessed as attributes. These must all | ||
|
@@ -73,6 +76,7 @@ def __init__( | |
axis=0, | ||
reverse_y=True, | ||
scene_id=None, | ||
thumbnail_size=32, | ||
): | ||
|
||
if not isinstance(app, Dash): | ||
|
@@ -97,6 +101,11 @@ def __init__( | |
self._other_axii = [0, 1, 2] | ||
self._other_axii.pop(self._axis) | ||
|
||
# Check and store thumbnail size | ||
if thumbnail_size is not None and not (isinstance(thumbnail_size, int)): | ||
raise ValueError("thumbnail_size must be an integer, or None.") | ||
self._thumbnail_size = thumbnail_size | ||
|
||
# Check and store scene id, and generate | ||
if scene_id is None: | ||
n = len(_assigned_scene_ids) | ||
|
@@ -120,7 +129,8 @@ def __init__( | |
|
||
# Build the slicer | ||
self._create_dash_components() | ||
self._create_server_callbacks() | ||
if thumbnail_size is not None: | ||
self._create_server_callbacks() | ||
self._create_client_callbacks() | ||
|
||
# Note(AK): we could make some stores public, but let's do this only when actual use-cases arise? | ||
|
@@ -137,6 +147,11 @@ def axis(self): | |
"""The axis at which the slicer is slicing.""" | ||
return self._axis | ||
|
||
@property | ||
def thumbnail_size(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we need a public prop for this. Or do you have a use-case in mind? |
||
"""Linear size of low-resolution data.""" | ||
return self._thumbnail_size | ||
|
||
@property | ||
def nslices(self): | ||
"""The number of slices for this slicer.""" | ||
|
@@ -260,12 +275,18 @@ def _create_dash_components(self): | |
info = self._slice_info | ||
|
||
# Prep low-res slices | ||
thumbnail_size = get_thumbnail_size(info["size"][:2], (32, 32)) | ||
if self._thumbnail_size is None: | ||
thumbnail_size = None | ||
info["lowres_size"] = info["size"] | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a check here to make |
||
thumbnail_size = get_thumbnail_size( | ||
info["size"][:2], (self._thumbnail_size, self._thumbnail_size) | ||
) | ||
info["lowres_size"] = thumbnail_size | ||
thumbnails = [ | ||
img_array_to_uri(self._slice(i), thumbnail_size) | ||
for i in range(info["size"][2]) | ||
] | ||
info["lowres_size"] = thumbnail_size | ||
|
||
# Create the figure object - can be accessed by user via slicer.graph.figure | ||
self._fig = fig = Figure(data=[]) | ||
|
@@ -324,7 +345,9 @@ def _create_dash_components(self): | |
self._overlay_data = Store(id=self._subid("overlay"), data=[]) | ||
|
||
# Slice data provided by the server | ||
self._server_data = Store(id=self._subid("server-data"), data="") | ||
self._server_data = Store( | ||
id=self._subid("server-data"), data={"index": -1, "slice": None} | ||
) | ||
|
||
# Store image traces for the slicer. | ||
self._img_traces = Store(id=self._subid("img-traces"), data=[]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feeling a bit uncomfortable about the
None
which is often used to denote a default value. What about justthumbnail
, which can be set toTrue
/False
, but also allowing an int with the size? Once we've fixed the anisotropy thing, the default size should be fine in nearly all cases.Let's also mention the default size here.