fix viewport importing
This commit is contained in:
+34
-24
@@ -284,23 +284,18 @@ 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) {
|
// @ts-ignore
|
||||||
// If load returns a promise, collect it
|
const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load(url);
|
||||||
// @ts-ignore
|
if (result && typeof result.then === "function") {
|
||||||
const result = cornerstoneDICOMImageLoader.wadouri.dataSetCacheManager.load(
|
loadPromises.push(result);
|
||||||
url,
|
|
||||||
);
|
|
||||||
if (result && typeof result.then === "function") {
|
|
||||||
loadPromises.push(result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.warn("MetaDataManager not found. Unable to cache metadata.");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
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,18 +1313,31 @@ 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[2] * plane.columnCosines[0] - plane.rowCosines[0] * plane.columnCosines[2],
|
plane.rowCosines[1] * plane.columnCosines[2] - plane.rowCosines[2] * plane.columnCosines[1],
|
||||||
plane.rowCosines[0] * plane.columnCosines[1] - plane.rowCosines[1] * plane.columnCosines[0],
|
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;
|
]
|
||||||
|
: 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user