Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter PlanarFreeHandROI annotations based on parallel normals instead of equal normals. #315

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/tools/src/tools/annotation/PlanarFreehandROITool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CONSTANTS,
getEnabledElement,
triggerEvent,
eventTarget,
Expand Down Expand Up @@ -42,7 +43,9 @@ import { PlanarFreehandROIAnnotation } from '../../types/ToolSpecificAnnotationT
import { PlanarFreehandROICommonData } from '../../utilities/math/polyline/planarFreehandROIInternalTypes';

const { pointCanProjectOnLine } = polyline;
const { EPSILON } = CONSTANTS;

const PARALLEL_THRESHOLD = 1 - EPSILON;
/**
* PlanarFreehandROITool lets you draw annotations that define an arbitrarily drawn region.
* You can use the PlanarFreehandROITool in all perpendicular views (axial, sagittal, coronal),
Expand Down Expand Up @@ -488,13 +491,21 @@ class PlanarFreehandROITool extends AnnotationTool {
spacingInNormalDirection: number
): Annotations {
const { viewPlaneNormal } = camera;
const annotationsWithSameNormal = annotations.filter((td: Annotation) => {
const annotationViewPlaneNormal = td.metadata.viewPlaneNormal;
return csUtils.isEqual(annotationViewPlaneNormal, viewPlaneNormal);
});

const annotationsWithParallelNormals = annotations.filter(
(td: Annotation) => {
const annotationViewPlaneNormal = td.metadata.viewPlaneNormal;

const isParallel =
Math.abs(vec3.dot(viewPlaneNormal, annotationViewPlaneNormal)) >
PARALLEL_THRESHOLD;

return annotationViewPlaneNormal && isParallel;
}
);

// No in plane annotations.
if (!annotationsWithSameNormal.length) {
if (!annotationsWithParallelNormals.length) {
return [];
}

Expand All @@ -506,7 +517,7 @@ class PlanarFreehandROITool extends AnnotationTool {

const annotationsWithinSlice = [];

for (const annotation of annotationsWithSameNormal) {
for (const annotation of annotationsWithParallelNormals) {
const data = annotation.data;
const point = data.polyline[0];

Expand Down