fix capture not maintaining flip/rotate state (#5843)

* fix capture not maintaining flip/rotate state

* fix capture not maintaining flip/rotate state

---------

Co-authored-by: silasshellenbarger <sdshe@Silas-Computer.localdomain>
This commit is contained in:
Silas Shellenbarger 2026-02-28 04:50:35 -05:00 committed by GitHub
parent 2b486f16ed
commit 6a3caa1ac9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -118,33 +118,50 @@ const CornerstoneViewportDownloadForm = ({
const downloadViewport = renderingEngine.getViewport(VIEWPORT_ID); const downloadViewport = renderingEngine.getViewport(VIEWPORT_ID);
try { try {
// Capture current viewport state
// - properties: VOI, colormap, interpolation, etc.
// - viewPresentation: flip/rotate/zoom presentation state added for
// saving flip and rotation for capture
// - viewReference: image/volume reference
const properties = viewport.getProperties(); const properties = viewport.getProperties();
const viewPresentation = viewport.getViewPresentation?.();
const viewRef = viewport.getViewReference?.();
if (downloadViewport instanceof StackViewport) { if (downloadViewport instanceof StackViewport) {
const imageId = viewport.getCurrentImageId(); const imageId = viewport.getCurrentImageId();
await downloadViewport.setStack([imageId]); await downloadViewport.setStack([imageId]);
downloadViewport.setProperties(properties);
} else if (downloadViewport instanceof BaseVolumeViewport) { } else if (downloadViewport instanceof BaseVolumeViewport) {
const volumeIds = viewport.getAllVolumeIds(); const volumeIds = viewport.getAllVolumeIds();
await downloadViewport.setVolumes([{ volumeId: volumeIds[0] }]); await downloadViewport.setVolumes([{ volumeId: volumeIds[0] }]);
} }
// Apply presentation state so captured image preserves flip/rotate
if (viewPresentation && downloadViewport.setViewPresentation) {
downloadViewport.setViewPresentation(viewPresentation);
}
// Apply viewport display properties
downloadViewport.setProperties(properties); downloadViewport.setProperties(properties);
const viewRef = viewport.getViewReference();
// Ensure correct image/volume reference
if (viewRef && downloadViewport.setViewReference) {
downloadViewport.setViewReference(viewRef); downloadViewport.setViewReference(viewRef);
}
downloadViewport.render(); downloadViewport.render();
// Re-apply segmentation overlays to the download viewport
if (segmentationRepresentations?.length) { if (segmentationRepresentations?.length) {
segmentationRepresentations.forEach(segRepresentation => { segmentationRepresentations.forEach(segRepresentation => {
const { segmentationId, colorLUTIndex, type } = segRepresentation; const { segmentationId, colorLUTIndex, type } = segRepresentation;
if (type === Enums.SegmentationRepresentations.Labelmap) { if (type === Enums.SegmentationRepresentations.Labelmap) {
segmentation.addLabelmapRepresentationToViewportMap({ segmentation.addLabelmapRepresentationToViewportMap({
[downloadViewport.id]: [ [downloadViewport.id]: [
{ {
segmentationId, segmentationId,
type: Enums.SegmentationRepresentations.Labelmap, type: Enums.SegmentationRepresentations.Labelmap,
config: { config: { colorLUTOrIndex: colorLUTIndex },
colorLUTOrIndex: colorLUTIndex,
},
}, },
], ],
}); });
@ -156,9 +173,7 @@ const CornerstoneViewportDownloadForm = ({
{ {
segmentationId, segmentationId,
type: Enums.SegmentationRepresentations.Contour, type: Enums.SegmentationRepresentations.Contour,
config: { config: { colorLUTOrIndex: colorLUTIndex },
colorLUTOrIndex: colorLUTIndex,
},
}, },
], ],
}); });