Skip to content

Commit

Permalink
fix(tools): Some older annotations were missing normal (#528)
Browse files Browse the repository at this point in the history
Compute the normal for the image when the measurement normal is missing.
  • Loading branch information
wayfarer3130 authored Mar 28, 2023
1 parent 1e40104 commit 319822a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/tools/src/utilities/cine/playClip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StackViewport,
VolumeViewport,
cache,
BaseVolumeViewport,
} from '@cornerstonejs/core';

import { Types } from '@cornerstonejs/core';
Expand Down Expand Up @@ -301,7 +302,7 @@ function _getVolumeFromViewport(viewport): Types.IImageVolume {
const actorEntry = viewport.getDefaultActor();

if (!actorEntry) {
console.warn('No actor found');
// This can happen during setup/teardown of viewports.
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { vec3 } from 'gl-matrix';
import { CONSTANTS } from '@cornerstonejs/core';
import { CONSTANTS, metaData } from '@cornerstonejs/core';
import type { Types } from '@cornerstonejs/core';
import { Annotations, Annotation } from '../../types';
import { debug } from 'console';

const { EPSILON } = CONSTANTS;

Expand Down Expand Up @@ -33,8 +34,33 @@ export default function filterAnnotationsWithinSlice(
// logic down below.
const annotationsWithParallelNormals = annotations.filter(
(td: Annotation) => {
const annotationViewPlaneNormal = td.metadata.viewPlaneNormal;

let annotationViewPlaneNormal = td.metadata.viewPlaneNormal;

if (!annotationViewPlaneNormal) {
// This code is run to set the annotation view plane normal
// for historical data which was saved without the normal.
const { referencedImageId } = td.metadata;
const { imageOrientationPatient } = metaData.get(
'imagePlaneModule',
referencedImageId
);
const rowCosineVec = vec3.fromValues(
imageOrientationPatient[0],
imageOrientationPatient[1],
imageOrientationPatient[2]
);

const colCosineVec = vec3.fromValues(
imageOrientationPatient[3],
imageOrientationPatient[4],
imageOrientationPatient[5]
);

annotationViewPlaneNormal = vec3.create() as Types.Point3;

vec3.cross(annotationViewPlaneNormal, rowCosineVec, colCosineVec);
td.metadata.viewPlaneNormal = annotationViewPlaneNormal;
}
const isParallel =
Math.abs(vec3.dot(viewPlaneNormal, annotationViewPlaneNormal)) >
PARALLEL_THRESHOLD;
Expand Down

0 comments on commit 319822a

Please sign in to comment.