Skip to content

Commit

Permalink
fix: filter planarFreeHandeROI based on parallel normals instead of e…
Browse files Browse the repository at this point in the history
…qual normals. (#315)

Co-authored-by: Ramon Emiliani <ramon@afxmedical.com>
  • Loading branch information
ramonemiliani93 and Ramon Emiliani authored Dec 1, 2022
1 parent ea8e32a commit 70e4ffa
Showing 1 changed file with 17 additions and 6 deletions.
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

0 comments on commit 70e4ffa

Please sign in to comment.