fix(rt): jump to segment discards the configured width (#4799)

This commit is contained in:
Ibrahim 2025-02-25 11:49:16 -05:00 committed by GitHub
parent 76da2d86a9
commit afd528b8d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 13 deletions

View File

@ -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(
{

View File

@ -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;
}