firmament: mark interpolated LEDs in the preview
Assisted-by: Claude Opus 5.5 via Claude Code
diff --git a/firmament/DESIGN.md b/firmament/DESIGN.md
index a84e06b..20243a0 100644
--- a/firmament/DESIGN.md
+++ b/firmament/DESIGN.md
@@ -153,7 +153,9 @@ each image and where it was actually seen.
A 3D plot of the points, colored by confidence, so bad ones are easy to spot.
Later, a web or native app for exploring the map, with interpolated LEDs shown
-apart from seen ones.
+apart from seen ones. For now, `firmament stream --preview` shows the map in
+Rerun's viewer, with interpolated LEDs in their own color and entity, but no
+confidence yet.
### 6. Streamer
diff --git a/firmament/README.md b/firmament/README.md
index 8e841af..c8ad2e1 100644
--- a/firmament/README.md
+++ b/firmament/README.md
@@ -90,6 +90,11 @@ uv run firmament stream examples/rainbow.py --map leds.csv --host wled.local --p
```
Leave out `--host` to only preview, or `--preview` to only light the LEDs.
+The preview marks the LEDs the solver interpolated rather than saw. Unlit,
+they're purple dots instead of gray, and lit, they're drawn flat instead of
+shaded. They're logged under `leds/interpolated` and `sockets/interpolated`,
+so you can hide them in the viewer's blueprint panel, and hovering over a dot
+shows its index and view count.
`stream` reloads the effect each time you save it. If a save fails to load
or raises an error, `stream` prints the error and keeps playing the last
version that worked. `--brightness` scales the colors sent to WLED, from 0 to
diff --git a/firmament/src/firmament/preview.py b/firmament/src/firmament/preview.py
index 6eb5f57..5dcd378 100644
--- a/firmament/src/firmament/preview.py
+++ b/firmament/src/firmament/preview.py
@@ -7,31 +7,63 @@ import rerun as rr
from firmament.positions import Led
# Unlit LEDs as faint dots, so the strand's shape stays visible when the effect is dark.
-SOCKET_COLOR = (60, 60, 60)
+# Interpolated ones get their own color, since their positions are guesses.
+SOCKET_COLORS = {"seen": (60, 60, 60), "interpolated": (150, 50, 150)}
SOCKET_RADIUS = 0.006
LED_RADIUS = 0.015
+LED_SHADING = {
+ "seen": rr.components.PointShading.Gradient,
+ "interpolated": rr.components.PointShading.Flat,
+}
+
+
+def groups(leds: Sequence[Led]) -> dict[str, list[int]]:
+ """Indices into `leds` of the LEDs the solver saw and the ones it interpolated."""
+ return {
+ "seen": [i for i, led in enumerate(leds) if led.views > 0],
+ "interpolated": [i for i, led in enumerate(leds) if led.views == 0],
+ }
+
+
+def label(led: Led) -> str:
+ if led.views == 0:
+ return f"LED {led.index}, interpolated"
+ return f"LED {led.index}, {led.views} view{'' if led.views == 1 else 's'}"
class Preview:
- def __init__(self, leds: Sequence[Led]) -> None:
- rr.init("firmament", spawn=True)
+ def __init__(self, leds: Sequence[Led], *, spawn: bool = True) -> None:
+ rr.init("firmament", spawn=spawn)
rr.log("/", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
self._positions = [(led.x, led.y, led.z) for led in leds]
- rr.log(
- "sockets",
- rr.Points3D(self._positions, colors=SOCKET_COLOR, radii=SOCKET_RADIUS),
- static=True,
- )
+ self._labels = [label(led) for led in leds]
+ self._groups = {name: indices for name, indices in groups(leds).items() if indices}
+ for name, indices in self._groups.items():
+ rr.log(
+ f"sockets/{name}",
+ rr.Points3D(
+ [self._positions[i] for i in indices],
+ colors=SOCKET_COLORS[name],
+ radii=SOCKET_RADIUS,
+ labels=[self._labels[i] for i in indices],
+ show_labels=False,
+ ),
+ static=True,
+ )
def show(self, t: float, frame: bytes) -> None:
"""Show one unscaled RGB frame at `t` seconds; black LEDs are left out."""
rr.set_time("t", duration=t)
- lit = [i for i in range(len(self._positions)) if any(frame[3 * i : 3 * i + 3])]
- rr.log(
- "leds",
- rr.Points3D(
- [self._positions[i] for i in lit],
- colors=[tuple(frame[3 * i : 3 * i + 3]) for i in lit],
- radii=LED_RADIUS,
- ),
- )
+ for name, indices in self._groups.items():
+ lit = [i for i in indices if any(frame[3 * i : 3 * i + 3])]
+ rr.log(
+ f"leds/{name}",
+ rr.Points3D(
+ [self._positions[i] for i in lit],
+ colors=[tuple(frame[3 * i : 3 * i + 3]) for i in lit],
+ radii=LED_RADIUS,
+ labels=[self._labels[i] for i in lit],
+ show_labels=False,
+ point_shading=LED_SHADING[name],
+ ),
+ )
diff --git a/firmament/tests/test_preview.py b/firmament/tests/test_preview.py
new file mode 100644
index 0000000..015486f
--- /dev/null
+++ b/firmament/tests/test_preview.py
@@ -0,0 +1,20 @@
+from firmament.positions import Led
+from firmament.preview import groups, label
+
+
+def _led(index: int, views: int) -> Led:
+ return Led(index, 0.0, 0.0, 0.0, views)
+
+
+def test_groups_separate_interpolated_leds():
+ leds = [_led(0, 2), _led(1, 0), _led(2, 1), _led(3, 0)]
+
+ assert groups(leds) == {"seen": [0, 2], "interpolated": [1, 3]}
+
+
+def test_label_says_how_each_led_was_placed():
+ assert [label(_led(4, v)) for v in (0, 1, 3)] == [
+ "LED 4, interpolated",
+ "LED 4, 1 view",
+ "LED 4, 3 views",
+ ]