modcam.mesh#

Tools to work with triangle mesh data

modcam.mesh.per_vertex_basis_pro2024(vertex_normals: numpy.ndarray[dtype=float64, shape=(*, 3), writable=False]) tuple[numpy.ndarray[dtype=float64, shape=(*, 3), order='C'], numpy.ndarray[dtype=float64, shape=(*, 3), order='C'], numpy.ndarray[dtype=float64, shape=(*, 3), order='C']]#

Compute an orthonormal set of basis vectors for each vertex in a mesh. Algorithm by [pro2024].

Each vertex in the mesh is assigned a local coordinate system, where the z-axis is aligned with the vertex normal.

Parameters:

vertex_normals (ndarray) – V-by-3 matrix of mesh vertex 3D normals

Returns:

  • b0 (ndarray) – V-by-3 matrix of basis vectors, corresponding to the vertex-local x-axis.

  • b1 (ndarray) – V-by-3 matrix of basis vectors, corresponding to the vertex-local y-axis.

  • b2 (ndarray) – V-by-3 matrix of basis vectors, corresponding to the vertex-local z-axis (aligned with the vertex normal).

References

[pro2024]

prosilio. Per-vertex basis. GitHub, 2024.

modcam.mesh.per_vertex_normals_max1999(vertices: numpy.ndarray[dtype=float64, shape=(*, 3), writable=False], faces: numpy.ndarray[dtype=int32, shape=(*, 3), writable=False]) numpy.ndarray[dtype=float64, shape=(*, *), order='C']#

Compute the per-vertex normal vectors for a set of vertices and faces, as described in [max1999].

Vertex normals are computed using a weighted sum of their surrounding face (triangle) normals.

Parameters:
  • vertices (ndarray) – V-by-3 matrix of vertex Cartesian coordinates. Each row specifies a vertex’s 3D position.

  • faces (ndarray) – F-by-3 matrix of face (triangle) indices. Each row represents a triangle by indexing three vertices (rows) from the vertices array.

Returns:

V-by-3 matrix of per-vertex normal vectors. If the vertices array is empty, then an empty array is returned. If the faces array is empty, then the returned array values are set to NaN.

Return type:

ndarray

References

[max1999]

Nelson Max. Weights for computing vertex normals from facet normals. Journal of Graphics Tools, 4:1-6, 1 1999.

modcam.mesh.principal_curvature_rus2004(vertices: numpy.ndarray[dtype=float64, shape=(*, 3), writable=False], faces: numpy.ndarray[dtype=int32, shape=(*, 3), writable=False]) tuple[numpy.ndarray[dtype=float64, shape=(*, *), order='C'], numpy.ndarray[dtype=float64, shape=(*, *), order='C'], numpy.ndarray[dtype=float64, shape=(*), order='C'], numpy.ndarray[dtype=float64, shape=(*), order='C']]#

Compute the (per-vertex) principal curvature on a triangle mesh using the algorithm described in [rus2004].

While many principal curvature algorithms use a tunable “neighborhood” to compute their estimates, this algorithm uses only 1-ring vertex neighborhoods. Although the algorithm in [rus2004] can be used to compute curvature derivates, that is not done here.

If the vertices array is empty, then all returned arrays are empty. If the faces array is empty, then all returned array values are set to NaN.

Parameters:
  • vertices (ndarray) – V-by-3 matrix of vertex Cartesian coordinates. Each row specifies a vertex’s 3D position.

  • faces (ndarray) – F-by-3 matrix of face (triangle) indices. Each row represents a triangle by indexing three vertices (rows) from the vertices array.

Returns:

  • pd1 (ndarray) – V-by-3 maximal curvature direction for each vertex.

  • pd2 (ndarray) – V-by-3 minimal curvature direction for each vertex.

  • pv1 (ndarray) – V-by-1 maximal curvature value for each vertex.

  • pv2 (ndarray) – V-by-1 minimal curvature value for each vertex.

References

[rus2004] (1,2)

S. Rusinkiewicz. Estimating curvatures and their derivatives on triangle meshes. pages 486-493. IEEE, 2004.

modcam.mesh.voronoi_area_mey2003(vertices: numpy.ndarray[dtype=float64, shape=(*, *), writable=False], faces: numpy.ndarray[dtype=int32, shape=(*, 3), writable=False]) numpy.ndarray[dtype=float64, shape=(*, *), order='C']#

Compute the Voronoi cell areas for the triangles in a mesh as described in [mey2003].

For a non-obtuse triangle, the Voronoi areas are bounded by segments connecting the triangle’s circumcenter to the midpoints of its edges. In the case of an obtuse triangle, we replace the triangle circumcenter with the midpoint of the edge opposite the obtuse angle.

Parameters:
  • vertices (ndarray) – V-by-3 (or V-by-2) matrix of vertex Cartesian coordinates. Each row specifies a vertex’s 3D (or 2D) position.

  • faces (ndarray) – F-by-3 matrix of face (triangle) indices. Each row represents a triangle by indexing three vertices (rows) from the vertices array.

Returns:

F-by-3 matrix of the Voronoi area of each vertex in each triangle. Each value in this array corresponds to a triangle corner in the faces array. If the faces array is empty, then an empty array is returned. If the vertices array is empty, then the returned array values are set to zero.

Return type:

ndarray

References

[mey2003]

Mark Meyer, Mathieu Desbrun, Peter Schröder, and Alan H. Barr. Discrete differential-geometry operators for triangulated 2-manifolds, 2003.