@qctrl/visualizer
Version:
The Q-CTRL Visualizer is a package for displaying animated 3d Bloch sphere visualizations.
137 lines (136 loc) • 4.83 kB
TypeScript
import { Color, Vector3, Group, Scene, Vector3Tuple, MeshBasicMaterial, Object3D } from "three";
import { Line2 } from "three/examples/jsm/lines/Line2";
import { SCENE_OBJECT_UPDATE_TYPES } from "../../constants";
import { Styles } from "../../styles/theme";
import { CustomLabel, Labels } from "../../types";
import createLights from "./lights";
import createAxes from "./axes";
import createSphere from "./sphere";
import createEquatorialPlane from "./equatorialPlane";
import createIndicatorStick from "./indicatorStick";
import createDecoherenceLine from "./decoherence";
type UpdatePathAnimationArgs = [
inputStateProp: {
theta: number;
phi: number;
} | null,
isPlaying: boolean
];
type ClearSegmentArgs = [isPlaying: boolean, clearAll?: boolean];
interface ObjectsManagerProps {
data: Vector3Tuple[];
nonErrorStateData: Vector3Tuple[];
segmentIndexes: number[];
initialFrameIndex: number;
finalFrameIndex: number;
style: Styles;
scene: Scene;
div: HTMLElement;
continuousSegments?: boolean;
drawArcs?: boolean;
drawPaths: boolean;
skipLastLineDraw?: boolean;
customLabels?: CustomLabel[];
}
/**
* Manages the creation and updating of all 3D objects in a subscene/Element
*/
declare class ObjectsManager {
optimisationCache: {
coordArcsVector: Vector3Tuple | [];
};
data: Vector3Tuple[];
nonErrorStateData: Vector3Tuple[];
frameIndex: number;
finalFrameIndex: number;
style: Styles;
scene: Scene;
segmentIndexes: number[];
currentSegmentNumber: number;
divWidthAndHeight: {
width: number;
height: number;
};
currentStateVector: Vector3;
currentNonErrorStateVector?: Vector3;
lights: ReturnType<typeof createLights>;
axes: ReturnType<typeof createAxes>;
labels: {
labelsGroup: Group;
nonErrorStateLabel: Group;
indicatorPoint: Group;
};
sphere: ReturnType<typeof createSphere>;
equatorialPlane: ReturnType<typeof createEquatorialPlane>;
path: {
segments: Group;
};
pathIndicator: ReturnType<typeof createIndicatorStick>;
coordinateArcMaterials: {
theta: MeshBasicMaterial;
phi: MeshBasicMaterial;
};
pathCurrentSegmentColor: Color;
showDecoherence?: boolean;
coordinateArcs?: Group;
inputStateVector?: Vector3;
decoherence?: ReturnType<typeof createDecoherenceLine>;
/**
*Creates an instance of ElementObjectsManager.
*/
constructor({ data, nonErrorStateData, segmentIndexes, initialFrameIndex, finalFrameIndex, style, scene, div, continuousSegments, drawArcs, drawPaths, skipLastLineDraw, customLabels, }: ObjectsManagerProps);
/**
* Test whether the phi label should be visible
* Will be false if current pulse vector is at |0\> or |1\> (x:0, y:0, z:+1 or -1)
*/
get phiShouldBeHidden(): boolean;
/**
* Test whether the theta label should be visible
* Will be false if current pulse vector is x:0, y:0, z+1
*/
get thetaShouldBeVisible(): boolean;
/**
* Shows or hides appropriate labels based on labels prop, decoherence state, and coordinate arc state
*/
showOrHideLabels(labels: Labels): void;
/**
* Creates new coordinate arcs, based on current vector, and adds them to the scene
*/
setCoordinateArcs(labelsProp: Labels): void;
/**
* Style a path segment
*/
styleSegment(segment: Group | Line2, isCurrentSegment: boolean): void;
/**
* Gets the current segment object
*/
getCurrentSegment(currentSegmentNumber: number): Object3D<import("three").Object3DEventMap> | undefined;
/**
* Finds and returns a segment based on it's segment number
*/
getSegment(segmentNumber: number): Object3D<import("three").Object3DEventMap> | undefined;
/**
* Clear all segment highlights, effectively resetting segment styling to defaults
*/
clearSegmentHighlights(...[isPlaying, clearAll]: ClearSegmentArgs): void;
/**
* Updates the indicator geometry/position baed on the current vector
*/
updateIndicatorPosition(): void;
/**
* Updates the position of the non error state indicator based on the current non error state vector
*/
updateNonErrorStateLabelPosition(): void;
/**
* Updates all objects effected by current vector
*/
updatePathAnimation(...[inputStateProp, isPlaying]: UpdatePathAnimationArgs): void;
/**
* Calls any matching instance methods found in update array after updating this.frameIndex and this.currentSegmentNumber
*/
update(frameIndex: number, currentSegmentNumber: number, updates: {
method: SCENE_OBJECT_UPDATE_TYPES;
args?: unknown;
}[]): void;
}
export default ObjectsManager;