Skip to content

Commit cb6bae4

Browse files
committed
cleanup
1 parent 589669e commit cb6bae4

File tree

4 files changed

+43
-48
lines changed

4 files changed

+43
-48
lines changed

src/layer/segmentation/index.ts

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,31 @@ import { computeInvlerp } from "#src/util/lerp.js";
145145

146146
const MAX_LAYER_BAR_UI_INDICATOR_COLORS = 6;
147147

148-
export interface SegmentPropertyColor {
148+
export interface SegmentPropertyColorBase {
149149
type: "tag" | "numeric";
150150
active: boolean;
151-
property?: string;
152-
map?: Map<string, string>; // TODO is there a color type?
153-
options?: {
151+
}
152+
153+
export interface SegmentPropertyColorNumeric extends SegmentPropertyColorBase {
154+
type: "numeric";
155+
active: boolean;
156+
property: string;
157+
options: {
154158
min?: number;
155159
max?: number;
156160
minColor: string;
157161
maxColor: string;
158162
};
159163
}
160164

165+
export interface SegmentPropertyColorTag extends SegmentPropertyColorBase {
166+
type: "tag";
167+
active: boolean;
168+
map: Map<string, string>;
169+
}
170+
171+
export type SegmentPropertyColor = SegmentPropertyColorNumeric | SegmentPropertyColorTag;
172+
161173
export class SegmentationUserLayerGroupState
162174
extends RefCounted
163175
implements SegmentationGroupState
@@ -325,42 +337,29 @@ export class SegmentationUserLayerColorGroupState
325337
this.segmentPropertyColorsMap = this.registerDisposer(
326338
makeCachedDerivedWatchableValue(
327339
(segmentPropertyMap, segmentPropertyColors) => {
328-
console.log("update segmentPropertyColorsMap");
329-
segmentPropertyColors;
330340
const map = new Uint64Map();
331341
if (!segmentPropertyMap) {
332342
return map;
333343
}
334-
335344
const { tags: tagsProperty } = segmentPropertyMap;
336-
337-
console.log("tags", segmentPropertyMap.tags);
338-
339345
for (const propertyColor of segmentPropertyColors) {
340346
if (!propertyColor.active) continue;
341-
342347
if (propertyColor.type === "tag" && tagsProperty) {
343348
const { tags, values } = tagsProperty;
344-
345-
// const colors = todo performance, cache colors as bigints
346-
347349
const bigIntColors = new Map<string, bigint>();
348350
for (const [tag, colorString] of propertyColor.map!.entries()) {
349351
const color = parseRGBColorSpecification(colorString);
350352
bigIntColors.set(tag, BigInt(packColor(color)));
351-
console.log("tag color", tag, colorString, color);
352353
}
353-
354354
for (const [index, id] of (
355355
segmentPropertyMap.segmentPropertyMap.inlineProperties?.ids ||
356356
[]
357357
).entries()) {
358-
if (map.has(id)) continue; // priority first color match
358+
if (map.has(id)) continue; // prioritize first color match
359359
const tagIndices = values[index];
360360
const segmentTags = new Set(
361361
tagIndices.split("").map((x) => tags[x.charCodeAt(0)]),
362362
);
363-
364363
for (const [tag, color] of bigIntColors.entries()) {
365364
if (segmentTags.has(tag)) {
366365
map.set(id, color);
@@ -369,7 +368,7 @@ export class SegmentationUserLayerColorGroupState
369368
}
370369
}
371370
} else if (propertyColor.type === "numeric") {
372-
const options = propertyColor.options!;
371+
const options = propertyColor.options;
373372
const { numericalProperties } = segmentPropertyMap;
374373
const numericalProperty = numericalProperties.find(
375374
(x) => x.id === propertyColor.property,
@@ -381,11 +380,11 @@ export class SegmentationUserLayerColorGroupState
381380
const { values, bounds } = numericalProperty;
382381
const min = Number(options.min ?? bounds[0]);
383382
const max = Number(options.max ?? bounds[1]);
384-
385383
for (const [index, id] of (
386384
segmentPropertyMap.segmentPropertyMap.inlineProperties?.ids ||
387385
[]
388386
).entries()) {
387+
if (map.has(id)) continue; // prioritize first color match
389388
const value = values[index];
390389
if (Number.isNaN(value)) continue;
391390
const normalized = Math.min(
@@ -398,7 +397,6 @@ export class SegmentationUserLayerColorGroupState
398397
}
399398
}
400399
}
401-
console.log("map", map.size);
402400
return map;
403401
},
404402
[
@@ -465,7 +463,7 @@ export class SegmentationUserLayerColorGroupState
465463
if (type === "tag") {
466464
const map = verifyObjectProperty(
467465
propertyColor,
468-
json_keys.MAP_JSON_KEY,
466+
"map",
469467
(x) => {
470468
verifyObject(x);
471469
const res = new Map<string, string>();
@@ -543,22 +541,25 @@ export class SegmentationUserLayerColorGroupState
543541
}
544542
}
545543
if (segmentPropertyColors.length > 0) {
546-
const j: any[] = (x[json_keys.SEGMENT_PROPERTY_COLORS_JSON_KEY] = []);
547-
for (const propertyColor of segmentPropertyColors) {
548-
const p: any = {};
549-
p["type"] = propertyColor.type;
550-
p["property"] = propertyColor.property;
551-
p["active"] = propertyColor.active ? undefined : false;
552-
if (propertyColor.type === "tag") {
553-
const map: any = (p[json_keys.MAP_JSON_KEY] = {});
554-
for (const [key, value] of propertyColor.map!.entries()) {
555-
map[key.toString()] = value;
556-
}
544+
x[json_keys.SEGMENT_PROPERTY_COLORS_JSON_KEY] = segmentPropertyColors.map((propertyColor) => {
545+
const {type, active} = propertyColor;
546+
if (type === "numeric") {
547+
const { property, options } = propertyColor;
548+
return {
549+
type,
550+
active,
551+
property,
552+
options
553+
};
557554
} else {
558-
p["options"] = propertyColor.options;
555+
const { map } = propertyColor;
556+
return {
557+
type,
558+
active,
559+
map: Object.fromEntries(map.entries().map(([k,v])=>[k.toString(),v])),
560+
};
559561
}
560-
j.push(p);
561-
}
562+
});
562563
}
563564
return x;
564565
}

src/layer/segmentation/json_keys.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const EQUIVALENCES_JSON_KEY = "equivalences";
1313
export const COLOR_SEED_JSON_KEY = "colorSeed";
1414
export const SEGMENT_STATED_COLORS_JSON_KEY = "segmentColors";
1515
export const SEGMENT_PROPERTY_COLORS_JSON_KEY = "segmentPropertyColors";
16-
export const MAP_JSON_KEY = "map";
1716
export const MESH_RENDER_SCALE_JSON_KEY = "meshRenderScale";
1817
export const CROSS_SECTION_RENDER_SCALE_JSON_KEY = "crossSectionRenderScale";
1918
export const SHADER_JSON_KEY = "shader";

src/sliceview/volume/segmentation_renderlayer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,9 @@ uint64_t getMappedObjectId(uint64_t value) {
431431

432432
const segmentPropertyColorsMap = displayState.segmentPropertyColorsMap.value;
433433

434-
435434
const combinedMap = new Uint64Map();
436-
segmentStatedColors;
437-
combinedMap.union(segmentPropertyColorsMap);
438-
combinedMap.union(segmentStatedColors);
435+
combinedMap.assignFrom(segmentStatedColors, false);
436+
combinedMap.assignFrom(segmentPropertyColorsMap, false);
439437

440438
let { gpuSegmentStatedColorHashTable } = this;
441439
if (

src/uint64_map.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,11 @@ export class Uint64Map
9090
return this.hashTable.size;
9191
}
9292

93-
assignFrom(other: Uint64Map) {
94-
this.clear();
95-
this.union(other);
96-
}
97-
98-
union(other: Uint64Map) {
93+
assignFrom(other: Uint64Map, clear = true) {
94+
if (clear) {
95+
this.clear();
96+
}
9997
for (const [key, value] of other) {
100-
this.delete(key);
10198
this.set(key, value);
10299
}
103100
}

0 commit comments

Comments
 (0)