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

Fix reload-precomputed-mesh functionality #6875

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed the layouting in the connectome tab. [#6864](https://github.com/scalableminds/webknossos/pull/6864)
- Fixed that the quick-select and floodfill tool didn't update the segment list. [#6867](https://github.com/scalableminds/webknossos/pull/6867)
- Fixed deprecation warnings for antd' <Menu> component in Navbar. [#6860](https://github.com/scalableminds/webknossos/pull/6860)
- Fixed that trying to reload a precomputed mesh via context menu could crash webKnossos. [#6875](https://github.com/scalableminds/webknossos/pull/6875)

### Removed
- Removed the old Datasets tab in favor of the Dataset Folders tab. [#6834](https://github.com/scalableminds/webknossos/pull/6834)
Expand Down
42 changes: 30 additions & 12 deletions frontend/javascripts/oxalis/model/sagas/isosurface_saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
getVisibleSegmentationLayer,
getSegmentationLayerByName,
} from "oxalis/model/accessors/dataset_accessor";
import type {
import {
LoadAdHocMeshAction,
LoadPrecomputedMeshAction,
AdHocIsosurfaceInfo,
loadPrecomputedMeshAction,
} from "oxalis/model/actions/segmentation_actions";
import type { Action } from "oxalis/model/actions/actions";
import type { Vector3 } from "oxalis/constants";
Expand Down Expand Up @@ -90,7 +91,7 @@ const MESH_CHUNK_THROTTLE_LIMIT = 50;
* Ad Hoc Meshes
*
*/
const isosurfacesMapByLayer: Record<string, Map<number, ThreeDMap<boolean>>> = {};
const adhocIsosurfacesMapByLayer: Record<string, Map<number, ThreeDMap<boolean>>> = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice renaming 👍

function marchingCubeSizeInMag1(): Vector3 {
// @ts-ignore
return window.__marchingCubeSizeInMag1 != null
Expand All @@ -108,8 +109,8 @@ export function isIsosurfaceStl(buffer: ArrayBuffer): boolean {
}

function getOrAddMapForSegment(layerName: string, segmentId: number): ThreeDMap<boolean> {
isosurfacesMapByLayer[layerName] = isosurfacesMapByLayer[layerName] || new Map();
const isosurfacesMap = isosurfacesMapByLayer[layerName];
adhocIsosurfacesMapByLayer[layerName] = adhocIsosurfacesMapByLayer[layerName] || new Map();
const isosurfacesMap = adhocIsosurfacesMapByLayer[layerName];
const maybeMap = isosurfacesMap.get(segmentId);

if (maybeMap == null) {
Expand All @@ -124,11 +125,11 @@ function getOrAddMapForSegment(layerName: string, segmentId: number): ThreeDMap<
}

function removeMapForSegment(layerName: string, segmentId: number): void {
if (isosurfacesMapByLayer[layerName] == null) {
if (adhocIsosurfacesMapByLayer[layerName] == null) {
return;
}

isosurfacesMapByLayer[layerName].delete(segmentId);
adhocIsosurfacesMapByLayer[layerName].delete(segmentId);
}

function getZoomedCubeSize(zoomStep: number, resolutionInfo: ResolutionInfo): Vector3 {
Expand Down Expand Up @@ -442,9 +443,9 @@ function* refreshIsosurfaces(): Saga<void> {
return;
}

isosurfacesMapByLayer[segmentationLayer.name] =
isosurfacesMapByLayer[segmentationLayer.name] || new Map();
const isosurfacesMapForLayer = isosurfacesMapByLayer[segmentationLayer.name];
adhocIsosurfacesMapByLayer[segmentationLayer.name] =
adhocIsosurfacesMapByLayer[segmentationLayer.name] || new Map();
const isosurfacesMapForLayer = adhocIsosurfacesMapByLayer[segmentationLayer.name];

for (const [cellId, threeDMap] of Array.from(isosurfacesMapForLayer.entries())) {
if (!currentlyModifiedCells.has(cellId)) {
Expand All @@ -457,9 +458,26 @@ function* refreshIsosurfaces(): Saga<void> {

function* refreshIsosurface(action: RefreshIsosurfaceAction): Saga<void> {
const { cellId, layerName } = action;
const threeDMap = isosurfacesMapByLayer[action.layerName].get(cellId);
if (threeDMap == null) return;
yield* call(_refreshIsosurfaceWithMap, cellId, threeDMap, layerName);

const isosurfaceInfo = yield* select(
(state) => state.localSegmentationData[layerName].isosurfaces[cellId],
);

if (isosurfaceInfo.isPrecomputed) {
yield* put(removeIsosurfaceAction(layerName, isosurfaceInfo.segmentId));
yield* put(
loadPrecomputedMeshAction(
isosurfaceInfo.segmentId,
isosurfaceInfo.seedPosition,
isosurfaceInfo.meshFileName,
layerName,
),
);
} else {
const threeDMap = adhocIsosurfacesMapByLayer[action.layerName].get(cellId);
if (threeDMap == null) return;
yield* call(_refreshIsosurfaceWithMap, cellId, threeDMap, layerName);
}
}

function* _refreshIsosurfaceWithMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function _MeshInfoItem(props: {
marginLeft: 6,
}}
>
{getRefreshButton(segment, isPrecomputed, isLoading, props.visibleSegmentationLayer)}
{getRefreshButton(segment, isLoading, props.visibleSegmentationLayer)}
{downloadButton}
{deleteButton}
</div>
Expand Down Expand Up @@ -542,7 +542,6 @@ const SegmentListItem = React.memo<Props>(_SegmentListItem);

function getRefreshButton(
segment: Segment,
isPrecomputed: boolean,
isLoading: boolean,
visibleSegmentationLayer: APISegmentationLayer | null | undefined,
) {
Expand All @@ -560,7 +559,7 @@ function getRefreshButton(
/>
);
} else {
return isPrecomputed ? null : (
return (
<Tooltip title="Refresh Mesh">
<ReloadOutlined
key="refresh-button"
Expand Down