Skip to content
21 changes: 19 additions & 2 deletions packages/core/src/RenderingEngine/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,25 @@ class Viewport {
const extent = imageData.getExtent();
const spacing = imageData.getSpacing();

widthWorld = (extent[1] - extent[0]) * spacing[0];
heightWorld = (extent[3] - extent[2]) * spacing[1];
// Determine which dimensions to use based on view plane normal
// The view plane normal tells us which axis we're looking along
const absNormal = viewPlaneNormal.map(Math.abs);
const maxIndex = absNormal.indexOf(Math.max(...absNormal));

// Based on which axis we're looking along, use the appropriate extents
if (maxIndex === 0) {
// Sagittal view (looking along X axis) - use Y for width, Z for height
widthWorld = (extent[3] - extent[2]) * spacing[1];
heightWorld = (extent[5] - extent[4]) * spacing[2];
} else if (maxIndex === 1) {
// Coronal view (looking along Y axis) - use X for width, Z for height
widthWorld = (extent[1] - extent[0]) * spacing[0];
heightWorld = (extent[5] - extent[4]) * spacing[2];
} else {
// Axial view (looking along Z axis) - use X for width, Y for height
widthWorld = (extent[1] - extent[0]) * spacing[0];
heightWorld = (extent[3] - extent[2]) * spacing[1];
}
} else {
({ widthWorld, heightWorld } = this._getWorldDistanceViewUpAndViewRight(
bounds,
Expand Down
Loading