Skip to content

marching_cubes

marching_cubes(S, GV, nx, ny, nz, isovalue=0.0)

Compute the marching cubes of a scalar field.

Parameters:

Name Type Description Default
S (n,) numpy double array

Vector of scalar values

required
GV (n,3) numpy double array

Matrix of grid vertices

required
nx int

Number of grid vertices in x direction

required
ny int

Number of grid vertices in y direction

required
nz int

Number of grid vertices in z direction

required
isovalue double, optional (default: 0)

Isovalue to use for reconstruction

0.0

Returns:

Name Type Description
V (m,3) numpy double array

Matrix of mesh vertices

F (p,3) numpy int array

Matrix of triangle indices

See Also

lazy_cage, fast_winding_number, squared_distance

Examples:

# Some scalar function fun
def fun(V):
    return np.sum(V**2,axis=1)
# Generate a grid
GV,_ = gpytoolbox.regular_cube_mesh(100)
# Evaluate scalar function on grid
S = fun(GV)
# Compute isosurface
V,F = gpytoolbox.marching_cubes(S,GV,100,100,100,0.5)
Source code in src/gpytoolbox/marching_cubes.py
 3
 4
 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
def marching_cubes(S,GV,nx,ny,nz,isovalue=0.0):
    """Compute the marching cubes of a scalar field.

    Parameters
    ----------
    S : (n,) numpy double array
        Vector of scalar values
    GV : (n,3) numpy double array
        Matrix of grid vertices
    nx : int
        Number of grid vertices in x direction
    ny : int
        Number of grid vertices in y direction
    nz : int
        Number of grid vertices in z direction
    isovalue : double, optional (default: 0)
        Isovalue to use for reconstruction

    Returns
    -------
    V : (m,3) numpy double array
        Matrix of mesh vertices
    F : (p,3) numpy int array
        Matrix of triangle indices

    See Also
    --------
    lazy_cage, fast_winding_number, squared_distance

    Examples
    --------
    ```python
    # Some scalar function fun
    def fun(V):
        return np.sum(V**2,axis=1)
    # Generate a grid
    GV,_ = gpytoolbox.regular_cube_mesh(100)
    # Evaluate scalar function on grid
    S = fun(GV)
    # Compute isosurface
    V,F = gpytoolbox.marching_cubes(S,GV,100,100,100,0.5)
    ```
    """
    # Try to import C++ binding
    try:
        from gpytoolbox_bindings import _marching_cubes_cpp_impl
    except:
        raise ImportError("Gpytoolbox cannot import its C++ marching cubes binding.")

    V,F = _marching_cubes_cpp_impl(S.astype(np.float64),GV.astype(np.float64),nx,ny,nz,isovalue)

    return V,F