Mesh
- class compas.datastructures.Mesh[source]
Bases:
Datastructure
Data structure for representing open or closed surface meshes.
- Parameters:
- default_vertex_attributesdict[str, Any], optional
Default values for vertex attributes.
- default_edge_attributesdict[str, Any], optional
Default values for edge attributes.
- default_face_attributesdict[str, Any], optional
Default values for face attributes.
- namestr, optional
Then name of the mesh.
- **kwargsdict, optional
Additional keyword arguments, which are stored in the attributes dict.
- Attributes:
- default_vertex_attributesdict[str, Any]
Dictionary containing default values for the attributes of vertices. It is recommended to add a default to this dictionary using
update_default_vertex_attributes()
for every vertex attribute used in the data structure.- default_edge_attributesdict[str, Any]
Dictionary containing default values for the attributes of edges. It is recommended to add a default to this dictionary using
update_default_edge_attributes()
for every edge attribute used in the data structure.- default_face_attributesdict[str, Any]
Dictionary contnaining default values for the attributes of faces. It is recommended to add a default to this dictionary using
update_default_face_attributes()
for every face attribute used in the data structure.
Examples
>>> from compas.datastructures import Mesh >>> mesh = Mesh.from_polyhedron(6) >>> V = mesh.number_of_vertices() >>> E = mesh.number_of_edges() >>> F = mesh.number_of_faces() >>> mesh.euler() == V - E + F True
Methods
Constructors
Construct an object of this type from a JSON file. |
|
Construct a mesh object from a list of lines described by start and end point coordinates. |
|
Construct a mesh from faces and vertices on a regular grid. |
|
Construct a mesh object from the data described in an OBJ file. |
|
Construct a mesh object from the data described in a OFF file. |
|
Construct a mesh object from the data described in a PLY file. |
|
Construct a mesh from a delaunay triangulation of a set of points. |
|
Construct a mesh from a series of polygons. |
|
Construct a mesh from a platonic solid. |
|
Construct mesh from polylines. |
|
Construct a mesh from a primitive shape. |
|
Construct a mesh object from the data described in a STL file. |
|
Construct a mesh object from a list of vertices and faces. |
Conversions
Convert an object to its native data representation and save it to a JSON file. |
|
Return the lines of the mesh as pairs of start and end point coordinates. |
|
Write the mesh to an OBJ file. |
|
Write a mesh object to an OFF file. |
|
Write a mesh object to a PLY file. |
|
Convert the mesh to a collection of points. |
|
Convert the mesh to a collection of polygons. |
|
Convert the mesh to a collection of polylines. |
|
Write a mesh to an STL file. |
|
Return the vertices and faces of a mesh. |
Builders and Modifiers
Add a face to the mesh object. |
|
Add a vertex to the mesh object. |
|
Collapse an edge to its first or second vertex, or to an intermediate point. |
|
Delete a face from the mesh object. |
|
Delete a vertex from the mesh and everything that is attached to it. |
|
Flip the cycle directions of all faces. |
|
Insert a vertex in the specified face. |
|
Add the vertices and faces of another mesh to the current mesh. |
|
Merge two faces of a mesh over their shared edge. |
|
Convert all quadrilateral faces to triangles by adding a diagonal edge. |
|
Remove all duplicate vertices and clean up any affected faces. |
|
Remove all unused vertices from the mesh object. |
|
Split and edge by inserting a vertex along its length. |
|
Split a face by inserting an edge between two specified vertices. |
|
Unify the cycles of the mesh. |
|
Unwelds a mesh along edges. |
|
Unweld a face of the mesh. |
|
Weld vertices that are closer than a given precision. |
Accessors
A random sample of the edges. |
|
Iterate over the edges of the mesh. |
|
Find the edges on all boundaries of the mesh. |
|
Find the edges on the longest boundary. |
|
Get edges for which a certain condition or set of conditions is true. |
|
Get edges for which a certain condition or set of conditions is true using a lambda function. |
|
A random sample of the faces. |
|
Iterate over the faces of the mesh. |
|
Find the faces on all boundaries of the mesh. |
|
Find the faces on the longest boundary. |
|
Get faces for which a certain condition or set of conditions is true. |
|
Get faces for which a certain condition or set of conditions is true using a lambda function. |
|
A random sample of the vertices. |
|
Iterate over the vertices of the mesh. |
|
Find the vertices on all boundaries of the mesh. |
|
Find the vertices on the longest boundary. |
|
Get vertices for which a certain condition or set of conditions is true. |
|
Get vertices for which a certain condition or set of conditions is true using a lambda function. |
Attributes
Get or set an attribute of an edge. |
|
Get or set multiple attributes of an edge. |
|
Get or set an attribute of multiple edges. |
|
Get or set multiple attributes of multiple edges. |
|
Get or set an attribute of a face. |
|
Get or set multiple attributes of a face. |
|
Get or set an attribute of multiple faces. |
|
Get or set multiple attributes of multiple faces. |
|
Get or set an attribute of a vertex. |
|
Get or set multiple attributes of a vertex. |
|
Get or set an attribute of multiple vertices. |
|
Get or set multiple attributes of multiple vertices. |
|
Update the default edge attributes. |
|
Update the default face attributes. |
|
Update the default vertex attributes. |
|
Unset the attribute of an edge. |
|
Unset the attribute of a face. |
|
Unset the attribute of a vertex. |
Topology
Find groups of connected vertices. |
|
Find groups of connected faces. |
|
Find the two faces adjacent to an edge. |
|
Find all edges on the same loop as a given edge. |
|
Find all edges on the same strip as a given edge. |
|
Calculate the Euler characteristic. |
|
Find one half-edge over which two faces are adjacent. |
|
Find all vertices over which two faces are adjacent. |
|
Return triplets of face vertices forming the corners of the face. |
|
Count the neighbors of a face. |
|
The halfedges of a face. |
|
Compute the maximum degree of all faces. |
|
Compute the minimum degree of all faces. |
|
Return the neighbors of a face across its edges. |
|
Return the faces in the neighborhood of a face. |
|
Return the n-th vertex before the specified vertex in a specific face. |
|
Return the n-th vertex after the specified vertex in a specific face. |
|
The vertices of a face. |
|
Find the halfedge after the given halfedge in the same face. |
|
Find the halfedge before the given halfedge in the same face. |
|
Find the face corresponding to a halfedge. |
|
Find all edges on the same loop as the halfedge, in the direction of the halfedge. |
|
Find all vertices on the same loop as a given halfedge. |
|
Find all edges on the same strip as a given halfedge. |
|
Find all faces on the same strip as a given halfedge. |
|
Verify that the mesh contains a specific edge. |
|
Verify that a face is part of the mesh. |
|
Verify that a halfedge is part of the mesh. |
|
Verify that a vertex is in the mesh. |
|
Verify that the mesh is closed. |
|
Verify that the mesh is connected. |
|
Verify that an edge is on the boundary. |
|
Verify that the mesh is empty. |
|
Verify that a face is on a boundary. |
|
Verify that the mesh is manifold. |
|
Verify that the mesh is orientable. |
|
Verify that the mesh consists of only quads. |
|
Verify that the mesh is regular. |
|
Verify that the mesh consists of only triangles. |
|
Verify that the mesh is valid. |
|
Verify that a vertex is connected. |
|
Verify that a vertex is on a boundary. |
|
Count the number of edges in the mesh. |
|
Count the number of faces in the mesh. |
|
Count the number of vertices in the mesh. |
|
Count the neighbors of a vertex. |
|
Find all edges connected to a given vertex. |
|
The faces connected to a vertex. |
|
Compute the maximum degree of all vertices. |
|
Compute the minimum degree of all vertices. |
|
Return the neighbors of a vertex. |
|
Return the vertices in the neighborhood of a vertex. |
Geometry
Calculate the axis aligned bounding box of the mesh. |
|
Calculate the total mesh area. |
|
Calculate the mesh centroid. |
|
Return the coordinates of the start and end point of an edge. |
|
Return the direction vector of an edge. |
|
Return the point at the end of an edge. |
|
Return the length of an edge. |
|
Return the line of an edge. |
|
Return the midpoint of an edge. |
|
Return a point along an edge. |
|
Return the point at the start of an edge. |
|
Return the vector of an edge. |
|
Compute the area of a face. |
|
Face aspect ratio as the ratio between the lengths of the maximum and minimum face edges. |
|
Compute the point at the center of mass of a face. |
|
Compute the point at the centroid of a face. |
|
The circle of a face. |
|
Compute the coordinates of the vertices of a face. |
|
Dimensionless face curvature. |
|
Compute the flatness of the mesh face. |
|
The frame of a face. |
|
Compute the normal of a face. |
|
A plane defined by the centroid and the normal of the face. |
|
Compute the points of the vertices of a face. |
|
The polygon of a face. |
|
Face skewness as the maximum absolute angular deviation from the idefault_edge_attributesl polygon angle. |
|
Calculate the average mesh normal. |
|
Calculate the oriented bounding box of the mesh. |
|
Compute the tributary area of a vertex. |
|
Return the coordinates of a vertex. |
|
Dimensionless vertex curvature. |
|
Return the point of a vertex. |
|
Compute the vector from a vertex to the centroid of its neighbors. |
|
Compute the centroid of the neighbors of a vertex. |
|
Return the normal vector at the vertex as the weighted average of the normals of the neighboring faces. |
|
Return the points of multiple vertices. |
|
Set the point of a vertex. |
|
Smooth a mesh by moving each vertex to the barycenter of the centroids of the surrounding faces, weighted by area. |
|
Smooth a mesh by moving every free vertex to the centroid of its neighbors. |
|
Transform the mesh. |
|
Returns a transformed copy of this data structure. |
Paths
Matrices
Compute the adjacency matrix of the mesh. |
|
Compute the connectivity matrix of the mesh. |
|
Compute the degree matrix of the mesh. |
|
Compute the face matrix of the mesh. |
|
Compute the Laplacian matrix of the mesh. |
Mappings
Returns a dictionary that maps geometric keys of a certain precision to the keys of the corresponding vertices. |
|
Returns a dictionary that maps vertex dictionary keys to the corresponding geometric key up to a certain precision. |
|
Returns a dictionary that maps vertex identifiers to the corresponding index in a vertex list or array. |
|
Returns a dictionary that maps the indices of a vertex list to the corresponding vertex identifiers. |
Utilities
Print a summary of the mesh. |
|
Make an independent copy of the data object. |
|
Clear all the mesh data. |
Other
Construct the dual of a mesh. |
|
Explode the mesh into its connected components. |
|
Generate an offset mesh. |
|
Subdivide the input mesh. |
|
Generate a thicknened mesh. |