fix(Segmentation): [Bug #5420] Segmentation color resets after using toggleOneUp (#5465)

This commit is contained in:
Vinícius Alves de Faria Resende 2025-10-07 14:23:26 -03:00 committed by GitHub
parent 0803dce328
commit 2c6ce21c8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 5 deletions

View File

@ -2031,6 +2031,9 @@ describe('SegmentationService', () => {
.spyOn(cstSegmentation.segmentLocking, 'setSegmentIndexLocked')
.mockReturnValue(undefined);
jest.spyOn(cstSegmentation.config.color, 'setSegmentIndexColor').mockReturnValue(undefined);
jest
.spyOn(cstSegmentation.state, 'getSegmentationRepresentations')
.mockReturnValue([{ colorLUTIndex: 1 }]);
service.addSegment(segmentationId, config);
@ -2192,16 +2195,25 @@ describe('SegmentationService', () => {
});
describe('setSegmentColor', () => {
it('should set the color of the segment', () => {
const viewportId = 'viewportId';
const segmentationId = 'segmentationId';
const segmentIndex = 1;
const color = [255, 0, 0, 255] as csTypes.Color;
const viewportId = 'viewportId';
const segmentationId = 'segmentationId';
const segmentIndex = 1;
const color = [255, 0, 0, 255] as csTypes.Color;
it('should set the color of the segment', () => {
jest
.spyOn(cstSegmentation.state, 'getSegmentationRepresentations')
.mockReturnValue([{ colorLUTIndex: 1 }]);
jest.spyOn(cstSegmentation.config.color, 'setSegmentIndexColor').mockReturnValue(undefined);
service.setSegmentColor(viewportId, segmentationId, segmentIndex, color);
expect(cstSegmentation.state.getSegmentationRepresentations).toHaveBeenCalledTimes(1);
expect(cstSegmentation.state.getSegmentationRepresentations).toHaveBeenCalledWith(
viewportId,
{ segmentationId }
);
expect(cstSegmentation.config.color.setSegmentIndexColor).toHaveBeenCalledTimes(1);
expect(cstSegmentation.config.color.setSegmentIndexColor).toHaveBeenCalledWith(
viewportId,
@ -2210,6 +2222,43 @@ describe('SegmentationService', () => {
color
);
});
it('should set the color of the segment with the colorLUTIndex', async () => {
jest
.spyOn(cstSegmentation.state, 'getSegmentationRepresentations')
.mockReturnValue([{ colorLUTIndex: 1 }]);
jest.spyOn(cstSegmentation.config.color, 'setSegmentIndexColor').mockReturnValue(undefined);
service.setSegmentColor(viewportId, segmentationId, segmentIndex, color);
jest
.spyOn(cstSegmentation.state, 'getSegmentation')
.mockReturnValue(mockCornerstoneSegmentation as cstTypes.Segmentation);
jest
.spyOn(serviceManagerMock.services.cornerstoneViewportService, 'getCornerstoneViewport')
// only needed interfaces for the addSegmentationRepresentation call
.mockReturnValue(mockCornerstoneStackViewport as unknown as csTypes.IStackViewport);
jest
.spyOn(cstSegmentation.state, 'updateLabelmapSegmentationImageReferences')
.mockReturnValue('labelmapImageId');
jest.spyOn(cstSegmentation, 'addSegmentationRepresentations').mockReturnValueOnce(undefined);
await service.addSegmentationRepresentation(viewportId, {
segmentationId: segmentationId,
type: csToolsEnums.SegmentationRepresentations.Labelmap,
config: { active: true },
suppressEvents: true,
});
expect(cstSegmentation.addSegmentationRepresentations).toHaveBeenCalledTimes(1);
expect(cstSegmentation.addSegmentationRepresentations).toHaveBeenCalledWith(viewportId, [
{
type: csToolsEnums.SegmentationRepresentations.Labelmap,
segmentationId: segmentationId,
config: { colorLUTOrIndex: 1, active: true },
},
]);
});
});
describe('getSegmentColor', () => {

View File

@ -983,6 +983,12 @@ class SegmentationService extends PubSubService {
segmentIndex: number,
color: csTypes.Color
): void {
const segmentationRepresentations = this.getSegmentationRepresentations(viewportId, {
segmentationId,
});
const { colorLUTIndex } = segmentationRepresentations[0];
this._segmentationIdToColorLUTIndexMap.set(segmentationId, colorLUTIndex);
cstSegmentation.config.color.setSegmentIndexColor(
viewportId,
segmentationId,