MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / main

Function main

scripts/remove_nan.py:16–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14 return parser.parse_args();
15
16def main():
17 args = parse_args();
18 mesh = pymesh.load_mesh(args.input_mesh);
19 assert(mesh.has_attribute("corner_texture"));
20
21 mesh.enable_connectivity();
22 vertices = np.copy(mesh.vertices);
23
24 bad_vertex = np.logical_not(np.all(np.isfinite(mesh.vertices), axis=1));
25 bad_vertex_indices = np.arange(mesh.num_vertices, dtype=int)[bad_vertex];
26 for i in bad_vertex_indices:
27 adj_v = mesh.get_vertex_adjacent_vertices(i);
28 adj_v = adj_v[np.logical_not(bad_vertex[adj_v])];
29 vertices[i] = np.mean(vertices[adj_v,:], axis=0);
30
31 out_mesh = pymesh.form_mesh(vertices, mesh.faces);
32
33 if mesh.has_attribute("corner_texture"):
34 faces = mesh.faces;
35 uv = np.copy(mesh.get_attribute("corner_texture").reshape((-1, 2)));
36 bad_uv = np.logical_not(np.all(np.isfinite(uv), axis=1));
37 bad_uv_indices = np.arange(len(uv), dtype=int)[bad_uv];
38 for i in bad_uv_indices:
39 fi = i // mesh.vertex_per_face;
40 ci = i % mesh.vertex_per_face;
41 vi = faces[fi, ci];
42 adj_f = mesh.get_vertex_adjacent_faces(vi);
43 adj_c = [adj_f[j]*mesh.vertex_per_face +
44 np.argwhere(f==vi).ravel()[0]
45 for j,f in enumerate(faces[adj_f, :])];
46 adj_c = np.array(adj_c, dtype=int);
47 adj_c = adj_c[np.logical_not(bad_uv[adj_c])];
48 if len(adj_c) > 0:
49 uv[i] = np.mean(uv[adj_c,:], axis=0);
50 else:
51 # All corner uv at this vertex is NaN. Average the one-ring instead.
52 adj_c = [adj_f[j]*mesh.vertex_per_face +
53 (np.argwhere(f==vi).ravel()[0]+1)%mesh.vertex_per_face
54 for j,f in enumerate(faces[adj_f, :])];
55 adj_c += [adj_f[j]*mesh.vertex_per_face +
56 (np.argwhere(f==vi).ravel()[0]+2)%mesh.vertex_per_face
57 for j,f in enumerate(faces[adj_f, :])];
58 adj_c = np.array(adj_c, dtype=int);
59 adj_c = adj_c[np.logical_not(bad_uv[adj_c])];
60 uv[i] = np.mean(uv[adj_c,:], axis=0);
61
62 out_mesh.add_attribute("corner_texture");
63 out_mesh.set_attribute("corner_texture", uv);
64
65 pymesh.save_mesh(args.output_mesh, out_mesh);
66
67if __name__ == "__main__":
68 main();

Callers 1

remove_nan.pyFile · 0.70

Calls 13

enumerateFunction · 0.85
parse_argsFunction · 0.70
load_meshMethod · 0.45
has_attributeMethod · 0.45
enable_connectivityMethod · 0.45
copyMethod · 0.45
form_meshMethod · 0.45
get_attributeMethod · 0.45
add_attributeMethod · 0.45
set_attributeMethod · 0.45

Tested by

no test coverage detected