Compute the signed distance from a set of points to a mesh. Args: mesh (:class:`Mesh`): A input mesh. pts (:class:`numpy.ndarray`): A :math:`N \\times dim` array of query points. engine (``string``): BVH engine name. Valid choices are "cgal", "ge
(mesh, pts, engine="igl", bvh=None)
| 92 | return squared_distances, face_indices, closest_points |
| 93 | |
| 94 | def signed_distance_to_mesh(mesh, pts, engine="igl", bvh=None): |
| 95 | """ Compute the signed distance from a set of points to a mesh. |
| 96 | |
| 97 | Args: |
| 98 | mesh (:class:`Mesh`): A input mesh. |
| 99 | pts (:class:`numpy.ndarray`): A :math:`N \\times dim` array of query |
| 100 | points. |
| 101 | engine (``string``): BVH engine name. Valid choices are "cgal", |
| 102 | "geogram", "igl" if all dependencies are used. The default is |
| 103 | "auto" where an available engine is automatically picked. |
| 104 | bvh (:class:`BVH`): BVH engine instance (optional) |
| 105 | |
| 106 | Returns: |
| 107 | Three values are returned. |
| 108 | |
| 109 | * ``signed_distances``: signed (unsquared) distances from each |
| 110 | point to mesh. |
| 111 | * ``face_indices`` : the closest face to each point. |
| 112 | * ``closest_points``: the point on mesh that is closest to each |
| 113 | query point. |
| 114 | """ |
| 115 | |
| 116 | if not bvh: |
| 117 | bvh = BVH(engine, mesh.dim) |
| 118 | bvh.load_mesh(mesh) |
| 119 | |
| 120 | # get face normals |
| 121 | try: |
| 122 | face_normals = np.reshape(mesh.get_attribute("face_normals"), |
| 123 | np.int32(mesh.get_attribute("face_normals_shape"))) |
| 124 | except RuntimeError: |
| 125 | face_normals = PyMesh.face_normals(mesh.vertices, mesh.faces) |
| 126 | mesh.add_attribute("face_normals") |
| 127 | mesh.add_attribute("face_normals_shape") |
| 128 | mesh.set_attribute("face_normals", face_normals) |
| 129 | mesh.set_attribute("face_normals_shape", np.array(face_normals.shape)) |
| 130 | |
| 131 | # get vertex normals |
| 132 | try: |
| 133 | vertex_normals = np.reshape(mesh.get_attribute("vertex_normals"), |
| 134 | np.int32(mesh.get_attribute("vertex_normals_shape"))) |
| 135 | except RuntimeError: |
| 136 | vertex_normals = PyMesh.vertex_normals(mesh.vertices, mesh.faces, face_normals) |
| 137 | mesh.add_attribute("vertex_normals") |
| 138 | mesh.add_attribute("vertex_normals_shape") |
| 139 | mesh.set_attribute("vertex_normals", vertex_normals) |
| 140 | mesh.set_attribute("vertex_normals_shape", np.array(vertex_normals.shape)) |
| 141 | |
| 142 | # get edge normals |
| 143 | try: |
| 144 | edge_normals = np.reshape(mesh.get_attribute("edge_normals"), |
| 145 | np.int32(mesh.get_attribute("edge_normals_shape"))) |
| 146 | edge_map = np.reshape(np.int32(mesh.get_attribute("edge_map")), |
| 147 | np.int32(mesh.get_attribute("edge_map_shape"))) |
| 148 | except RuntimeError: |
| 149 | edge_normals, _, edge_map = PyMesh.edge_normals(mesh.vertices, mesh.faces, face_normals) |
| 150 | mesh.add_attribute("edge_normals") |
| 151 | mesh.add_attribute("edge_map") |
nothing calls this directly
no test coverage detected