mcot.surface.grid

Defines many functions that take both a grid and a mesh as input.

Classes

GridSurfaceIntersection(surface, affine, …)

Represents the intersections between a surface and a grid.

Functions

bounding(surface[, resolution])

Computes the shape and affine of a grid spanning the bounding box with given voxel size.

closest_point(points, grid, orientation[, …])

Find for every point in the grid the closest point on the surface.

closest_surface(surface, grid[, affine, …])

Find for every non-zero point in the grid the closest point on the surface.

intersect(surface, shape[, affine])

Computes the intersection between surface and a grid.

intersect_resolution(surface[, resolution])

Computes the intersection between the surface and a grid spanning the bounding box with given voxel size.

signed_distance(surface, shape[, affine])

Signed distance from the surface to a grid with size shape in mm.

bounding

mcot.surface.grid.bounding(surface, resolution=1)[source]

Computes the shape and affine of a grid spanning the bounding box with given voxel size.

Parameters
  • surface (Mesh2D) – 2D surface in a 3D space

  • resolution (float) – voxel size

Returns

((nx, ny, nz), 4x4 affine transformation)

closest_point

mcot.surface.grid.closest_point(points, grid, orientation, test_orientation=False, max_dist=inf)[source]

Find for every point in the grid the closest point on the surface.

Parameters
  • points – (3, N) array of points in the grid in voxel coordinates

  • grid – (Nx, Ny, Nz) array, where all elements that are not -1 will be replaced by the index of the closest point.

  • orientation – (3, N) array of the hemisphere of each of these vertices (only grid vertices which are in the semi-hemisphere defined by this hemisphere will be considered

  • max_dist – maximum distance from the surface to consider. Points beyond this maximum are set to -1.

  • test_orientation – whether to test the hemisphere

closest_surface

mcot.surface.grid.closest_surface(surface, grid, affine=None, pos_inpr=None, max_dist=inf)[source]

Find for every non-zero point in the grid the closest point on the surface.

Parameters
  • surface (Mesh2D) – target surface

  • grid – (Nx, Ny, Nz) array, where for all non-zero elements the closest element on the target surface will be computed

  • affine – (4, 4) array with the transformation from voxel space to the mm space in which the surface has been defined (default: no transformation)

  • pos_inpr – whether the normal of the surface vertices should point towards (True) or away (False) from the grid point (default: no such constraint)

  • max_dist – maximum distance from the surface to consider (in mm). Points beyond this maximum are set to -1.

Returns

(Nx, Ny, Nz) integer array, which is -1 for all zero elements in grid and contains the indices of the closest surface vertices otherwise

intersect

mcot.surface.grid.intersect(surface, shape, affine=array([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]))[source]

Computes the intersection between surface and a grid.

Parameters
  • surface (Mesh2D) – 2D surface in a 3D space that intersects with the grid.

  • shape (tuple) – tuple of volume shape (nx, ny, nz)

  • affine (np.ndarray) – (4, 4) array describing the transformation from voxel space to the mm space that the surface is in

Returns

GridSurfaceIntersection object

intersect_resolution

mcot.surface.grid.intersect_resolution(surface, resolution=1)[source]

Computes the intersection between the surface and a grid spanning the bounding box with given voxel size.

Parameters
  • surface (Mesh2D) – 2D surface in a 3D space

  • resolution (float) – voxel size

Returns

GridSurfaceIntersection object

signed_distance

mcot.surface.grid.signed_distance(surface, shape, affine=None)[source]

Signed distance from the surface to a grid with size shape in mm.

Calls out to workbench to do the actual calculation.

Parameters
  • surface (Mesh2D) – reference surface

  • shape – (Nx, Ny, Nz) tuple defining the shape of the grid

  • affine – (4, 4) array transforming the voxel to mm coordinates (default: no transformation)

Returns

(Nx, Ny, Nz)-array with the signed distance from the surface (negative inside the brain)