Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions examples/egocap/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ The page is built for an operator mid-take: the cameras fill it, and everything
calibration files are an advisory item and takes are allowed; on, they fail and hold recording. A change is
followed by an immediate read of the checklist. The calibration tools are listed beneath it, each opening its
own dialog (see "Calibration tools" below).
- *Display* holds this browser's own choices: *Show the hand view* (see [Hand view](#hand-view)) and the side
panel's width, then the keyboard shortcuts. Nothing on it needs the control token.
- *Advanced* shows what the deployment runs with, read-only. Its *Capture checks* card names the thresholds takes are
judged by: whether a take marked bad is quarantined or flagged, the camera minimum rate, the frozen-stream limit,
the defaults file's name and SHA-256, and what the station file changed. They are set in files, never from the page.
Expand Down Expand Up @@ -376,8 +378,10 @@ The page is built for an operator mid-take: the cameras fill it, and everything
- **Control dock (bottom).** Record / Stop-Save / Discard are large; an unset operator or control-token field leads the dock,
and once set shrinks to a quiet line. The dock hides the recording panel's own header and status line, since the bar
above shows them, and the panel draws the last take's outcome above the cameras, not here.
- **Side panel (right).** Always showing: the 3D tracking view on top and the raw tracking tables and session details beneath
it (Details scrolls inside itself, so neither is pushed off the screen). **Drag the divider** between it and the main column
- **Side panel (right).** Always showing: the hand view on top while it is switched on, then the 3D tracking view, then
the raw tracking tables and session details (Details scrolls inside itself, so it and the 3D view are never pushed
off the screen; with the hand view above them a short window has no room for all three, and the side panel scrolls
to Details instead). **Drag the divider** between it and the main column
to choose its width -- pulling left widens the panel and narrows the cameras, status bar and controls, and the other way
round. The divider also works from the keyboard (focus it, then Left / Right arrows, Shift for bigger steps, Home / End for
the limits) and double-click resets it. The width is clamped between 400 px and 1000 px and never leaves the main column
Expand Down Expand Up @@ -565,6 +569,61 @@ EGOCAP_VISER_ENABLED=0 uv run uvicorn egocap_web.app:app --app-dir backend --por
- A failed or slow start of the view never stops capture or the page; the page shows the 3D view as unavailable with the
reason.

## Hand view

The side panel leads with a drawing of both hands as the gloves report them (`HandView.tsx`), the left hand on the
left. It is there to see at a glance that both gloves are tracking and that the drawing follows the fingers. It is a
panel of its own, never drawn over a camera picture, and it changes nothing in what is recorded.

- Each hand is drawn flat, seen from the back, wrist at the bottom and fingers up, at a size taken from the hand
itself. It shows how the fingers are bent, not where the hand is in the room: there is no floor and there are no
axes, and a hand that is moved, turned or flipped over without bending a finger is drawn exactly as before. A fist
is drawn at the open hand's scale, so closing the hand does not zoom in.
- The hands differ in colour and in the shape of their joints (discs on the left hand, diamonds on the right), and
each half is named under the drawing. A glove that sends nothing leaves a dashed outline and the words "No data
from the left glove" (or right). "Not enough valid joints from the left glove" means it reports, but not the wrist and
knuckles a drawing is built on. "Left hand, some joints missing" means the hand is drawn without the joints
flagged invalid: a dashed line bridges a gap, and nothing is drawn past the last valid joint of a finger. The
drawing's text alternative says the same for both hands.
- **Show the hand view** in Settings, Display, switches it on and off, and *Hide* on the panel flips the same
setting. The choice is remembered in this browser (`localStorage`) and is on until someone switches it off. Off,
the panel is gone and the side panel is the 3D view above Details, as without it.
- It draws from the tracking samples the Details tables list (`hand_left.*` and `hand_right.*`: the 26 OpenXR
joints of each hand, as positions in metres in the stream's reference space with a validity flag per joint), and
like them it shows nothing from a sample older than two seconds or from a feed that is not live.

How a hand is laid flat (`handProjection.ts`):

- The frame comes from three positions: the wrist and the index and little-finger knuckles. "Up" runs from the
wrist to the midpoint of the two knuckles, "across" is the line between them with its "up" part removed, and
every joint is projected onto those two. Joint orientations are not used: a glove passes its maker's bone
rotations through, and their axes are not the ones OpenXR gives a tracked hand.
- Only differences and dot products of positions go into it, so the result does not depend on the tracking space's
axes or origin. The price is that three positions cannot tell a hand from its mirror image: the side the stream
names decides the mirroring, so `hand_left` is always drawn as a left hand.
- The size is the longest wrist-to-fingertip chain measured along its bones, eased from sample to sample. Bone
lengths do not change as fingers bend. The scale is only ever reduced from that, and only to keep a joint from
leaving its half of the drawing.

### What has not been checked on real gloves

The finger chains (`HAND_FINGER_CHAINS` and `HAND_KNUCKLE_ROW` in `handJoints.ts`) are the OpenXR joint order taken
at its word, and `handJoints.test.ts` holds them to a synthetic hand, not to a glove. With gloves on, each of
these takes under a minute:

- **Joint order.** Hold both hands open with the fingers spread. Each finger must be one line from the wrist to its
tip, the joints evenly along it, with no bone crossing to another finger. Then bend one finger at a time, thumb
to little finger: only that finger's line may shorten, in that order across the drawing. Crossed bones or the
wrong finger moving mean the glove's joints arrive in another order: correct the tables in `handJoints.ts`.
- **Which hand is which.** Keep the right hand still and wiggle the left fingers: only the left half, the one drawn
in discs, may move. Then the other hand.
- **Thumb side.** With both hands open, both thumbs are drawn pointing toward the middle of the panel. A thumb
pointing outward means the index and little-finger knuckles are not the joints `HAND_KNUCKLE_ROW` names.
- **Axes.** Turn an open hand palm up, then palm down, then point the fingers at the floor: the drawing must stay
as it is. If it leans or flattens as the hand turns, a joint the frame is built from is misnamed (the wrist or a
knuckle).
- **Size.** Make a fist and open it: the palm must keep its size while the fingers fold toward it.

## Voice commands (optional)

The recording strip supports hands-free voice control via the browser's [SpeechRecognition
Expand Down
78 changes: 75 additions & 3 deletions examples/egocap/frontend/src/App.operatorLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* The cameras-first operator page: the status bar, the camera stage, the control dock and the side drawer that
* holds the 3D view and raw data. useCaptureSession is mocked so each test controls the snapshot directly.
* holds the hand view, the 3D view and raw data. useCaptureSession is mocked so each test controls the snapshot directly.
*/
import { afterEach, describe, expect, it, vi, type Mock } from "vitest";
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
Expand All @@ -14,6 +14,7 @@ import type { CalibrationDialogProps } from "./calibrationTypes";
import type { PreviewSnapshot } from "./captureProtocol";
import { DAY_REPORT_FIXTURE, UPTIME_FIXTURE } from "./dayReportTestDoubles";
import { GLOVES_MISSING } from "./glovesTestDoubles";
import { ABSENT_HAND, handDisplay, handSample, syntheticHand } from "./handTestDoubles";
import { CAMERA_STOPPED, HEADSET_FROZEN, RECOVER_RUNS_CHECKS, SESSION, earlierTake, pendingTake, takeResult } from "./recordingTestDoubles";
import type { RecordingSnapshot } from "./recordingTypes";
import { OPERATOR_SETTINGS_FIXTURE, STATIONS_FIXTURE, TOOLS_FIXTURE } from "./settingsTestDoubles";
Expand Down Expand Up @@ -123,10 +124,10 @@ describe("operator page layout", () => {
expect(screen.getByRole("separator", { name: "Resize side panel" })).not.toBeNull();
});

it("always shows the 3D view above the details, with nothing to toggle", () => {
it("always shows the side panel, the 3D view above the details under the hand view, with no drawer to open", () => {
const { container } = mount({ snapshot: snapshot({ visualization: { status: "ready", url: "http://lab:8085/", diagnostic: null } }) });
const panels = Array.from(container.querySelectorAll(".op-sidebar .op-panel")).map((p) => p.getAttribute("aria-label"));
expect(panels).toEqual(["3D view", "Details"]);
expect(panels).toEqual(["Hand view", "3D view", "Details"]);
expect(container.querySelector(".op-sidebar iframe")).not.toBeNull();
expect(screen.getByText("Tracking data")).not.toBeNull();
expect(screen.queryByRole("button", { name: "Details" })).toBeNull();
Expand Down Expand Up @@ -172,6 +173,77 @@ describe("operator page layout", () => {
});
});

/** The side panel's sections, top to bottom. */
const sidePanels = (container: HTMLElement) => Array.from(container.querySelectorAll(".op-sidebar .op-panel")).map((panel) => panel.getAttribute("aria-label"));

describe("hand view on the recording screen", () => {
const hands = () => handSample(handDisplay(syntheticHand("left")), handDisplay(syntheticHand("right")));

it("leads the side panel, in a panel of its own, and draws nothing on the camera stage", () => {
const { container } = mount({ trackingSample: hands() });
expect(sidePanels(container)).toEqual(["Hand view", "3D view", "Details"]);
expect(screen.getByRole("complementary", { name: "Hand view, 3D view and details" })).not.toBeNull();
expect(screen.getByRole("img", { name: "Both hands as the gloves report them. Left hand tracked; right hand tracked." })).not.toBeNull();
expect(container.querySelector(".op-stage svg")).toBeNull();
expect(container.querySelector(".op-stage .hand-view")).toBeNull();
});

it("says which glove sends nothing", () => {
mount({ trackingSample: handSample(ABSENT_HAND, handDisplay(syntheticHand("right"))) });
expect(screen.getByRole("img", { name: "Both hands as the gloves report them. The left glove sends nothing; right hand tracked." })).not.toBeNull();
expect(screen.getByText("No data from the left glove")).not.toBeNull();
});

it("does not draw hands from a feed that is no longer live", () => {
mount({ phase: "reconnecting", trackingSample: hands() });
expect(screen.getByRole("img", { name: /The left glove sends nothing; the right glove sends nothing\.$/ })).not.toBeNull();
});

it("hides from its own button, remembers that, and hands focus to the side panel it was in", () => {
const { container } = mount({ trackingSample: hands() });
expect(container.querySelector(".op-sidebar [role='status']")?.textContent).toBe("");
const hide = screen.getByRole("button", { name: "Hide the hand view" });
hide.focus();
fireEvent.click(hide);
expect(sidePanels(container)).toEqual(["3D view", "Details"]);
expect(container.querySelector(".hand-view")).toBeNull();
expect(window.localStorage.getItem("egocap.handView")).toBe("off");
// The button is gone with the panel: focus is on the side panel, not dropped to the top of the page.
expect(document.activeElement).toBe(screen.getByRole("complementary", { name: "3D view and details" }));
expect(container.querySelector(".op-sidebar [role='status']")?.textContent).toBe("The hand view is hidden. Show it again in Settings, under Display.");
// The rest of the page is as it was.
expect(container.querySelector(".op-stage .camera-grid")).not.toBeNull();
expect(container.querySelector(".op-dock .recording-panel")).not.toBeNull();
});

it("stays hidden on the next load, and comes back from Settings, Display", () => {
window.localStorage.setItem("egocap.handView", "off");
const { container } = mount({ trackingSample: hands() });
expect(sidePanels(container)).toEqual(["3D view", "Details"]);
fireEvent.click(screen.getByRole("button", { name: "Settings" }));
const dialog = screen.getByRole("dialog", { name: "Settings" });
fireEvent.click(within(dialog).getByRole("button", { name: "Display" }));
const setting = within(dialog).getByRole("checkbox", { name: "Show the hand view" }) as HTMLInputElement;
expect(setting.checked).toBe(false);
fireEvent.click(setting);
expect(setting.checked).toBe(true);
// The page behind the dialog follows at once, and the choice is remembered.
expect(sidePanels(container)).toEqual(["Hand view", "3D view", "Details"]);
expect(window.localStorage.getItem("egocap.handView")).toBe("on");
fireEvent.click(setting);
expect(sidePanels(container)).toEqual(["3D view", "Details"]);
expect(window.localStorage.getItem("egocap.handView")).toBe("off");
});

it("shows the setting switched off after Hide was pressed", () => {
mount({ trackingSample: hands() });
fireEvent.click(screen.getByRole("button", { name: "Hide the hand view" }));
fireEvent.click(screen.getByRole("button", { name: "Settings" }));
fireEvent.click(within(screen.getByRole("dialog", { name: "Settings" })).getByRole("button", { name: "Display" }));
expect((screen.getByRole("checkbox", { name: "Show the hand view" }) as HTMLInputElement).checked).toBe(false);
});
});

/** Answer the routes a test names and leave every other request unanswered, as a backend that is still starting would. */
function stubRoutes(routes: Record<string, unknown>) {
const fetched = vi.fn(async (url: string, _init?: RequestInit) => (url in routes ? new Response(JSON.stringify(routes[url]), { status: 200 }) : new Response("{}", { status: 503 })));
Expand Down
35 changes: 32 additions & 3 deletions examples/egocap/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
saveSidebarWidth,
} from "./sidebarWidth";
import { deviceTone, retainedTone, type Tone } from "./deviceHealth";
import { HandView } from "./HandView";
import { loadHandViewShown, saveHandViewShown } from "./handViewSetting";
import { PoseViserPanel } from "./PoseViserPanel";
import { RecordingPanel } from "./RecordingPanel";
import { RectificationDialog } from "./RectificationDialog";
Expand Down Expand Up @@ -476,8 +478,9 @@ export default function App() {
// A live take frames the cameras in red, so the state reads from across the room; never from a stale feed.
const recording = presentation.live && recordingSnapshot?.episodePhase === "RECORDING";
const [panelPhase, setPanelPhase] = useState<RecordingPhase>("idle");
// The side panel is always showing: the 3D view above the raw data. Its width is the operator's to choose by
// dragging the divider; the cameras, status bar and controls take whatever it leaves. The choice is remembered.
// The side panel is always showing: the hand view while it is on, then the 3D view above the raw data. Its width
// is the operator's to choose by dragging the divider; the cameras, status bar and controls take whatever it
// leaves. The choice is remembered.
const [sidebarWidth, setSidebarWidth] = useState(() => clampSidebarWidth(loadSidebarWidth(), window.innerWidth));
const [resizing, setResizing] = useState(false);
// The latest clamped width, readable from event handlers without a stale closure (a drag end must save the final value).
Expand All @@ -495,6 +498,21 @@ export default function App() {
window.addEventListener("resize", refit);
return () => window.removeEventListener("resize", refit);
}, []);
// The hand view is this browser's choice, flipped by the setting in Settings and by the panel's own Hide button.
const [handViewShown, setHandViewShown] = useState(loadHandViewShown);
const sidebarRef = useRef<HTMLElement | null>(null);
/** Show or hide the hand view and remember the choice. */
const showHandView = useCallback((shown: boolean) => {
setHandViewShown(shown);
saveHandViewShown(shown);
}, []);
/** Hide the hand view from its own button. The button goes with the panel, so focus is handed to the side
* panel it was in: left on a removed element it would fall back to the top of the page. The side panel is
* not a button, so Space still switches voice commands afterwards. */
const hideHandView = useCallback(() => {
showHandView(false);
sidebarRef.current?.focus();
}, [showHandView]);
const unavailable = response === null && feedHealth === "unavailable";
// At most one dialog is open over the page; while one is, the page behind it takes no input. A calibration
// tool is one of them: it is opened from Settings and takes its place.
Expand Down Expand Up @@ -610,6 +628,8 @@ export default function App() {
sidebarWidth={sidebarWidth}
sidebarDefault={SIDEBAR_DEFAULT_PX}
onResetSidebar={() => applyWidth(SIDEBAR_DEFAULT_PX, true)}
handViewShown={handViewShown}
onHandViewShown={showHandView}
controlToken={controlToken}
cameraSources={cameraSources}
setup={setup}
Expand Down Expand Up @@ -687,7 +707,16 @@ export default function App() {
if (!dragging) saveSidebarWidth(sidebarWidthRef.current);
}}
/>
<aside className="op-sidebar" aria-label="3D view and details">
<aside ref={sidebarRef} tabIndex={-1} className="op-sidebar" aria-label={handViewShown ? "Hand view, 3D view and details" : "3D view and details"}>
{handViewShown && (
<section className="op-panel op-panel--hands" aria-label="Hand view">
<HandView trackingSample={presentation.live ? trackingSample : null} onHide={hideHandView} />
</section>
)}
{/* Always in the page, so a screen reader hears the change when the panel goes and learns where to bring it back. */}
<p className="visually-hidden" role="status">
{handViewShown ? "" : "The hand view is hidden. Show it again in Settings, under Display."}
</p>
<section className="op-panel op-panel--3d" aria-label="3D view">
<PoseViserPanel
visualization={snapshot?.visualization ?? null}
Expand Down
Loading
Loading