"""The 620 output points as locations on the GNM Head mesh (points_gnm.json).""" import json import os import numpy as np DEFAULT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "points_gnm.json") def load_points(path=DEFAULT): """Return the point rows in output order: dicts with index, class, region, vertices, weights.""" with open(path, encoding="utf-8") as fh: return json.load(fh)["points"] def gnm_positions(vertices_xyz, points=None): """Return (620, 3) positions of the points on a posed GNM Head mesh from its (V, 3) vertices.""" points = load_points() if points is None else points V = np.asarray(vertices_xyz, np.float64) out = np.zeros((len(points), 3), np.float64) for p in points: out[p["index"]] = np.asarray(p["weights"], np.float64) @ V[p["vertices"]] return out