Add clearViewer function to reset viewer state and annotations
This commit is contained in:
@@ -2254,6 +2254,56 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
}
|
||||
}
|
||||
|
||||
function clearViewer() {
|
||||
const renderingEngine = renderingEngineRef.current;
|
||||
|
||||
// Disable viewports so stale frames are removed from the DOM/canvas.
|
||||
if (renderingEngine) {
|
||||
for (let i = 0; i < MAX_VIEWPORTS; i++) {
|
||||
const viewportId = `CT_${i}`;
|
||||
try {
|
||||
const viewport = renderingEngine.getViewport(viewportId);
|
||||
if (viewport) {
|
||||
renderingEngine.disableElement(viewportId);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore missing/disabled viewport errors.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear per-viewport DOM state so they can be re-enabled cleanly later.
|
||||
for (let i = 0; i < MAX_VIEWPORTS; i++) {
|
||||
const element = viewportRefs.current[i];
|
||||
if (!element) continue;
|
||||
if (element._resizeObserver) {
|
||||
try {
|
||||
element._resizeObserver.disconnect();
|
||||
} catch (e) {
|
||||
// Ignore observer teardown issues.
|
||||
}
|
||||
element._resizeObserver = undefined;
|
||||
}
|
||||
element._cornerstoneEnabled = false;
|
||||
element._lastViewportType = undefined;
|
||||
element._overlayListener = undefined;
|
||||
element.innerHTML = '';
|
||||
}
|
||||
|
||||
if (cornerstoneTools?.annotation?.state?.removeAllAnnotations) {
|
||||
cornerstoneTools.annotation.state.removeAllAnnotations();
|
||||
}
|
||||
|
||||
setAvailableStacks([]);
|
||||
setViewportImageIds(Array(MAX_VIEWPORTS).fill([]));
|
||||
setSelectedStackIdx(Array(MAX_VIEWPORTS).fill(0));
|
||||
setViewportModes(Array(MAX_VIEWPORTS).fill('stack'));
|
||||
setStackThumbnails({});
|
||||
thumbRequestedRef.current = {};
|
||||
setStackOrderModified(false);
|
||||
setActiveViewport(0);
|
||||
}
|
||||
|
||||
function truncateStack(lower: number, upper: number) {
|
||||
// Only allow when 1 viewport and 1 stack is loaded
|
||||
console.log("Truncating stack from", lower, "to", upper);
|
||||
@@ -2345,6 +2395,7 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
|
||||
window[`jumpToSliceByImageId_${apiKey}`] = jumpToSliceByImageId;
|
||||
window[`resetViewer_${apiKey}`] = resetViewer;
|
||||
window[`clearViewer_${apiKey}`] = clearViewer;
|
||||
window[`truncateStack_${apiKey}`] = truncateStack;
|
||||
window[`getCurrentStackPosition_${apiKey}`] = getCurrentStackPosition;
|
||||
|
||||
@@ -2864,6 +2915,7 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
window[`importLegacyViewport_${apiKey}`] = undefined;
|
||||
window[`jumpToSliceByImageId_${apiKey}`] = undefined;
|
||||
window[`resetViewer_${apiKey}`] = undefined;
|
||||
window[`clearViewer_${apiKey}`] = undefined;
|
||||
window[`truncateStack_${apiKey}`] = undefined;
|
||||
window[`getCurrentStackPosition_${apiKey}`] = undefined;
|
||||
window[`loadAdditionalStack_${apiKey}`] = undefined;
|
||||
|
||||
Reference in New Issue
Block a user