diff --git a/src/io/ReadImageDICOMFileSeriesOptions.ts b/src/io/ReadImageDICOMFileSeriesOptions.ts new file mode 100644 index 000000000..d7d609294 --- /dev/null +++ b/src/io/ReadImageDICOMFileSeriesOptions.ts @@ -0,0 +1,7 @@ +import CastImageOptions from '../core/CastImageOptions.js' + +interface ReadImageDICOMFileSeriesOptions extends CastImageOptions { + singleSortedSeries?: boolean +} + +export default ReadImageDICOMFileSeriesOptions diff --git a/src/io/browser/index.ts b/src/io/browser/index.ts index a49318f2a..3cef327e5 100644 --- a/src/io/browser/index.ts +++ b/src/io/browser/index.ts @@ -24,6 +24,7 @@ export { default as readImageHTTP } from './../readImageHTTP.js' export { default as readDICOMTags } from './../readDICOMTags.js' export { default as readDICOMTagsArrayBuffer } from './../readDICOMTagsArrayBuffer.js' +export { default as ReadImageDICOMFileSeriesOptions } from './../ReadImageDICOMFileSeriesOptions.js' export { default as readImageDICOMFileSeries } from './../readImageDICOMFileSeries.js' export { default as ReadImageDICOMArrayBufferSeriesOptions } from './../ReadImageDICOMArrayBufferSeriesOptions.js' export { default as readImageDICOMArrayBufferSeries } from './../readImageDICOMArrayBufferSeries.js' diff --git a/src/io/readImageDICOMFileSeries.ts b/src/io/readImageDICOMFileSeries.ts index f9d0228a0..86e8cabea 100644 --- a/src/io/readImageDICOMFileSeries.ts +++ b/src/io/readImageDICOMFileSeries.ts @@ -2,18 +2,30 @@ import { readAsArrayBuffer } from 'promise-file-reader' import ReadImageFileSeriesResult from './ReadImageFileSeriesResult.js' import readImageDICOMArrayBufferSeries from './readImageDICOMArrayBufferSeries.js' +import ReadImageDICOMFileSeriesOptions from './ReadImageDICOMFileSeriesOptions.js' +import ReadImageDICOMArrayBufferSeriesOptions from './ReadImageDICOMArrayBufferSeriesOptions.js' const readImageDICOMFileSeries = async ( fileList: FileList | File[], - singleSortedSeries = false + options?: ReadImageDICOMFileSeriesOptions | boolean ): Promise => { const fetchFileContents = Array.from(fileList, async function (file) { return await readAsArrayBuffer(file) }) const fileContents: ArrayBuffer[] = await Promise.all(fetchFileContents) + let optionsToPass: ReadImageDICOMArrayBufferSeriesOptions = {} + if (typeof options === 'object') { + optionsToPass = options + } + if (typeof options === 'boolean') { + // Backwards compatibility + optionsToPass.singleSortedSeries = options + } + const fileNames = Array.from(fileList, (file) => file.name) - return await readImageDICOMArrayBufferSeries(fileContents, singleSortedSeries, fileNames) + optionsToPass.fileNames = fileNames + return readImageDICOMArrayBufferSeries(fileContents, optionsToPass) } export default readImageDICOMFileSeries diff --git a/test/browser/io/DICOMSeriesTest.js b/test/browser/io/DICOMSeriesTest.js index c0bb8dc5c..9c26f5097 100644 --- a/test/browser/io/DICOMSeriesTest.js +++ b/test/browser/io/DICOMSeriesTest.js @@ -43,7 +43,7 @@ function verifyImage (t, image, expectedComponentType, expectedPixelType) { } export default function () { - test('Test reading DICOM file series', t => { + test('Test reading DICOM file series', async t => { const fetchFiles = fileNames.map(function (file) { const path = testSeriesDirectory + file return axios.get(path, { responseType: 'blob' }).then(function (response) { @@ -52,17 +52,13 @@ export default function () { }) }) - return Promise.all(fetchFiles) - .then(function (files) { - return readImageDICOMFileSeries(files) - }) - .then(function ({ image, webWorkerPool }) { - webWorkerPool.terminateWorkers() - verifyImage(t, image) - }) + const files = await Promise.all(fetchFiles) + const { image, webWorkerPool } = await readImageDICOMFileSeries(files) + webWorkerPool.terminateWorkers() + verifyImage(t, image) }) - test('Test reading DICOM file series, assume a single sorted series', t => { + test('Test reading DICOM file series, given componentType, pixelType', async t => { const fetchFiles = fileNames.map(function (file) { const path = testSeriesDirectory + file return axios.get(path, { responseType: 'blob' }).then(function (response) { @@ -71,15 +67,46 @@ export default function () { }) }) - return Promise.all(fetchFiles) - .then(function (files) { - const singleSortedSeries = true - return readImageDICOMFileSeries(files, singleSortedSeries) + const files = await Promise.all(fetchFiles) + const componentType = IntTypes.Int32 + const pixelType = PixelTypes.Vector + const { image, webWorkerPool } = await readImageDICOMFileSeries(files, { componentType, pixelType }) + webWorkerPool.terminateWorkers() + verifyImage(t, image, componentType, pixelType) + }) + + test('Test reading DICOM file series, assume a single sorted series', async t => { + const fetchFiles = fileNames.map(function (file) { + const path = testSeriesDirectory + file + return axios.get(path, { responseType: 'blob' }).then(function (response) { + const jsFile = new window.File([response.data], file) + return jsFile }) - .then(function ({ image, webWorkerPool }) { - webWorkerPool.terminateWorkers() - verifyImage(t, image) + }) + + const files = await Promise.all(fetchFiles) + const singleSortedSeries = true + const { image, webWorkerPool } = await readImageDICOMFileSeries(files, singleSortedSeries) + webWorkerPool.terminateWorkers() + verifyImage(t, image) + }) + + test('Test reading DICOM file series, assume a single sorted series, given componentType, pixelType', async t => { + const fetchFiles = fileNames.map(function (file) { + const path = testSeriesDirectory + file + return axios.get(path, { responseType: 'blob' }).then(function (response) { + const jsFile = new window.File([response.data], file) + return jsFile }) + }) + + const files = await Promise.all(fetchFiles) + const singleSortedSeries = true + const componentType = IntTypes.Int32 + const pixelType = PixelTypes.Vector + const { image, webWorkerPool } = await readImageDICOMFileSeries(files, { singleSortedSeries, componentType, pixelType }) + webWorkerPool.terminateWorkers() + verifyImage(t, image, componentType, pixelType) }) test('Test reading DICOM array buffer series', async t => {