From 594f54cdee5b9fb3880b2b8a1210e838586ee8e6 Mon Sep 17 00:00:00 2001 From: Zach Pearson Date: Thu, 23 Jan 2025 17:09:17 -0800 Subject: [PATCH] fix(dicom): Ignore the rotations of DICOM datasets DICOM datasets can be rotated in all kinds of wonky ways, but IMO the important things are the pixel and slice spacings, since those variables make sure DICOM datasets appear correctly proportioned. Ignoring rotations means that we don't have to figure out how to rotate the data or move the camera in the raycasting shader, and the PlaneViewers don't have to calculate relative-to-dataset axis down which to point their cameras. If someone complains we can explore those solutions but for now we won't. --- src/bundles/dicom/src/dicom_hierarchy.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/bundles/dicom/src/dicom_hierarchy.py b/src/bundles/dicom/src/dicom_hierarchy.py index 0cb5e0722c..7f0e2fbade 100644 --- a/src/bundles/dicom/src/dicom_hierarchy.py +++ b/src/bundles/dicom/src/dicom_hierarchy.py @@ -890,14 +890,21 @@ def pixel_spacing(self): return x_scale, y_scale, z_scale def rotation(self): - affine = self.affine - x_scale, y_scale, z_scale = self.pixel_spacing() - rotation_matrix = [ - [affine[0][0] / x_scale, affine[0][1] / y_scale, affine[0][2] / z_scale], - [affine[1][0] / x_scale, affine[1][1] / y_scale, affine[1][2] / z_scale], - [affine[2][0] / x_scale, affine[2][1] / y_scale, affine[2][2] / z_scale], - ] - return rotation_matrix + #affine = self.affine + #x_scale, y_scale, z_scale = self.pixel_spacing() + #rotation_matrix = [ + # [affine[0][0] / x_scale, affine[0][1] / y_scale, affine[0][2] / z_scale], + # [affine[1][0] / x_scale, affine[1][1] / y_scale, affine[1][2] / z_scale], + # [affine[2][0] / x_scale, affine[2][1] / y_scale, affine[2][2] / z_scale], + #] + # We're ignoring the rotation given by the DICOM files until someone complains about it. + # Doing this simplifies other areas of the codebase significantly. + # 1) The plane viewers use orthographic cameras pointed down the X, Y, and Z axes, and + # ignoring the rotations of the files means we don't have to calculate new axes to + # point the cameras down when files aren't axis aligned. + # 2) We don't have to modify the raycasting shader to do such calculations either. + return [[1, 0, 0], [0, 1, 0], [0, 0, 1]] + #return rotation_matrix def origin(self): affine = self.affine