docstr: Tests that perspective_correct_interpolation generates expected results.
docstr_tok: ["Tests","that","perspective_correct_interpolation","generates","expected","results","."]
code: def test_perspective_correct_interpolation_preset(self):
      """Tests that perspective_correct_interpolation generates expected results."""
      camera_origin = np.array((0.0, 0.0, 0.0))
      camera_up = np.array((0.0, 1.0, 0.0))
      look_at_point = np.array((0.0, 0.0, 1.0))
      fov = np.array((90.0 * np.math.pi / 180.0,))
      bottom_left = np.array((0.0, 0.0))
      image_size = np.array((501.0, 501.0))
      near_plane = np.array((0.01,))
      far_plane = np.array((10.0,))
      batch_size = np.random.randint(1, 5)
      triangle_x_y = np.random.uniform(-10.0, 10.0, (batch_size, 3, 2))
      triangle_z = np.random.uniform(2.0, 10.0, (batch_size, 3, 1))
      triangles = np.concatenate((triangle_x_y, triangle_z), axis=-1)
      # Builds barycentric weights.
      barycentric_weights = np.random.uniform(size=(batch_size, 3))
      barycentric_weights = barycentric_weights / np.sum(
          barycentric_weights, axis=-1, keepdims=True
      )
      # Barycentric interpolation of vertex positions.
      convex_combination = np.einsum(
          "ba, bac -> bc", barycentric_weights, triangles
      )
      # Build matrices.
      model_to_eye_matrix = look_at.right_handed(
          camera_origin, look_at_point, camera_up
      )
      perspective_matrix = perspective.right_handed(
          fov,
          (image_size[0:1] / image_size[1:2]),
          near_plane,
          far_plane,
      )
  
      # Computes where those points project in screen coordinates.
      pixel_position, _ = glm.model_to_screen(
          convex_combination,
          model_to_eye_matrix,
          perspective_matrix,
          image_size,
          bottom_left,
      )
  
      # Builds attributes.
      num_pixels = pixel_position.shape[0]
      attribute_size = np.random.randint(10)
      attributes = np.random.uniform(
          size=(num_pixels, 3, attribute_size)
      )
  
      prediction = glm.perspective_correct_interpolation(
          triangles,
          attributes,
          pixel_position[..., 0:2],
          model_to_eye_matrix,
          perspective_matrix,
          image_size,
          bottom_left,
      )
  
      groundtruth = np.einsum(
          "ba, bac -> bc", barycentric_weights, attributes
      )
      self.assertAllClose(prediction, groundtruth)
  
imports: import math
  from absl.testing import flagsaver
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_graphics.geometry.transformation import look_at
  from tensorflow_graphics.rendering.camera import perspective
  from tensorflow_graphics.rendering.opengl import math
  from tensorflow_graphics.util import test_case
label_desc: Use image node_id 29 for calling the MathTest obj's underlying member method code with example usage: obj.test_perspective_correct_interpolation_preset() without return types