Skip to content

Commit 323cd05

Browse files
committed
fix(segmentGroups): wait for image load before resample
1 parent 40ff400 commit 323cd05

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/composables/untilLoaded.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { computed, unref } from 'vue';
2+
import { until } from '@vueuse/core';
3+
import useChunkStore from '../store/chunks';
4+
5+
export function untilLoaded(imageID: string) {
6+
const doneLoading = computed(
7+
() => !unref(useChunkStore().chunkImageById[imageID].isLoading)
8+
);
9+
return until(doneLoading).toBe(true);
10+
}

src/store/datasets-layers.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { computed, ref, unref } from 'vue';
2-
import { until } from '@vueuse/core';
1+
import { ref } from 'vue';
32
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
43
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
54
import { defineStore } from 'pinia';
@@ -8,7 +7,7 @@ import { Maybe } from '@/src/types';
87
import { ensureSameSpace } from '@/src/io/resample/resample';
98
import { useErrorMessage } from '../composables/useErrorMessage';
109
import { Manifest, StateFile } from '../io/state-file/schema';
11-
import useChunkStore from './chunks';
10+
import { untilLoaded } from '../composables/untilLoaded';
1211

1312
// differ from Image/Volume IDs with a branded type
1413
export type LayerID = string & { __type: 'LayerID' };
@@ -39,6 +38,9 @@ export const useLayersStore = defineStore('layer', () => {
3938
{ selection: source, id } as Layer,
4039
];
4140

41+
// ensureSameSpace need final image array to resample, so wait for all chunks
42+
await untilLoaded(source);
43+
4244
const [parentImage, sourceImage] = await Promise.all(
4345
[parent, source].map(getImage)
4446
);
@@ -68,12 +70,6 @@ export const useLayersStore = defineStore('layer', () => {
6870
parent: DataSelection,
6971
source: DataSelection
7072
) {
71-
// ensureSameSpace need final image array to resample, so wait for all chunks
72-
const doneLoading = computed(
73-
() => !unref(useChunkStore().chunkImageById[source].isLoading)
74-
);
75-
await until(doneLoading).toBe(true);
76-
7773
return useErrorMessage('Failed to build layer', async () => {
7874
try {
7975
await this._addLayer(parent, source);

src/store/segmentGroups.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { FileEntry } from '../io/types';
2727
import { ensureSameSpace } from '../io/resample/resample';
2828
import { useDICOMStore } from './datasets-dicom';
29+
import { untilLoaded } from '../composables/untilLoaded';
2930

3031
const LabelmapArrayType = Uint8Array;
3132
export type LabelmapArrayType = Uint8Array;
@@ -248,7 +249,8 @@ export const useSegmentGroupStore = defineStore('segmentGroup', () => {
248249
if (imageID === parentID)
249250
throw new Error('Cannot convert an image to be a labelmap of itself');
250251

251-
// Build vtkImageData for DICOMs
252+
await untilLoaded(imageID);
253+
252254
const [childImage, parentImage] = await Promise.all(
253255
[imageID, parentID].map(getImage)
254256
);

0 commit comments

Comments
 (0)