morphogen.viz.surfaces¶
Triangle surfaces of morphologies and of the fields of simulations, for the 3D view of
the interface (morphogen.gui), with the volumes that colour the faces of the box
and the sections of that view.
A Surface is made of triangles in groups, each lying between two regions:
the one behind its triangles (inside) and the one in front of them (outside, -1
beyond the box). Its triangles turn counter-clockwise around their normal, which points
from inside to outside, so that a view of opaque regions draws, on each side of a
triangle, the region that a ray entering through it meets: the inside seen from the
front, the outside seen from the back (and the inside again behind the faces of the box,
whose shell is then seen from within, through a section). Between two regions, the
inside is the larger of the two. The regions are the phases of a morphology, or its
cells (grains) with their phases (Surface.region_phase,
Surface.region_label).
What the surfaces are:
morphologies with a level set (two phases): its zero level set by the marching cubes of scikit-image (the
surfaceextra), sampled at the centres of the voxels ofresolutioncells along the longest edge of the domain (asmorphogen.viz.sections.level_set_measures()), padded by one cell on every side (periodically, or by its last values) and cut by the faces of the box; without scikit-image, the faces of its voxels of phase 1. The level set is the volume of the view (Surface.volume), which draws the phases on the faces of the box and on a section;tessellations without grain boundaries (Voronoi and Laguerre polycrystals): the exact facets of their cells (
cell_complex()), between cells and on the faces of the box; their voxels give the sections;the other morphologies (cells or grains, several phases, no level set): the faces between voxels of different regions, those regions being the volume;
simulations on tetrahedral meshes (
vtu_surface()): the faces of the elements on the boundary of the mesh and between regions (phases, grains), with the field at their vertices (the nodal values, or on each side the mean of the values of the elements of that region around the node) and the displacement of their nodes;simulations on voxels (FFT,
vti_surface()): the faces between voxels of different regions; the regions and the field of the voxels are volumes.
The number of triangles is bounded (max_triangles, MAX_TRIANGLES by default):
the grids of morphologies are made coarser, voxel images subsampled, meshes simplified by
clustering their vertices. encode() turns a surface into the JSON data of the page,
its arrays in base64 (little-endian).
- morphogen.viz.surfaces.MAX_TRIANGLES = 300000¶
Largest number of triangles of a surface (the 3D view stays fluid with it)
- morphogen.viz.surfaces.MAX_VOLUME = 128¶
Largest number of cells along an edge of a volume (and of the voxel faces drawn)
- morphogen.viz.surfaces.MIN_RESOLUTION = 8¶
Coarsest grid (cells along the longest edge) to which a budget lowers a resolution
- morphogen.viz.surfaces.MAX_EXACT_CELLS = 500¶
Tessellations of more cells are drawn by their voxels (their exact cells take long)
- morphogen.viz.surfaces.EXTERIOR = -1¶
Region beyond the faces of the box
- morphogen.viz.surfaces.NOT_FIELDS = ('phase', 'grain', 'cell', 'euler', 'outer', 'fluctuation')¶
Arrays of the files of fields that are not fields (phases, grains, orientations…)
- class morphogen.viz.surfaces.Volume(kind: str, data: ndarray, periodic: bool = False, step: float = 1.0, range: tuple[float, float] | None = None, box: bool = True)[source]¶
Bases:
objectValues on the cells of a regular grid of the box (arrays
[i, j, k]along x, y and z, encoded x fastest), which colour the faces of the box (whenbox) and the sections of the 3D view.kind:"level_set"(negative in phase 1, quantized on 8 bits,phi = step (q - 128), interpolated linearly between the cell centres, across the faces of the box whenperiodic),"regions"(the region of each cell) or"field"(values quantized on 16 bits overrange:value = lo + q (hi - lo) / 65535).
- class morphogen.viz.surfaces.Surface(positions: ndarray, normals: ndarray, triangles: ndarray, groups: ndarray, region_phase: ndarray, region_label: ndarray | None, lower: ndarray, upper: ndarray, method: str, resolution: int | None = None, reduced: bool = False, volume: Volume | None = None, field: str | None = None, fields: list[str] = <factory>, values: ndarray | None = None, field_volume: Volume | None = None, field_range: tuple[float, float] | None=None, point_field: bool = False, displacement: ndarray | None = None, lattice: tuple | None = None)[source]¶
Bases:
objectTriangles in groups between regions (see the module).
- positions, normals
Vertices (n, 3) and their unit normals, from inside to outside.
- triangles¶
Vertex indices (m, 3), counter-clockwise around the normals.
- Type:
numpy.ndarray
- groups¶
One row per group (g, 6): inside and outside regions, first vertex and number of vertices, first triangle and number of triangles (vertices and triangles are stored group after group; vertices are not shared between groups).
- Type:
numpy.ndarray
- region_phase, region_label
Phase of each region, and its cell or grain (None without labels; -1: none).
- lower, upper
The box.
- method¶
How the triangles were made:
"marching cubes","cells"(exact facets),"voxels"(voxel faces) or"mesh"(faces of a tetrahedral mesh).- Type:
str
- resolution¶
Cells along the longest edge of the grid used (None for meshes and cells).
- Type:
int | None
- reduced¶
Whether the grid was made coarser, or the mesh simplified, to fit the budget.
- Type:
bool
- field, fields
Field drawn and the fields available (simulations).
- values¶
Field at the vertices (n, 2): seen from the inside, from the outside.
- Type:
numpy.ndarray | None
- field_volume¶
Field of the cells (voxel images), quantized over
field_range.- Type:
- field_range¶
Smallest and largest finite values of the field (all its elements or voxels).
- Type:
tuple[float, float] | None
- point_field¶
Whether the field is nodal (otherwise of the elements or voxels).
- Type:
bool
- displacement¶
Displacement of the vertices (n, 3), or None.
- Type:
numpy.ndarray | None
- lattice¶
Voxel faces: the nodes of their grid along each edge, and the node (C order) and the direction of the normal (
DIRECTIONS) of each vertex, which encode them compactly; None otherwise.- Type:
tuple | None
- property n_triangles: int¶
- property n_vertices: int¶
- morphogen.viz.surfaces.DIRECTIONS = array([[ 1., 0., 0.], [-1., 0., 0.], [ 0., 1., 0.], [ 0., -1., 0.], [ 0., 0., 1.], [ 0., 0., -1.]])¶
+x, -x, +y, -y, +z, -z
- Type:
Directions of the normals of voxel faces
- morphogen.viz.surfaces.voxel_surface(regions: ndarray, region_phase, region_label=None, lower=(0.0, 0.0, 0.0), upper=(1.0, 1.0, 1.0), *, values: ndarray | None = None, field: str | None = None, fields=(), max_triangles: int = 300000, method: str = 'voxels') Surface[source]¶
The faces between voxels of different regions of an image of regions (cells of the box
[lower, upper]), subsampled when its faces exceedmax_trianglesor its edgesMAX_VOLUMEcells; the regions and thevaluesof a field of the voxels are its volumes (the field:Surface.field_volume).
- morphogen.viz.surfaces.morphology_surface(micro, resolution: int = 96, *, max_triangles: int = 300000, method: str = 'auto') Surface[source]¶
The surface of a morphology between its regions, on a grid of
resolutioncells along the longest edge of its domain (coarser if it exceedsmax_triangles).method:"marching cubes"of the level set (two phases),"cells"(exact facets of tessellations),"voxels"(faces between voxels of different regions), or"auto": the cells of tessellations without grain boundaries, the voxels of morphologies with cells or grains, several phases or no level set, the marching cubes of the others (their voxels without scikit-image). See the module.
- morphogen.viz.surfaces.mesh_surface(nodes, elements, regions, region_phase, region_label=None, lower=None, upper=None, *, values=None, field: str | None = None, fields=(), displacement=None, resolution: int | None = 96, max_triangles: int = 300000) Surface[source]¶
The faces of a tetrahedral mesh (corners of
elements) on its boundary and betweenregionsof elements, with a field (values: one per node, or one per element, averaged at the nodes in each region) and thedisplacementof the nodes.Vertices are shared by the faces of a group on the same face of the box (or inside it), whose normals they average. The volumes of the sections are the regions and the field of the cells of a grid of
resolutioncells along the longest edge (None: none), from the elements containing their centres. A surface beyondmax_trianglesis simplified by clustering its vertices (_clustered()).
- morphogen.viz.surfaces.vtu_surface(path, field: str | None = None, *, resolution: int | None = 96, max_triangles: int = 300000) Surface[source]¶
The surface of the fields of a simulation on a tetrahedral mesh (a
.vtufile ofmorphogen.io.write_vtu_tet()): its faces between its phases (and grains, thecellarray of polycrystals),fieldat their vertices (by default the von Mises stress, else its first field;"displacement": its norm) and the displacement of their nodes; its volumes for the sections (mesh_surface()).
- morphogen.viz.surfaces.vti_surface(path, field: str | None = None, *, phases=None, morphology=None, max_triangles: int = 300000) Surface[source]¶
The surface of the fields of a simulation on voxels (a
.vtifile of fields): the faces between its phases and grains (grain) andfieldof the voxels as a volume (by default the von Mises stress, else its first field). The phases are thephasearray of the file, elsephases(an image of the same shape), else those ofmorphologyvoxelized on the grid of the file, else a single phase. Only the arrays needed are read.
- morphogen.viz.surfaces.SHOWN_TAIL = 0.01¶
The share of the values of a field left beyond each end of its default colour scale
- morphogen.viz.surfaces.magnification(surface: Surface) float | None[source]¶
The magnification of the displacement drawing the largest one as a tenth of the box (as the videos of
morphogen.viz.video), None without displacement.
- morphogen.viz.surfaces.encode(surface: Surface) dict[source]¶
JSON data of a surface for the page: its arrays in base64, little-endian (
positions,normals, fieldvaluesanddisplacementin float32,indicesin uint32, the volumes in unsigned integers, x fastest; voxel faces give the node and the direction of each vertex instead of its position and normal,lattice), its groups, the phase, label and colours of its regions (those of the sections,morphogen.viz.png.PALETTE, and of their cells).