fix viewport importing

This commit is contained in:
Ross
2025-06-03 16:06:37 +01:00
parent 8c218d42f4
commit c21fe2cbd7
+34 -24
View File
@@ -284,23 +284,18 @@ function App({ container_id, imageStacks, autoCacheStack, ...props }: AppProps)
if (autoCacheStack) {
for (const imageId of imageIds) {
console.log("Caching metadata for imageId:", imageId);
if (imageId.startsWith("wadouri:")) {
console.log("Caching metadata for imageId:", imageId);
try {
const url = imageId.slice(8);
if (url.startsWith("blob:") || url.startsWith("/")) {
if (cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager) {
// If load returns a promise, collect it
// @ts-ignore
const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load(
url,
);
if (result && typeof result.then === "function") {
loadPromises.push(result);
}
} else {
console.warn("MetaDataManager not found. Unable to cache metadata.");
if (cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager) {
// @ts-ignore
const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load(url);
if (result && typeof result.then === "function") {
loadPromises.push(result);
}
} else {
console.warn("MetaDataManager not found. Unable to cache metadata.");
}
} catch (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)) {
toolData.data.forEach((ann: any) => {
// Convert pixel handles to world coordinates
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 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 });
console.log("Importing legacy annotation:")
console.log(" Image ID:", imageId);
@@ -1318,18 +1313,31 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
if (!FrameOfReferenceUID && plane && plane.frameOfReferenceUID) {
FrameOfReferenceUID = plane.frameOfReferenceUID;
}
const viewPlaneNormal = plane?.rowCosines && plane?.columnCosines
? [
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[0] * plane.columnCosines[1] - plane.rowCosines[1] * plane.columnCosines[0],
]
: undefined;
const viewPlaneNormal =
plane?.rowCosines && plane?.columnCosines
? [
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[0] * plane.columnCosines[1] - plane.rowCosines[1] * plane.columnCosines[0],
]
: 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 = {
annotationUID: ann.uuid || cornerstoneTools.utilities.uuidv4(),
annotationUID: ann.uuid, // || cornerstoneTools.utilities.uuidv4(),
metadata: {
toolName: cs3Tool,
referencedImageId: imageId,
@@ -1348,6 +1356,7 @@ const endWorld = pixelToWorld(imageId, { x: ann.handles.end.y, y: ann.handles.en
visibility: ann.visible !== false,
active: ann.active || false,
};
// @ts-expect-error legacy
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 };
}
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") {
viewport.setCamera(camera);
}