Skip to content

Commit

Permalink
fix(dicom): Ignore the rotations of DICOM datasets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zjp committed Jan 24, 2025
1 parent c862916 commit 594f54c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/bundles/dicom/src/dicom_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 594f54c

Please sign in to comment.