Skip to content

Commit

Permalink
Merge pull request #658 from Kitware/fix-cropping-dicom
Browse files Browse the repository at this point in the history
fix(crop): wait for DICOM image load
  • Loading branch information
floryst authored Oct 9, 2024
2 parents a77aad8 + 81e2e3c commit d4b0cc1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/components/tools/crop/Crop3D.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default defineComponent({
const view = inject(VtkViewContext);
if (!view) throw new Error('No VtkView');
console.log('whee');
const { widgetManager } = view;
const { imageId } = toRefs(props);
Expand Down
4 changes: 2 additions & 2 deletions src/components/tools/crop/CropTool.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { useViewStore } from '@/src/store/views';
import { PropType, computed, defineComponent, toRefs } from 'vue';
import { watchImmediate } from '@vueuse/core';
import { wheneverImageLoaded } from '@/src/composables/wheneverImageLoaded';
import { useCropStore } from '@/src/store/tools/crop';
import { useToolStore } from '@/src/store/tools';
import { Tools } from '@/src/store/tools/types';
Expand Down Expand Up @@ -29,7 +29,7 @@ export default defineComponent({
const active = computed(() => toolStore.currentTool === Tools.Crop);
watchImmediate(imageId, (id) => {
wheneverImageLoaded(imageId, ({ id }) => {
if (id && !(id in cropStore.croppingByImageID)) {
cropStore.resetCropping(id);
}
Expand Down
25 changes: 25 additions & 0 deletions src/composables/wheneverImageLoaded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useImageStore } from '@/src/store/datasets-images';
import { Maybe } from '@/src/types';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
import { whenever } from '@vueuse/core';
import { computed, Ref, WatchCallback } from 'vue';

export function wheneverImageLoaded(
imageId: Ref<Maybe<string>>,
cb: WatchCallback<{ id: string; imageData: vtkImageData }>
) {
const imageStore = useImageStore();
const hasImageData = computed(() => {
const id = imageId.value;
if (!id) return false;
return !!imageStore.dataIndex[id];
});

return whenever(hasImageData, (newVal, oldVal, onCleanup) => {
cb(
{ id: imageId.value!, imageData: imageStore.dataIndex[imageId.value!] },
undefined,
onCleanup
);
});
}

0 comments on commit d4b0cc1

Please sign in to comment.