skshapes.triangle_mesh package¶
Functions related to triangle meshes.
Submodules¶
skshapes.triangle_mesh.edge_topology module¶
Specific functions for triangle meshes.
- class skshapes.triangle_mesh.edge_topology.EdgeTopology(triangles)¶
Bases:
object
Topology of the edges of a triangle mesh.
This class is initialized from the triangles connectivity of a triangle mesh. It computes : - the edges of the mesh - the degrees of the edges (number of adjacent triangles)
For manifold edges (degree 2), it also computes : - the adjacent triangles - the adjacent points
For boundary edges (degree 1), it also computes : - the adjacent triangle - the adjacent point
Manifold edges and boundary edges can be accessed separately using the attributes manifold_edges and boundary_edges.
The indices of manifold edges and boundary edges can be accessed using the attributes is_manifold and is_boundary.
- Parameters:
triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh
- property boundary_edges¶
Boundary edges of the mesh.
- property manifold_edges¶
Manifold edges of the mesh.
skshapes.triangle_mesh.geometry module¶
Geometric properties of a triangular mesh.
This module provides functions to compute geometric properties of a triangle mesh such as triangle areas, edge lengths, dihedral angles, etc.
In addition, it is possible to compute these properties for a set of triangle meshes at the same time, if they have the same topology. This is useful when we need to compute the same property along a sequence of deformation of a triangle mesh.
All the function in this module are implemented in PyTorch. They take the points and triangles of the mesh as input and return a tensor with the computed property.
Arguments points can be either a tensor of shape: - (n_points, dim) for a single mesh - (n_points, n_poses, dim) for a sequence of poses of the same mesh
- skshapes.triangle_mesh.geometry.cotan_weights(*, points, triangles, edge_topology=None)¶
Cotan weights of a triangular mesh
The cotan weights of an edge are a discrete version of the Laplace-Beltrami operator. They depend on the angles between the edge and the adjacent triangles. An illustration ca be found in figure 4 of https://arxiv.org/pdf/2204.04238
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.edge_topology (
EdgeTopology
|None
) – Edge topology of the mesh. If not provided, it will be computed from the triangles.
- Return type:
Float32[Tensor, '_']
|Float32[Tensor, '_ _']
- Returns:
The cotan weights of the edges with shape (n_edges,) for a single mesh or (n_edges, n_poses) for a sequence of meshes.
- skshapes.triangle_mesh.geometry.dihedral_angles(*, points, triangles, edge_topology=None)¶
Dihedral angles of the edges of a triangular mesh.
The dihedral angle of an edge is a discrete version of the second fundamental form, it is a function of the angle between the normals of adjacent triangles to an edge. More explanation can be found in the paper “Linear Surface Reconstruction from Discrete Fundamental Forms on Triangle Meshes” (https://www.cse.msu.edu/~ytong/DiscreteFundamentalForms.pdf)
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.edge_topology (
EdgeTopology
|None
) – Edge topology of the mesh. If not provided, it will be computed from the triangles.
- Return type:
Float32[Tensor, '_']
|Float32[Tensor, '_ _']
- Returns:
The dihedral angles of the edges with shape (n_edges,) for a single mesh or (n_edges, n_poses) for a sequence of meshes.
- skshapes.triangle_mesh.geometry.edge_centers(points, triangles, edge_topology=None)¶
Centers of the edges of a triangular mesh.
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.edge_topology (
EdgeTopology
|None
) – Edge topology of the mesh. If not provided, it will be computed from the triangles.
- Return type:
Float32[Tensor, '_ _']
|Float32[Tensor, '_ _ _']
- Returns:
_description_
- skshapes.triangle_mesh.geometry.edge_lengths(*, points, triangles, edge_topology=None)¶
Lengths of the edges of a triangular mesh.
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.edge_topology (
EdgeTopology
|None
) – Edge topology of the mesh. If not provided, it will be computed from the triangles.
- Return type:
Float32[Tensor, '_']
|Float32[Tensor, '_ _']
- Returns:
The lengths of the edges with shape (n_edges,) for a single mesh or (n_edges, n_poses) for a sequence of meshes.
- skshapes.triangle_mesh.geometry.triangle_areas(*, points, triangles)¶
Areas of the triangles of a triangular mesh.
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.
- Return type:
Float32[Tensor, '_']
|Float32[Tensor, '_ _']
- Returns:
The areas of the triangles with shape (n_triangles,) for a single mesh or (n_triangles, n_poses) for a sequence of meshes.
- skshapes.triangle_mesh.geometry.triangle_centers(*, points, triangles)¶
Centers of the triangles of a triangular mesh.
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.
- Return type:
Float32[Tensor, '_ _']
|Float32[Tensor, '_ _ _']
- Returns:
The centers of the triangles with shape (n_triangles, dim) for a single mesh or (n_triangles, n_poses, dim) for a sequence of meshes.
- skshapes.triangle_mesh.geometry.triangle_normals(*, points, triangles)¶
Triangle normals of a triangular mesh.
- Parameters:
points (
Float32[Tensor, '_ 2']
|Float32[Tensor, '_ 3']
|Float32[Tensor, '_ _ 2']
|Float32[Tensor, '_ _ 3']
) – Points or sequence of points with shape (n_points, n_poses, dim).triangles (
Int64[Tensor, '_ 3']
) – Triangles of the mesh.
- Return type:
Float32[Tensor, '_ _']
|Float32[Tensor, '_ _ _']
- Returns:
The normals of the triangles with shape (n_triangles, dim) for a single mesh or (n_meshes, n_triangles, dim) for a sequence of meshes.
skshapes.triangle_mesh.shell_energy module¶
Energy functions for triangle meshes.
- skshapes.triangle_mesh.shell_energy.bending_energy(*, points_undef, points_def, triangles, edge_topology=None)¶
Compute the bending energy of the mesh.
The mathematical formulation is given in page 4 of: https://ddg.math.uni-goettingen.de/pub/HeRuSc14.pdf
The implementation provided here is a pytorch version of the cpp implementation available at: https://gitlab.com/numod/shell-energy/-/blob/main/src/bending_energy.cpp
- Parameters:
points_undef (torch.Tensor) – The undeformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
points_def (torch.Tensor) – The deformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
triangles (torch.Tensor) – The triangles of the mesh(es). Shape: (n_triangles, 3).
weight (float, optional) – The weight of the bending energy. Default: 0.001.
- Return type:
Float32[Tensor, '']
|Float32[Tensor, '_']
- skshapes.triangle_mesh.shell_energy.membrane_energy(*, points_undef, points_def, triangles)¶
Compute the membrane energy of the mesh.
The mathematical formulation is given by equation (8) of: https://ddg.math.uni-goettingen.de/pub/HeRuWaWi12_final.pdf
The implementation provided here is a pytorch version of the cpp implementation available at: https://gitlab.com/numod/shell-energy/-/blob/main/src/membrane_energy.cpp
- Parameters:
points_undef (torch.Tensor) – The undeformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
points_def (torch.Tensor) – The deformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
triangles (torch.Tensor) – The triangles of the mesh(es). Shape: (n_triangles, 3).
- Return type:
Float32[Tensor, '']
|Float32[Tensor, '_']
- skshapes.triangle_mesh.shell_energy.shell_energy(*, points_undef, points_def, triangles, edge_topology=None, weight=0.001)¶
Compute the shell energy.
The shell energy is defined as the sum of the membrane and weight * bending energies.
- Parameters:
points_undef (torch.Tensor) – The undeformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
points_def (torch.Tensor) – The deformed points of the mesh. Shape: (n_points, dim) for a single mesh and (n_points, n_poses, dim) for a sequence of poses of the same mesh.
triangles (torch.Tensor) – The triangles of the mesh(es). Shape: (n_triangles, 3).
weight (float, optional) – The weight of the bending energy. Default: 0.001.
- Return type:
Float32[Tensor, '']
|Float32[Tensor, '_']