Commit 9f54b6b7b05f7df7f11121b6b19786b0d5bc7804

Authored by okahilak
Committed by GitHub
1 parent ff04a14f
Exists in master

CLP: Be explicit about the order of axes when computing Euler angles (#346)

- The angles returned by translations.decompose_matrix use the
  axe order 'sxyz'. It is also the default for translations.euler_from_matrix,
  although that function allows changing the order.

  Therefore, change to using euler_from_matrix, and instead of defaulting to the
  axe order 'sxyz', be explicit about it to make it easier to notice any bugs.
Showing 1 changed file with 12 additions and 4 deletions   Show diff stats
invesalius/data/coregistration.py
... ... @@ -108,20 +108,25 @@ def corregistrate_object_dynamic(inp, coord_raw, ref_mode_id, icp):
108 108  
109 109 # transform raw marker coordinate to object center
110 110 m_probe = object_marker_to_center(coord_raw, obj_ref_mode, t_obj_raw, s0_raw, r_s0_raw)
  111 +
111 112 # transform object center to reference marker if specified as dynamic reference
112 113 if ref_mode_id:
113 114 m_probe_ref = object_to_reference(coord_raw, m_probe)
114 115 else:
115 116 m_probe_ref = m_probe
  117 +
116 118 # invert y coordinate
117 119 m_probe_ref[2, -1] = -m_probe_ref[2, -1]
  120 +
118 121 # corregistrate from tracker to image space
119 122 m_img = tracker_to_image(m_change, m_probe_ref, r_obj_img, m_obj_raw, s0_dyn)
120 123 if icp[0]:
121 124 m_img = bases.transform_icp(m_img, icp[1])
  125 +
122 126 # compute rotation angles
123   - _, _, angles, _, _ = tr.decompose_matrix(m_img)
124   - # create output coordiante list
  127 + angles = tr.euler_from_matrix(m_img, axes='sxyz')
  128 +
  129 + # create output coordinate list
125 130 coord = m_img[0, -1], m_img[1, -1], m_img[2, -1], \
126 131 np.degrees(angles[0]), np.degrees(angles[1]), np.degrees(angles[2])
127 132  
... ... @@ -146,6 +151,7 @@ def corregistrate_dynamic(inp, coord_raw, ref_mode_id, icp):
146 151  
147 152 # transform raw marker coordinate to object center
148 153 m_probe = compute_marker_transformation(coord_raw, obj_ref_mode)
  154 +
149 155 # transform object center to reference marker if specified as dynamic reference
150 156 if ref_mode_id:
151 157 m_ref = compute_marker_transformation(coord_raw, 1)
... ... @@ -155,6 +161,7 @@ def corregistrate_dynamic(inp, coord_raw, ref_mode_id, icp):
155 161  
156 162 # invert y coordinate
157 163 m_probe_ref[2, -1] = -m_probe_ref[2, -1]
  164 +
158 165 # corregistrate from tracker to image space
159 166 m_img = m_change @ m_probe_ref
160 167  
... ... @@ -162,8 +169,9 @@ def corregistrate_dynamic(inp, coord_raw, ref_mode_id, icp):
162 169 m_img = bases.transform_icp(m_img, icp[1])
163 170  
164 171 # compute rotation angles
165   - _, _, angles, _, _ = tr.decompose_matrix(m_img)
166   - # create output coordiante list
  172 + angles = tr.euler_from_matrix(m_img, axes='sxyz')
  173 +
  174 + # create output coordinate list
167 175 coord = m_img[0, -1], m_img[1, -1], m_img[2, -1],\
168 176 np.degrees(angles[0]), np.degrees(angles[1]), np.degrees(angles[2])
169 177  
... ...