I am trying to display a NIfTI image in CornerstoneJS while progressively loading it from a backend URL. The backend exposes a URL to download the NIfTI file, and I want to visualize slices progressively while the file is being downloaded.
Currently, I am using @cornerstonejs/nifti-volume-loader
like this:
import * as cornerstone from '@cornerstonejs/core';
import { createNiftiImageIdsAndCacheMetadata } from '@cornerstonejs/nifti-volume-loader';
...
let renderingEngine = ...;
let volumeId = ...;
let imageIds = await createNiftiImageIdsAndCacheMetadata({ url: niftiUrl });
let volume = await cornerstone.volumeLoader.createAndCacheVolume(volumeId, {
imageIds: imageIds,
progressiveRendering: true
});
volume.load(() => {
cornerstone.setVolumesForViewports(
renderingEngine,
[{ volumeId }],
[...],
);
});
This works, but the entire NIfTI file needs to be downloaded before rendering. I want to progressively load and display slices as they arrive.
I found the @cmi-dair/nifti-stream library
, which allows me to extract the header and receive one slice at a time while downloading. Here’s how I am handling the streaming:
import { NiftiExtension, NiftiHeader, NiftiStream } from '@cmi-dair/nifti-stream';
...
let response = await fetch(niftiUrl);
if (!response.body) {
throw new Error('Failed to get response body');
}
let reader = new NiftiStream(response.body, {
sliceDimension: 2,
onHeader: async (header: NiftiHeader) => {
...
},
onExtension: (extension: NiftiExtension | null) => {
...
},
onSlice: (data: ArrayBuffer, indices: number[]) => {
...
},
onError: (error) => {
console.error(error);
}
});
await reader.start();
Now, how can I integrate this progressive slice loading with CornerstoneJS?
- Do I need to register a new volume loader to handle the streaming slices?
- Is there an alternative approach to achieve progressive rendering without waiting for the full file to download?
- Can I manually update a
StreamingImageVolume
as slices arrive?
Any guidance on integrating @cmi-dair/nifti-stream
with CornerstoneJS for progressive rendering would be highly appreciated!