fix tool import
This commit is contained in:
@@ -1198,7 +1198,27 @@ window.importViewerState = (json: string) => {
|
|||||||
// Export all annotations using cornerstoneTools.annotation.state.getAllAnnotations()
|
// Export all annotations using cornerstoneTools.annotation.state.getAllAnnotations()
|
||||||
window.exportAnnotations = () => {
|
window.exportAnnotations = () => {
|
||||||
try {
|
try {
|
||||||
const allAnnotations = cornerstoneTools.annotation.state.getAllAnnotations();
|
let allAnnotations = cornerstoneTools.annotation.state.getAllAnnotations();
|
||||||
|
console.log("Exporting annotations:", allAnnotations);
|
||||||
|
// Remove ReferenceLines annotations (toolName may be 'ReferenceLines')
|
||||||
|
if (Array.isArray(allAnnotations)) {
|
||||||
|
// Only keep annotations with toolName in the allowed list
|
||||||
|
const allowedTools = [
|
||||||
|
LengthTool.toolName,
|
||||||
|
ArrowAnnotateTool.toolName,
|
||||||
|
RectangleROITool.toolName,
|
||||||
|
EllipticalROITool.toolName,
|
||||||
|
PlanarFreehandROITool.toolName,
|
||||||
|
PlanarFreehandContourSegmentationTool.toolName,
|
||||||
|
ProbeTool.toolName,
|
||||||
|
SculptorTool.toolName,
|
||||||
|
];
|
||||||
|
allAnnotations = allAnnotations.filter(
|
||||||
|
ann => allowedTools.includes(ann.metadata.toolName)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return "{}"; // If no annotations found, return empty object
|
||||||
|
}
|
||||||
return JSON.stringify(allAnnotations, null, 2);
|
return JSON.stringify(allAnnotations, null, 2);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert("Failed to export annotations: " + e);
|
alert("Failed to export annotations: " + e);
|
||||||
@@ -1210,7 +1230,25 @@ window.importViewerState = (json: string) => {
|
|||||||
window.importAnnotations = (json: string) => {
|
window.importAnnotations = (json: string) => {
|
||||||
try {
|
try {
|
||||||
const annotationData = typeof json === "string" ? JSON.parse(json) : json;
|
const annotationData = typeof json === "string" ? JSON.parse(json) : json;
|
||||||
cornerstoneTools.annotation.state.restoreAnnotations(annotationData);
|
// Remove all existing annotations if needed
|
||||||
|
if (cornerstoneTools.annotation.state.removeAllAnnotations) {
|
||||||
|
cornerstoneTools.annotation.state.removeAllAnnotations();
|
||||||
|
}
|
||||||
|
// Add each annotation from the imported data
|
||||||
|
if (Array.isArray(annotationData)) {
|
||||||
|
annotationData.forEach(ann => {
|
||||||
|
cornerstoneTools.annotation.state.addAnnotation(ann);
|
||||||
|
});
|
||||||
|
} else if (annotationData && typeof annotationData === "object") {
|
||||||
|
// If the data is an object with tool types as keys
|
||||||
|
Object.values(annotationData).forEach((anns: any) => {
|
||||||
|
if (Array.isArray(anns)) {
|
||||||
|
anns.forEach(ann => {
|
||||||
|
cornerstoneTools.annotation.state.addAnnotation(ann);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
if (renderingEngineRef.current) {
|
if (renderingEngineRef.current) {
|
||||||
renderingEngineRef.current.render();
|
renderingEngineRef.current.render();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user