Skip to content

Mesh Subdivision

Due to the connectivity data attached to the meshes data structures, subdividing meshes by hand is unsafe and can lead to faulty results. To correctly apply subdivisions, one needs to first convert back the mesh to a RawMeshData, apply the combinatorial functions, and rebuild a correct mesh. This is handled by the SurfaceSubdivision and the VolumeSubdivision classes, which are designed to be used in a with block:

import mouette as M

surface = M.mesh.load("/path/to/my/mesh.obj")

# At the start of the with block, the mesh is transformed into a RawMeshData and its connectivity is disabled
with M.mesh.SurfaceSubdivision(surface) as editor:
    # Call here the subdivision functions
    editor.subdivide_triangles_3quads()
    editor.triangulate()
# When exiting the 'with' block, the mesh is transformed back into a SurfaceMesh
# and its connectivity is regenerated
M.mesh.save(surface, "path/to/my/new/mesh.obj")

SurfaceSubdivision(mesh, verbose=False)

Bases: Logger

loop_subdivision(n=1)

Subdivides triangles of a mesh in 4 triangles by splitting along middle of edges. If the mesh is not triangulated, will triangulate the mesh first.

References

https://en.wikipedia.org/wiki/Loop_subdivision_surface

Parameters:

Name Type Description Default
n int

Number of times the subdivision is applied. Defaults to 1.

1

split_face_as_fan(face_id)

Adds a vertex at the barycenter of face 'face_id' and create a fan of triangles that replaces the face

Parameters:

Name Type Description Default
face_id int

the face to split

required

subdivide_triangles_3quads()

Subdivides triangles of a mesh in 3 quads by adding a point at the barycenter and three middles of edges. If the mesh is not triangulated, will triangulate the mesh first.

subdivide_triangles_6(repeat=1)

Subdivides triangles of a mesh in 6 triangles by adding a point at the barycenter and three middles of edges. If the mesh is not triangulated, will triangulate the mesh first.

Same operation as subdividing into 3 quads and then splitting the quads along the corner-barycenter diagonal.

Parameters:

Name Type Description Default
repeat int

number of successive subdivisions. Eventual first triangulation does not count. Defaults to 1.

1

triangulate()

Triangulates all faces of a mesh. Calls triangulate_face on every faces.

triangulate_face(face_id)

Triangulates the face "face_id"

Parameters:

Name Type Description Default
face_id int

the face to triangulate

required

VolumeSubdivision(mesh, verbose=False)

Bases: Logger

split_cell_as_fan(cell_id)

Adds a vertex at the barycenter of cell 'cell_id' and create a fan of tetrahedra that replaces the cell. If the cell 'cell_id' is not a tetrahedron, does nothing.

Parameters:

Name Type Description Default
mesh VolumeMesh

the input mesh

required
cell_id int

the (tetrahedral) cell to split

required

Returns:

Type Description
VolumeMesh

the modified input mesh

split_tet_from_face_center(face_id)

Split the triangle face_id into three triangles by adding a point at its barycenter, and split adjacent tetrahedra accordingly.

Parameters:

Name Type Description Default
face_id int

index of the face to split

required

split_edge(polyline, edge_ind)

Split an edge of a polyline in half by adding a new vertex

Note

Polylines do not need a specific subdivision class to be used in a with block since their connectivity is simpler. Connectivity is cleared after processing.

Parameters:

Name Type Description Default
mesh PolyLine

the input polyline

required
edge_ind int

index of the edge to split

required

Returns:

Name Type Description
PolyLine PolyLine

the processed Polyline

split_double_boundary_edges_triangles(mesh)

A triangle with double edge on the boundary can occur on the border in a case like :

    /\ 
___/__\___

This function detects every occurrences of such a configuration and split the problematic triangle in three by adding a new vertex in the middle. Uses the SurfaceSubdivision class.

Parameters:

Name Type Description Default
mesh Mesh

the mesh (modified in place)

required

Raises:

Type Description
Exception

Isolated vertex

Returns:

Name Type Description
SurfaceMesh SurfaceMesh

the modified input mesh