Skip to content

Commit ee51ff3

Browse files
committed
fix(datasource/graphene) multicut tool no longer relies on showing segment zero in order to color it black (has the negative effect of giving it a highlight color when hovering above it, which is problematic for volume rendering)
1 parent f4a2c6f commit ee51ff3

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

src/datasource/graphene/frontend.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ const RED_COLOR_SEGMENT_PACKED = BigInt(packColor(RED_COLOR_SEGMENT));
226226
const BLUE_COLOR_SEGMENT_PACKED = BigInt(packColor(BLUE_COLOR_SEGMENT));
227227
const TRANSPARENT_COLOR_PACKED = BigInt(packColor(TRANSPARENT_COLOR));
228228
const MULTICUT_OFF_COLOR = vec4.fromValues(0, 0, 0, 0.5);
229+
const MULTICUT_OFF_COLOR_PACKED = BigInt(packColor(MULTICUT_OFF_COLOR));
229230
const WHITE_COLOR = vec3.fromValues(1, 1, 1);
230231

231232
class GrapheneMeshSource extends WithParameters(
@@ -2767,14 +2768,12 @@ class MulticutSegmentsTool extends LayerTool<SegmentationUserLayer> {
27672768
const priorBaseSegmentHighlighting =
27682769
displayState.baseSegmentHighlighting.value;
27692770
const priorHighlightColor = displayState.highlightColor.value;
2770-
const priorHideSegmentZero = displayState.hideSegmentZero.value;
27712771

27722772
activation.bindInputEventMap(MULTICUT_SEGMENTS_INPUT_EVENT_MAP);
27732773
activation.registerDisposer(() => {
27742774
resetMulticutDisplay();
27752775
displayState.baseSegmentHighlighting.value = priorBaseSegmentHighlighting;
27762776
displayState.highlightColor.value = priorHighlightColor;
2777-
displayState.hideSegmentZero.value = priorHideSegmentZero;
27782777
});
27792778
const resetMulticutDisplay = () => {
27802779
resetTemporaryVisibleSegmentsState(segmentationGroupState);
@@ -2795,7 +2794,6 @@ class MulticutSegmentsTool extends LayerTool<SegmentationUserLayer> {
27952794
displayState.highlightColor.value = multicutState.blueGroup.value
27962795
? BLUE_COLOR_HIGHTLIGHT
27972796
: RED_COLOR_HIGHLIGHT;
2798-
displayState.hideSegmentZero.value = false;
27992797
segmentsState.useTemporaryVisibleSegments.value = true;
28002798
segmentsState.useTemporarySegmentEquivalences.value = true;
28012799
// add focus segment and red/blue segments
@@ -2820,6 +2818,10 @@ class MulticutSegmentsTool extends LayerTool<SegmentationUserLayer> {
28202818
focusSegment,
28212819
TRANSPARENT_COLOR_PACKED,
28222820
);
2821+
displayState.tempSegmentStatedColors2d.value.set(
2822+
0n,
2823+
MULTICUT_OFF_COLOR_PACKED,
2824+
);
28232825
for (const segment of multicutState.redSegments) {
28242826
displayState.tempSegmentStatedColors2d.value.set(
28252827
segment,

src/sliceview/volume/segmentation_renderlayer.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,48 @@ uint64_t getMappedObjectId(uint64_t value) {
267267
float alpha = uSelectedAlpha;
268268
float saturation = uSaturation;
269269
`;
270+
271+
let getMappedIdColor = `vec4 getMappedIdColor(uint64_t value) {
272+
`;
273+
// If the value has a mapped color, use it; otherwise, compute the color.
274+
275+
// specific color, highlight ok
276+
if (parameters.hasSegmentStatedColors) {
277+
this.segmentStatedColorShaderManager.defineShader(builder);
278+
getMappedIdColor += `
279+
vec4 rgba;
280+
if (${this.segmentStatedColorShaderManager.getFunctionName}(value, rgba)) {
281+
return rgba;
282+
}
283+
`;
284+
}
285+
if (parameters.hasSegmentDefaultColor) {
286+
builder.addUniform("highp vec4", "uSegmentDefaultColor");
287+
getMappedIdColor += ` return uSegmentDefaultColor;
288+
`;
289+
} else {
290+
this.segmentColorShaderManager.defineShader(builder);
291+
getMappedIdColor += ` return vec4(segmentColorHash(value), 0.0);
292+
`;
293+
}
294+
getMappedIdColor += `
295+
}
296+
`;
297+
builder.addFragmentCode(getMappedIdColor);
298+
270299
if (parameters.hideSegmentZero) {
271300
fragmentMain += `
272-
if (value.value[0] == 0u && value.value[1] == 0u) {
301+
if (value.value[0] == 0u && value.value[1] == 0u) {`;
302+
if (parameters.hasSegmentStatedColors) {
303+
fragmentMain += `
304+
vec4 rgba;
305+
if (${this.segmentStatedColorShaderManager.getFunctionName}(valueForColor, rgba)) {
306+
emit(vec4(mix(vec3(1.0,1.0,1.0), vec3(rgba), saturation), alpha));
307+
return;
308+
}
309+
`;
310+
}
311+
fragmentMain += `
273312
emit(vec4(vec4(0, 0, 0, 0)));
274313
return;
275314
}
@@ -297,32 +336,6 @@ uint64_t getMappedObjectId(uint64_t value) {
297336
alpha = uNotSelectedAlpha;
298337
}
299338
`;
300-
let getMappedIdColor = `vec4 getMappedIdColor(uint64_t value) {
301-
`;
302-
// If the value has a mapped color, use it; otherwise, compute the color.
303-
if (parameters.hasSegmentStatedColors) {
304-
this.segmentStatedColorShaderManager.defineShader(builder);
305-
getMappedIdColor += `
306-
vec4 rgba;
307-
if (${this.segmentStatedColorShaderManager.getFunctionName}(value, rgba)) {
308-
return rgba;
309-
}
310-
`;
311-
}
312-
if (parameters.hasSegmentDefaultColor) {
313-
builder.addUniform("highp vec4", "uSegmentDefaultColor");
314-
getMappedIdColor += ` return uSegmentDefaultColor;
315-
`;
316-
} else {
317-
this.segmentColorShaderManager.defineShader(builder);
318-
getMappedIdColor += ` return vec4(segmentColorHash(value), 0.0);
319-
`;
320-
}
321-
getMappedIdColor += `
322-
}
323-
`;
324-
builder.addFragmentCode(getMappedIdColor);
325-
326339
fragmentMain += `
327340
vec4 rgba = getMappedIdColor(valueForColor);
328341
if (rgba.a > 0.0) {

0 commit comments

Comments
 (0)