From 7b90f8d79c5733d3a4818a39390cd7a7935ec0b8 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Tue, 26 Dec 2023 13:15:20 +0000 Subject: [PATCH] Add support for linear sizing of layers. --- glue_ar/scatter.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/glue_ar/scatter.py b/glue_ar/scatter.py index 749fd77..46b43e2 100644 --- a/glue_ar/scatter.py +++ b/glue_ar/scatter.py @@ -1,5 +1,4 @@ -from math import floor - +from numpy import isnan, ones import pyvista as pv from glue_ar.utils import layer_color, xyz_bounds, xyz_for_layer @@ -35,6 +34,8 @@ def scatter_layer_as_glyphs(viewer_state, layer_state, glyph): } +# This function creates a multiblock mesh for a given scatter layer +# Everything is scaled into clip space for better usability with e.g. model-viewer def scatter_layer_as_multiblock(viewer_state, layer_state, theta_resolution=8, phi_resolution=8, @@ -46,8 +47,24 @@ def scatter_layer_as_multiblock(viewer_state, layer_state, scaled=scaled) bounds = xyz_bounds(viewer_state) factor = max((abs(b[1] - b[0]) for b in bounds)) - radius = (layer_state.size_scaling * layer_state.size) / factor - spheres = [pv.Sphere(center=p, radius=radius, phi_resolution=phi_resolution, theta_resolution=theta_resolution) for p in data] + if layer_state.size_mode == "Fixed": + radius = (layer_state.size_scaling * layer_state.size) / factor + spheres = [pv.Sphere(center=p, radius=radius, + phi_resolution=phi_resolution, + theta_resolution=theta_resolution) for p in data] + else: + # The specific size calculation is take from the scatter layer artist + size_data = layer_state.layer[layer_state.size_attribute].ravel() + if layer_state.size_vmax == layer_state.size_vmin: + sizes = ones(size_data.shape) * 10 + else: + sizes = (20 * (size_data - layer_state.size_vmin) / + (layer_state.size_vmax - layer_state.size_vmin)) + sizes *= (layer_state.size_scaling / factor) + sizes[isnan(size_data)] = 0. + spheres = [pv.Sphere(center=p, radius=r, + phi_resolution=phi_resolution, + theta_resolution=theta_resolution) for p, r in zip(data, sizes)] blocks = pv.MultiBlock(spheres) geometry = blocks.extract_geometry()