Skip to content
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

[WIP] Update highlighted points when time changes #96

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
// PointCanvas is a Three.js canvas, updated via reducer
const [canvas, dispatchCanvas, sceneDivRef] = usePointCanvas(initialViewerState);
const numTracksLoaded = canvas.tracks.size;
const numPointsHighlighted = canvas.selectedPointIndices.length;
const trackHighlightLength = canvas.maxTime - canvas.minTime;

// this state is pure React
Expand Down Expand Up @@ -184,7 +185,7 @@
},
);
// TODO: add missing dependencies
}, [canvas.selectedPoints]);

Check warning on line 188 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / lint-and-test

React Hook useEffect has missing dependencies: 'canvas', 'dispatchCanvas', and 'trackManager'. Either include them or remove the dependency array

// playback time points
// TODO: this is basic and may drop frames
Expand Down Expand Up @@ -245,7 +246,8 @@
clearTracks={() => {
dispatchCanvas({ type: ActionType.REMOVE_ALL_TRACKS });
}}
numSelectedCells={numTracksLoaded}
numTracksLoaded={numTracksLoaded}
numPointsHighlighted={numPointsHighlighted}
trackManager={trackManager}
pointBrightness={canvas.pointBrightness}
setPointBrightness={(brightness: number) => {
Expand Down
10 changes: 7 additions & 3 deletions src/components/CellControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { TrackManager } from "@/lib/TrackManager";

interface CellControlsProps {
clearTracks: () => void;
numSelectedCells?: number;
numTracksLoaded?: number;
numPointsHighlighted?: number;
trackManager: TrackManager | null;
pointBrightness: number;
setPointBrightness: (value: number) => void;
Expand All @@ -31,7 +32,10 @@ export default function CellControls(props: CellControlsProps) {
</SmallCapsButton>
</Box>
<FontS>
<strong>{props.numSelectedCells ?? 0}</strong> cells selected
<strong>{props.numTracksLoaded ?? 0}</strong> cells selected
</FontS>
<FontS>
<strong>{props.numPointsHighlighted ?? 0}</strong> points highlighted
</FontS>
<label htmlFor="selection-mode-control">
<ControlLabel>Selection Mode</ControlLabel>
Expand All @@ -52,7 +56,7 @@ export default function CellControls(props: CellControlsProps) {
<InputSlider
id="points-brightness-slider"
aria-labelledby="input-slider-points-brightness-slider"
disabled={!props.numSelectedCells}
disabled={!props.numTracksLoaded}
min={0}
max={100}
valueLabelDisplay="on"
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/usePointCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function reducer(canvas: PointCanvas, action: PointCanvasAction): PointCanvas {
newCanvas.controls.autoRotate = action.autoRotate;
break;
case ActionType.HIGHLIGHT_POINTS:
newCanvas.selectedPointIndices = action.points;
newCanvas.highlightPoints(action.points);
break;
case ActionType.INIT_POINTS_GEOMETRY:
Expand All @@ -148,6 +149,7 @@ function reducer(canvas: PointCanvas, action: PointCanvasAction): PointCanvas {
case ActionType.POINTS_POSITIONS:
newCanvas.setPointsPositions(action.positions);
newCanvas.resetPointColors();
newCanvas.updateSelectedPointIndices();
break;
case ActionType.REMOVE_ALL_TRACKS:
newCanvas.removeAllTracks();
Expand Down
13 changes: 13 additions & 0 deletions src/lib/PointCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class PointCanvas {
readonly selector: PointSelector;

readonly tracks: Tracks = new Map();
selectedPointIndices: number[] = [];

showTracks = true;
showTrackHighlights = true;
Expand Down Expand Up @@ -124,6 +125,18 @@ export class PointCanvas {
this.controls.update();
};

updateSelectedPointIndices() {
const idOffset = this.curTime * this.maxPointsPerTimepoint;
this.selectedPointIndices = [];
for (const track of this.tracks.values()) {
if (this.curTime < track.startTime || this.curTime > track.endTime) continue;
const timeIndex = this.curTime - track.startTime;
const pointId = track.pointIds[timeIndex];
this.selectedPointIndices.push(pointId - idOffset);
}
this.highlightPoints(this.selectedPointIndices);
}

setCameraProperties(position?: Vector3, target?: Vector3) {
position && this.camera.position.set(position.x, position.y, position.z);
target && this.controls.target.set(target.x, target.y, target.z);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/three/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class Track extends Mesh {
type = "Track";
declare geometry: TrackGeometry;
declare material: TrackMaterial;
pointIds: Int32Array = new Int32Array(0);
startTime: number = -1;
endTime: number = -1;

static new(positions: Float32Array, pointIDs: Int32Array, maxPointsPerTimepoint: number) {
const geometry = new TrackGeometry();
Expand Down Expand Up @@ -44,6 +47,12 @@ export class Track extends Mesh {
track.geometry.setColors(colors);
track.geometry.setTime(time);
track.geometry.computeBoundingSphere();

track.pointIds = pointIDs;
if (time.length > 0) {
track.startTime = time[0];
track.endTime = time[time.length - 1];
}
return track;
}

Expand Down
Loading