Ejemplo n.º 1
0
    def test_face_normals_random(self):
        """Tests the computation of mesh face normals in each axis."""
        tensor_vertex_size = np.random.randint(1, 3)
        tensor_out_shape = np.random.randint(1, 5, size=tensor_vertex_size)
        tensor_out_shape = tensor_out_shape.tolist()
        tensor_vertex_shape = list(tensor_out_shape)
        tensor_vertex_shape[-1] *= 3
        tensor_index_shape = tensor_out_shape[-1]

        for i in range(3):
            vertices = np.random.random(size=tensor_vertex_shape + [3])
            indices = np.arange(tensor_vertex_shape[-1])
            np.random.shuffle(indices)
            indices = np.reshape(indices,
                                 newshape=[1] * (tensor_vertex_size - 1) \
                                 + [tensor_index_shape, 3])
            indices = np.tile(indices, tensor_vertex_shape[:-1] + [1, 1])
            vertices[..., i] = 0.
            expected = np.zeros(shape=tensor_out_shape + [3],
                                dtype=vertices.dtype)
            expected[..., i] = 1.
            faces = normals.gather_faces(vertices, indices)

            self.assertAllClose(tf.abs(normals.face_normals(faces)),
                                expected,
                                rtol=1e-3)
Ejemplo n.º 2
0
    def test_face_normals_jacobian_random(self):
        """Test the Jacobian of the face normals function."""
        tensor_vertex_size = np.random.randint(1, 3)
        tensor_out_shape = np.random.randint(1, 5, size=tensor_vertex_size)
        tensor_out_shape = tensor_out_shape.tolist()
        tensor_vertex_shape = list(tensor_out_shape)
        tensor_vertex_shape[-1] *= 3
        tensor_index_shape = tensor_out_shape[-1]
        vertex_init = np.random.random(size=tensor_vertex_shape + [3])
        index_init = np.arange(tensor_vertex_shape[-1])
        np.random.shuffle(index_init)
        index_init = np.reshape(index_init, newshape=[1] * (tensor_vertex_size - 1) \
                                + [tensor_index_shape, 3])
        index_init = np.tile(index_init, tensor_vertex_shape[:-1] + [1, 1])
        vertex_tensor = tf.convert_to_tensor(value=vertex_init)
        index_tensor = tf.convert_to_tensor(value=index_init)

        face_tensor = normals.gather_faces(vertex_tensor, index_tensor)
        y = normals.face_normals(face_tensor)

        self.assert_jacobian_is_correct(vertex_tensor,
                                        vertex_init,
                                        y,
                                        atol=1e-4,
                                        delta=1e-9)
Ejemplo n.º 3
0
 def face_normals(vertex_tensor):
   face_tensor = normals.gather_faces(vertex_tensor, index_tensor)
   return normals.face_normals(face_tensor)