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

Function map_face_attribute

python/pymesh/map_attributes.py:52–80  ·  view source on GitHub ↗

Map face attribute from mesh1 to mesh2 based on closest points. Args: mesh1 (:class:`Mesh`): Source mesh, where the attribute is defined. mesh2 (:class:`Mesh`): Target mesh, where the attribute is mapped to. attr_name (``string``): Attribute name. bvh (:class:`B

(mesh1, mesh2, attr_name, bvh=None)

Source from the content-addressed store, hash-verified

50
51
52def map_face_attribute(mesh1, mesh2, attr_name, bvh=None):
53 """ Map face attribute from mesh1 to mesh2 based on closest points.
54
55 Args:
56 mesh1 (:class:`Mesh`): Source mesh, where the attribute is defined.
57 mesh2 (:class:`Mesh`): Target mesh, where the attribute is mapped to.
58 attr_name (``string``): Attribute name.
59 bvh (:class:`BVH`): Pre-computed Bounded volume hierarchy if available.
60
61 A new attribute with name ``attr_name`` is added to ``mesh2``.
62 """
63
64 assert(mesh1.dim == mesh2.dim)
65 assert(mesh1.has_attribute(attr_name))
66 values = mesh1.get_face_attribute(attr_name)
67
68 if not mesh2.has_attribute("face_centroid"):
69 mesh2.add_attribute("face_centroid")
70 query_pts = mesh2.get_face_attribute("face_centroid")
71
72 if bvh is None:
73 bvh = BVH(dim=mesh1.dim)
74 bvh.load_mesh(mesh1)
75 dists, closest_faces, p = bvh.lookup(query_pts)
76 target_val = values[closest_faces, :]
77
78 if not mesh2.has_attribute(attr_name):
79 mesh2.add_attribute(attr_name)
80 mesh2.set_attribute(attr_name, target_val)
81
82def map_corner_attribute(mesh1, mesh2, attr_name, bvh=None):
83 """ Map per-vertex per-face attribute from mesh1 to mesh2 based on closest points.

Callers

nothing calls this directly

Calls 7

load_meshMethod · 0.95
lookupMethod · 0.95
BVHClass · 0.85
get_face_attributeMethod · 0.80
has_attributeMethod · 0.45
add_attributeMethod · 0.45
set_attributeMethod · 0.45

Tested by

no test coverage detected