Skip to content

subdivide

subdivide(V, F, method='upsample', iters=1, return_matrix=False)

Subdivides a triangle mesh, turning every element into more than one element with the specified method.

Parameters:

Name Type Description Default
V (n,d) numpy array

vertex list of vertex positions

required
F numpy int array

if (m,2), interpret input as ordered polyline; if (m,3) numpy int array, interpred as face index list of a triangle mesh

required
method string, optional (default

Which method to use for subdivison. Can be 'upsample' {default}, 'loop' (only triangle meshes)

'upsample'
iters int, optional (default

How many iterations of subdivision to perform.

1
return_matrix bool, optional (default

Whether to return the matrix for the sparse map S.

False

Returns:

Name Type Description
Vu (n_u,d) numpy array

vertex list of subdivided polyline / mesh

Fu (m_u,2) or (m_u) numpy int array

face index list of upsampled polyline or triangle mesh

S (n_u,n) sparse scipy csr_matrix (if requested)

sparse matrix such that Vu == S*V; returned only if return_matrix == True.

Examples:

# Get a fine mesh of a square by subdividing a coarse mesh of a square.
v, f = gpytoolbox.regular_square_mesh(2)
v, f = gpytoolbox.subdivide(v, f, iters=2)
Source code in src/gpytoolbox/subdivide.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def subdivide(V,F,
    method='upsample',
    iters=1,
    return_matrix=False):
    """Subdivides a triangle mesh, turning every element into more than one element with the specified method.

    Parameters
    ----------
    V : (n,d) numpy array
        vertex list of vertex positions
    F : numpy int array
        if (m,2), interpret input as ordered polyline;
        if (m,3) numpy int array, interpred as face index list of a triangle
        mesh
    method : string, optional (default: 'upsample')
        Which method to use for subdivison.
        Can be 'upsample' {default}, 'loop' (only triangle meshes)
    iters : int, optional (default: 1)
        How many iterations of subdivision to perform.
    return_matrix : bool, optional (default: False)
        Whether to return the matrix for the sparse map S.

    Returns
    -------
    Vu : (n_u,d) numpy array
        vertex list of subdivided polyline / mesh
    Fu : (m_u,2) or (m_u) numpy int array
        face index list of upsampled polyline or triangle mesh
    S : (n_u,n) sparse scipy csr_matrix (if requested)
        sparse matrix such that `Vu == S*V`;
        returned only if `return_matrix == True`.

    Examples
    --------
    ```python
    # Get a fine mesh of a square by subdividing a coarse mesh of a square.
    v, f = gpytoolbox.regular_square_mesh(2)
    v, f = gpytoolbox.subdivide(v, f, iters=2)
    ```

    """

    assert iters >= 0

    Vu,Fu = V,F
    if return_matrix:
        S = sp.sparse.eye(_n(V,F), format='csr')

    for i in range(iters):
        Vu,Fu,St = _one_subdivision(Vu,Fu,method,return_matrix)
        if return_matrix:
            S = St*S

    # If there were no iterations at all, we want to return a copy of the
    # original.
    if iters==0:
        Vu = None if V is None else V.copy()
        Fu = F.copy()

    if return_matrix:
        return Vu, Fu, S
    else:
        return Vu, Fu