Perturb the rays by randomly shifting the ray origin by [-shift, shift], and randomly rotating the ray direction with [-angle, angle] in degree. Args: shift: [-shift, shift] angle: [-angle, angle] in degrees
(
self,
shift: T.Optional[float],
angle: T.Optional[float],
)
| 1057 | return rays |
| 1058 | |
| 1059 | def random_perturb_direction( |
| 1060 | self, |
| 1061 | shift: T.Optional[float], |
| 1062 | angle: T.Optional[float], |
| 1063 | ): |
| 1064 | """ |
| 1065 | Perturb the rays by randomly shifting the ray origin by [-shift, shift], |
| 1066 | and randomly rotating the ray direction with [-angle, angle] in degree. |
| 1067 | |
| 1068 | Args: |
| 1069 | shift: |
| 1070 | [-shift, shift] |
| 1071 | angle: |
| 1072 | [-angle, angle] in degrees |
| 1073 | rng: |
| 1074 | the random generator |
| 1075 | """ |
| 1076 | |
| 1077 | if shift is not None and math.fabs(shift) > 1e-6: |
| 1078 | r_shifts = (torch.rand_like(self.origins_w) - 0.5) * 2. * shift # [-shift, shift] |
| 1079 | self.origins_w = self.origins_w + r_shifts # (b, *m_shape, 3) |
| 1080 | if angle is not None and math.fabs(angle) > 1e-3: |
| 1081 | r_angles = ( |
| 1082 | torch.rand_like(self.directions_w) - 0.5 |
| 1083 | ) * 2. * angle # (b, *m_shape, 3) [-angle, angle] in degree |
| 1084 | r_angles = r_angles.view(-1, 3) # (b*m_shape, 3) |
| 1085 | Rs = torch.from_numpy( |
| 1086 | Rotation.from_euler('xyz', r_angles, degrees=True).as_matrix() |
| 1087 | ) # (bm, 3, 3) rotation matrix |
| 1088 | Rs = Rs.reshape(*(self.directions_w.shape[:-1]), 3, 3) # (b, *m_shape, 3, 3) |
| 1089 | self.directions_w = (Rs @ self.directions_w.unsqueeze(-1))[..., 0] # (b, *m, 3) |
| 1090 | |
| 1091 | @staticmethod |
| 1092 | def cat(rays: T.List['Ray'], dim: int) -> 'Ray': |