mesh - meshes and discretised objects

This module defines triangular meshes and edges webs.

containers

The classes defined here are ‘points containers’ it means that they are storing a list of points (as a member point), a list of groups (member group) and index points and groups for other purpose (faces and edges). All of these follow this line:

  • storages are using basic types, no object inter-referencing, making it easy to copy it

  • storages (points, groups, faces, edges, …) are used as shared ressources

    python objects are ref-counted, allowing multiple Mesh instance to have the same point buffer. The user is responsible to ensure that there will be non conflict.

    To avoid conflicts, operations that are changing each point (or the most of them) reallocate a new list. Then operations like mergeclose or stripgroups won’t affect other Meshes that shared the same buffers initially.

  • as build from shared ressources, these classes can be build from existing parts at a nearly zero cost (few verifications, no computation)

  • the user is allowed to hack into the internal data, ensure that the Mesh is still consistent after.

classes

class Mesh(points=None, faces=None, tracks=None, groups=None, options=None)

set of triangles, used to represent volumes or surfaces. As volumes are represented by their exterior surface, there is no difference between representation of volumes and faces, juste the way we interpret it.

points

list of vec3 for points

faces

list of triplets for faces, the triplet is (a,b,c) such that cross(b-a, c-a) is the normal oriented to the exterior.

tracks

integer giving the group each face belong to

groups

custom information for each group

options

custom informations for the entire mesh

Point container methods

Support for +, += Mesh

transform(trans)

apply the transform to the points of the mesh, returning the new transformed mesh

flip()

flip all faces, getting the normals opposite

splitgroups(edges=None)

split the mesh groups into connectivity separated groups. the points shared by multiple groups will be duplicated if edges is provided, only the given edges at group frontier will be splitted

return a list of tracks for points

mergepoints(merges)

merge points with the merge dictionnary {src index: dst index} merged points are not removed from the buffer.

mergeclose(limit=None, start=0)

merge points below the specified distance, or below the precision return a dictionnary of points remapping {src index: dst index}

finish()

finish and clean the mesh note that this operation can cost as much as other transformation operation job done

  • mergeclose

  • strippoints

  • stripgroups

strippoints(used=None)

remove points that are used by no faces, return the reindex list. if used is provided, these points will be removed without usage verification

return a table of the reindex made

stripgroups()

remove groups that are used by no faces, return the reindex list

check methods

check()

raise if the internal data is inconsistent

isvalid()

return true if the internal data is consistent (all indices referes to actual points and groups)

issurface()

return True if the mesh is a well defined surface (an edge has 2 connected triangles at maximum, with coherent normals) such meshes are usually called ‘manifold’

isenvelope()

return True if the surfaces are a closed envelope (the outline is empty)

scan methods

pointat(point, neigh=1e-13)

return the index of the first point at the given location, or None

usepointat(point, neigh=1e-13)

Return the index of the first point in the mesh at the location. If none is found, insert it and return the index

pointnear(point)

return the nearest point the the given location

groupnear(point)

return the id of the group for the nearest surface to the given point

extraction methods

facenormal(f)

normal for a face

facenormals()

list normals for each face

edgenormals()

dict of normals for each UNORIENTED edge

vertexnormals()

list of normals for each point

edges()

set of UNORIENTED edges present in the mesh

edges_oriented()

iterator of ORIENTED edges, directly retreived of each face

group(groups)

return a new mesh linked with this one, containing only the faces belonging to the given groups

outlines_oriented()

return a set of the ORIENTED edges delimiting the surfaces of the mesh

outlines_unoriented()

return a set of the UNORIENTED edges delimiting the surfaces of the mesh this method is robust to face orientation aberations

outlines()

return a Web of ORIENTED edges

groupoutlines()

return a dict of ORIENTED edges indexing groups.

On a frontier between multiple groups, there is as many edges as groups, each associated to a group.

frontiers(*args)

return a Web of UNORIENTED edges that split the given groups appart.

if groups is None, then return the frontiers between any groups

tangents()

tangents to outline points

islands(conn=None) [Mesh]

return the unconnected parts of the mesh as several meshes

precision(propag=3)

numeric coordinate precision of operations on this mesh, allowed by the floating point precision

box()

return the extreme coordinates of the mesh (vec3, vec3)

surface()

total surface of triangles

barycenter()

surface barycenter of the mesh

class Web(points=None, edges=None, tracks=None, groups=None, options=None)

set of bipoint edges, used to represent wires this definition is very close to the definition of Mesh, but with edges instead of triangles

points

list of vec3 for points

edges

list of couples for edges, the couple is oriented (meanings of this depends on the usage)

tracks

integer giving the group each line belong to

groups

custom information for each group

options

custom informations for the entire web

Point container methods

Support for +, += Web

transform(trans)

apply the transform to the points of the mesh, returning the new transformed mesh

flip()

reverse direction of all edges

segmented(group=None)

return a copy of the mesh with a group each edge

if group is specified, it will be the new definition put in each groups

mergepoints(merges)

merge points with the merge dictionnary {src index: dst index} remaining points are not removed

mergeclose(limit=None, start=0)

merge points below the specified distance, or below the precision return a dictionnary of points remapping {src index: dst index}

finish()

finish and clean the mesh note that this operation can cost as much as other transformation operation job done

  • mergeclose

  • strippoints

  • stripgroups

strippoints(used=None)

remove points that are used by no edges, return the reindex list. if used is provided, these points will be removed without usage verification

return a table of the reindex made

stripgroups()

remove groups that are used by no faces, return the reindex list

check methods

check()

check that the internal data references are good (indices and list lengths)

isvalid()

return true if the internal data is consistent (all indices referes to actual points and groups)

isline()

true if each point is used at most 2 times by edges

isloop()

true if the wire form a loop

scan methods

pointat(point, neigh=1e-13)

return the index of the first point at the given location, or None

usepointat(point, neigh=1e-13)

Return the index of the first point in the mesh at the location. If none is found, insert it and return the index

pointnear(point)

return the nearest point the the given location

extraction methods

extremities()

return the points that are used once only (so at wire terminations) 1D equivalent of Mesh.outlines()

groupextremities()

return the extremities of each group. 1D equivalent of Mesh.groupoutlines()

On a frontier between multiple groups, there is as many points as groups, each associated to a group.

frontiers(*args)

return a Wire of points that split the given groups appart.

if groups is None, then return the frontiers between any groups

group(groups)

return a new mesh linked with this one, containing only the faces belonging to the given groups

arcs()

return the contiguous portions of this web

box()

return the extreme coordinates of the mesh (vec3, vec3)

precision(propag=3)

numeric coordinate precision of operations on this mesh, allowed by the floating point precision

length()

total length of edges

barycenter()

curve barycenter of the mesh

class Wire(points=None, indices=None, tracks=None, groups=None, options=None)

Line as continuous suite of points Used to borrow reference of points from a mesh by keeping their original indices

points

points buffer

indices

indices of the line’s points in the buffer

tracks

group index for each point in indices it can be used to associate groups to points or to edges (if to edges, then take care to still have as many track as indices)

groups

data associated to each point (or edge)

Support for item access to underlying points:

__getitem__(i)

return the ith point of the wire, useful to use the wire in a same way as list of points

equivalent to self.points[self.indices[i]]

Point container methods

Support for +, += Wire

transform(trans)

apply the transform to the points of the mesh, returning the new transformed mesh

flip()
segmented(group=None)

return a copy of the mesh with a group each edge

if group is specified, it will be the new definition put in each groups

close()
mergeclose(limit=None)

merge close points ONLY WHEN they are already linked by an edge. the meaning of this method is different than Web.mergeclose()

strippoints()

remove points that are used by no edge, return the reindex list. if used is provided, these points will be removed without usage verification

return a table of the reindex made

check methods

check()

raise if the internal data are not consistent

isvalid()

return True if the internal data are consistent

extraction methods

edges()

list of successive edges of the wire

edge(i)

ith edge of the wire

vertexnormals(loop=False)

return the opposed direction to the curvature in each point this is called normal because it would be the normal to a surface whose section would be that wire

tangents(loop=False)

return approximated tangents to the curve as if it was a surface section. if this is not a loop the result is undefined.

normal()

return an approximated normal to the curve as if it was the outline of a flat surface. if this is not a loop the result is undefined.

length()

curviform length of the wire (sum of all edges length)

barycenter()

curve barycenter

conversion functions

web(*arg)

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)

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

mesh internals manipulation

edgekey(a, b)

return a key for a non-directional edge

facekeyo(a, b, c)

return a key for an oriented face

connpp(ngons)

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

connef(faces)

connectivity dictionnary, from oriented edge to face

lineedges(line, closed=False)

yield the successive couples in line

striplist(list, used)

remove all elements of list that match a False in used, return a reindexation list

line_simplification(web, prec=None)

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

suites(lines, oriented=True, cut=True, loop=False)

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

mesh_distance(m0, m1)

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

Exceptions defined here

exception MeshError