From 8d6419430139ad11fe351e1d5c1ee87d94b96af7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 20 Dec 2023 17:08:09 +0100 Subject: [PATCH] Fix bugs related to mesh loading and short links (#7507) * Fix mesh serialization for sharing links * Fix that meshes (or chunks) that were loaded while the segmentation layer was not visible were always white * Fix race condition when opening short link * update changelog --- CHANGELOG.unreleased.md | 3 +++ frontend/javascripts/components/redirect.tsx | 7 ++++++- .../oxalis/controller/segment_mesh_controller.ts | 12 ++++++------ .../javascripts/oxalis/controller/url_manager.ts | 6 ++++-- frontend/javascripts/oxalis/store.ts | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 44f0a3b7807..a9c96f379e9 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -32,6 +32,9 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - The settings page for non-wkw datasets no longer shows a wall of non-applying errors. [#7475](https://github.com/scalableminds/webknossos/pull/7475) - Fixed a bug where dataset deletion for ND datasets and datasets with coordinate transforms would not free the name even if no referencing annotations exist. [#7495](https://github.com/scalableminds/webknossos/pull/7495) - Fixed a bug where the URL in the sharing link was wrongly decoded before encoding into a URI. [#7502](https://github.com/scalableminds/webknossos/pull/7502) +- Fixed a bug where loaded meshes were not encoded in the sharing link. [#7507](https://github.com/scalableminds/webknossos/pull/7507) +- Fixed a bug where meshes (or chunks of them) were always colored white, if they were loaded while the corresponding segmentation layer was disabled. [#7507](https://github.com/scalableminds/webknossos/pull/7507) +- Fixed a race condition when opening a short link, that would sometimes lead to an error toast. [#7507](https://github.com/scalableminds/webknossos/pull/7507) ### Removed diff --git a/frontend/javascripts/components/redirect.tsx b/frontend/javascripts/components/redirect.tsx index afaeb75627e..82898e6cab7 100644 --- a/frontend/javascripts/components/redirect.tsx +++ b/frontend/javascripts/components/redirect.tsx @@ -23,7 +23,12 @@ class AsyncRedirect extends React.PureComponent { if (newPath.startsWith(location.origin)) { // The link is absolute which react-router does not support // apparently. See https://stackoverflow.com/questions/42914666/react-router-external-link - location.replace(newPath); + if (this.props.pushToHistory) { + location.assign(newPath); + } else { + location.replace(newPath); + } + return; } if (this.props.pushToHistory) { diff --git a/frontend/javascripts/oxalis/controller/segment_mesh_controller.ts b/frontend/javascripts/oxalis/controller/segment_mesh_controller.ts index d761ebc87f2..bc8233a9260 100644 --- a/frontend/javascripts/oxalis/controller/segment_mesh_controller.ts +++ b/frontend/javascripts/oxalis/controller/segment_mesh_controller.ts @@ -64,8 +64,8 @@ export default class SegmentMeshController { ); } - constructMesh(segmentId: number, geometry: THREE.BufferGeometry) { - const color = this.getColorObjectForSegment(segmentId); + constructMesh(segmentId: number, layerName: string, geometry: THREE.BufferGeometry) { + const color = this.getColorObjectForSegment(segmentId, layerName); const meshMaterial = new THREE.MeshLambertMaterial({ color, }); @@ -127,7 +127,7 @@ export default class SegmentMeshController { targetGroup.scale.copy(new THREE.Vector3(...scale)); } } - const mesh = this.constructMesh(segmentationId, geometry); + const mesh = this.constructMesh(segmentationId, layerName, geometry); if (offset) { mesh.translateX(offset[0]); mesh.translateY(offset[1]); @@ -179,7 +179,7 @@ export default class SegmentMeshController { } setMeshColor(id: number, layerName: string): void { - const color = this.getColorObjectForSegment(id); + const color = this.getColorObjectForSegment(id, layerName); // if in nd-dataset, set the color for all additional coordinates for (const recordsOfLayers of Object.values(this.meshesGroupsPerSegmentationId)) { const meshDataForOneSegment = recordsOfLayers[layerName][id]; @@ -192,8 +192,8 @@ export default class SegmentMeshController { } } - getColorObjectForSegment(segmentId: number) { - const [hue, saturation, light] = getSegmentColorAsHSLA(Store.getState(), segmentId); + getColorObjectForSegment(segmentId: number, layerName: string) { + const [hue, saturation, light] = getSegmentColorAsHSLA(Store.getState(), segmentId, layerName); const color = new THREE.Color().setHSL(hue, 0.75 * saturation, light / 10); return color; } diff --git a/frontend/javascripts/oxalis/controller/url_manager.ts b/frontend/javascripts/oxalis/controller/url_manager.ts index f012f77ebdb..c1f081d3c78 100644 --- a/frontend/javascripts/oxalis/controller/url_manager.ts +++ b/frontend/javascripts/oxalis/controller/url_manager.ts @@ -24,6 +24,7 @@ import { additionalCoordinateToKeyValue, parseAdditionalCoordinateKey, } from "oxalis/model/helpers/nml_helpers"; +import { getMeshesForCurrentAdditionalCoordinates } from "oxalis/model/accessors/volumetracing_accessor"; const MAX_UPDATE_INTERVAL = 1000; const MINIMUM_VALID_CSV_LENGTH = 5; @@ -272,11 +273,12 @@ class UrlManager { } for (const layerName of Object.keys(state.localSegmentationData)) { - const { meshes: localMeshes, currentMeshFile } = state.localSegmentationData[layerName]; + const { currentMeshFile } = state.localSegmentationData[layerName]; const currentMeshFileName = currentMeshFile?.meshFileName; + const localMeshes = getMeshesForCurrentAdditionalCoordinates(state, layerName); const meshes = localMeshes != null - ? Utils.values(localMeshes as Record) + ? Utils.values(localMeshes) .filter(({ isVisible }) => isVisible) .map(mapMeshInfoToUrlMeshDescriptor) : []; diff --git a/frontend/javascripts/oxalis/store.ts b/frontend/javascripts/oxalis/store.ts index 54c6644a31f..21c029fb2a1 100644 --- a/frontend/javascripts/oxalis/store.ts +++ b/frontend/javascripts/oxalis/store.ts @@ -570,7 +570,7 @@ export type OxalisState = { readonly localSegmentationData: Record< string, //layerName { - //for meshes, the string represents additional coordinates, number is the segment ID. + // For meshes, the string represents additional coordinates, number is the segment ID. // The undefined types were added to enforce null checks when using this structure. readonly meshes: Record | undefined> | undefined; readonly availableMeshFiles: Array | null | undefined;