(tris, vertices_to, vertices_from, smooth, maps, warn)
| 1225 | |
| 1226 | |
| 1227 | def _hemi_morph(tris, vertices_to, vertices_from, smooth, maps, warn): |
| 1228 | _validate_type(smooth, (str, None, "int-like"), "smoothing steps") |
| 1229 | if len(vertices_from) == 0: |
| 1230 | return sparse.csr_array((len(vertices_to), 0)) |
| 1231 | e = mesh_edges(tris) |
| 1232 | e.data[e.data == 2] = 1 |
| 1233 | n_vertices = e.shape[0] |
| 1234 | e += _eye_array(n_vertices, format="csr") |
| 1235 | if isinstance(smooth, str): |
| 1236 | _check_option("smooth", smooth, ("nearest",), extra=" when used as a string.") |
| 1237 | mm = _surf_nearest(vertices_from, e).tocsr() |
| 1238 | elif smooth == 0: |
| 1239 | mm = sparse.csc_array( |
| 1240 | ( |
| 1241 | np.ones(len(vertices_from)), # data, indices, indptr |
| 1242 | vertices_from, |
| 1243 | np.arange(len(vertices_from) + 1), |
| 1244 | ), |
| 1245 | shape=(e.shape[0], len(vertices_from)), |
| 1246 | ).tocsr() |
| 1247 | else: |
| 1248 | mm, n_missing, n_iter = _surf_upsampling_mat(vertices_from, e, smooth) |
| 1249 | if n_missing and warn: |
| 1250 | warn_( |
| 1251 | f"{n_missing}/{e.shape[0]} vertices not included in " |
| 1252 | "smoothing, consider increasing the number of steps" |
| 1253 | ) |
| 1254 | logger.info(f" {n_iter} smooth iterations done.") |
| 1255 | assert mm.shape == (n_vertices, len(vertices_from)) |
| 1256 | if maps is not None: |
| 1257 | mm = maps[vertices_to] @ mm |
| 1258 | else: # to == from |
| 1259 | mm = mm[vertices_to] |
| 1260 | assert mm.shape == (len(vertices_to), len(vertices_from)) |
| 1261 | return mm |
| 1262 | |
| 1263 | |
| 1264 | @verbose |
no test coverage detected