Mesh data

A large part of Nanomesh deals with with generating and manipulating 2D and 3D meshes. To store the data, Nanomesh uses MeshContainer, which is a somewhat low-level, generic container for mesh data. It can store different types of cells and associated data. It is used to read/write data via meshio.

To deal with mesh data more directly, use a Mesh. Instantiating Mesh will create the appropriate subtype, LineMesh, TriangleMesh or TetraMesh. These contain dedicated methods for working with a specific type of mesh and plotting them.

In addition, each can be extracted from MeshContainer.

Classes

nanomesh.MeshContainer(points,Β cells[,Β ...])

Low-level container for storing mesh data.

nanomesh.Mesh(points,Β cells,Β *args,Β **kwargs)

Generic mesh class.

nanomesh.LineMesh(points,Β cells,Β *args,Β **kwargs)

Data class for line meshes.

nanomesh.TriangleMesh(points,Β cells,Β *args,Β ...)

Data class for triangle meshes.

nanomesh.TetraMesh(points,Β cells,Β *args,Β ...)

Data class for tetrahedral meshes.

Reference

class nanomesh.MeshContainer(points: ArrayLike, cells: dict[str, ArrayLike] | list[tuple[str, ArrayLike] | CellBlock], point_data: dict[str, ArrayLike] | None = None, cell_data: dict[str, list[ArrayLike]] | None = None, field_data=None, point_sets: dict[str, ArrayLike] | None = None, cell_sets: dict[str, list[ArrayLike]] | None = None, gmsh_periodic=None, info=None)[source]

Bases: Mesh, PruneZ0Mixin

Low-level container for storing mesh data.

Can contain multiple cell types sharing a set of points. It can store different types of cells and associated data. MeshContainer is based on meshio.Mesh (https://github.com/nschloe/meshio).

Parameters
  • points (numpy.ndarray) – Array storing the mesh points (e.g. vertices)

  • cells (list) – List of cell arrays

  • point_data (todo) –

  • cell_data (todo) –

  • field_data (dict) – Dictionary mapping field names to cell data values.

  • point_sets (todo) –

  • cell_sets (todo) –

  • gmsh_periodic (todo) –

  • info (todo) –

Attributes:

cell_data_dict

cell_sets_dict

cell_types

Return cell types in order.

cells_dict

field_to_number

Mapping from fields to numbers, proxy to MeshContainer.field_data.

number_to_field

Mapping from numbers to fields, proxy to MeshContainer.field_data.

Methods:

cell_data_to_sets(key)

Convert point_data to cell_sets.

cell_sets_to_data([data_name])

copy()

from_mesh(mesh)

Convert from nanomesh.mesh.Mesh to MeshContainer.

from_triangle_dict(triangle_dict)

Return instance of MeshContainer from triangle results dict.

get([cell_type])

Extract mesh with points/cells of cell_type.

get_all_cell_data([cell_type])

Get all cell data for given cell_type.

get_cell_data(name,Β cell_type)

get_cells_type(cell_type)

get_default_type()

Try to return highest dimension type.

plot([cell_type])

Plot data.

plot_itk([cell_type])

Plot data using itk.

plot_mpl([cell_type])

Plot data using matplotlib.

plot_points(**kwargs)

Plot points data using :mod:`matplotlib.

plot_pyvista([cell_type])

Plot data using pyvista.

point_data_to_sets(key)

Convert point_data to point_sets.

point_sets_to_data([join_char])

prune_z_0()

Drop third dimension (z) coordinates if present and all values are equal to 0 (within tolerance).

read(*args,Β **kwargs)

Wrapper for meshio.read().

set_cell_data(cell_type,Β key,Β value)

Set the cell data to the given value.

set_field_data(cell_type,Β field_data)

Update the values in MeshContainer.field_data.

write(filename[,Β file_format])

Thin wrapper of meshio.write to avoid altering class.

property cell_data_dict
cell_data_to_sets(key: str)

Convert point_data to cell_sets.

property cell_sets_dict
cell_sets_to_data(data_name: str | None = None)
property cell_types

Return cell types in order.

property cells_dict
copy()
property field_to_number

Mapping from fields to numbers, proxy to MeshContainer.field_data.

classmethod from_mesh(mesh: Mesh)[source]

Convert from nanomesh.mesh.Mesh to MeshContainer.

Parameters

mesh (Mesh) – Input mesh, must be a subclass of nanomesh.mesh.Mesh.

Return type

MeshContainer

classmethod from_triangle_dict(triangle_dict: dict)[source]

Return instance of MeshContainer from triangle results dict.

Parameters

triangle_dict (dict) – Triangle triangulate output dictionary.

Returns

mesh

Return type

MeshContainer

get(cell_type: Optional[str] = None)[source]

Extract mesh with points/cells of cell_type.

Parameters

cell_type (str, optional) – Element type, such as line, triangle, tetra, etc.

Returns

Mesh of the given type

Return type

Mesh

get_all_cell_data(cell_type: Optional[str] = None) dict[source]

Get all cell data for given cell_type.

Parameters

cell_type (str, optional) – Element type, such as line, triangle, tetra, etc.

Returns

data_dict – Dictionary with cell data

Return type

dict

get_cell_data(name: str, cell_type: str)
get_cells_type(cell_type: str)
get_default_type() str[source]

Try to return highest dimension type.

Default to first type MeshContainer.cells_dict.

Returns

cell_type

Return type

str

property number_to_field

Mapping from numbers to fields, proxy to MeshContainer.field_data.

plot(cell_type: Optional[str] = None, **kwargs)[source]

Plot data.

Parameters
  • cell_type (str, optional) – Cell type to plot.

  • **kwargs – These parameters are passed to plotting method.

plot_itk(cell_type: Optional[str] = None, **kwargs)[source]

Plot data using itk.

Parameters
  • cell_type (str, optional) – Cell type to plot.

  • **kwargs – These parameters are passed to plotting method.

plot_mpl(cell_type: Optional[str] = None, **kwargs)[source]

Plot data using matplotlib.

Parameters
  • cell_type (str, optional) – Cell type to plot.

  • **kwargs – These parameters are passed to plotting method.

plot_points(**kwargs)[source]

Plot points data using :mod:`matplotlib.

Parameters

**kwargs – These parameters are passed to the plotting method.

plot_pyvista(cell_type: Optional[str] = None, **kwargs)[source]

Plot data using pyvista.

Parameters
  • cell_type (str, optional) – Cell type to plot.

  • **kwargs – These parameters are passed to plotting method.

point_data_to_sets(key: str)

Convert point_data to point_sets.

point_sets_to_data(join_char: str = '-') None
prune_z_0()

Drop third dimension (z) coordinates if present and all values are equal to 0 (within tolerance).

For compatibility, sometimes a column with zeroes is added, for example when exporting to gmsh2.2 format. This method drops that column.

classmethod read(*args, **kwargs) MeshContainer[source]

Wrapper for meshio.read().

For gmsh:

  • remaps gmsh:physical -> physical

  • remaps gmsh:geometrical -> geometrical

Parameters
  • *args – These parameters passed to reader

  • **kwargs – These parameters are passed to the reader

Return type

MeshContainer

set_cell_data(cell_type: str, key: str, value: ndarray)[source]

Set the cell data to the given value.

Updates MeshContainer.cell_data.

Parameters
set_field_data(cell_type: str, field_data: Dict[int, str])[source]

Update the values in MeshContainer.field_data.

Parameters
  • cell_type (str) – Cell type to update the values for.

  • field_data (dict) – Dictionary with key-to-number mapping, i.e. field_data={0: β€˜green’, 1: β€˜blue’, 2: β€˜red’} maps 0 to green, etc.

write(filename, file_format: Optional[str] = None, **kwargs)[source]

Thin wrapper of meshio.write to avoid altering class.

For gmsh: - remaps physical -> gmsh:physical - remaps geometrical -> gmsh:geometrical

Parameters
  • filename (str) – File to write to.

  • file_format (str, optional) – Specify file format. By default, this is guessed from the extension.

  • **kwargs – These parameters are passed to meshio.write().

class nanomesh.Mesh(points: ndarray, cells: ndarray, *args, **kwargs)[source]

Bases: object

Generic mesh class.

Depending on the number of dimensions of the cells, the appropriate subclass will be chosen if possible.

Parameters
  • points ((m, n) numpy.ndarray[float]) – Array with points.

  • cells ((i, j) numpy.ndarray[int]) – Index array describing the cells of the mesh.

  • fields (Dict[str, int]:) – Mapping from field names to labels

  • region_markers (RegionMarkerList, optional) – List of region markers used for assigning labels to regions. Defaults to an empty list.

  • **cell_data – Additional cell data. Argument must be a 1D numpy array matching the number of cells defined by i.

Attributes:

cell_centers

Return centers of cells (mean of corner points).

cell_type

dimensions

Return number of dimensions for point data.

labels

Shortcut for cell labels.

number_to_field

Mapping from numbers to fields, proxy to {classname}.field_to_number.

zero_labels

Return zero labels as fallback.

Methods:

crop([xmin,Β xmax,Β ymin,Β ymax,Β zmin,Β zmax,Β ...])

Crop mesh to given region.

from_meshio(mesh)

Return {classname} from meshio object.

get_cell_data(key[,Β default_value])

Get cell data with optional default value.

plot(**kwargs)

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

plot_mpl(**kwargs)

plot_pyvista(**kwargs)

Wrapper for pyvista.plot().

read(filename,Β **kwargs)

Simple wrapper around meshio.read().

remove_cells(*,Β label[,Β key])

Remove cells with cell data matching given label.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

to_meshio()

Return instance of meshio.Mesh().

to_pyvista_unstructured_grid()

Return instance of pyvista.UnstructuredGrid.

write(*args,Β **kwargs)

Simple wrapper around meshio.write().

property cell_centers

Return centers of cells (mean of corner points).

cell_type: str = 'generic'
crop(xmin: float = -inf, xmax: float = inf, ymin: float = -inf, ymax: float = inf, zmin: float = -inf, zmax: float = inf, include_partial: bool = False)[source]

Crop mesh to given region.

Parameters
  • xmin (float, optional) – Minimum x value.

  • xmax (float, optional) – Maximum x value.

  • ymin (float, optional) – Minimum y value.

  • ymax (float, optional) – Maximum y value.

  • zmin (float, optional) – Minimum z value (3D point data only).

  • zmax (float, optional) – Maximum z value (3D point data only).

  • include_partial (bool, optional) – If True, include cells that are partially inside the given crop region, i.e. one of its points is inside.

Returns

cropped_mesh – Cropped mesh

Return type

{classname}

property dimensions: int

Return number of dimensions for point data.

classmethod from_meshio(mesh: meshio.Mesh)[source]

Return {classname} from meshio object.

get_cell_data(key: str, default_value: float = 0) ndarray[source]

Get cell data with optional default value.

Parameters
  • key (str) – Key of the cell data to retrieve.

  • default_value (float, optional) – Optional default value (if cell data does not exist)

Return type

numpy.ndarray

property labels: ndarray

Shortcut for cell labels.

property number_to_field

Mapping from numbers to fields, proxy to {classname}.field_to_number.

plot(**kwargs)[source]
plot_itk(**kwargs)[source]

Wrapper for pyvista.plot_itk().

Parameters

**kwargs – These parameters are passed to pyvista.plot_itk()

plot_mpl(**kwargs)[source]
plot_pyvista(**kwargs)[source]

Wrapper for pyvista.plot().

Parameters

**kwargs – These parameters are passed to pyvista.plot()

classmethod read(filename, **kwargs)[source]

Simple wrapper around meshio.read().

remove_cells(*, label: int, key: Optional[str] = None)[source]

Remove cells with cell data matching given label.

Parameters
  • label (int) – All cells with this label will be removed.

  • key (str, optional) – The key of the cell data to use. Uses Mesh.default_key if None.

remove_loose_points()[source]

Remove points that do not belong to any cells.

reverse_cell_order()[source]

Reverse order of cells and cell data.

Updates {classname}.cell_data.

to_meshio() meshio.Mesh[source]

Return instance of meshio.Mesh().

to_pyvista_unstructured_grid() pv.PolyData[source]

Return instance of pyvista.UnstructuredGrid.

References

https://docs.pyvista.org/core/point-grids.html#pv-unstructured-grid-class-methods

write(*args, **kwargs)[source]

Simple wrapper around meshio.write().

property zero_labels: ndarray

Return zero labels as fallback.

class nanomesh.LineMesh(points: ndarray, cells: ndarray, *args, **kwargs)[source]

Bases: Mesh

Data class for line meshes.

Depending on the number of dimensions of the cells, the appropriate subclass will be chosen if possible.

Parameters
  • points ((m, 2 or 3) numpy.ndarray[float]) – Array with points.

  • cells ((i, 2) numpy.ndarray[int]) – Index array describing the cells of the mesh.

  • fields (Dict[str, int]:) – Mapping from field names to labels

  • region_markers (RegionMarkerList, optional) – List of region markers used for assigning labels to regions. Defaults to an empty list.

  • **cell_data – Additional cell data. Argument must be a 1D numpy array matching the number of cells defined by i.

Attributes:

cell_centers

Return centers of cells (mean of corner points).

cell_type

dimensions

Return number of dimensions for point data.

labels

Shortcut for cell labels.

number_to_field

Mapping from numbers to fields, proxy to LineMesh.field_to_number.

zero_labels

Return zero labels as fallback.

Methods:

crop([xmin,Β xmax,Β ymin,Β ymax,Β zmin,Β zmax,Β ...])

Crop mesh to given region.

from_meshio()

Return LineMesh from meshio object.

get_cell_data(key[,Β default_value])

Get cell data with optional default value.

label_boundaries([left,Β right,Β top,Β bottom,Β key])

Labels the boundaries of the mesh with the given value.

plot(*args,Β **kwargs)

Simple line mesh plot using matplotlib.

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

plot_mpl(*args,Β **kwargs)

Simple line mesh plot using matplotlib.

plot_pyvista(**kwargs)

Wrapper for pyvista.plot().

read(filename,Β **kwargs)

Simple wrapper around meshio.read().

remove_cells(*,Β label[,Β key])

Remove cells with cell data matching given label.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

to_meshio()

Return instance of meshio.Mesh().

to_pyvista_unstructured_grid()

Return instance of pyvista.UnstructuredGrid.

triangulate([opts])

write(*args,Β **kwargs)

Simple wrapper around meshio.write().

property cell_centers

Return centers of cells (mean of corner points).

cell_type: str = 'line'
crop(xmin: float = -inf, xmax: float = inf, ymin: float = -inf, ymax: float = inf, zmin: float = -inf, zmax: float = inf, include_partial: bool = False)

Crop mesh to given region.

Parameters
  • xmin (float, optional) – Minimum x value.

  • xmax (float, optional) – Maximum x value.

  • ymin (float, optional) – Minimum y value.

  • ymax (float, optional) – Maximum y value.

  • zmin (float, optional) – Minimum z value (3D point data only).

  • zmax (float, optional) – Maximum z value (3D point data only).

  • include_partial (bool, optional) – If True, include cells that are partially inside the given crop region, i.e. one of its points is inside.

Returns

cropped_mesh – Cropped mesh

Return type

LineMesh

property dimensions: int

Return number of dimensions for point data.

classmethod from_meshio()

Return LineMesh from meshio object.

get_cell_data(key: str, default_value: float = 0) ndarray

Get cell data with optional default value.

Parameters
  • key (str) – Key of the cell data to retrieve.

  • default_value (float, optional) – Optional default value (if cell data does not exist)

Return type

numpy.ndarray

label_boundaries(left: Optional[int | str] = None, right: Optional[int | str] = None, top: Optional[int | str] = None, bottom: Optional[int | str] = None, key: str = None)[source]

Labels the boundaries of the mesh with the given value.

Parameters
  • left (int | str, optional) – Labels left boundary segments with the given value. If a string is passed, the LineMesh.fields attribute is updated with the field / value pair.

  • right (int | str, optional) – Same as above.

  • top (int | str, optional) – Same as above.

  • bottom (int | str, optional) – Same as above.

  • key (str, optional) – Key of the LineMesh.cell_data dictionary to update. Defaults to LineMesh.default_key.

property labels: ndarray

Shortcut for cell labels.

property number_to_field

Mapping from numbers to fields, proxy to LineMesh.field_to_number.

plot(*args, **kwargs)[source]

Simple line mesh plot using matplotlib.

Shortcut for plotting.linemeshplot().

Parameters
Return type

plt.Axes

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

Parameters

**kwargs – These parameters are passed to pyvista.plot_itk()

plot_mpl(*args, **kwargs) Axes[source]

Simple line mesh plot using matplotlib.

Shortcut for plotting.linemeshplot().

Parameters
Return type

plt.Axes

plot_pyvista(**kwargs)

Wrapper for pyvista.plot().

Parameters

**kwargs – These parameters are passed to pyvista.plot()

classmethod read(filename, **kwargs)

Simple wrapper around meshio.read().

remove_cells(*, label: int, key: Optional[str] = None)

Remove cells with cell data matching given label.

Parameters
  • label (int) – All cells with this label will be removed.

  • key (str, optional) – The key of the cell data to use. Uses Mesh.default_key if None.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

Updates LineMesh.cell_data.

to_meshio() meshio.Mesh

Return instance of meshio.Mesh().

to_pyvista_unstructured_grid() pv.PolyData

Return instance of pyvista.UnstructuredGrid.

References

https://docs.pyvista.org/core/point-grids.html#pv-unstructured-grid-class-methods

triangulate(opts: str = 'pq30Aa100', **kwargs) MeshContainer[source]
write(*args, **kwargs)

Simple wrapper around meshio.write().

property zero_labels: ndarray

Return zero labels as fallback.

class nanomesh.TriangleMesh(points: ndarray, cells: ndarray, *args, **kwargs)[source]

Bases: Mesh, PruneZ0Mixin

Data class for triangle meshes.

Depending on the number of dimensions of the cells, the appropriate subclass will be chosen if possible.

Parameters
  • points ((m, 2 or 3) numpy.ndarray[float]) – Array with points.

  • cells ((i, 3) numpy.ndarray[int]) – Index array describing the cells of the mesh.

  • fields (Dict[str, int]:) – Mapping from field names to labels

  • region_markers (RegionMarkerList, optional) – List of region markers used for assigning labels to regions. Defaults to an empty list.

  • **cell_data – Additional cell data. Argument must be a 1D numpy array matching the number of cells defined by i.

Attributes:

cell_centers

Return centers of cells (mean of corner points).

cell_type

dimensions

Return number of dimensions for point data.

labels

Shortcut for cell labels.

number_to_field

Mapping from numbers to fields, proxy to TriangleMesh.field_to_number.

zero_labels

Return zero labels as fallback.

Methods:

crop([xmin,Β xmax,Β ymin,Β ymax,Β zmin,Β zmax,Β ...])

Crop mesh to given region.

from_meshio()

Return TriangleMesh from meshio object.

from_open3d(mesh)

Return instance of TriangleMesh from open3d.

from_scipy(mesh)

Return instance of TriangleMesh from scipy.spatial.Delaunay object.

from_triangle_dict(dct)

Return instance of TriangleMesh from triangle results dict.

from_trimesh(mesh)

Return instance of TriangleMesh from trimesh.

get_cell_data(key[,Β default_value])

Get cell data with optional default value.

optimize(*[,Β method,Β tol,Β max_num_steps])

Optimize mesh using optimesh.

plot(**kwargs)

Shortcut for TriangleMesh.plot_mpl() or TriangleMesh.plot_itk() depending on dimensions.

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

plot_mpl(*args,Β **kwargs)

Simple triangle mesh plot using :mod:matplotlib.

plot_pyvista(**kwargs)

Wrapper for pyvista.plot().

prune_z_0()

Drop third dimension (z) coordinates if present and all values are equal to 0 (within tolerance).

read(filename,Β **kwargs)

Simple wrapper around meshio.read().

remove_cells(*,Β label[,Β key])

Remove cells with cell data matching given label.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

tetrahedralize(**kwargs)

Tetrahedralize mesh using tetrahedralize().

to_meshio()

Return instance of meshio.Mesh().

to_open3d()

Return instance of open3d.geometry.TriangleMesh.

to_polydata()

Return instance of pyvista.Polydata.

to_pyvista_unstructured_grid()

Return instance of pyvista.UnstructuredGrid.

to_trimesh()

Return instance of trimesh.Trimesh.

write(*args,Β **kwargs)

Simple wrapper around meshio.write().

property cell_centers

Return centers of cells (mean of corner points).

cell_type: str = 'triangle'
crop(xmin: float = -inf, xmax: float = inf, ymin: float = -inf, ymax: float = inf, zmin: float = -inf, zmax: float = inf, include_partial: bool = False)

Crop mesh to given region.

Parameters
  • xmin (float, optional) – Minimum x value.

  • xmax (float, optional) – Maximum x value.

  • ymin (float, optional) – Minimum y value.

  • ymax (float, optional) – Maximum y value.

  • zmin (float, optional) – Minimum z value (3D point data only).

  • zmax (float, optional) – Maximum z value (3D point data only).

  • include_partial (bool, optional) – If True, include cells that are partially inside the given crop region, i.e. one of its points is inside.

Returns

cropped_mesh – Cropped mesh

Return type

TriangleMesh

property dimensions: int

Return number of dimensions for point data.

classmethod from_meshio()

Return TriangleMesh from meshio object.

classmethod from_open3d(mesh: open3d.geometry.TriangleMesh) TriangleMesh[source]

Return instance of TriangleMesh from open3d.

classmethod from_scipy(mesh: scipy.spatial.qhull.Delaunay) TriangleMesh[source]

Return instance of TriangleMesh from scipy.spatial.Delaunay object.

classmethod from_triangle_dict(dct: dict) TriangleMesh[source]

Return instance of TriangleMesh from triangle results dict.

classmethod from_trimesh(mesh) TriangleMesh[source]

Return instance of TriangleMesh from trimesh.

get_cell_data(key: str, default_value: float = 0) ndarray

Get cell data with optional default value.

Parameters
  • key (str) – Key of the cell data to retrieve.

  • default_value (float, optional) – Optional default value (if cell data does not exist)

Return type

numpy.ndarray

property labels: ndarray

Shortcut for cell labels.

property number_to_field

Mapping from numbers to fields, proxy to TriangleMesh.field_to_number.

optimize(*, method='CVT (block-diagonal)', tol: float = 0.001, max_num_steps: int = 10, **kwargs) TriangleMesh[source]

Optimize mesh using optimesh.

Parameters
  • method (str, optional) – Method name

  • tol (float, optional) – Tolerance

  • max_num_steps (int, optional) – Maximum number of optimization steps.

  • **kwargs – Arguments to pass to optimesh.optimize_points_cells()

Return type

TriangleMesh

plot(**kwargs)[source]

Shortcut for TriangleMesh.plot_mpl() or TriangleMesh.plot_itk() depending on dimensions.

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

Parameters

**kwargs – These parameters are passed to pyvista.plot_itk()

plot_mpl(*args, **kwargs) Axes[source]

Simple triangle mesh plot using :mod:matplotlib. See plotting.trianglemeshplot() for details.

Parameters
Return type

plt.Axes

plot_pyvista(**kwargs)

Wrapper for pyvista.plot().

Parameters

**kwargs – These parameters are passed to pyvista.plot()

prune_z_0()

Drop third dimension (z) coordinates if present and all values are equal to 0 (within tolerance).

For compatibility, sometimes a column with zeroes is added, for example when exporting to gmsh2.2 format. This method drops that column.

classmethod read(filename, **kwargs)

Simple wrapper around meshio.read().

remove_cells(*, label: int, key: Optional[str] = None)

Remove cells with cell data matching given label.

Parameters
  • label (int) – All cells with this label will be removed.

  • key (str, optional) – The key of the cell data to use. Uses Mesh.default_key if None.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

Updates TriangleMesh.cell_data.

tetrahedralize(**kwargs) MeshContainer[source]

Tetrahedralize mesh using tetrahedralize().

Parameters
  • mesh (TriangleMesh) – Input contour mesh

  • opts (str, optional) –

    Command-line options passed to tetgen.

    More info: http://wias-berlin.de/software/tetgen/1.5/doc/manual/manual005.html

    Some useful flags:

    • -A: Assigns attributes to tetrahedra in different regions.

    • -p: Tetrahedralizes a piecewise linear complex (PLC).

    • -q: Refines mesh (to improve mesh quality).

    • -a: Applies a maximum tetrahedron volume constraint.

    Can be passed as a raw string, opts=’-pAq1.2’, or dict, `opts=dict(β€˜p’= True, β€˜A’= True, β€˜q’=1.2).

  • default_opts (dict, optional) – Dictionary with default options. These will be merged with opts.

Returns

Tetrahedralized mesh.

Return type

MeshContainer

to_meshio() meshio.Mesh

Return instance of meshio.Mesh().

to_open3d() open3d.geometry.TriangleMesh[source]

Return instance of open3d.geometry.TriangleMesh.

to_polydata() pv.PolyData[source]

Return instance of pyvista.Polydata.

to_pyvista_unstructured_grid() pv.PolyData

Return instance of pyvista.UnstructuredGrid.

References

https://docs.pyvista.org/core/point-grids.html#pv-unstructured-grid-class-methods

to_trimesh()[source]

Return instance of trimesh.Trimesh.

write(*args, **kwargs)

Simple wrapper around meshio.write().

property zero_labels: ndarray

Return zero labels as fallback.

class nanomesh.TetraMesh(points: ndarray, cells: ndarray, *args, **kwargs)[source]

Bases: Mesh

Data class for tetrahedral meshes.

Depending on the number of dimensions of the cells, the appropriate subclass will be chosen if possible.

Parameters
  • points ((m, 3) numpy.ndarray[float]) – Array with points.

  • cells ((i, 4) numpy.ndarray[int]) – Index array describing the cells of the mesh.

  • fields (Dict[str, int]:) – Mapping from field names to labels

  • region_markers (RegionMarkerList, optional) – List of region markers used for assigning labels to regions. Defaults to an empty list.

  • **cell_data – Additional cell data. Argument must be a 1D numpy array matching the number of cells defined by i.

Attributes:

cell_centers

Return centers of cells (mean of corner points).

cell_type

dimensions

Return number of dimensions for point data.

labels

Shortcut for cell labels.

number_to_field

Mapping from numbers to fields, proxy to TetraMesh.field_to_number.

zero_labels

Return zero labels as fallback.

Methods:

crop([xmin,Β xmax,Β ymin,Β ymax,Β zmin,Β zmax,Β ...])

Crop mesh to given region.

from_meshio()

Return TetraMesh from meshio object.

from_open3d(mesh)

Return instance of TetraMesh from open3d.

from_pyvista_unstructured_grid(grid)

Return infance of TetraMesh from pyvista.UnstructuredGrid.

get_cell_data(key[,Β default_value])

Get cell data with optional default value.

plot(**kwargs)

Shortcut for TetraMesh.plot_pyvista().

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

plot_mpl(**kwargs)

plot_pyvista(**kwargs)

Show grid using pyvista.

plot_submesh([index,Β along,Β invert,Β show,Β ...])

Show submesh using pyvista.

read(filename,Β **kwargs)

Simple wrapper around meshio.read().

remove_cells(*,Β label[,Β key])

Remove cells with cell data matching given label.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

to_meshio()

Return instance of meshio.Mesh().

to_open3d()

Return instance of open3d.geometry.TetraMesh.

to_pyvista_unstructured_grid()

Return instance of pyvista.UnstructuredGrid.

write(*args,Β **kwargs)

Simple wrapper around meshio.write().

property cell_centers

Return centers of cells (mean of corner points).

cell_type: str = 'tetra'
crop(xmin: float = -inf, xmax: float = inf, ymin: float = -inf, ymax: float = inf, zmin: float = -inf, zmax: float = inf, include_partial: bool = False)

Crop mesh to given region.

Parameters
  • xmin (float, optional) – Minimum x value.

  • xmax (float, optional) – Maximum x value.

  • ymin (float, optional) – Minimum y value.

  • ymax (float, optional) – Maximum y value.

  • zmin (float, optional) – Minimum z value (3D point data only).

  • zmax (float, optional) – Maximum z value (3D point data only).

  • include_partial (bool, optional) – If True, include cells that are partially inside the given crop region, i.e. one of its points is inside.

Returns

cropped_mesh – Cropped mesh

Return type

TetraMesh

property dimensions: int

Return number of dimensions for point data.

classmethod from_meshio()

Return TetraMesh from meshio object.

classmethod from_open3d(mesh) TetraMesh[source]

Return instance of TetraMesh from open3d.

classmethod from_pyvista_unstructured_grid(grid: pv.UnstructuredGrid)[source]

Return infance of TetraMesh from pyvista.UnstructuredGrid.

get_cell_data(key: str, default_value: float = 0) ndarray

Get cell data with optional default value.

Parameters
  • key (str) – Key of the cell data to retrieve.

  • default_value (float, optional) – Optional default value (if cell data does not exist)

Return type

numpy.ndarray

property labels: ndarray

Shortcut for cell labels.

property number_to_field

Mapping from numbers to fields, proxy to TetraMesh.field_to_number.

plot(**kwargs)[source]

Shortcut for TetraMesh.plot_pyvista().

plot_itk(**kwargs)

Wrapper for pyvista.plot_itk().

Parameters

**kwargs – These parameters are passed to pyvista.plot_itk()

plot_mpl(**kwargs)
plot_pyvista(**kwargs)[source]

Show grid using pyvista.

Parameters

**kwargs – These parameters are first passed to pyvista.plot() and then to pyvista.Plotter().add_mesh().

plot_submesh(index: Optional[int] = None, along: str = 'x', invert: bool = False, show: bool = True, backend: Optional[str] = None, **kwargs)[source]

Show submesh using pyvista.

Parameters
  • index (int, optional) – Index of where to cut the mesh. Shows all tetrahedra with cell center < index. Picks the half-way point along the axis by default.

  • along (str, optional) – Direction along which to cut.

  • invert (bool, optional) – Invert the cutting operation, and show all tetrahedra with cell center > index.

  • show (bool, optional) – If true, show the plot

  • **kwargs – Keyword arguments passed to pyvista.Plotter.add_mesh().

  • plotter (pyvista.Plotter) – Return plotter instance.

classmethod read(filename, **kwargs)

Simple wrapper around meshio.read().

remove_cells(*, label: int, key: Optional[str] = None)

Remove cells with cell data matching given label.

Parameters
  • label (int) – All cells with this label will be removed.

  • key (str, optional) – The key of the cell data to use. Uses Mesh.default_key if None.

remove_loose_points()

Remove points that do not belong to any cells.

reverse_cell_order()

Reverse order of cells and cell data.

Updates TetraMesh.cell_data.

to_meshio() meshio.Mesh

Return instance of meshio.Mesh().

to_open3d()[source]

Return instance of open3d.geometry.TetraMesh.

to_pyvista_unstructured_grid() pv.PolyData

Return instance of pyvista.UnstructuredGrid.

References

https://docs.pyvista.org/core/point-grids.html#pv-unstructured-grid-class-methods

write(*args, **kwargs)

Simple wrapper around meshio.write().

property zero_labels: ndarray

Return zero labels as fallback.