simnibs.Msh

class simnibs.Msh(nodes=None, elements=None, fn=None)

class to handle the meshes. Gathers Nodes, Elements and Data

Parameters:
  • nodes ((optional) simnibs.msh.Nodes) – Nodes structure

  • elements ((optional) simnibs.msh.Elements()) – Elements structure

  • fn (str (optional)) – Name of “.msh” file to be read. Overides nodes and elements

nodes

a Nodes field

Type:

simnibs.msh.Nodes

elm

A Elements field

Type:

simnibs.msh.Elements

nodedata

list of NodeData filds

Type:

simnibs.msh.NodeData

elmdata

list of ElementData fields

Type:

simnibs.msh.ElementData

fn

name of file

Type:

str

binary

wheather or not the mesh was in binary format

Type:

bool

__init__(nodes=None, elements=None, fn=None)

Methods

__init__([nodes, elements, fn])

add_element_field(field, field_name)

Adds field defined in the elements

add_node_field(field, field_name)

Adds field defined in the nodes

add_sizing_field(sizing_field[, affine])

Add sizing field from sizing image to mesh in a NodeData field called "sizing_field:metric" for mmg.

any_pts_inside_surface(pts, AABBTree)

Test if any of the points are inside the surface.

calc_matsimnibs(center, pos_ydir, distance)

Calculate the matsimnibs matrix for TMS simulations

compact_ordering(node_number)

Changes the node and element ordering so that it goes from 1 to nr_nodes

crop_mesh([tags, elm_type, nodes, elements])

Crops the specified tags from the mesh Generates a new mesh, with only the specified tags The nodes are also reordered

elements_baricenters()

Calculates the baricenter of the elements

elements_volumes_and_areas()

Calculates the volumes of tetrahedra and areas of triangles

elm2node_matrix([elm_indices])

Calculates a sparse matrix to tranform from ElementData to NodeData Uses Superconvergent patch recovery for volumetric data.

elm_node_coords([elm_nr, tag, elm_type])

Returns the position of each of the element's nodes

fields_summary([roi, fields, percentiles, ...])

Creates a text summary of the field

find_closest_element(querry_points[, ...])

Finds the closest element to each point in p

find_corresponding_tetrahedra()

Finds the tetrahedra corresponding to each triangle

find_shared_nodes(tags)

Finds the nodes which are shared by all given tags

find_tetrahedron_with_points(points[, ...])

Finds the tetrahedron that contains each of the described points using a stochastic walk algorithm

fix_surface_labels()

Fixels labels of surfaces

fix_surface_orientation()

Ensure that the majority of triangle normals point outwards.

fix_th_node_ordering()

Fixes the node ordering of tetrahedra in-place

fix_tr_node_ordering()

Fixes the node ordering of the triangles in-place

gamma_metric()

calculates the (normalized) Gamma quality metric for tetrahedra

gaussian_curvature()

Calculates the Gaussian curvature at each node

get_AABBTree()

Build AABBTree for efficient intersection tests

get_min_distance_on_grid([resolution, AABBTree])

Generates a distance field on a grid to the mesh surface

interp_matrix(pos[, out_fill, th_indices, ...])

Calculates a matrix to perform interpolation y = M.dot(x)

intersect_ray(points, directions[, AABBTree])

Finds the triangle (if any) that intersects with the rays starting

intersect_segment(near, far)

Finds the triangle (if any) that intersects a line segment

join_mesh(other)

Join the current mesh with another

nodes_areas()

Areas for all nodes in a surface

nodes_normals([triangles, smooth])

Normals for all nodes in a surface

nodes_volumes_or_areas()

Return the volume (volume mesh) if area (surface mesh) of all nodes Only works for ordered values of mesh and node indices

open_in_gmsh()

Opens the mesh in gmsh

partition_skin_surface([...])

Return indices of vertices and faces estimated to be on the inner and outer skin surface (the inner part would be those inside nasal cavities, ear canals etc.

prepare_surface_tags()

pts_inside_surface(pts[, AABBTree])

Test which points are inside the surface.

read_hdf5(hdf5_fn[, path, load_data])

Reads mesh information from an hdf5 file

reconstruct_surfaces([tags])

Reconstruct the mesh surfaces for each label/connected component individually This function acts in-place, and will keep any surfaces already present in the mesh

reconstruct_unique_surface([hierarchy, ...])

Reconstructs the mesh surfaces from the tetrahedra.

remove_from_mesh([tags, elm_type, nodes, ...])

Removes the specified tags from the mesh Generates a new mesh, with the specified tags removed The nodes are also reordered

smooth_surfaces(n_steps[, step_size, tags, ...])

In-place smoothing of the mesh surfaces using Taubin smoothing,

smooth_surfaces_simple(n_steps[, step_size, ...])

In-place smoothing of the mesh surfaces using Taubin smoothing,

split_tets_along_line(idx_n1, idx_n2[, ...])

Adds a new node in the middle between the two given nodes and splits all tetrahedra connected to the line between the two given nodes.

surface_EC()

return euler characteristic of surfaces

test_inside_volume(points)

Tests if points are iside the volume using the Möller–Trumbore intersection algorithm

tetrahedra_quality()

calculates the quality measures of the tetrahedra

triangle_angles()

Calculates minimum angle of the mesh triangles

triangle_normals([smooth])

Calculates the normals of triangles

view([visible_tags, visible_fields, cond_list])

Visualize mesh in Gmsh

write(out_fn)

Writes out the mesh as a ".msh" file

write_hdf5(hdf5_fn[, path, compression])

Writes a HDF5 file with mesh information

Attributes

field

Dictionary of fields indexed by their name