From afd528b8d72c3d8360b54bb52604758e83ada863 Mon Sep 17 00:00:00 2001 From: Ibrahim <93064150+IbrahimCSAE@users.noreply.github.com> Date: Tue, 25 Feb 2025 11:49:16 -0500 Subject: [PATCH] fix(rt): jump to segment discards the configured width (#4799) --- .../SegmentationService.ts | 16 +++-------- .../cornerstone/src/utils/transitions.ts | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts index 4290cc4e5..0541e6c7c 100644 --- a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts +++ b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts @@ -16,7 +16,7 @@ import { } from '@cornerstonejs/tools'; import { PubSubService, Types as OHIFTypes } from '@ohif/core'; import i18n from '@ohif/i18n'; -import { easeInOutBell, reverseEaseInOutBell } from '../../utils/transitions'; +import { easeInOutBell, easeInOutBellRelative } from '../../utils/transitions'; import { mapROIContoursToRTStructData } from './RTSTRUCT/mapROIContoursToRTStructData'; import { SegmentationRepresentations } from '@cornerstonejs/tools/enums'; import { addColorLUT } from '@cornerstonejs/tools/segmentation/addColorLUT'; @@ -1637,10 +1637,7 @@ class SegmentationService extends PubSubService { const startTime = performance.now(); const prevStyle = cstSegmentation.config.style.getStyle({ - viewportId, - segmentationId, type: CONTOUR, - segmentIndex, }) as ContourStyle; const prevOutlineWidth = prevStyle.outlineWidth; @@ -1650,18 +1647,11 @@ class SegmentationService extends PubSubService { const animate = (currentTime: number) => { const progress = (currentTime - startTime) / animationLength; if (progress >= 1) { - cstSegmentation.config.style.setStyle( - { - segmentationId, - segmentIndex, - type: CONTOUR, - }, - {} - ); + cstSegmentation.config.style.resetToGlobalStyle(); return; } - const reversedProgress = reverseEaseInOutBell(progress, baseline); + const reversedProgress = easeInOutBellRelative(progress, baseline, prevOutlineWidth); cstSegmentation.config.style.setStyle( { diff --git a/extensions/cornerstone/src/utils/transitions.ts b/extensions/cornerstone/src/utils/transitions.ts index 28d2dacd0..7d63f26f7 100644 --- a/extensions/cornerstone/src/utils/transitions.ts +++ b/extensions/cornerstone/src/utils/transitions.ts @@ -34,3 +34,30 @@ export function reverseEaseInOutBell(x: number, baseline: number): number { const y = easeInOutBell(x, baseline); return -y + 1 + baseline; } + +export function easeInOutBellRelative( + x: number, + baseline: number, + prevOutlineWidth: number +): number { + const range = baseline - prevOutlineWidth; + + if (x < 1 / 4) { + return prevOutlineWidth + 4 * Math.pow(2 * x, 3) * range; + } else if (x < 1 / 2) { + return prevOutlineWidth + (1 - Math.pow(-4 * x + 2, 3) / 2) * range; + } else if (x < 3 / 4) { + return prevOutlineWidth + (1 - Math.pow(4 * x - 2, 3) / 2) * range; + } else { + return prevOutlineWidth + -4 * Math.pow(2 * x - 2, 3) * range; + } +} + +export function reverseEaseInOutBellRelative( + x: number, + baseline: number, + prevOutlineWidth: number +): number { + const y = easeInOutBellRelative(x, baseline, prevOutlineWidth); + return y; +}