Decimate surface data. Parameters ---------- points : ndarray The surface to be decimated, a 3 x number of points array. triangles : ndarray The surface to be decimated, a 3 x number of triangles array. n_triangles : int The desired number of triangles.
(points, triangles, n_triangles, method="quadric", *, verbose=None)
| 1543 | |
| 1544 | @verbose |
| 1545 | def decimate_surface(points, triangles, n_triangles, method="quadric", *, verbose=None): |
| 1546 | """Decimate surface data. |
| 1547 | |
| 1548 | Parameters |
| 1549 | ---------- |
| 1550 | points : ndarray |
| 1551 | The surface to be decimated, a 3 x number of points array. |
| 1552 | triangles : ndarray |
| 1553 | The surface to be decimated, a 3 x number of triangles array. |
| 1554 | n_triangles : int |
| 1555 | The desired number of triangles. |
| 1556 | method : str |
| 1557 | Can be "quadric" or "sphere". "sphere" will inflate the surface to a |
| 1558 | sphere using Freesurfer and downsample to an icosahedral or |
| 1559 | octahedral mesh. |
| 1560 | |
| 1561 | .. versionadded:: 0.20 |
| 1562 | %(verbose)s |
| 1563 | |
| 1564 | Returns |
| 1565 | ------- |
| 1566 | points : ndarray |
| 1567 | The decimated points. |
| 1568 | triangles : ndarray |
| 1569 | The decimated triangles. |
| 1570 | |
| 1571 | Notes |
| 1572 | ----- |
| 1573 | **"quadric" mode** |
| 1574 | |
| 1575 | This requires VTK. If an odd target number was requested, |
| 1576 | the ``'decimation'`` algorithm used results in the |
| 1577 | next even number of triangles. For example a reduction request |
| 1578 | to 30001 triangles may result in 30000 triangles. |
| 1579 | |
| 1580 | **"sphere" mode** |
| 1581 | |
| 1582 | This requires Freesurfer to be installed and available in the |
| 1583 | environment. The destination number of triangles must be one of |
| 1584 | ``[20, 80, 320, 1280, 5120, 20480]`` for ico (0-5) downsampling or one of |
| 1585 | ``[8, 32, 128, 512, 2048, 8192, 32768]`` for oct (1-7) downsampling. |
| 1586 | |
| 1587 | This mode is slower, but could be more suitable for decimating meshes for |
| 1588 | BEM creation (recommended ``n_triangles=5120``) due to better topological |
| 1589 | property preservation. |
| 1590 | """ |
| 1591 | n_triangles = _ensure_int(n_triangles) |
| 1592 | method_map = dict(quadric=_decimate_surface_vtk, sphere=_decimate_surface_sphere) |
| 1593 | _check_option("method", method, sorted(method_map)) |
| 1594 | if n_triangles > len(triangles): |
| 1595 | raise ValueError( |
| 1596 | f"Requested n_triangles ({n_triangles}) exceeds number of " |
| 1597 | f"original triangles ({len(triangles)})" |
| 1598 | ) |
| 1599 | return method_map[method](points, triangles, n_triangles) |
| 1600 | |
| 1601 | |
| 1602 | ############################################################################### |