def _perspective_correct_attributes(attribute, barycentrics, triangles,
                                    triangle_index, len_batch_shape):
  attribute = tf.gather(attribute, triangles, axis=-2)
  attribute_per_pixel = tf.gather(
      attribute, triangle_index, axis=-3, batch_dims=len_batch_shape)

  return glm.interpolate_attributes(attribute_per_pixel, barycentrics)
Esempio n. 2
0
  def test_interpolate_attributes_random(self):
    """Checks the output of interpolate_attributes."""
    attributes = np.random.uniform(-1.0, 1.0, size=(3,))
    barycentric = np.random.uniform(0.0, 1.0, size=(3,))
    barycentric = barycentric / np.linalg.norm(
        barycentric, axis=-1, ord=1, keepdims=True)

    groundtruth = np.sum(attributes * barycentric, keepdims=True)
    attributes = np.reshape(attributes, (3, 1))
    prediction = glm.interpolate_attributes(attributes, barycentric)
    self.assertAllClose(groundtruth, prediction)