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

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

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
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