fix viewport importing

This commit is contained in:
Ross
2025-06-03 16:06:37 +01:00
parent 8c218d42f4
commit c21fe2cbd7
+22 -12
View File
@@ -284,24 +284,19 @@ function App({ container_id, imageStacks, autoCacheStack, ...props }: AppProps)
if (autoCacheStack) { if (autoCacheStack) {
for (const imageId of imageIds) { for (const imageId of imageIds) {
console.log("Caching metadata for imageId:", imageId);
if (imageId.startsWith("wadouri:")) { if (imageId.startsWith("wadouri:")) {
console.log("Caching metadata for imageId:", imageId);
try { try {
const url = imageId.slice(8); const url = imageId.slice(8);
if (url.startsWith("blob:") || url.startsWith("/")) {
if (cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager) { if (cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager) {
// If load returns a promise, collect it
// @ts-ignore // @ts-ignore
const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load( const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load(url);
url,
);
if (result && typeof result.then === "function") { if (result && typeof result.then === "function") {
loadPromises.push(result); loadPromises.push(result);
} }
} else { } else {
console.warn("MetaDataManager not found. Unable to cache metadata."); console.warn("MetaDataManager not found. Unable to cache metadata.");
} }
}
} catch (e) { } catch (e) {
console.warn(`Failed to cache metadata for ${imageId}:`, e); console.warn(`Failed to cache metadata for ${imageId}:`, e);
} }
@@ -1303,8 +1298,8 @@ function App({ container_id, imageStacks, autoCacheStack, ...props }: AppProps)
if (toolData.data && Array.isArray(toolData.data)) { if (toolData.data && Array.isArray(toolData.data)) {
toolData.data.forEach((ann: any) => { toolData.data.forEach((ann: any) => {
// Convert pixel handles to world coordinates // Convert pixel handles to world coordinates
const startWorld = pixelToWorld(imageId, { x: ann.handles.start.y, y: ann.handles.start.x }); const startWorld = pixelToWorld(imageId, { x: ann.handles.start.y, y: ann.handles.start.x });
const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.end.x }); const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.end.x });
console.log("Importing legacy annotation:") console.log("Importing legacy annotation:")
console.log(" Image ID:", imageId); console.log(" Image ID:", imageId);
@@ -1318,7 +1313,8 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
if (!FrameOfReferenceUID && plane && plane.frameOfReferenceUID) { if (!FrameOfReferenceUID && plane && plane.frameOfReferenceUID) {
FrameOfReferenceUID = plane.frameOfReferenceUID; FrameOfReferenceUID = plane.frameOfReferenceUID;
} }
const viewPlaneNormal = plane?.rowCosines && plane?.columnCosines const viewPlaneNormal =
plane?.rowCosines && plane?.columnCosines
? [ ? [
plane.rowCosines[1] * plane.columnCosines[2] - plane.rowCosines[2] * plane.columnCosines[1], plane.rowCosines[1] * plane.columnCosines[2] - plane.rowCosines[2] * plane.columnCosines[1],
plane.rowCosines[2] * plane.columnCosines[0] - plane.rowCosines[0] * plane.columnCosines[2], plane.rowCosines[2] * plane.columnCosines[0] - plane.rowCosines[0] * plane.columnCosines[2],
@@ -1326,10 +1322,22 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
] ]
: undefined; : undefined;
// Only include viewPlaneNormal if it's a valid 3-element array
const metadata: any = {
toolName: cs3Tool,
referencedImageId: imageId,
FrameOfReferenceUID,
};
if (Array.isArray(viewPlaneNormal) && viewPlaneNormal.length === 3) {
metadata.viewPlaneNormal = viewPlaneNormal as [number, number, number];
}
const annotation = { const annotation = {
annotationUID: ann.uuid || cornerstoneTools.utilities.uuidv4(), annotationUID: ann.uuid, // || cornerstoneTools.utilities.uuidv4(),
metadata: { metadata: {
toolName: cs3Tool, toolName: cs3Tool,
referencedImageId: imageId, referencedImageId: imageId,
@@ -1348,6 +1356,7 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
visibility: ann.visible !== false, visibility: ann.visible !== false,
active: ann.active || false, active: ann.active || false,
}; };
// @ts-expect-error legacy
cornerstoneTools.annotation.state.addAnnotation(annotation, annotation.annotationUID); cornerstoneTools.annotation.state.addAnnotation(annotation, annotation.annotationUID);
}); });
} }
@@ -1400,8 +1409,9 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
camera.translation = { ...camera.translation, ...legacy.translation }; camera.translation = { ...camera.translation, ...legacy.translation };
} }
if (legacy.scale) { if (legacy.scale) {
camera.parallelScale = 1 / legacy.scale; camera.parallelScale = 200 / legacy.scale;
} }
console.log("Applying legacy camera properties:", camera);
if (typeof viewport.setCamera === "function") { if (typeof viewport.setCamera === "function") {
viewport.setCamera(camera); viewport.setCamera(camera);
} }