Grid3D
Extends:
A class containing (mostly static) utility functions for dealing with 3D grids. Extends the Grid class but implements functions specific to the 3D grid (such as neighborhoods).
Example:
let CPM = require("path/to/build")
// Make a grid with a torus, and find the neighborhood of the upper left pixel [0,0,0]
let grid = new CPM.Grid3D( [100,100,100], [true,true,true] )
console.log( grid.neigh( [0,0,0] ) ) // returns coordinates of 26 neighbors (9+8+9)
// Now try a grid without torus; the corner now has fewer neighbors.
let grid2 = new CPM.Grid3D( [100,100,100], [false,false,false] )
console.log( grid2.neigh( [0,0,0] ) ) // returns only 7 neighbors
// Or try a torus in one dimension
let grid2 = new CPM.Grid3D( [100,100,100], [true,false,false] )
console.log( grid2.neigh( [0,0,0] ) )
Constructor Summary
Public Constructor | ||
public |
constructor(extents: GridSize, torus: boolean[]) Constructor of the Grid3D object. |
Member Summary
Public Members | ||
public |
|
Private Members | ||
private |
Array with values for each pixel stored at the position of its IndexCoordinate. |
Method Summary
Public Methods | ||
public |
Method for conversion from an IndexCoordinate to an ArrayCoordinate. |
|
public |
neighi(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] Return array of IndexCoordinate of the Moore neighbor pixels of the pixel at coordinate i. |
|
public |
Method for conversion from an ArrayCoordinate to an IndexCoordinate. |
|
public |
This iterator returns locations and values of all non-zero pixels. |
|
public |
* pixelsi(): IndexCoordinate This iterator returns locations and values of all non-zero pixels. |
Inherited Summary
From class Grid | ||
private get |
_pixels: Uint16Array | Float32Array: * Return the array this._pixelArray, which should be set in the grid subclass. |
|
private set |
_pixels(pixels: Uint16Array | Float32Array) Set or update the private this._pixelArray. |
|
public |
datatype: * |
|
public |
field_size array of field size in each dimension. |
|
public |
Array coordinates to the middle pixel on the grid. |
|
public |
Number of dimensions of the grid. |
|
public |
Should the borders of the grid be linked, so that a cell moving out on the left reappears on the right? Warning: setting to false can give artifacts if done incorrectly. |
|
private |
_pixelArray: * Array with values for each pixel stored at the position of its IndexCoordinate. |
|
private |
For storing a copy of all pixel values; eg for synchronous updating of some sort. |
|
public |
Apply a function to all pixel values on the grid. |
|
public |
Method to check if a given ArrayCoordinate falls within the bounds of this grid. |
|
public |
Method to correct an ArrayCoordinate outside the grid dimensions when the grid is wrapped (torus = true). |
|
public |
Perform a diffusion step on the grid, updating the values of all pixels according to Fick's second law of diffusion. |
|
public |
Method to compute the gradient at location p on the grid (location given in array coordinates). |
|
public |
gradienti(i: IndexCoordinate): number[] Template method to compute the gradient at location i on the grid (location given in index coordinates). |
|
public abstract |
Method for conversion from an IndexCoordinate to an ArrayCoordinate. |
|
public |
Method to compute the laplacian at location p on the grid (location given in array coordinates). |
|
public |
Method to compute the laplacian at location i on the grid (location given in index coordinates). |
|
public |
multiplyBy(r: number) Multiply all pixel values on the grid with a constant factor r. |
|
public |
neigh(p: ArrayCoordinate, torus: boolean[]): ArrayCoordinate[] The neigh method returns the neighborhood of a pixel p. |
|
public abstract |
* neighNeumanni(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] A method to compute the Neumann neighborhood should be implemented in the Grid subclass if the laplacian (see below) is used. |
|
public abstract |
neighi(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] Method returning the (Moore) neighborhood of a pixel based on its IndexCoordinate. |
|
public abstract |
Method for conversion from an ArrayCoordinate to an IndexCoordinate. |
|
public abstract |
This iterator returns locations and values of all non-zero pixels. |
|
public |
This method pre-allocates an array of the correct datatype to make a copy of the current pixel values. |
|
public abstract |
* pixelsi(): IndexCoordinate This iterator returns locations all pixels including background. |
|
public |
pixt(p: ArrayCoordinate): number The pixt method finds the current value of a pixel p on the grid. |
|
public |
pixti(i: IndexCoordinate): number The pixti method finds the current value of a pixel i on the grid. |
|
public |
setpix(p: ArrayCoordinate, t: number) The setpix method changes the value of a pixel p on the grid to t. |
|
public |
setpixi(i: IndexCoordinate, t: number) The setpixi method changes the value of a pixel i on the grid to t. |
|
private |
_isValidValue(t: number, tol: number): void Check if a value is valid on this type of grid. |
Public Constructors
public constructor(extents: GridSize, torus: boolean[]) source
Constructor of the Grid3D object.
Override:
Grid#constructorParams:
Name | Type | Attribute | Description |
extents | GridSize | the size of the grid in each dimension |
|
torus | boolean[] |
|
should the borders of the grid be linked, so that a cell moving out on the left reappears on the right? Warning: setting the torus to false can give artifacts if not done properly, see Grid#torus. |
Public Members
Private Members
private _pixelArray: Uint16Array source
Array with values for each pixel stored at the position of its IndexCoordinate. E.g. the value of pixel with coordinate i is stored as this._pixelArray[i]. Note that this array is accessed indirectly via the _pixels set- and get methods.
Override:
Grid#_pixelArrayPublic Methods
public i2p(i: IndexCoordinate): ArrayCoordinate source
Method for conversion from an IndexCoordinate to an ArrayCoordinate.
See also Grid3D#p2i for the backward conversion.
Override:
Grid#i2pParams:
Name | Type | Attribute | Description |
i | IndexCoordinate | the coordinate of the pixel to convert |
Example:
let grid = new CPM.Grid3D( [100,100,100], [true,true,true] )
let p = grid.i2p( 5 )
console.log( p )
console.log( grid.p2i( p ))
public neighi(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] source
Return array of IndexCoordinate of the Moore neighbor pixels of the pixel at coordinate i. This function takes the 3D equivalent of the 2D Moore-8 neighborhood, excluding the pixel itself.
Override:
Grid#neighiParams:
Name | Type | Attribute | Description |
i | IndexCoordinate | location of the pixel to get neighbors of. |
|
torus | boolean[] |
|
does the grid have linked borders? Defaults to the setting on this grid, see torus |
public p2i(p: ArrayCoordinate): IndexCoordinate source
Method for conversion from an ArrayCoordinate to an IndexCoordinate.
See also Grid3D#i2p for the backward conversion.
Override:
Grid#p2iParams:
Name | Type | Attribute | Description |
p | ArrayCoordinate | the coordinate of the pixel to convert |
Example:
let grid = new CPM.Grid3D( [100,100,100], [true,true,true] )
let p = grid.i2p( 5 )
console.log( p )
console.log( grid.p2i( p ))
public * pixels(): Pixel source
This iterator returns locations and values of all non-zero pixels.
Override:
Grid#pixelsReturn:
Pixel | for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value. |
Example:
let CPM = require( "path/to/build" )
// make a grid and set some values
let grid = new CPM.Grid3D( [100,100,100], [true,true,true] )
grid.setpix( [0,0,0], 1 )
grid.setpix( [0,0,1], 5 )
// iterator
for( let p of grid.pixels() ){
console.log( p )
}
public * pixelsi(): IndexCoordinate source
This iterator returns locations and values of all non-zero pixels. Whereas the pixels generator yields only non-background pixels and specifies both their ArrayCoordinate and value, this generator yields all pixels by IndexCoordinate and does not report value.
Override:
Grid#pixelsiExample:
let CPM = require( "path/to/build" )
// make a grid and set some values
let grid = new CPM.Grid3D( [100,100,100], [true,true,true] )
grid.setpixi( 0, 1 )
grid.setpixi( 1, 5 )
// iterator
for( let i of grid.pixelsi() ){
console.log( i )
}