From 5e2bf3012f2deb90222de14769da3b34b776af10 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 5 Dec 2023 18:40:40 -0500 Subject: [PATCH] fix(io): remove itk-image-io dependency --- package-lock.json | 17 ----------------- package.json | 1 - src/io/readers.ts | 18 +++++------------- src/main.js | 6 ++++++ src/store/dicom-web/dicom-web-store.ts | 1 + vite.config.ts | 4 ++-- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ebe00e6d..83c713b68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "dicomweb-client-typed": "^0.8.6", "file-saver": "^2.0.5", "gl-matrix": "3.4.3", - "itk-image-io": "1.0.0-b.156", "itk-wasm": "1.0.0-b.156", "jszip": "3.10.0", "mitt": "^3.0.0", @@ -13166,14 +13165,6 @@ "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", "dev": true }, - "node_modules/itk-image-io": { - "version": "1.0.0-b.156", - "resolved": "https://registry.npmjs.org/itk-image-io/-/itk-image-io-1.0.0-b.156.tgz", - "integrity": "sha512-PxhCRK0QqBKbQy20moj7ecftlXZjvjlEZDY9WjxsKif4jN1z8VYOxQS9Ie5eOdOVQDylbXu3Ejgg+xa4DBf1Rw==", - "dependencies": { - "itk-wasm": "1.0.0-b.156" - } - }, "node_modules/itk-wasm": { "version": "1.0.0-b.156", "resolved": "https://registry.npmjs.org/itk-wasm/-/itk-wasm-1.0.0-b.156.tgz", @@ -32536,14 +32527,6 @@ "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", "dev": true }, - "itk-image-io": { - "version": "1.0.0-b.156", - "resolved": "https://registry.npmjs.org/itk-image-io/-/itk-image-io-1.0.0-b.156.tgz", - "integrity": "sha512-PxhCRK0QqBKbQy20moj7ecftlXZjvjlEZDY9WjxsKif4jN1z8VYOxQS9Ie5eOdOVQDylbXu3Ejgg+xa4DBf1Rw==", - "requires": { - "itk-wasm": "1.0.0-b.156" - } - }, "itk-wasm": { "version": "1.0.0-b.156", "resolved": "https://registry.npmjs.org/itk-wasm/-/itk-wasm-1.0.0-b.156.tgz", diff --git a/package.json b/package.json index 6e31d66fc..4d6ec07b5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "dicomweb-client-typed": "^0.8.6", "file-saver": "^2.0.5", "gl-matrix": "3.4.3", - "itk-image-io": "1.0.0-b.156", "itk-wasm": "1.0.0-b.156", "jszip": "3.10.0", "mitt": "^3.0.0", diff --git a/src/io/readers.ts b/src/io/readers.ts index 62ff3425f..14ce9336b 100644 --- a/src/io/readers.ts +++ b/src/io/readers.ts @@ -1,8 +1,9 @@ import vtkITKImageReader from '@kitware/vtk.js/IO/Misc/ITKImageReader'; +import { convertItkToVtkImage } from '@kitware/vtk.js/Common/DataModel/ITKHelper'; import { readImageArrayBuffer, extensionToImageIO } from 'itk-wasm'; +import { readImage } from '@itk-wasm/image-io'; import { FileReaderMap } from '.'; -import { readFileAsArrayBuffer } from './io'; import { stlReader, vtiReader, vtpReader } from './vtk/async'; import { FILE_EXT_TO_MIME } from './mimeTypes'; @@ -17,18 +18,9 @@ export const ITK_IMAGE_MIME_TYPES = Array.from( vtkITKImageReader.setReadImageArrayBufferFromITK(readImageArrayBuffer); async function itkReader(file: File) { - const fileBuffer = await readFileAsArrayBuffer(file); - - const reader = vtkITKImageReader.newInstance(); - reader.setFileName(file.name); - try { - await reader.parseAsArrayBuffer(fileBuffer); - } catch (e) { - // itkreader doesn't give us a meaningful error - throw new Error('Failed to parse file'); - } - - return reader.getOutputData(); + const { image, webWorker } = await readImage(null, file); + webWorker.terminate(); + return convertItkToVtkImage(image); } /** diff --git a/src/main.js b/src/main.js index 4501beec5..b53260df4 100644 --- a/src/main.js +++ b/src/main.js @@ -12,7 +12,9 @@ import { createPinia } from 'pinia'; import vtkProxyManager from '@kitware/vtk.js/Proxy/Core/ProxyManager'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkImageMapper from '@kitware/vtk.js/Rendering/Core/ImageMapper'; +import { setPipelinesBaseUrl, setPipelineWorkerUrl } from '@itk-wasm/image-io'; +import itkConfig from '@/src/io/itk/itkConfig'; import App from './components/App.vue'; import vuetify from './plugins/vuetify'; import { DICOMIO } from './io/dicom'; @@ -44,6 +46,10 @@ const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration }); const dicomIO = new DICOMIO(); dicomIO.initialize(); +// for @itk-wasm/image-io +setPipelineWorkerUrl(itkConfig.pipelineWorkerUrl); +setPipelinesBaseUrl(itkConfig.imageIOUrl); + const pinia = createPinia(); pinia.use( CorePiniaProviderPlugin({ diff --git a/src/store/dicom-web/dicom-web-store.ts b/src/store/dicom-web/dicom-web-store.ts index fe33fc1a5..a51c8bb2b 100644 --- a/src/store/dicom-web/dicom-web-store.ts +++ b/src/store/dicom-web/dicom-web-store.ts @@ -203,6 +203,7 @@ export const useDicomWebStore = defineStore('dicom-web', () => { state: 'Done', }; } catch (error) { + console.error(error); const messageStore = useMessageStore(); messageStore.addError('Failed to load DICOM', error as Error); volumes.value[volumeKey] = { diff --git a/vite.config.ts b/vite.config.ts index b3d5f6a86..3da1114f7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -151,8 +151,8 @@ export default defineConfig({ }, { src: resolvePath( - resolveNodeModulePath('itk-image-io'), - '*{.wasm,.js,.zst}' + resolveNodeModulePath('@itk-wasm/image-io'), + 'dist/pipelines/*{.wasm,.js,.zst}' ), dest: 'itk/image-io', },