Skip to content

Commit

Permalink
fix(measurements): Cached stats are now considered non-existent for v…
Browse files Browse the repository at this point in the history
…arious null or undefined attributes. (#810)

* fix(measurements): Cached stats are now considered non-existent for various null or undefined attributes.

* fix(contour): should not display on stack viewport

---------

Co-authored-by: Alireza <ar.sedghi@gmail.com>
  • Loading branch information
jbocce and sedghi committed Oct 4, 2023
1 parent e084999 commit 2d7f7b6
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/tools/src/tools/annotation/AngleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,10 @@ class AngleTool extends AnnotationTool {
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));

// WE HAVE TO CACHE STATS BEFORE FETCHING TEXT
if (!data.cachedStats[targetId]) {
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].angle == null
) {
data.cachedStats[targetId] = {
angle: null,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/BidirectionalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ class BidirectionalTool extends AnnotationTool {
// force to recalculate the stats from the points
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].unit === undefined
data.cachedStats[targetId].unit == null
) {
data.cachedStats[targetId] = {
length: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/CircleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class CircleROITool extends AnnotationTool {
// force to recalculate the stats from the points
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].areaUnit === undefined
data.cachedStats[targetId].areaUnit == null
) {
data.cachedStats[targetId] = {
Modality: null,
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/tools/annotation/CobbAngleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ class CobbAngleTool extends AnnotationTool {
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));

// WE HAVE TO CACHE STATS BEFORE FETCHING TEXT
if (!data.cachedStats[targetId]) {
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].angle == null
) {
data.cachedStats[targetId] = {
angle: null,
};
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/tools/annotation/DragProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ class DragProbeTool extends ProbeTool {
),
};

if (!data.cachedStats[targetId]) {
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].value == null
) {
data.cachedStats[targetId] = {
Modality: null,
index: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class EllipticalROITool extends AnnotationTool {
// force to recalculate the stats from the points
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].areaUnit === undefined
data.cachedStats[targetId].areaUnit == null
) {
data.cachedStats[targetId] = {
Modality: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/LengthTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ class LengthTool extends AnnotationTool {
// force to recalculate the stats from the points
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].unit === undefined
data.cachedStats[targetId].unit == null
) {
data.cachedStats[targetId] = {
length: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class PlanarFreehandROITool extends AnnotationTool {
const { data } = annotation;
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].areaUnit === undefined
data.cachedStats[targetId].areaUnit == null
) {
data.cachedStats[targetId] = {
Modality: null,
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/tools/annotation/ProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ class ProbeTool extends AnnotationTool {
),
};

if (!data.cachedStats[targetId]) {
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].value == null
) {
data.cachedStats[targetId] = {
Modality: null,
index: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/RectangleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ class RectangleROITool extends AnnotationTool {
// force to recalculate the stats from the points
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].areaUnit === undefined
data.cachedStats[targetId].areaUnit == null
) {
data.cachedStats[targetId] = {
Modality: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
getEnabledElementByIds,
Types,
utilities as csUtils,
StackViewport,
} from '@cornerstonejs/core';

import Representations from '../../../enums/SegmentationRepresentations';
Expand Down Expand Up @@ -128,6 +129,13 @@ async function render(
const contourData = segmentation.representationData[Representations.Contour];
const { geometryIds } = contourData;


// We don't have a good way to handle stack viewports for contours at the moment.
// Plus, if we add a segmentation to one viewport, it gets added to all the viewports in the toolGroup too.
if (viewport instanceof StackViewport) {
return;
}

if (!geometryIds?.length) {
console.warn(
`No contours found for segmentationId ${segmentationId}. Skipping render.`
Expand Down

0 comments on commit 2d7f7b6

Please sign in to comment.