Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 53 additions & 45 deletions bun.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions extensions/cornerstone/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EVENTS,
metaData,
volumeLoader,
imageLoader,
imageLoadPoolManager,
getEnabledElement,
Settings,
Expand Down Expand Up @@ -164,6 +165,9 @@ export default async function init({
cornerstoneStreamingDynamicImageVolumeLoader
);

imageLoader.registerImageLoader('nifti', cornerstoneNiftiImageLoader);


// Register strategies using the wrapper
const imageLoadStrategies = {
interleaveCenter: interleaveCenterLoader,
Expand Down
1 change: 1 addition & 0 deletions extensions/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@babel/runtime": "7.28.2",
"@cornerstonejs/calculate-suv": "1.1.0",
"@cornerstonejs/nifti-volume-loader": "4.14.6",
"lodash.get": "4.4.2",
"lodash.uniqby": "4.7.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ function PanelStudyBrowser({
currentDisplaySets.forEach(async dSet => {
const newImageSrcEntry = {};
const displaySet = displaySetService.getDisplaySetByUID(dSet.displaySetInstanceUID);
const imageIds = dataSource.getImageIdsForDisplaySet(dSet);

const imageId = getImageIdForThumbnail(displaySet, imageIds);
// Wait for imageIds if NIFTI is detected and imageIds are not yet loaded
let imageId;
if (displaySet.niftiURL && (!imageIds || imageIds.length === 0)) {
await displaySet.loadImageIds();
imageIds = displaySet.imageIds;
}
imageId = getImageIdForThumbnail(displaySet, imageIds);

// TODO: Is it okay that imageIds are not returned here for SR displaySets?
if (displaySet?.unsupported) {
Expand Down
34 changes: 34 additions & 0 deletions extensions/default/src/getSopClassHandlerModule.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { utils, classes } from '@ohif/core';
import { createNiftiImageIdsAndCacheMetadata } from '@cornerstonejs/nifti-volume-loader';

import i18n from '@ohif/i18n';
import { id } from './id';
import getDisplaySetMessages from './getDisplaySetMessages';
import getDisplaySetsFromUnsupportedSeries from './getDisplaySetsFromUnsupportedSeries';
import { chartHandler } from './SOPClassHandlers/chartSOPClassHandler';
import { joinUrl, isAbsolutePathOrUrl } from './utils/urlUtils';

const {
isImage,
Expand Down Expand Up @@ -88,6 +91,37 @@ const makeDisplaySet = (instances, index) => {
// set appropriate attributes to image set...
const messages = getDisplaySetMessages(instances, isReconstructable, isDynamicVolume);

const { niftiPrivateTagName, niftiBaseUrl } = dataSource.getConfig?.() || {};
let niftiURL;
const niftiPath = instance[niftiPrivateTagName];
if (niftiPath) {
if (typeof niftiPath === 'string' && !niftiPath.includes('dedupped')) {
if (isAbsolutePathOrUrl(niftiPath)) {
niftiURL = niftiPath;
} else {
niftiURL = joinUrl(niftiBaseUrl, niftiPath);
}
}
}

if (niftiURL) {
imageSet.setAttributes({
niftiURL,
loadImageIds: async () => {
try {
const imageIds = await createNiftiImageIdsAndCacheMetadata({ url: niftiURL });
imageSet.setAttributes({ imageIds });
imageSet.setAttributes({
numImageFrames: Array.isArray(imageIds) ? imageIds.length : 0,
});
imageSet.setAttributes({ isReconstructable: true });
} catch (e) {
console.error('Error loading niftiURL:', e);
}
},
});
}

imageSet.setAttributes({
volumeLoaderSchema,
displaySetInstanceUID: imageSet.uid, // create a local alias for the imageSet UID
Expand Down
28 changes: 28 additions & 0 deletions extensions/default/src/utils/urlUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Checks if a path is an absolute URL (http/https) or absolute path (starts with /)
* @param {string} path - The path to check
* @returns {boolean} True if the path is absolute
*/
export function isAbsolutePathOrUrl(path) {
if (!path || typeof path !== 'string') {
return false;
}
return path.startsWith('http://') || path.startsWith('https://') || path.startsWith('/');
}

/**
* Joins a base URL with a relative path
* @param {string} baseUrl - The base URL
* @param {string} path - The path to join
* @returns {string} The joined URL
*/
export function joinUrl(baseUrl, path) {
if (!baseUrl) return path || '';
if (!path) return baseUrl;

// Remove trailing slash from baseUrl and leading slash from path
const base = baseUrl.replace(/\/+$/, '');
const relativePath = path.replace(/^\/+/, '');

return `${base}/${relativePath}`;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"link-list": "npm ls --depth=0 --link=true"
},
"dependencies": {
"@cornerstonejs/nifti-volume-loader": "^4.10.0",
"execa": "8.0.1"
},
"optionalDependencies": {
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,20 @@
"@itk-wasm/morphological-contour-interpolation" "1.1.0"
itk-wasm "1.0.0-b.165"

"@cornerstonejs/[email protected]":
version "4.14.6"
resolved "https://registry.yarnpkg.com/@cornerstonejs/nifti-volume-loader/-/nifti-volume-loader-4.14.6.tgz#8d22858f48d736076bf52c8951b5d9db60c54968"
integrity sha512-KmLt3kP3DdwjlKMEFGb2hn0IjMP4P/WzHrkVGFFf2V6V9l3AWlJjwrlV1kFSr9vsQSesBEwWM60j9Km1jGL0qA==
dependencies:
nifti-reader-js "0.6.9"

"@cornerstonejs/nifti-volume-loader@^4.10.0":
version "4.15.0"
resolved "https://registry.yarnpkg.com/@cornerstonejs/nifti-volume-loader/-/nifti-volume-loader-4.15.0.tgz#7119c14801a7222507de786475af667e3df9b8fa"
integrity sha512-mbpdPB8zzfJ7Gnq0cx3ka1hE9VcWKU/So9OQQqk0HrQl03yB9uIIDu9GnvvNtX+IDZN7jkZWMbYHUJu7I2+BxA==
dependencies:
nifti-reader-js "0.6.9"

"@cornerstonejs/[email protected]":
version "4.14.6"
resolved "https://registry.yarnpkg.com/@cornerstonejs/polymorphic-segmentation/-/polymorphic-segmentation-4.14.6.tgz#26154ddd0b1edceca9e6136e264d2d7b34df7c4f"
Expand Down Expand Up @@ -8833,6 +8847,11 @@ fetch-blob@^3.1.2, fetch-blob@^3.1.4:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"

fflate@*:
version "0.8.2"
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.8.2.tgz#fc8631f5347812ad6028bbe4a2308b2792aa1dea"
integrity sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==

[email protected]:
version "0.7.3"
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.7.3.tgz#288b034ff0e9c380eaa2feff48c787b8371b7fa5"
Expand Down Expand Up @@ -13355,6 +13374,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.3.0.tgz#b4d2a866137a67d42564b07f3a3e720e2ff3871a"
integrity sha512-/QHIrsYpd6Kfk7xakK4svpDI5mmXP0gfvCoJdGpZQ2TOrQZmsW0QxjaiLn8wbIKjtm4BTSqLoix4lxYYOnLJ/w==

[email protected]:
version "0.6.9"
resolved "https://registry.yarnpkg.com/nifti-reader-js/-/nifti-reader-js-0.6.9.tgz#737b88eb951c6b98841ce888204a9370214b17e5"
integrity sha512-oEC35cuYFR0i+KeXhaK0hJz4oSj511Vo7LmO/6iqbxzwek6XWnBi77VURlk4jsnJ86tlJNpYv6ujmSDpPP46Tw==
dependencies:
fflate "*"

no-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d"
Expand Down
Loading