mesh -- Meshes and discretised objects¶
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
vec3it 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)
¶
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
Source code in madcad/mesh/conversions.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
web(*arg, resolution=None)
¶
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
Source code in madcad/mesh/conversions.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
wire(*arg, resolution=None)
¶
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
Source code in madcad/mesh/conversions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
typedlist_to_numpy(array, dtype)
¶
Convert a typedlist to a numpy.ndarray with the given dtype, if the conversion is possible term to term
Source code in madcad/mesh/container.py
267 268 269 270 271 272 273 | |
numpy_to_typedlist(array, dtype)
¶
Convert a numpy.ndarray into a typedlist with the given dtype, if the conversion is possible term to term
Source code in madcad/mesh/container.py
259 260 261 262 263 264 265 | |
ensure_typedlist(obj, dtype)
¶
Return a typedlist with the given dtype, create it from whatever is in obj if needed
Source code in madcad/mesh/container.py
275 276 277 278 279 280 | |
Misc¶
MeshError
¶
Bases: Exception
Inconsistent data in mesh
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
Source code in madcad/mesh/__init__.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
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
Source code in madcad/mesh/__init__.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
distance2_pm(point, mesh)
¶
squared distance from a point to a mesh
Source code in madcad/mesh/__init__.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |