Skip to content

copyleft.mesh_boolean

mesh_boolean(V1, F1, V2, F2, boolean_type='union')

Finds intersection, union or subtraction of two triangle meshes.

Given two triangle meshes dA and dB, uses exact predicates to compute the intersection, union or subtraction of the two solids A and B, and output its surface dC

Parameters:

Name Type Description Default
V1 numpy double array

Matrix of vertex coordinates of the first mesh

required
F1 numpy int array

Matrix of triangle indices of the first mesh

required
V2 numpy double array

Matrix of vertex coordinates of the second mesh

required
F2 numpy int array

Matrix of triangle indices of the second mesh

required
boolean_type str, optional (default 'union')

Operation: one of 'union' (default), 'intersection', 'difference'

'union'

Returns:

Name Type Description
V3 numpy double array

Matrix of vertex coordinates of the first mesh

F3 numpy int array

Matrix of triangle indices of the first mesh

See Also

do_meshes_intersect.

Notes

'minus', 'difference' and 'subtraction' are alias or one another

Examples:

```python

Meshes in v,f and u,g

vv,ff = gpytoolbox.do_meshes_intersect(v,f,u,g,boolean_type='union')

vv,ff is the union of both meshes

```

Source code in src/gpytoolbox/copyleft/mesh_boolean.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def mesh_boolean(V1,F1,V2,F2,boolean_type='union'):
    """Finds intersection, union or subtraction of two triangle meshes.

    Given two triangle meshes dA and dB, uses exact predicates to compute the intersection, union or subtraction of the two solids A and B, and output its surface dC

    Parameters
    ----------
    V1 : numpy double array
        Matrix of vertex coordinates of the first mesh
    F1 : numpy int array
        Matrix of triangle indices of the first mesh
    V2 : numpy double array
        Matrix of vertex coordinates of the second mesh
    F2 : numpy int array
        Matrix of triangle indices of the second mesh
    boolean_type : str, optional (default 'union')
        Operation: one of 'union' (default), 'intersection', 'difference'

    Returns
    -------
    V3 : numpy double array
        Matrix of vertex coordinates of the first mesh
    F3 : numpy int array
        Matrix of triangle indices of the first mesh


    See Also
    --------
    do_meshes_intersect.

    Notes
    -----
    'minus', 'difference' and 'subtraction' are alias or one another

    Examples
    --------
     ```python
    # Meshes in v,f and u,g
    vv,ff = gpytoolbox.do_meshes_intersect(v,f,u,g,boolean_type='union')
    # vv,ff is the union of both meshes
    ```
    """

    try:
        from gpytoolbox_bindings_copyleft import _mesh_union_cpp_impl
        from gpytoolbox_bindings_copyleft import _mesh_intersection_cpp_impl
        from gpytoolbox_bindings_copyleft import _mesh_difference_cpp_impl
    except:
        raise ImportError("Gpytoolbox cannot import its C++ binding.")

    dictionary ={
    'union' : 0,
    'intersection' : 1,
    'difference' : 2,
    'minus' : 2
    }
    btype = dictionary.get(boolean_type,-1)
    if btype==0:
        v, f = _mesh_union_cpp_impl(V1.astype(np.float64),F1.astype(np.int32),V2.astype(np.float64),F2.astype(np.int32))
    elif btype==1:
        v, f = _mesh_intersection_cpp_impl(V1.astype(np.float64),F1.astype(np.int32),V2.astype(np.float64),F2.astype(np.int32))
    elif btype==2:
        v, f = _mesh_difference_cpp_impl(V1.astype(np.float64),F1.astype(np.int32),V2.astype(np.float64),F2.astype(np.int32))


    return v,f