Enhance metadata caching in setLoadedImageIdsAndCacheMeta and add forced warm-up for visible stack viewports
This commit is contained in:
@@ -856,12 +856,13 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
}, [availableStacks, generateThumbnail, stackThumbnails]);
|
||||
|
||||
// Wrap setLoadedImageIds to also cache DICOM metadata
|
||||
const setLoadedImageIdsAndCacheMeta = async (imageIds: string[]) => {
|
||||
const setLoadedImageIdsAndCacheMeta = async (imageIds: string[], options?: { force?: boolean }) => {
|
||||
console.log("Setting loaded imageIds:", imageIds);
|
||||
console.log("autoCacheStack:", autoCacheStack);
|
||||
const loadPromises: Promise<any>[] = [];
|
||||
const shouldCache = Boolean(autoCacheStack || options?.force);
|
||||
|
||||
if (autoCacheStack) {
|
||||
if (shouldCache) {
|
||||
for (const imageId of imageIds) {
|
||||
if (imageId.startsWith("wadouri:")) {
|
||||
try {
|
||||
@@ -1171,6 +1172,19 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
const modifierActive = shiftPressed || (altEnablesReferenceCursors && altPressed);
|
||||
|
||||
if (modifierActive) {
|
||||
// Force metadata warm-up for visible stack viewports so nearest-slice lookup
|
||||
// can consider the entire stack (including images not yet viewed/cached).
|
||||
const visibleCount = viewportGrid.rows * viewportGrid.cols;
|
||||
const visibleStackImageIds = viewportImageIds
|
||||
.slice(0, visibleCount)
|
||||
.filter((ids, idx) => viewportModes[idx] === 'stack' && Array.isArray(ids) && ids.length > 0);
|
||||
|
||||
visibleStackImageIds.forEach((ids) => {
|
||||
setLoadedImageIdsAndCacheMeta(ids, { force: true }).catch((err) => {
|
||||
console.warn('Reference cursor metadata warm-up failed:', err);
|
||||
});
|
||||
});
|
||||
|
||||
if (!mainToolGroup.hasTool(ReferenceCursors.toolName)) {
|
||||
mainToolGroup.addTool(ReferenceCursors.toolName);
|
||||
}
|
||||
@@ -1181,7 +1195,16 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
mainToolGroup.setToolDisabled(ReferenceCursors.toolName);
|
||||
}
|
||||
}
|
||||
}, [altPressed, shiftPressed, altEnablesReferenceCursors]);
|
||||
}, [
|
||||
altPressed,
|
||||
shiftPressed,
|
||||
altEnablesReferenceCursors,
|
||||
viewportGrid.rows,
|
||||
viewportGrid.cols,
|
||||
viewportImageIds,
|
||||
viewportModes,
|
||||
setLoadedImageIdsAndCacheMeta,
|
||||
]);
|
||||
|
||||
// Helper to apply all mouse tool bindings (normal or ctrl)
|
||||
const applyMouseToolBindings = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user