# Mesh

class compas.datastructures.Mesh(name=None, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None)[source]

Geometric implementation of a half edge data structure for polygon meshses.

Parameters
• name (str, optional) – The name of the graph. Defaults to “Graph”.

• default_vertex_attributes (dict, optional) – Default values for vertex attributes.

• default_edge_attributes (dict, optional) – Default values for edge attributes.

• default_face_attributes (dict, optional) – Default values for face attributes.

Attributes
• attributes (dict) – A dictionary of general mesh attributes: {'name': "Mesh"}.

• default_vertex_attributes (dict) – The names of pre-assigned vertex attributes and their default values: {'x': 0.0, 'y': 0.0, 'z': 0.0}

• default_edge_attributes (dict) – The default data attributes assigned to every new edge.

• default_face_attributes (dict) – The default data attributes assigned to every new face.

• name (str) – The name of the mesh. Shorthand for mesh.attributes['name']

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

 add_face(vertices[, fkey, attr_dict]) Add a face to the mesh object. add_vertex([key, attr_dict]) Add a vertex to the mesh object. Calculate the total mesh area. Compute the (axis aligned) bounding box of a mesh. Compute the (axis aligned) bounding box of a projection of the mesh in the XY plane. Calculate the mesh centroid. Clear all the mesh data. collapse_edge(u, v[, t, allow_boundary, fixed]) Collapse an edge to its first or second vertex, or to an intermediate point. copy([cls]) Make an independent copy of the data object. Remove all unused vertices from the mesh object. delete_face(fkey) Delete a face from the mesh object. Delete a vertex from the mesh and everything that is attached to it. dual([cls]) Construct the dual of a mesh. edge_attribute(edge, name[, value]) Get or set an attribute of an edge. edge_attributes(edge[, names, values]) Get or set multiple attributes of an edge. edge_coordinates(u, v[, axes]) Return the coordinates of the start and end point of an edge. edge_direction(u, v) Return the direction vector of an edge. edge_faces(u, v) Find the two faces adjacent to an edge. edge_length(u, v) Return the length of an edge. edge_loop(edge) Find all edges on the same loop as a given edge. edge_midpoint(u, v) Return the location of the midpoint of an edge. edge_point(u, v[, t]) Return the location of a point along an edge. edge_sample([size]) A random sample of the edges. edge_strip(edge) Find all edges on the same strip as a given edge. edge_vector(u, v) Return the vector of an edge. edges([data]) Iterate over the edges of the mesh. edges_attribute(name[, value, keys]) Get or set an attribute of multiple edges. edges_attributes([names, values, keys]) Get or set multiple attributes of multiple edges. Find the edges on all boundaries of the mesh. Find the edges on the longest boundary. edges_where(conditions[, data]) Get edges for which a certain condition or set of conditions is true. edges_where_predicate(predicate[, data]) Get edges for which a certain condition or set of conditions is true using a lambda function. Calculate the Euler characteristic. Build a face adjacency dict. Find one half-edge over which two faces are adjacent. Find all vertices over which two faces are adjacent. face_area(fkey) Compute the area of a face. Face aspect ratio as the ratio between the lengths of the maximum and minimum face edges. face_attribute(key, name[, value]) Get or set an attribute of a face. face_attributes(key[, names, values]) Get or set multiple attributes of a face. face_center(fkey) Compute the location of the center of mass of a face. face_centroid(fkey) Compute the location of the centroid of a face. face_coordinates(fkey[, axes]) Compute the coordinates of the vertices of a face. face_corners(fkey) Return triplets of face vertices forming the corners of the face. face_curvature(fkey) Dimensionless face curvature as the maximum face vertex deviation from the best-fit plane of the face vertices divided by the average lengths of the face vertices to the face centroid. face_degree(fkey) Count the neighbors of a face. face_flatness(fkey[, maxdev]) Compute the flatness of the mesh face. face_halfedges(fkey) The halfedges of a face. Compute the maximum degree of all faces. Compute the minimum degree of all faces. face_neighborhood(key[, ring]) Return the faces in the neighborhood of a face. face_neighbors(fkey) Return the neighbors of a face across its edges. face_normal(fkey[, unitized]) Compute the normal of a face. face_plane(face) A plane defined by the centroid and the normal of the face. face_sample([size]) A random sample of the faces. face_skewness(fkey) Face skewness as the maximum absolute angular deviation from the ideal polygon angle. face_vertex_after(fkey, key[, n]) Return the n-th vertex after the specified vertex in a specific face. face_vertex_ancestor(fkey, key[, n]) Return the n-th vertex before the specified vertex in a specific face. face_vertex_before(fkey, key[, n]) Return the n-th vertex before the specified vertex in a specific face. face_vertex_descendant(fkey, key[, n]) Return the n-th vertex after the specified vertex in a specific face. face_vertices(fkey) The vertices of a face. faces([data]) Iterate over the faces of the mesh. faces_attribute(name[, value, keys]) Get or set an attribute of multiple faces. faces_attributes([names, values, keys]) Get or set multiple attributes of multiple faces. Find the faces on all boundaries of the mesh. Find the faces on the longest boundary. faces_where(conditions[, data]) Get faces for which a certain condition or set of conditions is true. faces_where_predicate(predicate[, data]) Get faces for which a certain condition or set of conditions is true using a lambda function. Flip the cycle directions of all faces. from_data(data) Construct an object of this type from the provided data. from_json(filepath) Construct an object from serialized data contained in a JSON file. from_jsonstring(string) Construct an object from serialized data contained in a JSON string. from_lines(lines[, delete_boundary_face, ...]) Construct a mesh object from a list of lines described by start and end point coordinates. from_meshgrid(dx, nx[, dy, ny]) Create a mesh from faces and vertices on a regular grid. from_obj(filepath[, precision]) Construct a mesh object from the data described in an OBJ file. from_off(filepath) Construct a mesh object from the data described in a OFF file. from_ply(filepath[, precision]) Construct a mesh object from the data described in a PLY file. from_points(points[, boundary, holes]) Construct a mesh from a delaunay triangulation of a set of points. from_polygons(polygons[, precision]) Construct a mesh from a series of polygons. Construct a mesh from a platonic solid. from_polylines(boundary_polylines, ...) Construct mesh from polylines. from_shape(shape, **kwargs) Construct a mesh from a primitive shape. from_stl(filepath[, precision]) Construct a mesh object from the data described in a STL file. from_vertices_and_faces(vertices, faces) Construct a mesh object from a list of vertices and faces. Calculate the genus. Get the identifier of a random face. Get the identifier of a random vertex of a specific face. Get the identifier of a random vertex. get_any_vertices(n[, exclude_leaves]) Get a list of identifiers of a random set of n vertices. gkey_key([precision]) Returns a dictionary that maps geometric keys of a certain precision to the keys of the corresponding vertices. gkey_vertex([precision]) Returns a dictionary that maps geometric keys of a certain precision to the keys of the corresponding vertices. halfedge_after(u, v) halfedge_face(u, v) Find the face corresponding to a halfedge. halfedge_strip(edge) Find all edges on the same strip as a given halfedge. has_edge(key) Verify that the mesh contains a specific edge. has_face(fkey) Verify that a face is part of the mesh. Verify that a halfedge is part of the mesh. has_vertex(key) Verify that a vertex is in the mesh. Returns a dictionary that maps the indices of a vertex list to keys in a vertex dictionary. Returns a dictionary that maps the indices of a vertex list to keys in a vertex dictionary. insert_vertex(fkey[, key, xyz, return_fkeys]) Insert a vertex in the specified face. 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. join(other) Add the vertices and faces of another mesh to the current mesh. key_gkey([precision]) Returns a dictionary that maps vertex dictionary keys to the corresponding geometric key up to a certain precision. Returns a dictionary that maps vertex dictionary keys to the corresponding index in a vertex list or array. merge_faces(faces) Merge two faces of a mesh over their shared edge. Compute the (axis aligned) bounding box of a mesh. Compute the (axis aligned) bounding box of a projection of the mesh in the XY plane. Calculate the average mesh normal. Count the number of edges in the mesh. Count the number of faces in the mesh. Count the number of vertices in the mesh. Compute the (axis aligned) bounding box of a mesh. Compute the (axis aligned) bounding box of a projection of the mesh in the XY plane. quads_to_triangles([check_angles]) Remove all unused vertices from the mesh object. slice_plane(plane) Slice a mesh with a plane and construct the resulting submeshes. smooth_area([fixed, kmax, damping, ...]) Smooth a mesh by moving each vertex to the barycenter of the centroids of the surrounding faces, weighted by area. smooth_centroid([fixed, kmax, damping, ...]) Smooth a mesh by moving every free vertex to the centroid of its neighbors. split_edge(u, v[, t, allow_boundary]) Split and edge by inserting a vertex along its length. split_face(fkey, u, v) Split a face by inserting an edge between two specified vertices. subdivide([scheme]) Subdivide the input mesh. Print a summary of the mesh. Convert an object to its native data representation. to_json(filepath[, pretty]) Serialize the data representation of an object to a JSON file. to_jsonstring([pretty]) Serialize the data representation of an object to a JSON string. to_lines(filepath) to_obj(filepath[, precision, unweld]) Write the mesh to an OBJ file. to_off(filepath, **kwargs) Write a mesh object to an OFF file. to_ply(filepath, **kwargs) Write a mesh object to a PLY file. to_stl(filepath[, precision, binary]) Write a mesh to an STL file. Return the vertices and faces of a mesh. transform(transformation) Transform a mesh. transformed(transformation) Transform a copy of mesh. unify_cycles([root]) Unify the cycle directions of all faces. unset_edge_attribute(edge, name) Unset the attribute of an edge. unset_face_attribute(key, name) Unset the attribute of a face. unset_vertex_attribute(key, name) Unset the attribute of a vertex. update_default_edge_attributes([attr_dict]) Update the default edge attributes. update_default_face_attributes([attr_dict]) Update the default face attributes. update_default_vertex_attributes([attr_dict]) Update the default vertex attributes. Validate the object's data against its data schema (self.DATASCHEMA). Validate the object's data against its json schema (self.JSONSCHEMA). Compute the tributary area of a vertex. vertex_attribute(key, name[, value]) Get or set an attribute of a vertex. vertex_attributes(key[, names, values]) Get or set multiple attributes of a vertex. vertex_coordinates(key[, axes]) Return the coordinates of a vertex. Dimensionless vertex curvature. Count the neighbors of a vertex. vertex_edges(vertex) vertex_faces(key[, ordered, include_none]) The faces connected to a vertex. vertex_gkey([precision]) Returns a dictionary that maps vertex dictionary keys to the corresponding geometric key up to a certain precision. Returns a dictionary that maps vertex dictionary keys to the corresponding index in a vertex list or array. Compute the vector from a vertex to the centroid of its neighbors. Compute the maximum degree of all vertices. Compute the minimum degree of all vertices. vertex_neighborhood(key[, ring]) Return the vertices in the neighborhood of a vertex. Compute the centroid of the neighbors of a vertex. vertex_neighbors(key[, ordered]) Return the neighbors of a vertex. Return the normal vector at the vertex as the weighted average of the normals of the neighboring faces. vertex_sample([size]) A random sample of the vertices. vertices([data]) Iterate over the vertices of the mesh. vertices_attribute(name[, value, keys]) Get or set an attribute of multiple vertices. vertices_attributes([names, values, keys]) Get or set multiple attributes of multiple vertices. Find the vertices on all boundaries of the mesh. Find the vertices on the longest boundary. vertices_where(conditions[, data]) Get vertices for which a certain condition or set of conditions is true. vertices_where_predicate(predicate[, data]) Get vertices for which a certain condition or set of conditions is true using a lambda function.