mesh - meshes and discretised objects

This module defines meshes composed of triangles or of edges.

Classes defined here

Topology

A lot of similarities exists between these classes, because many of their methods are topologically generic to every dimension. They are often implemented for specific mesh For convenience, there is aliases to these classes highlighting their topology genericity

  • Mesh0 (alias to Wire) mesh with inner dimension 0 (simplices are points)
  • Mesh1 (alias to Web) mesh with inner dimension 1 (simplices are edges)
  • Mesh2 (alias to Mesh) mesh with inner dimension 2 (simplices are triangles)

naming:

  • a mesh outer dimension is the dimension of the space its points belong to. for vec3 it is 3. In madcad, all meshes have outer dimension 3
  • a mesh inner dimension is the dimension of the space of its simplices. for a line it is 1 because 1 scalar is sufficient to interpolate over a line

Architecture

The data structures defined here are just containers, they do not intend a specific usage of the geometries as it can be with halfedges, binary trees, etc. The data structures here intend to store efficiently the mesh information and allow basic data operation like concatenation, find-replace, and so.

The following considerations are common to the classes here:

  • the classes are just wrapping references to data buffers

    they do not own exclusively their content, nor it is forbidden to hack into their content (it is just lists, you can append, insert, copy, etc what you want). As so, it is almost no cost to shallow-copy a mesh, or to create it from existing buffers without computation nor data copy. It is very common that several meshes are sharing the same buffer of points, faces, groups …

  • the management of the container’s data ownership is left to the user

    the user has to copy the data explicitely when necessary to unlink containers sharing the same buffers. To allow the user to do so, the madcad functions observe the following rules:

    • the container’s methods that modify a small portion of its data does so in-place. when they do not return a particular value, they do return ‘self’ (lowercase, meaning the current container instance)
    • the container’s methods that modify a big amount of its data do return a new container instance, sharing the untouched buffers with the current one and duplicating the altered data. They do return a new instance of ‘Self’ (uppercase, meaning it is the current container type)
  • the methods defined for containers are only simple and very general operations.

    The more complex operations are left to separated functions. Most of the time, container methods are for data/buffers management, connectivity operations, and mathematical caracteristics extractions (like normals, surface, volume, etc)

See Mesh.own() for instance.

Inner identification

The containers are provided with an inner-identification system allowing to keep track of portion of geometries in the mesh across operations applies on. This is permitted by their field tracks and groups. Each simplex (point, edge or face depending of the mesh inner dimension) is associated to a group number referencing a group definition in the group list.

Groups definitions can be anything, but more often is a dictionnary (containing the group attributes we can filter on), or simply None. To easily extract portions of one mesh, its is straightforward to associate keys to the interesting groups using .qualify(key) and then select groups calling .group(key) to retreive it later. groups can also be filtered manually.

See Mesh.qualify() for more details

Conversions

mesh(*arg, resolution=None) Mesh[source]

Build a Mesh object from supported objects:

Mesh:return it with no copy
Primitive:call its .mesh method and convert the result to web
Iterable:convert each element to web and join them
web(*arg, resolution=None) Web[source]

Build a Web object from supported objects:

Web:return it with no copy
Wire:reference points and generate edge couples
Primitive:call its .mesh method and convert the result to web
Iterable:convert each element to web and join them
List of vec3:reference it and generate trivial indices
Iterable of vec3:
 get points and generate trivial indices
wire(*arg, resolution=None) Wire[source]

Build a Wire object from the other compatible types. Supported types are:

Wire:return it with no copy
Web:find the edges to joint, keep the same point buffer
Primitive:call its .mesh method and convert the result to wire
Iterable:convert each element to Wire and joint them
List of vec3:reference it and put trivial indices
Iterable of vec3:
 create internal point list from it, and put trivial indices
typedlist_to_numpy(array: typedlist, dtype) ndarray[source]

Convert a typedlist to a numpy.ndarray with the given dtype, if the conversion is possible term to term

numpy_to_typedlist(array: ndarray, dtype) typedlist[source]

Convert a numpy.ndarray into a typedlist with the given dtype, if the conversion is possible term to term

ensure_typedlist(obj, dtype)[source]

Return a typedlist with the given dtype, create it from whatever is in obj if needed

Connectivity

edgekey(a, b)[source]

Return a key for a non-directional edge

facekeyo(a, b, c)[source]

Return a key for an oriented face

arrangeface(f, p)[source]

Return the face indices rotated the way the p is the first one

arrangeedge(e, p)[source]
connpp(ngons)[source]

Point to point connectivity input is a list of ngons (tuple of 2 to n indices)

connef(faces)[source]

Connectivity dictionary, from oriented edge to face

connpe(edges)[source]
connexity(links)[source]

Return the number of links referencing each point as a dictionary {point: num links}

suites(lines, oriented=True, cut=True, loop=False)[source]

Return a list of the suites that can be formed with lines. lines is an iterable of edges

Parameters:
  • oriented – specifies that (a,b) and (c,b) will not be assembled
  • cut – cut suites when they are crossing each others

Return a list of the sequences that can be formed

Misc

class MeshError[source]

Inconsistent data in mesh

line_simplification(web, prec=None)[source]

return a dictionnary of merges to simplify edges when there is points aligned.

This function sort the points to remove on the height of the triangle with adjacent points. The returned dictionnary is guaranteed without cycles

mesh_distance(m0, m1)[source]

minimal distance between elements of meshes

The result is a tuple (distance, primitive from m0, primitive from m1). primitive can be:

int:index of the closest point
(int,int):indices of the closest edge
(int,int,int):indices of the closest triangle
distance2_pm(point, mesh)[source]

squared distance from a point to a mesh