# Wildmeshing tutorial¶

This is a jupyter notebook. The “real” notebook can be found here.

To use it just import it!

```import wildmeshing as wm
```

We also import meshplot to visualize

```import meshplot as mp
```

## Triangulation¶

The 2D meshing supports high order

```V, F, nodes, F_nodes = wm.triangulate_svg("rocket.svg")
```
```1/3 n sub paths: 18
2/3 n sub paths: 5
3/3 n sub paths: 12
```

Plot the resulting mesh

```mp.plot(V, F, shading={"wireframe": True})
```

The resulting mesh with the high-order nodes:

```p = mp.plot(V, F, return_plot=True, shading={"wireframe": True})
p
```

The previous mesh also outside triangles, to avoid this we enable the option `cut_outside`

```V, F, nodes, F_nodes = wm.triangulate_svg("rocket.svg", cut_outside=True)
```
```1/3 n sub paths: 18
2/3 n sub paths: 5
3/3 n sub paths: 12
```
```p = mp.plot(V, F, return_plot=True, shading={"wireframe": True})
p
```

I we want to carve out the window we need to speficy a point inside

```V, F, nodes, F_nodes = wm.triangulate_svg("rocket.svg", cut_outside=True, hole_pts=[[255, 165]])
```
```1/3 n sub paths: 18
2/3 n sub paths: 5
3/3 n sub paths: 12
```
```import numpy as np

p = mp.plot(V, F, return_plot=True, shading={"wireframe": True})
p
```

## Tetrahedralization¶

```?wm.Tetrahedralizer
```
```tetra = wm.Tetrahedralizer(stop_quality=500)
tetra.tetrahedralize()
```
```?tetra.get_tet_mesh
```
```V, T = tetra.get_tet_mesh()

mp.plot(V, T)
```

### Boolean operations¶

Tetwild support boolean operation between meshes!

```import igl
import json
```

We need json for passing the CSG tree and igl to load the data

```v0, f0 = igl.read_triangle_mesh('csg_input/ball.stl')
```

We load a couple of meshes to to get classical CGR tree example We create a `Tetrahedralizer`, load all meshes, and tetrahedralize.

Note 1 we set the `stop_quality` to 100 since we dont care to have high-quality meshes

Note 2 the order of the 5 meshes matters, first mesh will have id 0 and so on

```tetra = wm.Tetrahedralizer(stop_quality=100)
tetra.set_meshes([v0, v1, v2, v3, v4], [f0, f1, f2, f3, f4])
tetra.tetrahedralize()
```

The mesh has been generated!

We can do the union between the last two meshes (id 3, and 4). It is fast, since it dosent require to regenerate the tet mesh

```V, T = tetra.get_tet_mesh_from_csg(json.dumps({"operation":"union", "left": 3, "right": 4}))
mp.plot(V, T)
```