Files
NODEDC_MISSION_CORE/packages/sensor-ui/src/observation.ts
T

33 lines
2.3 KiB
TypeScript

import type {SceneSettings} from '../../spatial-ui/src/sceneSettings';
import type {ComponentType} from 'react';
import type {Sensor,SensorTransport} from './contracts';
import type {RerunHostFactory} from './rerunHost';
export interface SensorObservationView {id:string;label:string;header?:'overlay'|'flow';scene?:boolean;layers?:{value:string;label:string}[]}
/** Stable host slots let a session update its header without moving its media. */
export interface ObservationHeaderTargets {statusTarget:HTMLElement;actionsTarget:HTMLElement}
export interface CameraPresentation {rotations:Record<string,number>;panoramaYaw:number}
export interface SensorObservationProps {
/** Open the shared device workflow without navigation or an implicit command. */
configure?:(view?:string)=>void;reconnect?:()=>void;
sceneProfiles?:Record<string,SceneSettings>;onSceneChange?:(view:string,value:SceneSettings)=>void;
presentation?:CameraPresentation;onPresentationChange?:(value:CameraPresentation)=>void;
device:Sensor;transport:SensorTransport;enabled:boolean;fresh?:boolean;createRerunHost:RerunHostFactory;
views:({id:string;layer:string;target:HTMLElement}&ObservationHeaderTargets)[];
}
export interface SensorObservationContribution {
/** The session separates fresh control admission from existing media progress. */
independentMediaLiveness?:boolean;
views:(device:Sensor)=>SensorObservationView[];
Session:ComponentType<SensorObservationProps>;
catalog?:{label:string;views:SensorObservationView[]};
}
export const sensorLayerLabels:Record<string,string>={color:'RGB',depth:'Глубина',infrared1:'ИК · 1',infrared2:'ИК · 2',points:'Облако точек',motion:'Движение'};
export function cameraObservationViews(device:Sensor):SensorObservationView[] {
const published=device.layers.length?device.layers:/^RealSense D455$/i.test(device.model??'')?['color','depth','infrared1','infrared2','points','motion']:[];
const layers=published.filter(value=>Object.hasOwn(sensorLayerLabels,value)).map(value=>({value,label:sensorLayerLabels[value]}));
layers.sort((a,b)=>Number(b.value==='color')-Number(a.value==='color'));
return layers.length?[{id:'camera',label:device.name,layers}]:[];
}
export function observationKey(deviceID:string,viewID:string):string {return JSON.stringify([deviceID,viewID]);}