Commit 681310a9fa231a7c8819b3358cf2ad4bc5a6261d
1 parent
a7cfe280
Exists in
rotvol
Avoiding zero division in vector normalize
Showing
1 changed file
with
5 additions
and
1 deletions
Show diff stats
invesalius/data/styles.py
@@ -1566,7 +1566,11 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): | @@ -1566,7 +1566,11 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): | ||
1566 | p1 = self.get_image_point_coord(x, y, z) | 1566 | p1 = self.get_image_point_coord(x, y, z) |
1567 | 1567 | ||
1568 | axis = np.cross(p0, p1) | 1568 | axis = np.cross(p0, p1) |
1569 | - axis = axis / np.linalg.norm(axis) | 1569 | + norm = np.linalg.norm(axis) |
1570 | + if norm == 0: | ||
1571 | + print "NORM 0" | ||
1572 | + return | ||
1573 | + axis = axis / norm | ||
1570 | angle = np.arccos(np.dot(p0, p1)/(np.linalg.norm(p0)*np.linalg.norm(p1))) | 1574 | angle = np.arccos(np.dot(p0, p1)/(np.linalg.norm(p0)*np.linalg.norm(p1))) |
1571 | 1575 | ||
1572 | self.viewer.slice_.q_orientation = transformations.quaternion_multiply(self.viewer.slice_.q_orientation, transformations.quaternion_about_axis(angle, axis)) | 1576 | self.viewer.slice_.q_orientation = transformations.quaternion_multiply(self.viewer.slice_.q_orientation, transformations.quaternion_about_axis(angle, axis)) |