Home Manual Reference Source Test
import GridManipulator from 'Artistoo/src/grid/GridManipulator.js'
public class | source

GridManipulator

This class contains methods that should be executed once per Monte Carlo Step. Examples are cell division, cell death etc.

Methods are written for CPMs, but some of the methods may also apply to other models of class (GridBasedModel, e.g. the cell seeding methods) or even a general grid (Grid, e.g. the makePlane and changeKind methods).

Example:

// Build CPM and attach a gridmanipulator 
let C = new CPM.CPM( [100,100], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )

Test:

Constructor Summary

Public Constructor
public

Constructor of class GridManipulator.

Member Summary

Public Members
public

The model whose grid we are manipulating.

Method Summary

Public Methods
public

changeKind(voxels: ArrayCoordinate[], cellkind: CellKind)

Helper method that converts all pixels in a given array to a specific cellkind: changes the pixels defined by voxels (array of coordinates p) into the given cellkind.

public

Let cell "id" divide by splitting it along a line perpendicular to its major axis.

public

killCell(cellid: *)

this method is experimental.
public

makePlane(voxels: ArrayCoordinate[], coord: number, coordvalue: number): ArrayCoordinate[]

Helper method to set an entire plane or line of pixels to a certain CellId at once.

public

seedCell(kind: CellKind, max_attempts: number): CellId

Seed a new cell at a random position.

public

Seed a new cell of celltype "kind" onto position "p".

public

seedCellsInCircle(kind: CellKind, n: number, center: ArrayCoordinate, radius: number, max_attempts: number)

Seed "n" cells of celltype "kind" at random points lying within a circle surrounding "center" with radius "radius".

Public Constructors

public constructor(C: CPM | GridBasedModel | Grid) source

Constructor of class GridManipulator.

Params:

NameTypeAttributeDescription
C CPM | GridBasedModel | Grid

the model whose grid you wish to manipulate. Methods are written for CPMs, but some of the methods may also apply to other models of class (GridBasedModel, e.g. the cell seeding methods) or even a general grid (Grid, e.g. the makePlane and changeKind methods).

Public Members

public C: CPM | GridBasedModel | Grid source

The model whose grid we are manipulating.

Public Methods

public changeKind(voxels: ArrayCoordinate[], cellkind: CellKind) source

Helper method that converts all pixels in a given array to a specific cellkind: changes the pixels defined by voxels (array of coordinates p) into the given cellkind.

Params:

NameTypeAttributeDescription
voxels ArrayCoordinate[]

Array of pixels to change.

cellkind CellKind

cellkind to change these pixels into.

Example:

let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let myline = gm.makePlane( [], 0, 2 )
gm.changeKind( myline, 1 )

public divideCell(id: CellId): CellId source

Let cell "id" divide by splitting it along a line perpendicular to its major axis.

Params:

NameTypeAttributeDescription
id CellId

the id of the cell that needs to divide.

Return:

CellId

the id of the newly generated daughter cell.

Example:

let C = new CPM.CPM( [10,10], {
	T:20, 
J:[[0,20],[20,10]], 
V:[0,200], 
LAMBDA_V:[0,2] 
})
let gm = new CPM.GridManipulator( C )

// Seed a single cell
gm.seedCell( 1 )

// Perform some Monte Carlo Steps before dividing the cell
for( let t = 0; t < 100; t++ ){
	C.timeStep()
}
gm.divideCell( 1 )

// Check which pixels belong to which cell. Should be roughly half half.
C.getStat( PixelsByCell )

public killCell(cellid: *) source

this method is experimental.

Params:

NameTypeAttributeDescription
cellid *

public makePlane(voxels: ArrayCoordinate[], coord: number, coordvalue: number): ArrayCoordinate[] source

Helper method to set an entire plane or line of pixels to a certain CellId at once. The method takes an existing array of coordinates (which can be empty) and adds the pixels of the specified plane to it. See changeKind for a method that sets such a pixel set to a new value.

The plane is specified by fixing one coordinate (x,y,or z) to a fixed value, and letting the others range from their min value 0 to their max value.

Params:

NameTypeAttributeDescription
voxels ArrayCoordinate[]

Existing array of pixels; this can be empty [].

coord number

the dimension to fix the coordinate of: 0 = x, 1 = y, 2 = z.

coordvalue number

the value of the coordinate in the fixed dimension; location of the plane.

Return:

ArrayCoordinate[]

the updated array of pixels.

Example:

let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let myline = gm.makePlane( [], 0, 2 )
gm.changeKind( myline, 1 )

public seedCell(kind: CellKind, max_attempts: number): CellId source

Seed a new cell at a random position. Return 0 if failed, ID of new cell otherwise. Try a specified number of times, then give up if grid is too full. The first cell will always be seeded at the midpoint of the grid.

See also seedCellAt to seed a cell on a predefined position.

Params:

NameTypeAttributeDescription
kind CellKind

what kind of cell should be seeded? This determines the CPM parameters that will be used for that cell.

max_attempts number
  • optional
  • default: 10000

number of tries allowed. The method will attempt to seed a cell at a random position, but this will fail if the position is already occupied. After max_attempts fails, it will not try again. This can happen if the grid is very full.

Return:

CellId

the CellId of the newly seeded cell, or 0 if the seeding has failed.

Example:

// Build CPM and attach a gridmanipulator
let C = new CPM.CPM( [100,100], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )

// Seed some cells
gm.seedCell( 1 )
gm.seedCell( 1 )

// Check which pixels are nonzero. One is always the grid midpoint.
for( let p of C.pixels() ){
	console.log( p )
}

public seedCellAt(kind: CellKind, p: ArrayCoordinate): CellId source

Seed a new cell of celltype "kind" onto position "p". This succeeds regardless of whether there is already a cell there.

See also seedCell to seed a cell on a random position.

Params:

NameTypeAttributeDescription
kind CellKind

what kind of cell should be seeded? This determines the CPM parameters that will be used for that cell.

p ArrayCoordinate

position to seed the cell at.

Return:

CellId

the CellId of the newly seeded cell, or 0 if the seeding has failed.

Example:

// Build CPM and attach a gridmanipulator
let C = new CPM.CPM( [100,100], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )

// Seed some cells
gm.seedCellAt( 1, [2,4] )
gm.seedCellAt( 1, [9,3] )

// Check which pixels are nonzero. These should be the positions defined above.
for( let p of C.pixels() ){
	console.log( p )
}

Test:

public seedCellsInCircle(kind: CellKind, n: number, center: ArrayCoordinate, radius: number, max_attempts: number) source

Seed "n" cells of celltype "kind" at random points lying within a circle surrounding "center" with radius "radius".

See also seedCell to seed a cell on a random position in the entire grid, and seedCellAt to seed a cell at a specific position.

Params:

NameTypeAttributeDescription
kind CellKind

what kind of cell should be seeded? This determines the CPM parameters that will be used for that cell.

n number

the number of cells to seed (must be integer).

center ArrayCoordinate

position on the grid where the center of the circle should be.

radius number

the radius of the circle to seed cells in.

max_attempts number

the maximum number of attempts to seed a cell. Seeding can fail if the randomly chosen position is outside the circle, or if there is already a cell there. After max_attempts the method will stop trying and throw an error.

Example:

// Build CPM and attach a gridmanipulator
let C = new CPM.CPM( [100,100], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )

// Seed cells within a circle
gm.seedCellsInCircle( 1, 10, [50,30], 20 )

// Check which pixels are nonzero. These should be within the circle.
for( let p of C.pixels() ){
	console.log( p )
}