def atlas_packed(self) -> torch.Tensor: if self.isempty(): return torch.zeros( (self._N, 0, 0, 3), dtype=torch.float32, device=self.device ) atlas_list = self.atlas_list() return list_to_packed(atlas_list)[0]
def test_list_to_packed(self): device = torch.device("cuda:0") N = 5 K = 20 x, x_dims = [], [] dim2 = torch.randint(K, size=(1, )).item() for _ in range(N): dim1 = torch.randint(K, size=(1, )).item() x_dims.append(dim1) x.append(torch.rand([dim1, dim2], device=device)) out = struct_utils.list_to_packed(x) x_packed = out[0] num_items = out[1] item_packed_first_idx = out[2] item_packed_to_list_idx = out[3] cur = 0 for i in range(N): self.assertTrue(num_items[i] == x_dims[i]) self.assertTrue(item_packed_first_idx[i] == cur) self.assertTrue(item_packed_to_list_idx[cur:cur + x_dims[i]].eq(i).all()) self.assertClose(x_packed[cur:cur + x_dims[i]], x[i]) cur += x_dims[i]
def faces_uvs_packed(self) -> torch.Tensor: if self.isempty(): return torch.zeros((self._N, 3), dtype=torch.float32, device=self.device) faces_uvs_list = self.faces_uvs_list() return list_to_packed(faces_uvs_list)[0]
def verts_uvs_packed(self) -> torch.Tensor: if self.isempty(): return torch.zeros((self._N, 2), dtype=torch.float32, device=self.device) verts_uvs_list = self.verts_uvs_list() return list_to_packed(verts_uvs_list)[0]
def transform_verts_list(verts_list, camera_info): """ input: @meshes: verts_list in local frame @camera_info: plane params from camera info, type = dict, must contain 'position' and 'rotation' as keys output: verts_list in global frame. """ tran = camera_info["position"] rot = camera_info["rotation"] verts_list_to_packed = struct_utils.list_to_packed(verts_list) verts_packed = verts_list_to_packed[0] num_verts_per_mesh = verts_list_to_packed[1] verts_packed = verts_packed * torch.tensor( [1.0, -1.0, -1.0], dtype=torch.float32) # suncg2habitat rot_matrix = torch.tensor(quaternion.as_rotation_matrix(rot), dtype=torch.float32) verts_packed = torch.mm(rot_matrix, verts_packed.T).T + torch.tensor( tran, dtype=torch.float32) verts_list = list(verts_packed.split(num_verts_per_mesh.tolist(), dim=0)) return verts_list