mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw CCTV camera icons through the renderer ports and take rendering.js off the Cesium list
The camera icons are now a draw-port icon set kept by an icon book; only icons a view pass or restyle changes are written, in one write per pass. Picks read the renderer's hit, the view pass and focus pass project through the camera pose (geo/frustum.js poseProjector, matching the renderer's projection and near clip) and the query port, and tile readiness for ground sampling comes from the globe port.
This commit is contained in:
1 parent
2a607ec4d8
commit
1d08043bf9
20 files changed
+810
-457
No files matched your search
+27
-24
@@ -349,6 +349,8 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
|
||||
test('camera icons are violet for video feeds, cyan for stills, amber when active', () => {
|
||||
const record = (id, feedType) => ({
|
||||
camera: { ...UNCLAMPED_CAMERA, id, feedType, groundElevationM: 0 },
|
||||
// Every catalog record is placed as it is made, and drawn there.
|
||||
position: { x: 6378137, y: 0, z: 0 },
|
||||
coverageEntities: [],
|
||||
projection: null,
|
||||
});
|
||||
@@ -370,18 +372,12 @@ test('camera icons are violet for video feeds, cyan for stills, amber when activ
|
||||
});
|
||||
refreshCoverageStyles();
|
||||
const icons = _cctvIconsForTest();
|
||||
const color = (record) => icons.color(icons.row(record.camera.id));
|
||||
const bytes = (c) =>
|
||||
[c.red, c.green, c.blue, c.alpha].map(Cesium.Color.floatToByte);
|
||||
const policyBytes = (rgba) => rgba.map(Cesium.Color.floatToByte);
|
||||
assert.deepEqual(bytes(color(idleVideo)), policyBytes(LIVE_CAMERA_COLOR));
|
||||
assert.deepEqual(bytes(color(idleStill)), policyBytes(IDLE_CAMERA_COLOR));
|
||||
assert.deepEqual(
|
||||
bytes(color(activeVideo)),
|
||||
policyBytes(ACTIVE_CAMERA_COLOR),
|
||||
);
|
||||
assert.equal(icons.scale(icons.row(activeVideo.camera.id)), 1.25);
|
||||
assert.equal(icons.scale(icons.row(idleVideo.camera.id)), 1);
|
||||
const color = (record) => icons.item(record.camera.id).color;
|
||||
assert.deepEqual(color(idleVideo), LIVE_CAMERA_COLOR);
|
||||
assert.deepEqual(color(idleStill), IDLE_CAMERA_COLOR);
|
||||
assert.deepEqual(color(activeVideo), ACTIVE_CAMERA_COLOR);
|
||||
assert.equal(icons.item(activeVideo.camera.id).scale, 1.25);
|
||||
assert.equal(icons.item(idleVideo.camera.id).scale, 1);
|
||||
} finally {
|
||||
_setCctvCoverageStateForTest({ enabled: false });
|
||||
unbind();
|
||||
@@ -1154,29 +1150,36 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
|
||||
);
|
||||
assert.ok(coverage.items.has('cctv-shared-id-cap'));
|
||||
const lineHit = (set, id) => ({
|
||||
id: { set, id, meta: { cameraId: 'shared-id' } },
|
||||
set,
|
||||
id,
|
||||
meta: { cameraId: 'shared-id' },
|
||||
surface: false,
|
||||
});
|
||||
assert.equal(
|
||||
_extractPickedCameraIdForTest({
|
||||
set: _cctvIconsForTest().setId,
|
||||
id: 'shared-id',
|
||||
iconSet: _cctvIconsForTest(),
|
||||
primitive: { id: 'shared-id' },
|
||||
surface: false,
|
||||
}),
|
||||
'shared-id',
|
||||
);
|
||||
assert.equal(
|
||||
_extractPickedCameraIdForTest({
|
||||
set: 'sibling:1:icons',
|
||||
id: 'shared-id',
|
||||
iconSet: {},
|
||||
primitive: { id: 'shared-id' },
|
||||
surface: false,
|
||||
}),
|
||||
null,
|
||||
'a sibling primitive with the same canonical ID cannot activate CCTV',
|
||||
"a sibling set's icon with the same canonical ID cannot activate CCTV",
|
||||
);
|
||||
assert.equal(
|
||||
_extractPickedCameraIdForTest({ id: { id: 'shared-id' } }),
|
||||
_extractPickedCameraIdForTest({
|
||||
set: _cctvIconsForTest().setId,
|
||||
id: 'not-a-camera',
|
||||
surface: false,
|
||||
}),
|
||||
null,
|
||||
'a sibling Entity with the same canonical ID cannot activate CCTV',
|
||||
'an id the icon book does not draw is not a camera',
|
||||
);
|
||||
assert.equal(
|
||||
_extractPickedCameraIdForTest(
|
||||
@@ -1194,10 +1197,10 @@ test('CCTV camera extraction requires layer ownership, not a colliding sibling I
|
||||
);
|
||||
assert.equal(
|
||||
_extractPickedCameraIdForTest({
|
||||
id: {
|
||||
id: 'sibling-entity',
|
||||
properties: { cctvCameraId: 'shared-id' },
|
||||
},
|
||||
set: 'sibling:1:entities',
|
||||
id: 'sibling-entity',
|
||||
meta: { cctvCameraId: 'shared-id', cameraId: 'shared-id' },
|
||||
surface: false,
|
||||
}),
|
||||
null,
|
||||
'a sibling cannot impersonate CCTV by copying its property shape',
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
// near the screen show, a zoomed-out view keeps one camera per world-anchored
|
||||
// cell, and the layer's UI state never rebuilds every camera for a listener
|
||||
// that does not read the list.
|
||||
import { test } from 'node:test';
|
||||
import { afterEach, test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { fakeCameraPort } from '../testSupport/fakeCameraPort.mjs';
|
||||
import cctvLayer, {
|
||||
_cctvIconsForTest,
|
||||
_setCctvCoverageStateForTest,
|
||||
@@ -15,18 +17,10 @@ import cctvLayer, {
|
||||
const WIDTH = 800;
|
||||
const HEIGHT = 600;
|
||||
|
||||
/**
|
||||
* Records at the given [lon, lat] degrees near the origin, each drawn at the
|
||||
* screen point `screenAt` gives it (default: the middle of the screen).
|
||||
*/
|
||||
function recordsAt(
|
||||
lonLats,
|
||||
screenAt = () => ({ x: WIDTH / 2, y: HEIGHT / 2 }),
|
||||
) {
|
||||
const screenByPosition = new Map();
|
||||
/** Records at the given [lon, lat] degrees near the origin. */
|
||||
function recordsAt(lonLats) {
|
||||
const records = lonLats.map(([lon, lat], index) => {
|
||||
const position = Cesium.Cartesian3.fromDegrees(lon, lat, 10);
|
||||
screenByPosition.set(position, screenAt(index));
|
||||
return {
|
||||
camera: {
|
||||
id: `cam-${index}`,
|
||||
@@ -40,42 +34,62 @@ function recordsAt(
|
||||
rangeM: 145,
|
||||
mountHeightM: 8,
|
||||
},
|
||||
position,
|
||||
position: { x: position.x, y: position.y, z: position.z },
|
||||
coverageEntities: [],
|
||||
projection: null,
|
||||
};
|
||||
});
|
||||
return { records, screenByPosition };
|
||||
return { records };
|
||||
}
|
||||
|
||||
function viewerAt(heightM, screenByPosition, shiftX = 0) {
|
||||
return {
|
||||
isDestroyed: () => false,
|
||||
camera: {
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(0, 0, heightM),
|
||||
positionCartographic: { latitude: 0, longitude: 0, height: heightM },
|
||||
frustum: { fovy: Math.PI / 3 },
|
||||
/**
|
||||
* A viewer looking straight down from `heightM` over `lonDeg` on the
|
||||
* equator, north up, through a camera port: the view pass projects the
|
||||
* cameras from its pose.
|
||||
*/
|
||||
function viewerAt(heightM, lonDeg = 0) {
|
||||
const eye = Cesium.Cartesian3.fromDegrees(lonDeg, 0, heightM);
|
||||
const down = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.negate(eye, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const north = { x: 0, y: 0, z: 1 };
|
||||
const right = Cesium.Cartesian3.cross(down, north, new Cesium.Cartesian3());
|
||||
const { port } = fakeCameraPort({
|
||||
pose: {
|
||||
lon: lonDeg,
|
||||
lat: 0,
|
||||
height: heightM,
|
||||
position: { x: eye.x, y: eye.y, z: eye.z },
|
||||
direction: { x: down.x, y: down.y, z: down.z },
|
||||
up: north,
|
||||
right: { x: right.x, y: right.y, z: right.z },
|
||||
fovy: Math.PI / 3,
|
||||
aspectRatio: WIDTH / HEIGHT,
|
||||
near: 0.1,
|
||||
far: 5e8,
|
||||
},
|
||||
scene: {
|
||||
});
|
||||
const viewer = {};
|
||||
bindings.push(
|
||||
bindRenderer(viewer, {
|
||||
camera: port,
|
||||
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
||||
cartesianToCanvasCoordinates: (position) => {
|
||||
// Match by value: a record's position may be a copy of the fixture's.
|
||||
const key = [...screenByPosition.keys()].find((candidate) =>
|
||||
Cesium.Cartesian3.equals(candidate, position),
|
||||
);
|
||||
const screen = screenByPosition.get(key);
|
||||
return screen && { x: screen.x + shiftX, y: screen.y };
|
||||
},
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
return viewer;
|
||||
}
|
||||
|
||||
/** The renderers bound for the running test, let go when it ends. */
|
||||
const bindings = [];
|
||||
afterEach(() => {
|
||||
for (const unbind of bindings.splice(0)) unbind();
|
||||
});
|
||||
|
||||
function shownIds(records) {
|
||||
const icons = _cctvIconsForTest();
|
||||
return records
|
||||
.filter((record) => {
|
||||
const icons = _cctvIconsForTest();
|
||||
return icons.shown(icons.row(record.camera.id));
|
||||
})
|
||||
.filter((record) => icons.item(record.camera.id)?.show === true)
|
||||
.map((record) => record.camera.id)
|
||||
.sort();
|
||||
}
|
||||
@@ -89,9 +103,9 @@ const CLUSTER = [
|
||||
];
|
||||
|
||||
test('zoomed out, cameras sharing a ground cell show one icon', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
||||
const { records } = recordsAt(CLUSTER);
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition),
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
});
|
||||
assert.equal(
|
||||
@@ -106,34 +120,34 @@ test('zoomed out, cameras sharing a ground cell show one icon', () => {
|
||||
});
|
||||
|
||||
test('a pan keeps the same winners, and an unchanged view keeps its list', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER, (index) => ({
|
||||
x: 100 + index * 7,
|
||||
y: 300,
|
||||
}));
|
||||
const { records } = recordsAt(CLUSTER);
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition),
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
const before = shownIds(records);
|
||||
const list = _viewRecordIdsForTest();
|
||||
for (const shiftX of [3, 11, 20, 37]) {
|
||||
// A pan of a few to some 40 px (a pixel is about 30 m from 20 km up).
|
||||
for (const shiftM of [90, 330, 600, 1110]) {
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition, shiftX),
|
||||
viewer: viewerAt(20_000, shiftM / 111_320),
|
||||
records,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
assert.deepEqual(shownIds(records), before, `pan by ${shiftX} px`);
|
||||
assert.deepEqual(shownIds(records), before, `pan by ${shiftM} m`);
|
||||
}
|
||||
_setCctvCoverageStateForTest({ viewer: viewerAt(20_000), records });
|
||||
refreshHorizonCulling();
|
||||
assert.equal(refreshHorizonCulling(), false, 'the same view changes nothing');
|
||||
assert.deepEqual(_viewRecordIdsForTest(), list);
|
||||
});
|
||||
|
||||
test('a small zoom within one cell size keeps the same winners', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
||||
const { records } = recordsAt(CLUSTER);
|
||||
const shownAt = (heightM) => {
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(heightM, screenByPosition),
|
||||
viewer: viewerAt(heightM),
|
||||
records,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
@@ -145,11 +159,11 @@ test('a small zoom within one cell size keeps the same winners', () => {
|
||||
});
|
||||
|
||||
test('a healthy camera wins its cell over an unknown one', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 2));
|
||||
const { records } = recordsAt(CLUSTER.slice(0, 2));
|
||||
// Whichever camera the id order would pick, the healthy one must win.
|
||||
for (const id of ['cam-0', 'cam-1']) {
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition),
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
healthById: new Map([[id, { status: 'ok' }]]),
|
||||
});
|
||||
@@ -159,34 +173,31 @@ test('a healthy camera wins its cell over an unknown one', () => {
|
||||
});
|
||||
|
||||
test('the active camera always shows, even in a crowded cell', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 3));
|
||||
const { records } = recordsAt(CLUSTER.slice(0, 3));
|
||||
for (const active of records) {
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition),
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
activeCameraId: active.camera.id,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
const icons = _cctvIconsForTest();
|
||||
assert.ok(
|
||||
icons.shown(icons.row(active.camera.id)),
|
||||
icons.item(active.camera.id).show,
|
||||
`${active.camera.id} shows while active`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('close up, every camera near the screen shows and far-off ones hide', () => {
|
||||
const { records, screenByPosition } = recordsAt(
|
||||
[
|
||||
[0, 0],
|
||||
[0.0001, 0],
|
||||
[0.0002, 0],
|
||||
],
|
||||
(index) =>
|
||||
index === 2 ? { x: WIDTH * 3, y: HEIGHT / 2 } : { x: 100, y: 100 },
|
||||
);
|
||||
// From 300 m up the screen spans some 460 m: the third camera is 1.1 km off.
|
||||
const { records } = recordsAt([
|
||||
[0, 0],
|
||||
[0.0001, 0],
|
||||
[0.01, 0],
|
||||
]);
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(300, screenByPosition),
|
||||
viewer: viewerAt(300),
|
||||
records,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
@@ -194,9 +205,9 @@ test('close up, every camera near the screen shows and far-off ones hide', () =>
|
||||
});
|
||||
|
||||
test('a disabled layer skips the view pass', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER);
|
||||
const { records } = recordsAt(CLUSTER);
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(20_000, screenByPosition),
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
enabled: false,
|
||||
});
|
||||
@@ -205,9 +216,9 @@ test('a disabled layer skips the view pass', () => {
|
||||
});
|
||||
|
||||
test('UI state builds the full camera list only when it is read', () => {
|
||||
const { records, screenByPosition } = recordsAt(CLUSTER.slice(0, 2));
|
||||
const { records } = recordsAt(CLUSTER.slice(0, 2));
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(300, screenByPosition),
|
||||
viewer: viewerAt(300),
|
||||
records,
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
@@ -238,16 +249,13 @@ test('UI state builds the full camera list only when it is read', () => {
|
||||
});
|
||||
|
||||
test('the camera picker lists the view, with the active camera first', () => {
|
||||
const { records, screenByPosition } = recordsAt(
|
||||
[
|
||||
[0, 0],
|
||||
[0.0001, 0],
|
||||
[0.0002, 0],
|
||||
],
|
||||
(index) => (index === 1 ? { x: WIDTH * 3, y: 0 } : { x: 100, y: 100 }),
|
||||
);
|
||||
const { records } = recordsAt([
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
[0.0002, 0],
|
||||
]);
|
||||
_setCctvCoverageStateForTest({
|
||||
viewer: viewerAt(300, screenByPosition),
|
||||
viewer: viewerAt(300),
|
||||
records,
|
||||
activeCameraId: 'cam-1',
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { applyVesselFocusDeemphasis } from './aisLiveVessels.js';
|
||||
import { applyCctvFocusDeemphasis } from './cctv.js';
|
||||
import { applySatellitePointFocusDeemphasis } from './satellites.js';
|
||||
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
|
||||
import { createIconSet } from './iconSet.js';
|
||||
import { createIconBook } from '../render/motion/iconBook.js';
|
||||
import { createVesselIconBook } from '../layers/vessels/iconBook.js';
|
||||
|
||||
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
||||
@@ -88,10 +88,13 @@ assertResumeGate('vessel', () => {
|
||||
});
|
||||
|
||||
assertResumeGate('CCTV', () => {
|
||||
const icons = createIconSet();
|
||||
const row = icons.add('cam-1', { id: 'cam-1' });
|
||||
icons.setSize(row, 24, 24);
|
||||
icons.setShown(row, true);
|
||||
const icons = createIconBook();
|
||||
icons.put({
|
||||
id: 'cam-1',
|
||||
pos: { x: 1, y: 2, z: 3 },
|
||||
size: [24, 24],
|
||||
meta: { id: 'cam-1' },
|
||||
});
|
||||
const record = { camera: { id: 'cam-1' }, position: { x: 1, y: 2, z: 3 } };
|
||||
return {
|
||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) =>
|
||||
@@ -105,7 +108,7 @@ assertResumeGate('CCTV', () => {
|
||||
cameraDistanceFor: () => 1200,
|
||||
params,
|
||||
}),
|
||||
readAlpha: () => icons.focus(icons.row('cam-1')),
|
||||
readAlpha: () => icons.focus('cam-1'),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user