nanomesh.image2mesh.mesher2d

Classes:

Polygon(points)

Functions:

pad(mesh,Β *,Β side,Β width[,Β label,Β name])

Pad a triangle mesh (2D).

plane2mesh(image,Β *[,Β level,Β max_edge_dist,Β ...])

Generate a triangular mesh from a 2D segmented image.

class nanomesh.image2mesh._mesher2d.Polygon(points: numpy.ndarray)[source]

Bases: object

Methods:

approximate(*args,Β **kwargs)

Approximate polygon.

close_corner(shape)

Check if polygons are in the corner, and close them if needed.

contains_point(point)

Test whether point lies inside polygon.

contains_points(points)

Test whether points lie inside polygon.

find_point()

Use rejection sampling to find point in polygon.

remove_duplicate_points()

Remove duplicate points from polygon.

subdivide([max_dist,Β plot])

This algorithm looks for long edges in the polygon and subdivides them so they are no longer than max_dist

Attributes:

points

approximate(*args, **kwargs) Polygon[source]

Approximate polygon.

Parameters
  • *args (list) – Extra arguments padded to skimage.measure.approximate_polygon.

  • **kwargs – These parameters are passed to skimage.measure.approximate_polygon.

Returns

new_polygon

Return type

Polygon

close_corner(shape: tuple) Polygon[source]

Check if polygons are in the corner, and close them if needed.

Polygons which cover a corner cannot be closed by joining the first and last element, because some of the area is missed. This algorithm adds the corner point to close the polygons.

Parameters

shape (tuple) – Shape of the source image. Used to check which corners the polygon touches.

Returns

polygon – Return a polygon with a corner point added if needed (n+1,2), otherwise return the input polygon (n,2)

Return type

Polygon

contains_point(point: ndarray) bool[source]

Test whether point lies inside polygon.

Parameters

point ((2,) numpy.ndarray) – Point coordinates

Returns

True if corresponding point is inside the polygon

Return type

bool

contains_points(points: ndarray) ndarray[source]

Test whether points lie inside polygon.

Parameters

points ((n,2) numpy.ndarray) – List of points

Returns

mask – Boolean array where true corresponds to points lying inside the polygon

Return type

(n,) numpy.ndarray[bool]

find_point() ndarray[source]

Use rejection sampling to find point in polygon.

Returns

point – Coordinate of point in the polygon

Return type

numpy.ndarray

points: ndarray
remove_duplicate_points() Polygon[source]

Remove duplicate points from polygon.

For a polygon it is implied that the last point connects to the first point. In case the first point equals the last point, this results in errors down the line.

Return type

Polygon

subdivide(max_dist: int = 10, plot: bool = False) Polygon[source]

This algorithm looks for long edges in the polygon and subdivides them so they are no longer than max_dist

Parameters
  • max_dist (int, optional) – Maximum distance between neighbouring coordinates.

  • plot (bool, optional) – Show plot of the generated points.

Returns

Polygon with updated coordinate array.

Return type

Polygon

nanomesh.image2mesh._mesher2d.pad(mesh: LineMesh, *, side: str, width: int, label: int = None, name: str = None) LineMesh[source]

Pad a triangle mesh (2D).

Parameters
  • mesh (LineMesh) – The mesh to pad.

  • side (str) – Side to pad, must be one of left, right, top, bottom.

  • width (int) – Width of the padded area.

  • label (int, optional) – The label to assign to the padded area. If not defined, generates the next unique label based on the existing ones.

  • name (str, optional) – Name of the added region. Note that in case of conflicts, the label takes presedence over the name.

Returns

new_mesh – Padded line mesh.

Return type

LineMesh

Raises

ValueError – When the value of side is invalid.

nanomesh.image2mesh._mesher2d.plane2mesh(image: np.ndarray | Plane, *, level: float = None, max_edge_dist: int = 5, opts: str = 'q30a10', plot: bool = False) MeshContainer[source]

Generate a triangular mesh from a 2D segmented image.

Parameters
Returns

mesh – Triangulated 2D mesh with domain labels.

Return type

MeshContainer