Skip to content

Commit

Permalink
fix(io): remove itk-image-io dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Dec 5, 2023
1 parent ce33cc7 commit df5e8f1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 33 deletions.
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 5 additions & 13 deletions src/io/readers.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/store/dicom-web/dicom-web-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
4 changes: 2 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down

0 comments on commit df5e8f1

Please sign in to comment.