Exemple #1
0
 def test_packed_face_areas(self, device, dtype):
     vertices = torch.tensor(
         [[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [2., 0., 0.2],
          [0., 0., 0.], [0., 1., 1.], [2., 0., 0.]],
         device=device,
         dtype=dtype)
     faces = torch.tensor([[0, 1, 2], [1, 0, 3], [0, 1, 2]],
                          device=device,
                          dtype=torch.long)
     first_idx_vertices = torch.LongTensor([0, 4, 7], device='cpu')
     num_faces_per_mesh = torch.LongTensor([2, 1], device='cpu')
     output = mesh.packed_face_areas(vertices, first_idx_vertices, faces,
                                     num_faces_per_mesh)
     expected_output = torch.tensor([0.5, 1., math.sqrt(2.)],
                                    device=device,
                                    dtype=dtype)
     assert torch.allclose(output, expected_output)
Exemple #2
0
    def test_packed_sample_points_with_areas(self, packed_vertices_info,
                                             packed_faces_info, dtype, device):
        num_samples = 1000
        vertices, first_idx_vertices = packed_vertices_info
        faces, num_faces_per_mesh = packed_faces_info

        face_areas = mesh.packed_face_areas(vertices, first_idx_vertices,
                                            faces, num_faces_per_mesh)

        points1, face_choices1 = with_seed(1234)(mesh.packed_sample_points)(
            vertices, first_idx_vertices, faces, num_faces_per_mesh,
            num_samples, face_areas)

        points2, face_choices2 = with_seed(1234)(
            mesh.packed_sample_points)(vertices, first_idx_vertices, faces,
                                       num_faces_per_mesh, num_samples)

        assert torch.allclose(points1, points2)
        assert torch.equal(face_choices1, face_choices2)