code: def rasterize_triangles(vertices, triangles, h, w):
      """
      Args:
          vertices: [nver, 3]
          triangles: [ntri, 3]
          h: height
          w: width
      Returns:
          depth_buffer: [h, w] saves the depth, here, the bigger the z, the fronter the point.
          triangle_buffer: [h, w] saves the tri id(-1 for no triangle).
          barycentric_weight: [h, w, 3] saves corresponding barycentric weight.
  
      # Each triangle has 3 vertices & Each vertex has 3 coordinates x, y, z.
      # h, w is the size of rendering
      """
      # initial
      depth_buffer = (
          np.zeros([h, w]) - 999999.0
      )  # + np.min(vertices[2,:]) - 999999. # set the initial z to the farest position
      triangle_buffer = (
          np.zeros([h, w], dtype=np.int32) - 1
      )  # if tri id = -1, the pixel has no triangle correspondance
      barycentric_weight = np.zeros([h, w, 3], dtype=np.float32)  #
  
      for i in range(triangles.shape[0]):
          tri = triangles[i, :]  # 3 vertex indices
  
          # the inner bounding box
          umin = max(int(np.ceil(np.min(vertices[tri, 0]))), 0)
          umax = min(int(np.floor(np.max(vertices[tri, 0]))), w - 1)
  
          vmin = max(int(np.ceil(np.min(vertices[tri, 1]))), 0)
          vmax = min(int(np.floor(np.max(vertices[tri, 1]))), h - 1)
  
          if umax < umin or vmax < vmin:
              continue
  
          for u in range(umin, umax + 1):
              for v in range(vmin, vmax + 1):
                  if not isPointInTri([u, v], vertices[tri, :2]):
                      continue
                  w0, w1, w2 = get_point_weight(
                      [u, v], vertices[tri, :2]
                  )  # barycentric weight
                  point_depth = (
                      w0 * vertices[tri[0], 2]
                      + w1 * vertices[tri[1], 2]
                      + w2 * vertices[tri[2], 2]
                  )
                  if point_depth > depth_buffer[v, u]:
                      depth_buffer[v, u] = point_depth
                      triangle_buffer[v, u] = i
                      barycentric_weight[v, u, :] = np.array(
                          [w0, w1, w2]
                      )
  
      return depth_buffer, triangle_buffer, barycentric_weight
  
file_path: insightface/python-package/insightface/thirdparty/face3d/mesh_numpy/render.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from time import time
label_desc: Use image node_id 3 for calling a global function with example usage: rasterize_triangles(vertices, triangles, h, w) and returns: depth_buffer,  triangle_buffer,  barycentric_weight