This commit is contained in:
parent
0803dce328
commit
2c6ce21c8f
@ -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', () => {
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user