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.

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
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.

Methods

Constructors

from_json

Construct an object of this type from a JSON file.

from_lines

Construct a mesh object from a list of lines described by start and end point coordinates.

from_meshgrid

Construct a mesh from faces and vertices on a regular grid.

from_obj

Construct a mesh object from the data described in an OBJ file.

from_off

Construct a mesh object from the data described in a OFF file.

from_ply

Construct a mesh object from the data described in a PLY file.

from_points

Construct a mesh from a delaunay triangulation of a set of points.

from_polygons

Construct a mesh from a series of polygons.

from_polyhedron

Construct a mesh from a platonic solid.

from_polylines

Construct mesh from polylines.

from_shape

Construct a mesh from a primitive shape.

from_stl

Construct a mesh object from the data described in a STL file.

from_vertices_and_faces

Construct a mesh object from a list of vertices and faces.

Conversions

to_json

Convert an object to its native data representation and save it to a JSON file.

to_lines

Return the lines of the mesh as pairs of start and end point coordinates.

to_obj

Write the mesh to an OBJ file.

to_off

Write a mesh object to an OFF file.

to_ply

Write a mesh object to a PLY file.

to_points

Convert the mesh to a collection of points.

to_polygons

Convert the mesh to a collection of polygons.

to_polylines

Convert the mesh to a collection of polylines.

to_stl

Write a mesh to an STL file.

to_vertices_and_faces

Return the vertices and faces of a mesh.

Builders and Modifiers

add_face

Add a face to the mesh object.

add_vertex

Add a vertex to the mesh object.

collapse_edge

Collapse an edge to its first or second vertex, or to an intermediate point.

delete_face

Delete a face from the mesh object.

delete_vertex

Delete a vertex from the mesh and everything that is attached to it.

flip_cycles

Flip the cycle directions of all faces.

insert_vertex

Insert a vertex in the specified face.

join

Add the vertices and faces of another mesh to the current mesh.

merge_faces

Merge two faces of a mesh over their shared edge.

quads_to_triangles

Convert all quadrilateral faces to triangles by adding a diagonal edge.

remove_duplicate_vertices

Remove all duplicate vertices and clean up any affected faces.

remove_unused_vertices

Remove all unused vertices from the mesh object.

split_edge

Split and edge by inserting a vertex along its length.

split_face

Split a face by inserting an edge between two specified vertices.

unify_cycles

Unify the cycles of the mesh.

unweld_edges

Unwelds a mesh along edges.

unweld_vertices

Unweld a face of the mesh.

weld

Weld vertices that are closer than a given precision.

Accessors

edge_sample

A random sample of the edges.

edges

Iterate over the edges of the mesh.

edges_on_boundaries

Find the edges on all boundaries of the mesh.

edges_on_boundary

Find the edges on the longest boundary.

edges_where

Get edges for which a certain condition or set of conditions is true.

edges_where_predicate

Get edges for which a certain condition or set of conditions is true using a lambda function.

face_sample

A random sample of the faces.

faces

Iterate over the faces of the mesh.

faces_on_boundaries

Find the faces on all boundaries of the mesh.

faces_on_boundary

Find the faces on the longest boundary.

faces_where

Get faces for which a certain condition or set of conditions is true.

faces_where_predicate

Get faces for which a certain condition or set of conditions is true using a lambda function.

vertex_sample

A random sample of the vertices.

vertices

Iterate over the vertices of the mesh.

vertices_on_boundaries

Find the vertices on all boundaries of the mesh.

vertices_on_boundary

Find the vertices on the longest boundary.

vertices_where

Get vertices for which a certain condition or set of conditions is true.

vertices_where_predicate

Get vertices for which a certain condition or set of conditions is true using a lambda function.

Attributes

edge_attribute

Get or set an attribute of an edge.

edge_attributes

Get or set multiple attributes of an edge.

edges_attribute

Get or set an attribute of multiple edges.

edges_attributes

Get or set multiple attributes of multiple edges.

face_attribute

Get or set an attribute of a face.

face_attributes

Get or set multiple attributes of a face.

faces_attribute

Get or set an attribute of multiple faces.

faces_attributes

Get or set multiple attributes of multiple faces.

vertex_attribute

Get or set an attribute of a vertex.

vertex_attributes

Get or set multiple attributes of a vertex.

vertices_attribute

Get or set an attribute of multiple vertices.

vertices_attributes

Get or set multiple attributes of multiple vertices.

update_default_edge_attributes

Update the default edge attributes.

update_default_face_attributes

Update the default face attributes.

update_default_vertex_attributes

Update the default vertex attributes.

unset_edge_attribute

Unset the attribute of an edge.

unset_face_attribute

Unset the attribute of a face.

unset_vertex_attribute

Unset the attribute of a vertex.

Topology

connected_vertices

Find groups of connected vertices.

connected_faces

Find groups of connected faces.

edge_faces

Find the two faces adjacent to an edge.

edge_loop

Find all edges on the same loop as a given edge.

edge_strip

Find all edges on the same strip as a given edge.

euler

Calculate the Euler characteristic.

face_adjacency_halfedge

Find one half-edge over which two faces are adjacent.

face_adjacency_vertices

Find all vertices over which two faces are adjacent.

face_corners

Return triplets of face vertices forming the corners of the face.

face_degree

Count the neighbors of a face.

face_halfedges

The halfedges of a face.

face_max_degree

Compute the maximum degree of all faces.

face_min_degree

Compute the minimum degree of all faces.

face_neighbors

Return the neighbors of a face across its edges.

face_neighborhood

Return the faces in the neighborhood of a face.

face_vertex_ancestor

Return the n-th vertex before the specified vertex in a specific face.

face_vertex_descendant

Return the n-th vertex after the specified vertex in a specific face.

face_vertices

The vertices of a face.

halfedge_after

Find the halfedge after the given halfedge in the same face.

halfedge_before

Find the halfedge before the given halfedge in the same face.

halfedge_face

Find the face corresponding to a halfedge.

halfedge_loop

Find all edges on the same loop as the halfedge, in the direction of the halfedge.

halfedge_loop_vertices

Find all vertices on the same loop as a given halfedge.

halfedge_strip

Find all edges on the same strip as a given halfedge.

halfedge_strip_faces

Find all faces on the same strip as a given halfedge.

has_edge

Verify that the mesh contains a specific edge.

has_face

Verify that a face is part of the mesh.

has_halfedge

Verify that a halfedge is part of the mesh.

has_vertex

Verify that a vertex is in the mesh.

is_closed

Verify that the mesh is closed.

is_connected

Verify that the mesh is connected.

is_edge_on_boundary

Verify that an edge is on the boundary.

is_empty

Verify that the mesh is empty.

is_face_on_boundary

Verify that a face is on a boundary.

is_manifold

Verify that the mesh is manifold.

is_orientable

Verify that the mesh is orientable.

is_quadmesh

Verify that the mesh consists of only quads.

is_regular

Verify that the mesh is regular.

is_trimesh

Verify that the mesh consists of only triangles.

is_valid

Verify that the mesh is valid.

is_vertex_connected

Verify that a vertex is connected.

is_vertex_on_boundary

Verify that a vertex is on a boundary.

number_of_edges

Count the number of edges in the mesh.

number_of_faces

Count the number of faces in the mesh.

number_of_vertices

Count the number of vertices in the mesh.

vertex_degree

Count the neighbors of a vertex.

vertex_edges

Find all edges connected to a given vertex.

vertex_faces

The faces connected to a vertex.

vertex_max_degree

Compute the maximum degree of all vertices.

vertex_min_degree

Compute the minimum degree of all vertices.

vertex_neighbors

Return the neighbors of a vertex.

vertex_neighborhood

Return the vertices in the neighborhood of a vertex.

Geometry

aabb

Calculate the axis aligned bounding box of the mesh.

area

Calculate the total mesh area.

centroid

Calculate the mesh centroid.

edge_coordinates

Return the coordinates of the start and end point of an edge.

edge_direction

Return the direction vector of an edge.

edge_end

Return the point at the end of an edge.

edge_length

Return the length of an edge.

edge_line

Return the line of an edge.

edge_midpoint

Return the midpoint of an edge.

edge_point

Return a point along an edge.

edge_start

Return the point at the start of an edge.

edge_vector

Return the vector of an edge.

face_area

Compute the area of a face.

face_aspect_ratio

Face aspect ratio as the ratio between the lengths of the maximum and minimum face edges.

face_center

Compute the point at the center of mass of a face.

face_centroid

Compute the point at the centroid of a face.

face_circle

The circle of a face.

face_coordinates

Compute the coordinates of the vertices of a face.

face_curvature

Dimensionless face curvature.

face_flatness

Compute the flatness of the mesh face.

face_frame

The frame of a face.

face_normal

Compute the normal of a face.

face_plane

A plane defined by the centroid and the normal of the face.

face_points

Compute the points of the vertices of a face.

face_polygon

The polygon of a face.

face_skewness

Face skewness as the maximum absolute angular deviation from the idefault_edge_attributesl polygon angle.

normal

Calculate the average mesh normal.

obb

Calculate the oriented bounding box of the mesh.

vertex_area

Compute the tributary area of a vertex.

vertex_coordinates

Return the coordinates of a vertex.

vertex_curvature

Dimensionless vertex curvature.

vertex_point

Return the point of a vertex.

vertex_laplacian

Compute the vector from a vertex to the centroid of its neighbors.

vertex_neighborhood_centroid

Compute the centroid of the neighbors of a vertex.

vertex_normal

Return the normal vector at the vertex as the weighted average of the normals of the neighboring faces.

vertices_points

Return the points of multiple vertices.

set_vertex_point

Set the point of a vertex.

smooth_area

Smooth a mesh by moving each vertex to the barycenter of the centroids of the surrounding faces, weighted by area.

smooth_centroid

Smooth a mesh by moving every free vertex to the centroid of its neighbors.

transform

Transform the mesh.

transformed

Returns a transformed copy of this data structure.

Paths

Matrices

adjacency_matrix

Compute the adjacency matrix of the mesh.

connectivity_matrix

Compute the connectivity matrix of the mesh.

degree_matrix

Compute the degree matrix of the mesh.

face_matrix

Compute the face matrix of the mesh.

laplacian_matrix

Compute the Laplacian matrix of the mesh.

Mappings

gkey_vertex

Returns a dictionary that maps geometric keys of a certain precision to the keys of the corresponding vertices.

vertex_gkey

Returns a dictionary that maps vertex dictionary keys to the corresponding geometric key up to a certain precision.

vertex_index

Returns a dictionary that maps vertex identifiers to the corresponding index in a vertex list or array.

index_vertex

Returns a dictionary that maps the indices of a vertex list to the corresponding vertex identifiers.

Utilities

summary

Print a summary of the mesh.

copy

Make an independent copy of the data object.

clear

Clear all the mesh data.

Other

dual

Construct the dual of a mesh.

exploded

Explode the mesh into its connected components.

offset

Generate an offset mesh.

subdivided

Subdivide the input mesh.

thickened

Generate a thicknened mesh.