fix(segmentation): upgrade cs3d to fix various segmentation bugs (#3885)

This commit is contained in:
Alireza authored and GitHub committed 2024-01-09 10:15:56 -05:00
1 parent a8a0bdb2df
commit b1efe40aa1
26 files changed
+241 -171

No files matched your search

@@ -1,5 +1,3 @@
import cloneDeep from 'lodash.clonedeep';
import { Types as OhifTypes, ServicesManager, PubSubService } from '@ohif/core';
import {
cache,
@@ -11,7 +9,6 @@ import {
volumeLoader,
} from '@cornerstonejs/core';
import {
CONSTANTS as cstConstants,
Enums as csToolsEnums,
segmentation as cstSegmentation,
Types as cstTypes,
@@ -23,7 +20,6 @@ import { easeInOutBell, reverseEaseInOutBell } from '../../utils/transitions';
import { Segment, Segmentation, SegmentationConfig } from './SegmentationServiceTypes';
import { mapROIContoursToRTStructData } from './RTSTRUCT/mapROIContoursToRTStructData';
const { COLOR_LUT } = cstConstants;
const LABELMAP = csToolsEnums.SegmentationRepresentations.Labelmap;
const CONTOUR = csToolsEnums.SegmentationRepresentations.Contour;
@@ -465,15 +461,6 @@ class SegmentationService extends PubSubService {
},
]);
// if first segmentation, we can use the default colorLUT, otherwise
// we need to generate a new one and use a new colorLUT
const colorLUTIndex = 0;
if (Object.keys(this.segmentations).length !== 0) {
const newColorLUT = this.generateNewColorLUT();
const colorLUTIndex = this.getNextColorLUTIndex();
cstSegmentation.config.color.addColorLUT(newColorLUT, colorLUTIndex);
}
this.segmentations[segmentationId] = {
...segmentation,
label: segmentation.label || '',
@@ -482,7 +469,6 @@ class SegmentationService extends PubSubService {
segmentCount: segmentation.segmentCount ?? 0,
isActive: false,
isVisible: true,
colorLUTIndex,
};
cachedSegmentation = this.segmentations[segmentationId];
@@ -1037,8 +1023,6 @@ class SegmentationService extends PubSubService {
segmentation.hydrated = true;
}
const { colorLUTIndex } = segmentation;
// Based on the segmentationId, set the colorLUTIndex.
const segmentationRepresentationUIDs = await cstSegmentation.addSegmentationRepresentations(
toolGroupId,
@@ -1057,12 +1041,6 @@ class SegmentationService extends PubSubService {
segmentationRepresentationUIDs[0]
);
cstSegmentation.config.color.setColorLUT(
toolGroupId,
segmentationRepresentationUIDs[0],
colorLUTIndex
);
// add the segmentation segments properly
for (const segment of segmentation.segments) {
if (segment === null || segment === undefined) {
@@ -1530,7 +1508,6 @@ class SegmentationService extends PubSubService {
segments: [],
isVisible: true,
isActive: false,
colorLUTIndex: 0,
};
}
@@ -2124,23 +2101,6 @@ class SegmentationService extends PubSubService {
return viewportInfo.getToolGroupId();
};
private getNextColorLUTIndex = (): number => {
let i = 0;
while (true) {
if (cstSegmentation.state.getColorLUT(i) === undefined) {
return i;
}
i++;
}
};
private generateNewColorLUT() {
const newColorLUT = cloneDeep(COLOR_LUT);
return newColorLUT;
}
/**
* Converts object of objects to array.
*
@@ -1,5 +1,5 @@
import { Types, Enums } from '@cornerstonejs/core';
import { Types as UITypes } from '@ohif/ui';
import { Types as CoreTypes } from '@ohif/core';
import { StackViewportData, VolumeViewportData } from '../../types/CornerstoneCacheService';
import getCornerstoneBlendMode from '../../utils/getCornerstoneBlendMode';
import getCornerstoneOrientation from '../../utils/getCornerstoneOrientation';
@@ -18,7 +18,7 @@ export type ViewportOptions = {
toolGroupId: string;
viewportId: string;
// Presentation ID to store/load presentation state from
presentationIds?: UITypes.PresentationIds;
presentationIds?: CoreTypes.PresentationIds;
orientation?: Enums.OrientationAxis;
background?: Types.Point3;
displayArea?: Types.DisplayArea;
@@ -36,7 +36,7 @@ export type PublicViewportOptions = {
id?: string;
viewportType?: string;
toolGroupId?: string;
presentationIds?: UITypes.PresentationIds;
presentationIds?: CoreTypes.PresentationIds;
viewportId?: string;
orientation?: Enums.OrientationAxis;
background?: Types.Point3;
@@ -71,7 +71,7 @@ export type DisplaySetOptions = {
voiInverted: boolean;
blendMode?: Enums.BlendModes;
slabThickness?: number;
colormap?: { name: string, opacity?: number };
colormap?: { name: string; opacity?: number };
displayPreset?: string;
};