Ejemplo n.º 1
0
 def test_clone(self):
     tex = TexturesAtlas(atlas=torch.rand(size=(1, 10, 2, 2, 3)))
     tex.atlas_list()
     tex_cloned = tex.clone()
     self.assertSeparate(tex._atlas_padded, tex_cloned._atlas_padded)
     self.assertClose(tex._atlas_padded, tex_cloned._atlas_padded)
     self.assertSeparate(tex.valid, tex_cloned.valid)
     self.assertTrue(tex.valid.eq(tex_cloned.valid).all())
     for i in range(tex._N):
         self.assertSeparate(tex._atlas_list[i], tex_cloned._atlas_list[i])
         self.assertClose(tex._atlas_list[i], tex_cloned._atlas_list[i])
Ejemplo n.º 2
0
    def test_padded_to_packed(self):
        # Case where each face in the mesh has 3 unique uv vertex indices
        # - i.e. even if a vertex is shared between multiple faces it will
        # have a unique uv coordinate for each face.
        R = 2
        N = 20
        num_faces_per_mesh = torch.randint(size=(N, ), low=0, high=30)
        atlas_list = [torch.rand(f, R, R, 3) for f in num_faces_per_mesh]
        tex = TexturesAtlas(atlas=atlas_list)

        # This is set inside Meshes when textures is passed as an input.
        # Here we set _num_faces_per_mesh explicity.
        tex1 = tex.clone()
        tex1._num_faces_per_mesh = num_faces_per_mesh.tolist()
        atlas_packed = tex1.atlas_packed()
        atlas_list_new = tex1.atlas_list()
        atlas_padded = tex1.atlas_padded()

        for f1, f2 in zip(atlas_list_new, atlas_list):
            self.assertTrue((f1 == f2).all().item())

        sum_F = num_faces_per_mesh.sum()
        max_F = num_faces_per_mesh.max().item()
        self.assertTrue(atlas_packed.shape == (sum_F, R, R, 3))
        self.assertTrue(atlas_padded.shape == (N, max_F, R, R, 3))

        # Case where num_faces_per_mesh is not set and textures
        # are initialized with a padded tensor.
        atlas_list_padded = _list_to_padded_wrapper(atlas_list)
        tex2 = TexturesAtlas(atlas=atlas_list_padded)
        atlas_packed = tex2.atlas_packed()
        atlas_list_new = tex2.atlas_list()

        # Packed is just flattened padded as num_faces_per_mesh
        # has not been provided.
        self.assertTrue(atlas_packed.shape == (N * max_F, R, R, 3))

        for i, (f1, f2) in enumerate(zip(atlas_list_new, atlas_list)):
            n = num_faces_per_mesh[i]
            self.assertTrue((f1[:n] == f2).all().item())
Ejemplo n.º 3
0
 def test_clone(self):
     tex = TexturesAtlas(atlas=torch.rand(size=(1, 10, 2, 2, 3)))
     tex_cloned = tex.clone()
     self.assertSeparate(tex._atlas_padded, tex_cloned._atlas_padded)
     self.assertSeparate(tex.valid, tex_cloned.valid)