Skip to content

Commit 6dbda91

Browse files
committed
feat(segmentGroups): cycle colors on create new segment
1 parent 1e9d8c4 commit 6dbda91

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,4 @@ export const CATEGORICAL_COLORS = [
505505
[228, 114, 126],
506506
[89, 38, 119],
507507
[105, 47, 61],
508-
];
508+
] as const;

src/store/segmentGroups.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { computed, reactive, ref, toRaw, watch } from 'vue';
22
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
33
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
44
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
5-
import type { RGBAColor, TypedArray } from '@kitware/vtk.js/types';
5+
import type { TypedArray } from '@kitware/vtk.js/types';
66
import { defineStore } from 'pinia';
77
import { useImageStore } from '@/src/store/datasets-images';
88
import { join, normalize } from '@/src/utils/path';
@@ -32,7 +32,6 @@ const LabelmapArrayType = Uint8Array;
3232
export type LabelmapArrayType = Uint8Array;
3333

3434
export const LABELMAP_BACKGROUND_VALUE = 0;
35-
export const DEFAULT_SEGMENT_COLOR: RGBAColor = [255, 0, 0, 255];
3635
export const makeDefaultSegmentName = (value: number) => `Segment ${value}`;
3736
export const makeDefaultSegmentGroupName = (baseName: string, index: number) =>
3837
`Segment Group ${index} for ${baseName}`;
@@ -254,7 +253,7 @@ export const useSegmentGroupStore = defineStore('segmentGroup', () => {
254253
function getNextColor() {
255254
const color = CATEGORICAL_COLORS[nextColorIndex];
256255
nextColorIndex = (nextColorIndex + 1) % CATEGORICAL_COLORS.length;
257-
return [...color, 255];
256+
return [...color, 255] as const;
258257
}
259258

260259
async function decodeSegments(
@@ -290,7 +289,7 @@ export const useSegmentGroupStore = defineStore('segmentGroup', () => {
290289
return values.map((value) => ({
291290
value,
292291
name: makeDefaultSegmentName(value),
293-
color: getNextColor(),
292+
color: [...getNextColor()],
294293
visible: true,
295294
}));
296295
}
@@ -398,7 +397,7 @@ export const useSegmentGroupStore = defineStore('segmentGroup', () => {
398397
return {
399398
name: makeDefaultSegmentName(value),
400399
value,
401-
color: DEFAULT_SEGMENT_COLOR,
400+
color: [...getNextColor()],
402401
visible: true,
403402
};
404403
}

0 commit comments

Comments
 (0)