Skip to content

Commit c826934

Browse files
committed
feat(annotation) Add default annontation properties
add line length property
1 parent 5898236 commit c826934

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

src/annotation/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { parseDataTypeValue } from "#src/util/lerp.js";
5555
import { getRandomHexString } from "#src/util/random.js";
5656
import { NullarySignal, Signal } from "#src/util/signal.js";
5757
import { Uint64 } from "#src/util/uint64.js";
58+
import { vec3 } from "gl-matrix";
5859

5960
export type AnnotationId = string;
6061

@@ -695,6 +696,13 @@ export interface AnnotationTypeHandler<T extends Annotation = Annotation> {
695696
annotation: T,
696697
callback: (vec: Float32Array, isVector: boolean) => void,
697698
) => void;
699+
defaultProperties: (
700+
annotation: T,
701+
scales: vec3,
702+
) => {
703+
properties: AnnotationNumericPropertySpec[];
704+
values: number[];
705+
};
698706
}
699707

700708
function serializeFloatVector(
@@ -814,6 +822,24 @@ export const annotationTypeHandlers: Record<
814822
callback(annotation.pointA, false);
815823
callback(annotation.pointB, false);
816824
},
825+
defaultProperties(annotation: Line, scales: vec3) {
826+
return {
827+
properties: [
828+
{
829+
type: "float32",
830+
identifier: "Length",
831+
default: 0,
832+
description: "Length of the line annotation in nanometers",
833+
},
834+
],
835+
values: [
836+
vec3.dist(
837+
vec3.mul(vec3.create(), scales, annotation.pointA as vec3),
838+
vec3.mul(vec3.create(), scales, annotation.pointB as vec3),
839+
),
840+
],
841+
};
842+
},
817843
},
818844
[AnnotationType.POINT]: {
819845
icon: "⚬",
@@ -858,6 +884,11 @@ export const annotationTypeHandlers: Record<
858884
visitGeometry(annotation: Point, callback) {
859885
callback(annotation.point, false);
860886
},
887+
defaultProperties(annotation: Point, scales: vec3) {
888+
annotation;
889+
scales;
890+
return { properties: [], values: [] };
891+
},
861892
},
862893
[AnnotationType.AXIS_ALIGNED_BOUNDING_BOX]: {
863894
icon: "❑",
@@ -926,6 +957,11 @@ export const annotationTypeHandlers: Record<
926957
callback(annotation.pointA, false);
927958
callback(annotation.pointB, false);
928959
},
960+
defaultProperties(annotation: AxisAlignedBoundingBox, scales: vec3) {
961+
annotation;
962+
scales;
963+
return { properties: [], values: [] };
964+
},
929965
},
930966
[AnnotationType.ELLIPSOID]: {
931967
icon: "◎",
@@ -994,6 +1030,11 @@ export const annotationTypeHandlers: Record<
9941030
callback(annotation.center, false);
9951031
callback(annotation.radii, true);
9961032
},
1033+
defaultProperties(annotation: Ellipsoid, scales: vec3) {
1034+
annotation;
1035+
scales;
1036+
return { properties: [], values: [] };
1037+
},
9971038
},
9981039
};
9991040

src/ui/annotations.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,22 @@ export function UserLayerWithAnnotationsMixin<
18541854

18551855
const { relationships, properties } = annotationLayer.source;
18561856
const sourceReadonly = annotationLayer.source.readonly;
1857+
const globalCoordinateSpace =
1858+
this.manager.root.coordinateSpace.value;
1859+
const scales = new Float32Array(
1860+
globalCoordinateSpace.scales.map((x) => x / 1e-9),
1861+
) as vec3;
1862+
const defaultProperties = annotationTypeHandlers[
1863+
annotation.type
1864+
].defaultProperties(annotation, scales);
1865+
const allProperties = [
1866+
...defaultProperties.properties,
1867+
...properties,
1868+
];
1869+
const allValues = [
1870+
...defaultProperties.values,
1871+
...annotation.properties,
1872+
];
18571873

18581874
// Add the ID to the annotation details.
18591875
const label = document.createElement("label");
@@ -1872,8 +1888,10 @@ export function UserLayerWithAnnotationsMixin<
18721888
label.appendChild(valueElement);
18731889
parent.appendChild(label);
18741890

1875-
for (let i = 0, count = properties.length; i < count; ++i) {
1876-
const property = properties[i];
1891+
for (let i = 0, count = allProperties.length; i < count; ++i) {
1892+
const property = allProperties[i];
1893+
const value = allValues[i];
1894+
18771895
const label = document.createElement("label");
18781896
label.classList.add("neuroglancer-annotation-property");
18791897
const idElement = document.createElement("span");
@@ -1886,7 +1904,6 @@ export function UserLayerWithAnnotationsMixin<
18861904
if (description !== undefined) {
18871905
label.title = description;
18881906
}
1889-
const value = annotation.properties[i];
18901907
const valueElement = document.createElement("span");
18911908
valueElement.classList.add(
18921909
"neuroglancer-annotation-property-value",

0 commit comments

Comments
 (0)