Skip to content

Commit b5e89f4

Browse files
MichaelBuessemeyerAaron Kanzer
authored and
Aaron Kanzer
committed
Mapping in default view config (scalableminds#7858)
* allow viewing a mapping * WIP: enable setting default active mappings in default view configuration * add default active mapping to default view configuration - add config settings to dataset settings default view config tab - auto load initial default mapping * fix bottom margin of layer settings - was broken in view mode with multiple segmentation layers; the "Save View Config..." Button had no spacing to towards * fix having the mapping settings enabled for layers with default mapping * WIP: move default mapping store proeprty to dataset layer config - undo moving mapping selection to a shared component * moved default active mapping from separate select to view config layer config - Also added validation check whether the mapping exists in the dataset view config settings * allow saving no default active mapping from view mode & model init to new dataset config version * rename defaultMapping to mapping * cache available mappings fetched from backend when checking config in dataset settings * remove logging statements * clean up * add changelog entry * apply pr feedback
1 parent dc788cc commit b5e89f4

File tree

8 files changed

+191
-20
lines changed

8 files changed

+191
-20
lines changed

CHANGELOG.unreleased.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
1212

1313
### Added
1414
- Added the option for the owner to lock explorative annotations. Locked annotations cannot be modified by any user. An annotation can be locked in the annotations table and when viewing the annotation via the navbar dropdown menu. [#7801](https://github.com/scalableminds/webknossos/pull/7801)
15+
- Added the option to set a default mapping for a dataset in the dataset view configuration. The default mapping is loaded when the dataset is opened and the user / url does not configure something else. [#7858](https://github.com/scalableminds/webknossos/pull/7858)
1516
- Uploading an annotation into a dataset that it was not created for now also works if the dataset is in a different organization. [#7816](https://github.com/scalableminds/webknossos/pull/7816)
1617
- When downloading + reuploading an annotation that is based on a segmentation layer with active mapping, that mapping is now still be selected after the reupload. [#7822](https://github.com/scalableminds/webknossos/pull/7822)
1718
- In the Voxelytics workflow list, the name of the WEBKNOSSOS user who started the job is displayed. [#7794](https://github.com/scalableminds/webknossos/pull/7795)

frontend/javascripts/dashboard/dataset/dataset_settings_view.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,10 @@ class DatasetSettingsView extends React.PureComponent<PropsWithFormAndRouter, St
890890
forceRender: true,
891891
children: (
892892
<Hideable hidden={this.state.activeTabKey !== "defaultConfig"}>
893-
<DatasetSettingsViewConfigTab />
893+
<DatasetSettingsViewConfigTab
894+
datasetId={this.props.datasetId}
895+
dataStoreURL={this.state.dataset?.dataStore.url}
896+
/>
894897
</Hideable>
895898
),
896899
},

frontend/javascripts/dashboard/dataset/dataset_settings_viewconfig_tab.tsx

+107-11
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,88 @@ import {
1414
Slider,
1515
Divider,
1616
} from "antd";
17-
import * as React from "react";
17+
import React, { useMemo, useState } from "react";
1818
import { Vector3Input } from "libs/vector_input";
1919
import { validateLayerViewConfigurationObjectJSON, syncValidator } from "types/validation";
2020
import { getDefaultLayerViewConfiguration } from "types/schemas/dataset_view_configuration.schema";
21-
import {
21+
import messages, {
2222
RecommendedConfiguration,
2323
layerViewConfigurations,
2424
settings,
2525
settingsTooltips,
2626
} from "messages";
27-
import type { DatasetLayerConfiguration } from "oxalis/store";
27+
import type { DatasetConfiguration, DatasetLayerConfiguration } from "oxalis/store";
2828
import { FormItemWithInfo, jsonEditStyle } from "./helper_components";
2929
import { BLEND_MODES } from "oxalis/constants";
3030
import ColorLayerOrderingTable from "./color_layer_ordering_component";
31+
import { APIDatasetId } from "types/api_flow_types";
32+
import { getAgglomeratesForDatasetLayer, getMappingsForDatasetLayer } from "admin/admin_rest_api";
3133

3234
const FormItem = Form.Item;
3335

34-
export default function DatasetSettingsViewConfigTab() {
36+
export default function DatasetSettingsViewConfigTab(props: {
37+
datasetId: APIDatasetId;
38+
dataStoreURL: string | undefined;
39+
}) {
40+
const { datasetId, dataStoreURL } = props;
41+
const [availableMappingsPerLayerCache, setAvailableMappingsPerLayer] = useState<
42+
Record<string, [string[], string[]]>
43+
>({});
44+
45+
// biome-ignore lint/correctness/useExhaustiveDependencies: Update is not necessary when availableMappingsPerLayer[layerName] changes.
46+
const validateDefaultMappings = useMemo(
47+
() => async (configStr: string, dataStoreURL: string, datasetId: APIDatasetId) => {
48+
let config = {} as DatasetConfiguration["layers"];
49+
try {
50+
config = JSON.parse(configStr);
51+
} catch (e: any) {
52+
return Promise.reject(new Error("Invalid JSON format for : " + e.message));
53+
}
54+
const layerNamesWithDefaultMappings = Object.keys(config).filter(
55+
(layerName) => config[layerName].mapping != null,
56+
);
57+
58+
const maybeMappingRequests = layerNamesWithDefaultMappings.map(async (layerName) => {
59+
if (layerName in availableMappingsPerLayerCache) {
60+
return availableMappingsPerLayerCache[layerName];
61+
}
62+
try {
63+
const jsonAndAgglomerateMappings = await Promise.all([
64+
getMappingsForDatasetLayer(dataStoreURL, datasetId, layerName),
65+
getAgglomeratesForDatasetLayer(dataStoreURL, datasetId, layerName),
66+
]);
67+
setAvailableMappingsPerLayer((prev) => ({
68+
...prev,
69+
[layerName]: jsonAndAgglomerateMappings,
70+
}));
71+
return jsonAndAgglomerateMappings;
72+
} catch (e: any) {
73+
console.error(e);
74+
throw new Error(messages["mapping.loading_failed"](layerName));
75+
}
76+
});
77+
const mappings = await Promise.all(maybeMappingRequests);
78+
const errors = layerNamesWithDefaultMappings
79+
.map((layerName, index) => {
80+
const [mappingsForLayer, agglomeratesForLayer] = mappings[index];
81+
const mappingType = config[layerName]?.mapping?.type;
82+
const mappingName = config[layerName]?.mapping?.name;
83+
const doesMappingExist =
84+
mappingType === "HDF5"
85+
? agglomeratesForLayer.some((agglomerate) => agglomerate === mappingName)
86+
: mappingsForLayer.some((mapping) => mapping === mappingName);
87+
return doesMappingExist
88+
? null
89+
: `The mapping "${mappingName}" of type "${mappingType}" does not exist for layer ${layerName}.`;
90+
})
91+
.filter((error) => error != null);
92+
if (errors.length > 0) {
93+
throw new Error("The following mappings are invalid: " + errors.join("\n"));
94+
}
95+
},
96+
[availableMappingsPerLayerCache],
97+
);
98+
3599
const columns = [
36100
{
37101
title: "Name",
@@ -50,23 +114,48 @@ export default function DatasetSettingsViewConfigTab() {
50114
dataIndex: "comment",
51115
},
52116
];
53-
const comments: Partial<Record<keyof DatasetLayerConfiguration, string>> = {
54-
alpha: "20 for segmentation layer",
55-
min: "Only for color layers",
56-
max: "Only for color layers",
57-
intensityRange: "Only for color layers",
117+
const comments: Partial<
118+
Record<keyof DatasetLayerConfiguration, { shortComment: string; tooltip: string }>
119+
> = {
120+
alpha: { shortComment: "20 for segmentation layer", tooltip: "The default alpha value." },
121+
min: {
122+
shortComment: "Only for color layers",
123+
tooltip: "The minimum possible color range value adjustable with the histogram slider.",
124+
},
125+
max: {
126+
shortComment: "Only for color layers",
127+
tooltip: "The maximum possible color range value adjustable with the histogram slider.",
128+
},
129+
intensityRange: {
130+
shortComment: "Only for color layers",
131+
tooltip: "The color value range between which color values are interpolated and shown.",
132+
},
133+
mapping: {
134+
shortComment: "Active Mapping",
135+
tooltip:
136+
"The mapping whose type and name is active by default. This field is an object with the keys 'type' and 'name' like {name: 'agglomerate_65', type: 'HDF5'}.",
137+
},
58138
};
59139
const layerViewConfigurationEntries = _.map(
60140
{ ...getDefaultLayerViewConfiguration(), min: 0, max: 255, intensityRange: [0, 255] },
61141
(defaultValue: any, key: string) => {
62142
// @ts-ignore Typescript doesn't infer that key will be of type keyof DatasetLayerConfiguration
63143
const layerViewConfigurationKey: keyof DatasetLayerConfiguration = key;
64144
const name = layerViewConfigurations[layerViewConfigurationKey];
145+
const comment = comments[layerViewConfigurationKey];
146+
const commentContent =
147+
comment != null ? (
148+
<Tooltip title={comment.tooltip}>
149+
{comment.shortComment} <InfoCircleOutlined />
150+
</Tooltip>
151+
) : (
152+
""
153+
);
65154
return {
66155
name,
67156
key,
68157
value: defaultValue == null ? "not set" : defaultValue.toString(),
69-
comment: comments[layerViewConfigurationKey] || "",
158+
comment: commentContent,
70159
};
71160
},
72161
);
@@ -92,6 +181,7 @@ export default function DatasetSettingsViewConfigTab() {
92181
</FormItem>
93182
</Col>
94183
));
184+
95185
return (
96186
<div>
97187
<Alert
@@ -212,7 +302,13 @@ export default function DatasetSettingsViewConfigTab() {
212302
info="Use the following JSON to define layer-specific properties, such as color, alpha and intensityRange."
213303
rules={[
214304
{
215-
validator: validateLayerViewConfigurationObjectJSON,
305+
validator: (_rule, config: string) =>
306+
Promise.all([
307+
validateLayerViewConfigurationObjectJSON(_rule, config),
308+
dataStoreURL
309+
? validateDefaultMappings(config, dataStoreURL, datasetId)
310+
: Promise.resolve(),
311+
]),
216312
},
217313
]}
218314
>

frontend/javascripts/messages.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const layerViewConfigurations: Partial<Record<keyof DatasetLayerConfigura
9393
isInverted: "Inverted Layer",
9494
isInEditMode: "Configuration Mode",
9595
gammaCorrectionValue: "Gamma Correction",
96+
mapping: "Active Mapping",
9697
};
9798
export const layerViewConfigurationTooltips: Partial<
9899
Record<keyof DatasetLayerConfiguration, string>
@@ -262,6 +263,8 @@ instead. Only enable this option if you understand its effect. All layers will n
262263
"The active volume annotation layer has an active mapping. By mutating the layer, the mapping will be permanently locked and can no longer be changed or disabled. This can only be undone by restoring an older version of this annotation. Are you sure you want to continue?",
263264
"tracing.locked_mapping_confirmed": (mappingName: string) =>
264265
`The mapping ${mappingName} is now locked for this annotation and can no longer be changed or disabled.`,
266+
"mapping.loading_failed": (layerName: string) =>
267+
`Loading the available mappings for layer ${layerName} failed.`,
265268
"layouting.missing_custom_layout_info":
266269
"The annotation views are separated into four classes. Each of them has their own layouts. If you can't find your layout please open the annotation in the correct view mode or just add it here manually.",
267270
"datastore.unknown_type": "Unknown datastore type:",

frontend/javascripts/oxalis/model_initialization.ts

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
setViewModeAction,
5858
setMappingAction,
5959
updateLayerSettingAction,
60+
setMappingEnabledAction,
6061
} from "oxalis/model/actions/settings_actions";
6162
import {
6263
initializeEditableMappingAction,
@@ -620,7 +621,24 @@ function determineDefaultState(
620621
}
621622

622623
const stateByLayer = urlStateByLayer ?? {};
624+
// Add the default mapping to the state for each layer that does not have a mapping set in its URL settings.
625+
for (const layerName in datasetConfiguration.layers) {
626+
if (!(layerName in stateByLayer)) {
627+
stateByLayer[layerName] = {};
628+
}
629+
const { mapping } = datasetConfiguration.layers[layerName];
630+
if (stateByLayer[layerName].mappingInfo == null && mapping != null) {
631+
stateByLayer[layerName].mappingInfo = {
632+
mappingName: mapping.name,
633+
mappingType: mapping.type,
634+
};
635+
}
636+
}
623637

638+
// Overwriting the mapping to load for each volume layer in case
639+
// - the volume tracing has a not locked mapping set and the url does not.
640+
// - the volume tracing has a locked mapping set.
641+
// - the volume tracing has locked that no tracing should be loaded.
624642
const volumeTracings = tracings.filter(
625643
(tracing) => tracing.typ === "Volume",
626644
) as ServerVolumeTracing[];
@@ -730,6 +748,7 @@ async function applyLayerState(stateByLayer: UrlStateByLayer) {
730748
showLoadingIndicator: true,
731749
}),
732750
);
751+
Store.dispatch(setMappingEnabledAction(effectiveLayerName, true));
733752

734753
if (agglomerateIdsToImport != null) {
735754
const { tracing } = Store.getState();

frontend/javascripts/oxalis/store.ts

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export type DatasetLayerConfiguration = {
295295
readonly isInverted: boolean;
296296
readonly isInEditMode: boolean;
297297
readonly gammaCorrectionValue: number;
298+
readonly mapping?: { name: string; type: MappingType } | null | undefined;
298299
};
299300
export type LoadingStrategy = "BEST_QUALITY_FIRST" | "PROGRESSIVE_QUALITY";
300301

frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx

+42-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import {
8888
} from "oxalis/model/actions/settings_actions";
8989
import { userSettings } from "types/schemas/user_settings.schema";
9090
import type { Vector3, ControlMode } from "oxalis/constants";
91-
import Constants, { ControlModeEnum } from "oxalis/constants";
91+
import Constants, { ControlModeEnum, MappingStatusEnum } from "oxalis/constants";
9292
import EditableTextLabel from "oxalis/view/components/editable_text_label";
9393
import LinkButton from "components/link_button";
9494
import { Model } from "oxalis/singletons";
@@ -923,11 +923,13 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
923923
layerName,
924924
layerConfiguration,
925925
isColorLayer,
926+
isLastLayer,
926927
hasLessThanTwoColorLayers = true,
927928
}: {
928929
layerName: string;
929930
layerConfiguration: DatasetLayerConfiguration | null | undefined;
930931
isColorLayer: boolean;
932+
isLastLayer: boolean;
931933
hasLessThanTwoColorLayers?: boolean;
932934
}) => {
933935
// Ensure that every layer needs a layer configuration and that color layers have a color layer.
@@ -936,8 +938,10 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
936938
}
937939
const elementClass = getElementClass(this.props.dataset, layerName);
938940
const { isDisabled, isInEditMode } = layerConfiguration;
941+
const lastLayerMarginBottom = isLastLayer ? { marginBottom: 30 } : {};
942+
const betweenLayersMarginBottom = isLastLayer ? {} : { marginBottom: 30 };
939943
return (
940-
<div key={layerName}>
944+
<div key={layerName} style={lastLayerMarginBottom}>
941945
{this.getLayerSettingsHeader(
942946
isDisabled,
943947
isColorLayer,
@@ -950,7 +954,7 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
950954
{isDisabled ? null : (
951955
<div
952956
style={{
953-
marginBottom: 30,
957+
...betweenLayersMarginBottom,
954958
marginLeft: 10,
955959
}}
956960
>
@@ -1314,8 +1318,8 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
13141318
<br />
13151319
This will overwrite the current default view configuration.
13161320
<br />
1317-
This includes all color and segmentation layer settings, as well as these additional
1318-
settings:
1321+
This includes all color and segmentation layer settings, currently active mappings (even
1322+
those of disabled layers), as well as these additional settings:
13191323
<br />
13201324
<br />
13211325
{dataSource.map((field, index) => {
@@ -1338,14 +1342,42 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
13381342
),
13391343
onOk: async () => {
13401344
try {
1341-
const { flycam } = Store.getState();
1345+
const { flycam, temporaryConfiguration } = Store.getState();
13421346
const position = V3.floor(getPosition(flycam));
13431347
const zoom = flycam.zoomStep;
1348+
const { activeMappingByLayer } = temporaryConfiguration;
13441349
const completeDatasetConfiguration = Object.assign({}, datasetConfiguration, {
13451350
position,
13461351
zoom,
13471352
});
1348-
await updateDatasetDefaultConfiguration(dataset, completeDatasetConfiguration);
1353+
const updatedLayers = {
1354+
...completeDatasetConfiguration.layers,
1355+
} as DatasetConfiguration["layers"];
1356+
Object.keys(activeMappingByLayer).forEach((layerName) => {
1357+
const mappingInfo = activeMappingByLayer[layerName];
1358+
if (
1359+
mappingInfo.mappingStatus === MappingStatusEnum.ENABLED &&
1360+
mappingInfo.mappingName != null
1361+
) {
1362+
updatedLayers[layerName] = {
1363+
...updatedLayers[layerName],
1364+
mapping: {
1365+
name: mappingInfo.mappingName,
1366+
type: mappingInfo.mappingType,
1367+
},
1368+
};
1369+
} else {
1370+
updatedLayers[layerName] = {
1371+
...updatedLayers[layerName],
1372+
mapping: null,
1373+
};
1374+
}
1375+
});
1376+
const updatedConfiguration = {
1377+
...completeDatasetConfiguration,
1378+
layers: updatedLayers,
1379+
};
1380+
await updateDatasetDefaultConfiguration(dataset, updatedConfiguration);
13491381
Toast.success("Successfully saved the current view configuration as default.");
13501382
} catch (error) {
13511383
Toast.error(
@@ -1390,16 +1422,18 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps, State> {
13901422
layerConfiguration={layers[layerName]}
13911423
isColorLayer
13921424
index={index}
1425+
isLastLayer={index === colorLayerOrder.length - 1}
13931426
disabled={hasLessThanTwoColorLayers}
13941427
hasLessThanTwoColorLayers={hasLessThanTwoColorLayers}
13951428
/>
13961429
);
13971430
});
1398-
const segmentationLayerSettings = segmentationLayerNames.map((layerName) => {
1431+
const segmentationLayerSettings = segmentationLayerNames.map((layerName, index) => {
13991432
return (
14001433
<LayerSettings
14011434
key={layerName}
14021435
layerName={layerName}
1436+
isLastLayer={index === segmentationLayerNames.length - 1}
14031437
layerConfiguration={layers[layerName]}
14041438
isColorLayer={false}
14051439
/>

0 commit comments

Comments
 (0)