test(SegmentationService): Adding 98.63% of test line coverage to Segmentation Service through unit tests (#5421)

This commit is contained in:
Vinícius Alves de Faria Resende 2025-09-30 14:49:13 -03:00 committed by GitHub
parent 9353a840ee
commit 12ac509c40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 3142 additions and 111 deletions

View File

@ -35,6 +35,7 @@ module.exports = {
'@babel/plugin-transform-typescript',
'@babel/plugin-transform-class-static-block',
'@babel/plugin-transform-for-of',
['babel-plugin-transform-import-meta', { module: 'ES6' }],
],
},
production: {

View File

@ -25,6 +25,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "0.5.17",
"babel-loader": "8.4.1",
"babel-plugin-istanbul": "^7.0.0",
"babel-plugin-transform-import-meta": "2.3.3",
"css-loader": "6.11.0",
"cypress": "14.5.2",
"cypress-file-upload": "^5.0.8",
@ -50,7 +51,7 @@
},
"addOns/externals/devDependencies": {
"name": "@externals/devDependencies",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@kitware/vtk.js": "32.12.0",
@ -135,14 +136,14 @@
},
"addOns/externals/dicom-microscopy-viewer": {
"name": "@externals/dicom-microscopy-viewer",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"dicom-microscopy-viewer": "^0.48.6",
},
},
"extensions/cornerstone": {
"name": "@ohif/extension-cornerstone",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "4.3.10",
@ -168,8 +169,8 @@
"@cornerstonejs/codec-openjpeg": "^1.2.4",
"@cornerstonejs/codec-openjph": "^2.4.5",
"@cornerstonejs/dicom-image-loader": "4.3.10",
"@ohif/core": "3.12.0-beta.32",
"@ohif/ui": "3.12.0-beta.32",
"@ohif/core": "3.12.0-beta.35",
"@ohif/ui": "3.12.0-beta.35",
"dcmjs": "0.43.1",
"dicom-parser": "^1.8.21",
"hammerjs": "^2.0.8",
@ -181,7 +182,7 @@
},
"extensions/cornerstone-dicom-pmap": {
"name": "@ohif/extension-cornerstone-dicom-pmap",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "4.3.10",
@ -204,7 +205,7 @@
},
"extensions/cornerstone-dicom-rt": {
"name": "@ohif/extension-cornerstone-dicom-rt",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"react-color": "^2.19.3",
@ -224,7 +225,7 @@
},
"extensions/cornerstone-dicom-seg": {
"name": "@ohif/extension-cornerstone-dicom-seg",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "4.3.10",
@ -247,7 +248,7 @@
},
"extensions/cornerstone-dicom-sr": {
"name": "@ohif/extension-cornerstone-dicom-sr",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "4.3.10",
@ -256,10 +257,10 @@
"classnames": "^2.3.2",
},
"peerDependencies": {
"@ohif/core": "3.12.0-beta.32",
"@ohif/extension-cornerstone": "3.12.0-beta.32",
"@ohif/extension-measurement-tracking": "3.12.0-beta.32",
"@ohif/ui": "3.12.0-beta.32",
"@ohif/core": "3.12.0-beta.35",
"@ohif/extension-cornerstone": "3.12.0-beta.35",
"@ohif/extension-measurement-tracking": "3.12.0-beta.35",
"@ohif/ui": "3.12.0-beta.35",
"dcmjs": "0.43.1",
"dicom-parser": "^1.8.9",
"hammerjs": "^2.0.8",
@ -269,7 +270,7 @@
},
"extensions/cornerstone-dynamic-volume": {
"name": "@ohif/extension-cornerstone-dynamic-volume",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/core": "4.3.10",
@ -291,7 +292,7 @@
},
"extensions/default": {
"name": "@ohif/extension-default",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/calculate-suv": "^1.1.0",
@ -299,8 +300,8 @@
"lodash.uniqby": "^4.7.0",
},
"peerDependencies": {
"@ohif/core": "3.12.0-beta.32",
"@ohif/i18n": "3.12.0-beta.32",
"@ohif/core": "3.12.0-beta.35",
"@ohif/i18n": "3.12.0-beta.35",
"dcmjs": "0.43.1",
"dicomweb-client": "^0.10.4",
"prop-types": "^15.6.2",
@ -314,7 +315,7 @@
},
"extensions/dicom-microscopy": {
"name": "@ohif/extension-dicom-microscopy",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/codec-charls": "^1.2.3",
@ -339,7 +340,7 @@
},
"extensions/dicom-pdf": {
"name": "@ohif/extension-dicom-pdf",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"classnames": "^2.3.2",
@ -356,7 +357,7 @@
},
"extensions/dicom-video": {
"name": "@ohif/extension-dicom-video",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"classnames": "^2.3.2",
@ -373,20 +374,20 @@
},
"extensions/measurement-tracking": {
"name": "@ohif/extension-measurement-tracking",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@ohif/ui": "3.12.0-beta.32",
"@ohif/ui": "3.12.0-beta.35",
"@xstate/react": "^3.2.2",
"xstate": "^4.10.0",
},
"peerDependencies": {
"@cornerstonejs/core": "4.3.10",
"@cornerstonejs/tools": "4.3.10",
"@ohif/core": "3.12.0-beta.32",
"@ohif/extension-cornerstone-dicom-sr": "3.12.0-beta.32",
"@ohif/extension-default": "3.12.0-beta.32",
"@ohif/ui": "3.12.0-beta.32",
"@ohif/core": "3.12.0-beta.35",
"@ohif/extension-cornerstone-dicom-sr": "3.12.0-beta.35",
"@ohif/extension-default": "3.12.0-beta.35",
"@ohif/ui": "3.12.0-beta.35",
"classnames": "^2.3.2",
"dcmjs": "0.43.1",
"lodash.debounce": "^4.0.8",
@ -399,7 +400,7 @@
},
"extensions/test-extension": {
"name": "@ohif/extension-test",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"classnames": "^2.3.2",
@ -416,7 +417,7 @@
},
"extensions/tmtv": {
"name": "@ohif/extension-tmtv",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"classnames": "^2.3.2",
@ -433,7 +434,7 @@
},
"extensions/usAnnotation": {
"name": "@ohif/extension-ultrasound-pleura-bline",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/core": "4.3.10",
@ -485,7 +486,7 @@
},
"modes/basic-dev-mode": {
"name": "@ohif/mode-basic-dev-mode",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -505,7 +506,7 @@
},
"modes/basic-test-mode": {
"name": "@ohif/mode-test",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -527,7 +528,7 @@
},
"modes/longitudinal": {
"name": "@ohif/mode-longitudinal",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -550,7 +551,7 @@
},
"modes/microscopy": {
"name": "@ohif/mode-microscopy",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -562,7 +563,7 @@
},
"modes/preclinical-4d": {
"name": "@ohif/mode-preclinical-4d",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
},
@ -581,7 +582,7 @@
},
"modes/segmentation": {
"name": "@ohif/mode-segmentation",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -625,7 +626,7 @@
},
"modes/tmtv": {
"name": "@ohif/mode-tmtv",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next": "^17.0.3",
@ -646,7 +647,7 @@
},
"modes/usAnnotation": {
"name": "@ohif/mode-ultrasound-pleura-bline",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/core": "4.3.10",
@ -685,7 +686,7 @@
},
"platform/app": {
"name": "@ohif/app",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/codec-charls": "^1.2.3",
@ -764,7 +765,7 @@
},
"platform/cli": {
"name": "@ohif/cli",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"bin": {
"ohif-cli": "src/index.js",
},
@ -788,7 +789,7 @@
},
"platform/core": {
"name": "@ohif/core",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"dcmjs": "0.43.1",
@ -815,14 +816,14 @@
"@cornerstonejs/codec-openjph": "^2.4.5",
"@cornerstonejs/core": "4.3.10",
"@cornerstonejs/dicom-image-loader": "4.3.10",
"@ohif/ui": "3.12.0-beta.32",
"@ohif/ui": "3.12.0-beta.35",
"cornerstone-math": "0.1.9",
"dicom-parser": "^1.8.21",
},
},
"platform/i18n": {
"name": "@ohif/i18n",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@babel/runtime": "^7.20.13",
"i18next-locize-backend": "^2.0.0",
@ -847,7 +848,7 @@
},
"platform/ui": {
"name": "@ohif/ui",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@testing-library/react": "^13.1.0",
"browser-detect": "^0.2.28",
@ -898,7 +899,7 @@
},
"platform/ui-next": {
"name": "@ohif/ui-next",
"version": "3.12.0-beta.32",
"version": "3.12.0-beta.35",
"dependencies": {
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-checkbox": "^1.1.1",
@ -2245,6 +2246,8 @@
"babel-plugin-polyfill-regenerator": ["babel-plugin-polyfill-regenerator@0.6.5", "", { "dependencies": { "@babel/helper-define-polyfill-provider": "^0.6.5" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, "sha512-ISqQ2frbiNU9vIJkzg7dlPpznPZ4jOiUQ1uSmB0fEHeowtN3COYRsXr/xexn64NpU13P06jc/L5TgiJXOgrbEg=="],
"babel-plugin-transform-import-meta": ["babel-plugin-transform-import-meta@2.3.3", "", { "dependencies": { "@babel/template": "^7.25.9", "tslib": "^2.8.1" }, "peerDependencies": { "@babel/core": "^7.10.0" } }, "sha512-bbh30qz1m6ZU1ybJoNOhA2zaDvmeXMnGNBMVMDOJ1Fni4+wMBoy/j7MTRVmqAUCIcy54/rEnr9VEBsfcgbpm3Q=="],
"babel-preset-current-node-syntax": ["babel-preset-current-node-syntax@1.1.1", "", { "dependencies": { "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-bigint": "^7.8.3", "@babel/plugin-syntax-class-properties": "^7.12.13", "@babel/plugin-syntax-class-static-block": "^7.14.5", "@babel/plugin-syntax-import-attributes": "^7.24.7", "@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-syntax-json-strings": "^7.8.3", "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4", "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", "@babel/plugin-syntax-numeric-separator": "^7.10.4", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-syntax-optional-chaining": "^7.8.3", "@babel/plugin-syntax-private-property-in-object": "^7.14.5", "@babel/plugin-syntax-top-level-await": "^7.14.5" }, "peerDependencies": { "@babel/core": "^7.0.0 || ^8.0.0-0" } }, "sha512-23fWKohMTvS5s0wwJKycOe0dBdCwQ6+iiLaNR9zy8P13mtFRFM9qLLX6HJX5DL2pi/FNDf3fCQHM4FIMoHH/7w=="],
"babel-preset-jest": ["babel-preset-jest@29.6.3", "", { "dependencies": { "babel-plugin-jest-hoist": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0" }, "peerDependencies": { "@babel/core": "^7.0.0" } }, "sha512-0B3bhxR6snWXJZtR/RliHTDPRgn1sNHOR0yVtq/IiQFyuOVjFS+wuio/R4gSNkyYmKmJB4wGZv2NZanmKmTnNA=="],

View File

@ -1,9 +1,13 @@
const base = require('../../jest.config.base.js');
const pkg = require('./package');
module.exports = {
...base,
displayName: pkg.name,
moduleNameMapper: {
...base.moduleNameMapper,
'@ohif/(.*)': '<rootDir>/../../platform/$1/src',
'^@cornerstonejs/([^/]+)/(.*)$': '<rootDir>/../../node_modules/@cornerstonejs/$1/dist/esm/$2',
'^@cornerstonejs/([^/]+)$': '<rootDir>/../../node_modules/@cornerstonejs/$1/dist/esm',
},
// rootDir: "../.."
// testMatch: [
// //`<rootDir>/platform/${pack.name}/**/*.spec.js`

View File

@ -9,30 +9,34 @@ import {
utilities as csUtils,
metaData,
} from '@cornerstonejs/core';
import { ViewportType } from '@cornerstonejs/core/enums';
import {
Enums as csToolsEnums,
segmentation as cstSegmentation,
Types as cstTypes,
} from '@cornerstonejs/tools';
import { PubSubService, Types as OHIFTypes } from '@ohif/core';
import i18n from '@ohif/i18n';
import { EasingFunctionEnum, EasingFunctionMap } from '../../utils/transitions';
import { mapROIContoursToRTStructData } from './RTSTRUCT/mapROIContoursToRTStructData';
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
import { addColorLUT } from '@cornerstonejs/tools/segmentation/addColorLUT';
import { getNextColorLUTIndex } from '@cornerstonejs/tools/segmentation/getNextColorLUTIndex';
import { Segment } from '@cornerstonejs/tools/types/SegmentationStateTypes';
import { ContourStyle, LabelmapStyle, SurfaceStyle } from '@cornerstonejs/tools/types';
import { ViewportType } from '@cornerstonejs/core/enums';
import { SegmentationPresentation, SegmentationPresentationItem } from '../../types/Presentation';
import { updateLabelmapSegmentationImageReferences } from '@cornerstonejs/tools/segmentation/updateLabelmapSegmentationImageReferences';
import { triggerSegmentationRepresentationModified } from '@cornerstonejs/tools/segmentation/triggerSegmentationEvents';
import { convertStackToVolumeLabelmap } from '@cornerstonejs/tools/segmentation/helpers/convertStackToVolumeLabelmap';
import { getLabelmapImageIds } from '@cornerstonejs/tools/segmentation';
import { VOLUME_LOADER_SCHEME } from '../../constants';
const LABELMAP = csToolsEnums.SegmentationRepresentations.Labelmap;
const CONTOUR = csToolsEnums.SegmentationRepresentations.Contour;
import { VOLUME_LOADER_SCHEME } from '../../constants';
import { mapROIContoursToRTStructData } from './RTSTRUCT/mapROIContoursToRTStructData';
import { SegmentationPresentation, SegmentationPresentationItem } from '../../types/Presentation';
import { EasingFunctionEnum, EasingFunctionMap } from '../../utils/transitions';
const {
Labelmap: LABELMAP,
Contour: CONTOUR,
Surface: SURFACE,
} = csToolsEnums.SegmentationRepresentations;
const {
getLabelmapImageIds,
helpers: { convertStackToVolumeLabelmap },
state: { addColorLUT, updateLabelmapSegmentationImageReferences },
triggerSegmentationEvents: { triggerSegmentationRepresentationModified },
} = cstSegmentation;
export type SegmentRepresentation = {
segmentIndex: number;
@ -149,13 +153,11 @@ class SegmentationService extends PubSubService {
const representations = this.getSegmentationRepresentations(viewportId);
for (const representation of representations) {
const { segmentationId } = representation;
if (!representation) {
continue;
}
const { type } = representation;
const { segmentationId, type } = representation;
segmentationsMap.set(segmentationId, {
segmentationId,
@ -212,7 +214,7 @@ class SegmentationService extends PubSubService {
viewportId: string,
specifier: {
segmentationId?: string;
type?: SegmentationRepresentations;
type?: csToolsEnums.SegmentationRepresentations;
} = {}
): SegmentationRepresentation[] {
// Get all representations for the viewportId
@ -245,9 +247,19 @@ class SegmentationService extends PubSubService {
this._onSegmentationDataModifiedFromSource
);
eventTarget.removeEventListener(
csToolsEnums.Events.SEGMENTATION_REPRESENTATION_MODIFIED,
this._onSegmentationRepresentationModifiedFromSource
);
eventTarget.removeEventListener(
csToolsEnums.Events.SEGMENTATION_REPRESENTATION_ADDED,
this._onSegmentationModifiedFromSource
this._onSegmentationRepresentationModifiedFromSource
);
eventTarget.removeEventListener(
csToolsEnums.Events.SEGMENTATION_REPRESENTATION_REMOVED,
this._onSegmentationRepresentationModifiedFromSource
);
eventTarget.removeEventListener(
@ -283,11 +295,11 @@ class SegmentationService extends PubSubService {
const colorLUTIndex = this._segmentationIdToColorLUTIndexMap.get(segmentationId);
const defaultRepresentationType = csToolsEnums.SegmentationRepresentations.Labelmap;
const defaultRepresentationType = LABELMAP;
let representationTypeToUse = type || defaultRepresentationType;
let isConverted = false;
if (type === csToolsEnums.SegmentationRepresentations.Labelmap) {
if (representationTypeToUse === LABELMAP) {
const { isVolumeViewport, isVolumeSegmentation } = this.determineViewportAndSegmentationType(
csViewport,
segmentation
@ -354,7 +366,7 @@ class SegmentationService extends PubSubService {
const derivedImages = await imageLoader.createAndCacheDerivedLabelmapImages(referenceImageIds);
const segs = this.getSegmentations();
const label = options.label || `Segmentation ${segs.length + 1}`;
const label = options?.label || `Segmentation ${segs.length + 1}`;
const segImageIds = derivedImages.map(image => image.imageId);
@ -371,7 +383,7 @@ class SegmentationService extends PubSubService {
config: {
label,
segments:
options.segments && Object.keys(options.segments).length > 0
options?.segments && Object.keys(options.segments).length > 0
? options.segments
: {
1: {
@ -393,7 +405,7 @@ class SegmentationService extends PubSubService {
segDisplaySet,
options: {
segmentationId?: string;
type: SegmentationRepresentations;
type: csToolsEnums.SegmentationRepresentations;
} = {
type: LABELMAP,
}
@ -503,9 +515,7 @@ class SegmentationService extends PubSubService {
};
});
// get next color lut index
const colorLUTIndex = getNextColorLUTIndex();
addColorLUT(colorLUT, colorLUTIndex);
const colorLUTIndex = addColorLUT(colorLUT);
this._segmentationIdToColorLUTIndexMap.set(segmentationId, colorLUTIndex);
this._broadcastEvent(EVENTS.SEGMENTATION_LOADING_COMPLETE, {
@ -540,7 +550,7 @@ class SegmentationService extends PubSubService {
rtDisplaySet,
options: {
segmentationId?: string;
type: SegmentationRepresentations;
type: csToolsEnums.SegmentationRepresentations;
} = {
type: CONTOUR,
}
@ -616,7 +626,9 @@ class SegmentationService extends PubSubService {
const colorLUT = [[0, 0, 0, 0]]; // First entry is transparent for index 0
// Process each segment similarly to the SEG function
for (const rtStructData of allRTStructData) {
for (let i = 0; i < allRTStructData.length; i++) {
const rtStructData = allRTStructData[i];
const { data, id, color, segmentIndex, geometryId, group } = rtStructData;
// Add the color to the colorLUT array
@ -665,8 +677,7 @@ class SegmentationService extends PubSubService {
}
// Create and register the colorLUT
const colorLUTIndex = getNextColorLUTIndex();
addColorLUT(colorLUT, colorLUTIndex);
const colorLUTIndex = addColorLUT(colorLUT);
this._segmentationIdToColorLUTIndexMap.set(segmentationId, colorLUTIndex);
// Assign processed segments to segmentation config
@ -763,7 +774,7 @@ class SegmentationService extends PubSubService {
public hasCustomStyles(specifier: {
viewportId: string;
segmentationId: string;
type: SegmentationRepresentations;
type: csToolsEnums.SegmentationRepresentations;
}): boolean {
return cstSegmentation.config.style.hasCustomStyle(specifier);
}
@ -771,7 +782,7 @@ class SegmentationService extends PubSubService {
public getStyle = (specifier: {
viewportId: string;
segmentationId: string;
type: SegmentationRepresentations;
type: csToolsEnums.SegmentationRepresentations;
segmentIndex?: number;
}) => {
const style = cstSegmentation.config.style.getStyle(specifier);
@ -781,12 +792,12 @@ class SegmentationService extends PubSubService {
public setStyle = (
specifier: {
type: SegmentationRepresentations;
type: csToolsEnums.SegmentationRepresentations;
viewportId?: string;
segmentationId?: string;
segmentIndex?: number;
},
style: LabelmapStyle | ContourStyle | SurfaceStyle
style: cstTypes.LabelmapStyle | cstTypes.ContourStyle | cstTypes.SurfaceStyle
) => {
cstSegmentation.config.style.setStyle(specifier, style);
};
@ -904,7 +915,7 @@ class SegmentationService extends PubSubService {
segmentationId: string,
segmentIndex: number,
isVisible: boolean,
type?: SegmentationRepresentations
type?: csToolsEnums.SegmentationRepresentations
): void {
this._setSegmentVisibility(viewportId, segmentationId, segmentIndex, isVisible, type);
}
@ -941,7 +952,7 @@ class SegmentationService extends PubSubService {
viewportId: string,
segmentationId: string,
segmentIndex: number,
type: SegmentationRepresentations
type: csToolsEnums.SegmentationRepresentations
): void {
const isVisible = cstSegmentation.config.visibility.getSegmentIndexVisibility(
viewportId,
@ -1013,7 +1024,7 @@ class SegmentationService extends PubSubService {
public getLabelmapVolume(segmentationId: string) {
const csSegmentation = cstSegmentation.state.getSegmentation(segmentationId);
const labelmapData = csSegmentation.representationData[
SegmentationRepresentations.Labelmap
LABELMAP
] as cstTypes.LabelmapToolOperationDataVolume;
if (!labelmapData || !labelmapData.volumeId) {
@ -1115,7 +1126,10 @@ class SegmentationService extends PubSubService {
*/
public toggleSegmentationRepresentationVisibility = (
viewportId: string,
{ segmentationId, type }: { segmentationId: string; type: SegmentationRepresentations }
{
segmentationId,
type,
}: { segmentationId: string; type: csToolsEnums.SegmentationRepresentations }
): void => {
this._toggleSegmentationRepresentationVisibility(viewportId, segmentationId, type);
};
@ -1164,7 +1178,7 @@ class SegmentationService extends PubSubService {
viewportId: string,
specifier: {
segmentationId?: string;
type?: SegmentationRepresentations;
type?: csToolsEnums.SegmentationRepresentations;
} = {}
): void {
cstSegmentation.removeSegmentationRepresentations(viewportId, specifier);
@ -1276,7 +1290,7 @@ class SegmentationService extends PubSubService {
private _setSegmentationRepresentationVisibility(
viewportId: string,
segmentationId: string,
type: SegmentationRepresentations,
type: csToolsEnums.SegmentationRepresentations,
isVisible: boolean
): void {
const representations = this.getSegmentationRepresentations(viewportId, {
@ -1336,14 +1350,17 @@ class SegmentationService extends PubSubService {
private async handleVolumeViewportCase(csViewport, segmentation, isVolumeSegmentation) {
if (csViewport.type === ViewportType.VOLUME_3D) {
return { representationTypeToUse: SegmentationRepresentations.Surface, isConverted: false };
return {
representationTypeToUse: SURFACE,
isConverted: false,
};
} else {
await this.handleVolumeViewport(
csViewport as csTypes.IVolumeViewport,
segmentation,
isVolumeSegmentation
);
return { representationTypeToUse: SegmentationRepresentations.Labelmap, isConverted: false };
return { representationTypeToUse: LABELMAP, isConverted: false };
}
}
@ -1353,14 +1370,17 @@ class SegmentationService extends PubSubService {
isVolumeSegmentation: boolean,
viewportId: string,
segmentationId: string
): Promise<{ representationTypeToUse: SegmentationRepresentations; isConverted: boolean }> {
): Promise<{
representationTypeToUse: csToolsEnums.SegmentationRepresentations;
isConverted: boolean;
}> {
if (isVolumeSegmentation) {
const isConverted = await this.convertStackToVolumeViewport(csViewport);
return { representationTypeToUse: SegmentationRepresentations.Labelmap, isConverted };
return { representationTypeToUse: LABELMAP, isConverted };
}
if (updateLabelmapSegmentationImageReferences(viewportId, segmentationId)) {
return { representationTypeToUse: SegmentationRepresentations.Labelmap, isConverted: false };
return { representationTypeToUse: LABELMAP, isConverted: false };
}
const isConverted = await this.attemptStackToVolumeConversion(
@ -1370,7 +1390,7 @@ class SegmentationService extends PubSubService {
segmentationId
);
return { representationTypeToUse: SegmentationRepresentations.Labelmap, isConverted };
return { representationTypeToUse: LABELMAP, isConverted };
}
private async _addSegmentationRepresentation(
@ -1481,11 +1501,7 @@ class SegmentationService extends PubSubService {
segImage.FrameOfReferenceUID === frameOfReferenceUID
) {
const isConverted = await this.convertStackToVolumeViewport(viewport);
triggerSegmentationRepresentationModified(
viewportId,
segmentationId,
SegmentationRepresentations.Labelmap
);
triggerSegmentationRepresentationModified(viewportId, segmentationId, LABELMAP);
return isConverted;
}
@ -1613,7 +1629,7 @@ class SegmentationService extends PubSubService {
segmentIndex: number,
alpha: number,
hideOthers: boolean,
segments: Segment[],
segments: cstTypes.Segment[],
viewportId: string,
animationLength: number,
representation: cstTypes.SegmentationRepresentation,
@ -1685,7 +1701,7 @@ class SegmentationService extends PubSubService {
segmentIndex: number,
alpha: number,
hideOthers: boolean,
segments: Segment[],
segments: cstTypes.Segment[],
viewportId: string,
animationLength: number,
representation: cstTypes.SegmentationRepresentation,
@ -1696,7 +1712,7 @@ class SegmentationService extends PubSubService {
const prevStyle = cstSegmentation.config.style.getStyle({
type: CONTOUR,
}) as ContourStyle;
}) as cstTypes.ContourStyle;
const prevOutlineWidth = prevStyle.outlineWidth;
@ -1730,7 +1746,7 @@ class SegmentationService extends PubSubService {
private _toggleSegmentationRepresentationVisibility = (
viewportId: string,
segmentationId: string,
type: SegmentationRepresentations
type: csToolsEnums.SegmentationRepresentations
): void => {
const representations = this.getSegmentationRepresentations(viewportId, {
segmentationId,
@ -1798,7 +1814,7 @@ class SegmentationService extends PubSubService {
segmentationId: string,
segmentIndex: number,
isVisible: boolean,
type?: SegmentationRepresentations
type?: csToolsEnums.SegmentationRepresentations
) {
cstSegmentation.config.visibility.setSegmentIndexVisibility(
viewportId,

View File

@ -83,23 +83,24 @@
},
"devDependencies": {
"@babel/core": "7.28.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-arrow-functions": "^7.16.7",
"@babel/plugin-transform-class-properties": "^7.27.1",
"@babel/plugin-transform-for-of": "^7.27.1",
"@babel/plugin-transform-object-rest-spread": "^7.28.0",
"@babel/plugin-transform-private-methods": "^7.27.1",
"@babel/plugin-transform-private-property-in-object": "^7.27.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-arrow-functions": "^7.16.7",
"@babel/plugin-transform-for-of": "^7.27.1",
"@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "7.28.0",
"@babel/plugin-transform-typescript": "^7.28.0",
"@babel/preset-env": "7.28.0",
"@babel/preset-react": "^7.27.1",
"@babel/preset-typescript": "^7.27.1",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.17",
"babel-loader": "8.4.1",
"babel-plugin-istanbul": "^7.0.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"babel-plugin-transform-import-meta": "2.3.3",
"css-loader": "6.11.0",
"cypress": "14.5.2",
"cypress-file-upload": "^5.0.8",

View File

@ -1212,7 +1212,7 @@
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.6.tgz#ec4070a04d76bae8ddbb10770ba55714a417b7c6"
integrity sha512-vbavdySgbTTrmFE+EsiqUTzlOr5bzlnJtUv9PynGCAKvfQqjIXbvFdumPM/GxMDfyuGMJaJAU6TO4zc1Jf1i8Q==
"@babel/template@^7.27.1", "@babel/template@^7.27.2", "@babel/template@^7.3.3":
"@babel/template@^7.25.9", "@babel/template@^7.27.1", "@babel/template@^7.27.2", "@babel/template@^7.3.3":
version "7.27.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.2.tgz#fa78ceed3c4e7b63ebf6cb39e5852fca45f6809d"
integrity sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==
@ -5354,6 +5354,14 @@ babel-plugin-polyfill-regenerator@^0.6.5:
dependencies:
"@babel/helper-define-polyfill-provider" "^0.6.5"
babel-plugin-transform-import-meta@2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-import-meta/-/babel-plugin-transform-import-meta-2.3.3.tgz#863de841f7df37e2bf39a057572a24e4f65f3c51"
integrity sha512-bbh30qz1m6ZU1ybJoNOhA2zaDvmeXMnGNBMVMDOJ1Fni4+wMBoy/j7MTRVmqAUCIcy54/rEnr9VEBsfcgbpm3Q==
dependencies:
"@babel/template" "^7.25.9"
tslib "^2.8.1"
babel-preset-current-node-syntax@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz#9a929eafece419612ef4ae4f60b1862ebad8ef30"
@ -18079,7 +18087,7 @@ tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4.0, tslib@^2.8.0:
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4.0, tslib@^2.8.0, tslib@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==