From 43c3e4aa0325ace712444b7a503ebb86aa33ed53 Mon Sep 17 00:00:00 2001 From: Chris Jordan Date: Tue, 21 Jan 2025 15:55:52 -0500 Subject: [PATCH] fix default annotation properties to use transformed coordinates --- src/annotation/index.ts | 22 +++++++++++++++++----- src/ui/annotations.ts | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/annotation/index.ts b/src/annotation/index.ts index 50614d6c8..fcd261743 100644 --- a/src/annotation/index.ts +++ b/src/annotation/index.ts @@ -703,6 +703,7 @@ export interface AnnotationTypeHandler { ) => void; defaultProperties: ( annotation: T, + layerPosition: Float32Array[], scales: Float64Array, units: readonly string[], ) => { @@ -766,12 +767,16 @@ function deserializeTwoFloatVectors( } function lineLength( - line: Line, + annotationLayerPositions: Float32Array[], scales: Float64Array, units: readonly string[], ) { + if (annotationLayerPositions.length !== 2) { + return; + } + const [pointA, pointB] = annotationLayerPositions; const scalesRank = scales.length; - const lineRank = line.pointA.length; + const lineRank = pointA.length; if (scalesRank < lineRank) { return; } @@ -782,8 +787,7 @@ function lineLength( return; } const voxelToNanometers = scales[dim] * unitInfo.lengthInNanometers; - lengthSquared += - ((line.pointA[dim] - line.pointB[dim]) * voxelToNanometers) ** 2; + lengthSquared += ((pointA[dim] - pointB[dim]) * voxelToNanometers) ** 2; } return Math.sqrt(lengthSquared); } @@ -853,12 +857,14 @@ export const annotationTypeHandlers: Record< }, defaultProperties( annotation: Line, + annotationLayerPositions: Float32Array[], scales: Float64Array, units: readonly string[], ) { + annotation; const properties: AnnotationNumericPropertySpec[] = []; const values: number[] = []; - const length = lineLength(annotation, scales, units); + const length = lineLength(annotationLayerPositions, scales, units); if (length) { properties.push({ type: "float32", @@ -917,10 +923,12 @@ export const annotationTypeHandlers: Record< }, defaultProperties( annotation: Point, + layerPosition: Float32Array[], scales: Float64Array, units: string[], ) { annotation; + layerPosition; scales; units; return { properties: [], values: [] }; @@ -995,10 +1003,12 @@ export const annotationTypeHandlers: Record< }, defaultProperties( annotation: AxisAlignedBoundingBox, + layerPosition: Float32Array[], scales: Float64Array, units: string[], ) { annotation; + layerPosition; scales; units; return { properties: [], values: [] }; @@ -1073,10 +1083,12 @@ export const annotationTypeHandlers: Record< }, defaultProperties( annotation: Ellipsoid, + layerPosition: Float32Array[], scales: Float64Array, units: string[], ) { annotation; + layerPosition; scales; units; return { properties: [], values: [] }; diff --git a/src/ui/annotations.ts b/src/ui/annotations.ts index b78ca632a..49b1e63e9 100644 --- a/src/ui/annotations.ts +++ b/src/ui/annotations.ts @@ -1783,6 +1783,8 @@ export function UserLayerWithAnnotationsMixin< icon.textContent = handler.icon; positionGrid.appendChild(icon); + const annotationLayerPositions: Float32Array[] = + []; if (layerRank !== 0) { const { layerDimensionNames } = ( chunkTransform as ChunkTransformParameters @@ -1800,6 +1802,7 @@ export function UserLayerWithAnnotationsMixin< annotation, chunkTransform as ChunkTransformParameters, (layerPosition, isVector) => { + annotationLayerPositions.push(layerPosition); const copyButton = makeCopyButton({ title: "Copy position", onClick: () => { @@ -1860,6 +1863,7 @@ export function UserLayerWithAnnotationsMixin< annotation.type ].defaultProperties( annotation, + annotationLayerPositions, globalCoordinateSpace.scales, globalCoordinateSpace.units, );