Skip to content

Commit

Permalink
points2gfx: correctly parse multiple colors
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Apr 27, 2024
1 parent 24d70db commit f3220ac
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions octarine/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,40 @@ def points2gfx(points, color, size=2, marker=None, size_space="screen"):

geometry_kwargs = {}
material_kwargs = {}
# material_kwargs["pick_write"] = True # for picking

# Parse sizes
if utils.is_iterable(size):
if len(size) != len(points):
raise ValueError(
"Expected `size` to be a single value or "
"an array of the same length as `points`."
)
geometry_kwargs["sizes"] = np.asarray(size).astype(np.float32, copy=False)
material_kwargs["size_mode"] = 'vertex'
material_kwargs["size_mode"] = "vertex"
else:
material_kwargs["size"] = size

# Parse color(s)
if isinstance(color, np.ndarray) and color.ndim == 2:
# If colors are provided for each node we have to make sure
# that we also include `None` for the breaks in the segments
n_points = len(points)
if len(color) != n_points:
raise ValueError(f"Got {len(color)} colors for {n_points} points.")
color = color.astype(np.float32, copy=False)
geometry_kwargs["colors"] = color
material_kwargs["color_mode"] = "vertex"
else:
if isinstance(color, np.ndarray):
color = color.astype(np.float32, copy=False)
material_kwargs["color"] = color

if marker is None:
material = gfx.PointsMaterial(
color=color, size_space=size_space, **material_kwargs
)
material = gfx.PointsMaterial(size_space=size_space, **material_kwargs)
else:
material = gfx.PointsMarkerMaterial(
color=color, marker=marker, size_space=size_space, **material_kwargs
marker=marker, size_space=size_space, **material_kwargs
)

vis = gfx.Points(gfx.Geometry(positions=points, **geometry_kwargs), material)
Expand Down

0 comments on commit f3220ac

Please sign in to comment.