nanomesh.image2mesh.mesher2dο
Classes:
|
Functions:
|
Pad a triangle mesh (2D). |
|
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.
Use rejection sampling to find point in polygon.
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:
- 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.
- 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
- 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
- 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
- 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
- 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
image ((i,j) numpy.ndarray or Plane) β Input image to mesh.
level (float, optional) β Level to generate contours at from image
max_edge_dist (int, optional) β Maximum distance between neighbouring pixels in contours.
opts (str, optional) β Options passed to
triangulate()
. For more info, see: https://rufat.be/triangle/API.html#triangle.triangulate
- Returns
mesh β Triangulated 2D mesh with domain labels.
- Return type