in tacto/renderer.py [0:0]
def _generate_trimesh_from_depth(self, depth):
# Load config
g = self.conf.sensor.gel
origin = g.origin
_, Y0, Z0 = origin[0], origin[1], origin[2]
W, H = g.width, g.height
N = depth.shape[1]
M = depth.shape[0]
# Create grid mesh
vertices = []
faces = []
y = np.linspace(Y0 - W / 2, Y0 + W / 2, N)
z = np.linspace(Z0 - H / 2, Z0 + H / 2, M)
yy, zz = np.meshgrid(y, z)
# Vertex format: [x, y, z]
vertices = np.zeros([N * M, 3])
# Add x, y, z position to vertex
vertices[:, 0] = depth.reshape([-1])
vertices[:, 1] = yy.reshape([-1])
vertices[:, 2] = zz.reshape([-1])
# Create faces
faces = np.zeros([(N - 1) * (M - 1) * 6], dtype=np.uint)
# calculate id for each vertex: (i, j) => i * m + j
xid = np.arange(N)
yid = np.arange(M)
yyid, xxid = np.meshgrid(xid, yid)
ids = yyid[:-1, :-1].reshape([-1]) + xxid[:-1, :-1].reshape([-1]) * N
# create upper triangle
faces[::6] = ids # (i, j)
faces[1::6] = ids + N # (i+1, j)
faces[2::6] = ids + 1 # (i, j+1)
# create lower triangle
faces[3::6] = ids + 1 # (i, j+1)
faces[4::6] = ids + N # (i+1, j)
faces[5::6] = ids + N + 1 # (i+1, j+1)
faces = faces.reshape([-1, 3])
gel_trimesh = trimesh.Trimesh(vertices=vertices, faces=faces, process=False)
return gel_trimesh