Skip to content

Commit

Permalink
fix default annotation properties to use transformed coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Jan 21, 2025
1 parent 324342f commit 43c3e4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ export interface AnnotationTypeHandler<T extends Annotation = Annotation> {
) => void;
defaultProperties: (
annotation: T,
layerPosition: Float32Array<ArrayBufferLike>[],
scales: Float64Array,
units: readonly string[],
) => {
Expand Down Expand Up @@ -766,12 +767,16 @@ function deserializeTwoFloatVectors(
}

function lineLength(
line: Line,
annotationLayerPositions: Float32Array<ArrayBufferLike>[],
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;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -853,12 +857,14 @@ export const annotationTypeHandlers: Record<
},
defaultProperties(
annotation: Line,
annotationLayerPositions: Float32Array<ArrayBufferLike>[],
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",
Expand Down Expand Up @@ -917,10 +923,12 @@ export const annotationTypeHandlers: Record<
},
defaultProperties(
annotation: Point,
layerPosition: Float32Array<ArrayBufferLike>[],
scales: Float64Array,
units: string[],
) {
annotation;
layerPosition;
scales;
units;
return { properties: [], values: [] };
Expand Down Expand Up @@ -995,10 +1003,12 @@ export const annotationTypeHandlers: Record<
},
defaultProperties(
annotation: AxisAlignedBoundingBox,
layerPosition: Float32Array<ArrayBufferLike>[],
scales: Float64Array,
units: string[],
) {
annotation;
layerPosition;
scales;
units;
return { properties: [], values: [] };
Expand Down Expand Up @@ -1073,10 +1083,12 @@ export const annotationTypeHandlers: Record<
},
defaultProperties(
annotation: Ellipsoid,
layerPosition: Float32Array<ArrayBufferLike>[],
scales: Float64Array,
units: string[],
) {
annotation;
layerPosition;
scales;
units;
return { properties: [], values: [] };
Expand Down
4 changes: 4 additions & 0 deletions src/ui/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ export function UserLayerWithAnnotationsMixin<
icon.textContent = handler.icon;
positionGrid.appendChild(icon);

const annotationLayerPositions: Float32Array<ArrayBufferLike>[] =
[];
if (layerRank !== 0) {
const { layerDimensionNames } = (
chunkTransform as ChunkTransformParameters
Expand All @@ -1800,6 +1802,7 @@ export function UserLayerWithAnnotationsMixin<
annotation,
chunkTransform as ChunkTransformParameters,
(layerPosition, isVector) => {
annotationLayerPositions.push(layerPosition);
const copyButton = makeCopyButton({
title: "Copy position",
onClick: () => {
Expand Down Expand Up @@ -1860,6 +1863,7 @@ export function UserLayerWithAnnotationsMixin<
annotation.type
].defaultProperties(
annotation,
annotationLayerPositions,
globalCoordinateSpace.scales,
globalCoordinateSpace.units,
);
Expand Down

0 comments on commit 43c3e4a

Please sign in to comment.