Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selective segment visibility regardless of proofreading tool #8281

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class PlaneMaterialFactory {
selectiveVisibilityInProofreading: {
value: true,
},
selectiveSegmentVisibility: {
value: false,
},
is3DViewBeingRendered: {
value: true,
},
Expand Down Expand Up @@ -562,6 +565,17 @@ class PlaneMaterialFactory {
true,
),
);

this.storePropertyUnsubscribers.push(
listenToStoreProperty(
(storeState) => storeState.datasetConfiguration.selectiveSegmentVisibility,
(selectiveSegmentVisibility) => {
this.uniforms.selectiveSegmentVisibility.value = selectiveSegmentVisibility;
},
true,
),
);

this.storePropertyUnsubscribers.push(
listenToStoreProperty(
(storeState) => getMagInfoByLayer(storeState.dataset),
Expand Down
29 changes: 10 additions & 19 deletions frontend/javascripts/oxalis/shaders/main_data_shaders.glsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
convertCellIdToRGB,
getBrushOverlay,
getCrossHairOverlay,
getSegmentationAlphaIncrement,
getSegmentId,
} from "./segmentation.glsl";
import { getMaybeFilteredColorOrFallback } from "./filtering.glsl";
Expand Down Expand Up @@ -110,6 +111,7 @@ uniform highp uint LOOKUP_CUCKOO_TWIDTH;

uniform float sphericalCapRadius;
uniform bool selectiveVisibilityInProofreading;
uniform bool selectiveSegmentVisibility;
uniform float viewMode;
uniform float alpha;
uniform bool renderBucketIndices;
Expand Down Expand Up @@ -178,6 +180,7 @@ ${compileShader(
hasSegmentation ? getBrushOverlay : null,
hasSegmentation ? getSegmentId : null,
hasSegmentation ? getCrossHairOverlay : null,
hasSegmentation ? getSegmentationAlphaIncrement : null,
almostEq,
)}

Expand Down Expand Up @@ -291,25 +294,13 @@ void main() {
&& hoveredUnmappedSegmentIdHigh == <%= segmentationName %>_unmapped_id_high;
bool isActiveCell = activeCellIdLow == <%= segmentationName %>_id_low
&& activeCellIdHigh == <%= segmentationName %>_id_high;
// Highlight cell only if it's hovered or active during proofreading
// and if segmentation opacity is not zero
float alphaIncrement = isProofreading
? (isActiveCell
? (isHoveredUnmappedSegment
? 0.4 // Highlight the hovered super-voxel of the active segment
: (isHoveredSegment
? 0.15 // Highlight the not-hovered super-voxels of the hovered segment
: 0.0
)
)
: (isHoveredSegment
? 0.2
// We are in proofreading mode, but the current voxel neither belongs
// to the active segment nor is it hovered. When selective visibility
// is enabled, lower the opacity.
: (selectiveVisibilityInProofreading ? -<%= segmentationName %>_alpha : 0.0)
)
) : (isHoveredSegment ? 0.2 : 0.0);
float alphaIncrement = getSegmentationAlphaIncrement(
<%= segmentationName %>_alpha,
isHoveredSegment,
isHoveredUnmappedSegment,
isActiveCell
);

gl_FragColor = vec4(mix(
data_color.rgb,
convertCellIdToRGB(<%= segmentationName %>_id_high, <%= segmentationName %>_id_low),
Expand Down
41 changes: 41 additions & 0 deletions frontend/javascripts/oxalis/shaders/segmentation.glsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,44 @@ export const getSegmentId: ShaderModule = {
<% }) %>
`,
};

export const getSegmentationAlphaIncrement: ShaderModule = {
requirements: [],
code: `
float getSegmentationAlphaIncrement(float alpha, bool isHoveredSegment, bool isHoveredUnmappedSegment, bool isActiveCell) {
// Highlight segment only if
// - it's hovered or
// - active during proofreading
// Also, make segments invisible if selective visibility is turned on (unless the segment
// is active or hovered).

if (isProofreading) {
if (isActiveCell) {
return (isHoveredUnmappedSegment
? 0.4 // Highlight the hovered super-voxel of the active segment
: (isHoveredSegment
? 0.15 // Highlight the not-hovered super-voxels of the hovered segment
: 0.0
)
);
} else {
return (isHoveredSegment
? 0.2
// We are in proofreading mode, but the current voxel neither belongs
// to the active segment nor is it hovered. When selective visibility
// is enabled, lower the opacity.
: (selectiveVisibilityInProofreading ? -alpha : 0.0)
);
}
}

if (isHoveredSegment) {
return 0.2;
} else if (selectiveSegmentVisibility) {
return isActiveCell ? 0.15 : -alpha;
} else {
return 0.;
}
}
`,
};
1 change: 1 addition & 0 deletions frontend/javascripts/oxalis/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export type DatasetConfiguration = {
readonly renderMissingDataBlack: boolean;
readonly loadingStrategy: LoadingStrategy;
readonly segmentationPatternOpacity: number;
readonly selectiveSegmentVisibility: boolean;
readonly blendMode: BLEND_MODES;
// If nativelyRenderedLayerName is not-null, the layer with
// that name (or id) should be rendered without any transforms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
reloadHistogramAction,
} from "oxalis/model/actions/settings_actions";
import { userSettings } from "types/schemas/user_settings.schema";
import type { Vector3, ControlMode } from "oxalis/constants";
import type { Vector3 } from "oxalis/constants";
import Constants, { ControlModeEnum, MappingStatusEnum } from "oxalis/constants";
import EditableTextLabel from "oxalis/view/components/editable_text_label";
import LinkButton from "components/link_button";
Expand All @@ -97,9 +97,6 @@ import type {
DatasetLayerConfiguration,
OxalisState,
UserConfiguration,
HistogramDataForAllLayers,
Tracing,
Task,
} from "oxalis/store";
import Store from "oxalis/store";
import Toast from "libs/toast";
Expand Down Expand Up @@ -132,33 +129,8 @@ import {
} from "types/schemas/dataset_view_configuration.schema";
import defaultState from "oxalis/default_state";

type DatasetSettingsProps = {
userConfiguration: UserConfiguration;
datasetConfiguration: DatasetConfiguration;
dataset: APIDataset;
onChange: (propertyName: keyof DatasetConfiguration, value: any) => void;
onChangeLayer: (
layerName: string,
propertyName: keyof DatasetLayerConfiguration,
value: any,
) => void;
onClipHistogram: (layerName: string, shouldAdjustClipRange: boolean) => Promise<void>;
histogramData: HistogramDataForAllLayers;
onChangeRadius: (value: number) => void;
onChangeShowSkeletons: (arg0: boolean) => void;
onSetPosition: (arg0: Vector3) => void;
onZoomToMag: (layerName: string, arg0: Vector3) => number;
onChangeUser: (key: keyof UserConfiguration, value: any) => void;
reloadHistogram: (layerName: string) => void;
tracing: Tracing;
task: Task | null | undefined;
onEditAnnotationLayer: (tracingId: string, layerProperties: EditableLayerProperties) => void;
controlMode: ControlMode;
isArbitraryMode: boolean;
isAdminOrDatasetManager: boolean;
isAdminOrManager: boolean;
isSuperUser: boolean;
};
type DatasetSettingsProps = ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>;

type State = {
// If this is set to not-null, the downsampling modal
Expand Down Expand Up @@ -927,9 +899,37 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
defaultValue={defaultDatasetViewConfigurationWithoutNull.segmentationPatternOpacity}
/>
);

const isProofreadingMode = this.props.activeTool === "PROOFREAD";
const isSelectiveVisibilityDisabled = isProofreadingMode;

const selectiveVisibilitySwitch = (
<FastTooltip
title={
isSelectiveVisibilityDisabled
? "This behavior is overriden by the 'selective segment visibility' button in the toolbar, because the proofreading tool is active."
: "When enabled, only hovered or active segments will be shown."
}
>
<div
style={{
marginBottom: 6,
}}
>
<SwitchSetting
onChange={_.partial(this.props.onChange, "selectiveSegmentVisibility")}
value={this.props.datasetConfiguration.selectiveSegmentVisibility}
label="Selective Visibility"
disabled={isSelectiveVisibilityDisabled}
/>
</div>
</FastTooltip>
);

return (
<div>
{segmentationOpacitySetting}
{selectiveVisibilitySwitch}
<MappingSettingsView layerName={layerName} />
</div>
);
Expand Down Expand Up @@ -1338,6 +1338,7 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
"loadingStrategy",
"segmentationPatternOpacity",
"blendMode",
"selectiveSegmentVisibility",
] as Array<keyof RecommendedConfiguration>
).map((key) => ({
name: settings[key] as string,
Expand Down Expand Up @@ -1585,6 +1586,7 @@ const mapStateToProps = (state: OxalisState) => ({
state.activeUser != null ? Utils.isUserAdminOrDatasetManager(state.activeUser) : false,
isAdminOrManager: state.activeUser != null ? Utils.isUserAdminOrManager(state.activeUser) : false,
isSuperUser: state.activeUser?.isSuperUser || false,
activeTool: state.uiInformation.activeTool,
});

const mapDispatchToProps = (dispatch: Dispatch<any>) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const defaultDatasetViewConfigurationWithoutNull: DatasetConfiguration =
blendMode: BLEND_MODES.Additive,
colorLayerOrder: [],
nativelyRenderedLayerName: null,
selectiveSegmentVisibility: false,
};
export const defaultDatasetViewConfiguration = {
...defaultDatasetViewConfigurationWithoutNull,
Expand Down