From 3c177eaf46a6ddaffe08fda81b9a96dcab6d6230 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 11 Apr 2024 18:17:49 -0400 Subject: [PATCH] fix(datasets-dicom): rebuild volume if image deleted And only build volume if not already requested to build. --- src/store/datasets-dicom.ts | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/store/datasets-dicom.ts b/src/store/datasets-dicom.ts index 7f05daae5..6520654af 100644 --- a/src/store/datasets-dicom.ts +++ b/src/store/datasets-dicom.ts @@ -1,4 +1,5 @@ import vtkITKHelper from '@kitware/vtk.js/Common/DataModel/ITKHelper'; +import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData'; import { defineStore } from 'pinia'; import { Image } from 'itk-wasm'; import { DataSourceWithFile } from '@/src/io/import/dataSource'; @@ -61,6 +62,9 @@ interface State { // volume invalidation information needsRebuild: Record; + // Promise resolving to vtkImageData + volumeImageData: Record>; + // patientKey -> patient info patientInfo: Record; // patientKey -> array of studyKeys @@ -122,6 +126,7 @@ export const useDICOMStore = defineStore('dicom', { sliceData: {}, volumeToImageID: {}, imageIDToVolumeKey: {}, + volumeImageData: {}, patientInfo: {}, patientStudies: {}, studyInfo: {}, @@ -254,6 +259,10 @@ export const useDICOMStore = defineStore('dicom', { delete this.imageIDToVolumeKey[imageID]; } + if (volumeKey in this.volumeImageData) { + delete this.volumeImageData[volumeKey]; + } + removeFromArray(this.studyVolumes[studyKey], volumeKey); if (this.studyVolumes[studyKey].length === 0) { this.deleteStudy(studyKey); @@ -354,15 +363,17 @@ export const useDICOMStore = defineStore('dicom', { return this.getVolumeSlice(volumeKey, middleSlice, true); }, - async buildVolume(volumeKey: string, forceRebuild: boolean = false) { + async _buildVolume(volumeKey: string, forceRebuild: boolean = false) { const imageStore = useImageStore(); const dicomIO = this.$dicomIO; const rebuild = forceRebuild || this.needsRebuild[volumeKey]; - if (!rebuild && this.volumeToImageID[volumeKey]) { - const imageID = this.volumeToImageID[volumeKey]!; - return imageStore.dataIndex[imageID]; + const existingImageID = this.volumeToImageID[volumeKey]; + const imageExists = + existingImageID && imageStore.dataIndex[existingImageID]; + if (!rebuild && imageExists) { + return imageStore.dataIndex[existingImageID]; } const fileStore = useFileStore(); @@ -372,21 +383,29 @@ export const useDICOMStore = defineStore('dicom', { await dicomIO.buildImage(files) ); - const existingImageID = this.volumeToImageID[volumeKey]; - if (existingImageID) { + if (imageExists) { + // was a rebuild imageStore.updateData(existingImageID, image); } else { const info = this.volumeInfo[volumeKey]; const name = cleanupName(info.SeriesDescription) || info.SeriesInstanceUID; - const imageID = imageStore.addVTKImageData(name, image); - this.imageIDToVolumeKey[imageID] = volumeKey; - this.volumeToImageID[volumeKey] = imageID; + const newImageID = imageStore.addVTKImageData(name, image); + this.imageIDToVolumeKey[newImageID] = volumeKey; + this.volumeToImageID[volumeKey] = newImageID; } delete this.needsRebuild[volumeKey]; return image; }, + + buildVolume(volumeKey: string) { + if (volumeKey in this.volumeImageData) { + return this.volumeImageData[volumeKey]; + } + this.volumeImageData[volumeKey] = this._buildVolume(volumeKey); + return this.volumeImageData[volumeKey]; + }, }, });