GridManipulator
This class contains methods that should be executed once per Monte Carlo Step. Examples are cell division, cell death etc.
It also contains methods to seed new cells in certain shapes and configurations. 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 makeLine and assignCellPixels 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 )
Constructor Summary
Public Constructor  
public 
constructor(C: CPM  GridBasedModel  Grid) Constructor of class GridManipulator. 
Member Summary
Public Members  
public 
C: CPM  GridBasedModel  Grid The model whose grid we are manipulating. 
Method Summary
Public Methods  
public 
assignCellPixels(voxels: ArrayCoordinate[], cellkind: CellKind, newID: CellId) Helper method that assigns all pixels in a given array to a cell of a given cellkind: changes the pixels defined by voxels (array of coordinates p) into the given cellKind and a corresponding cellID. 

public 
changeKind(voxels: *, cellkind: *, newid: *) Abrogated; this is now assignCellPixels. 

public 
divideCell(id: CellId): CellId Let cell "id" divide by splitting it along a line perpendicular to its major axis. 

public 
divideCellTorus(id: CellId): CellId this method is experimental. Let cell "id" divide by splitting it along a line perpendicular to
its major axis, with Torus enabled. Watch out that this can give
rise to weird artefacts when cells span more than half the grid in
a wrapped direction.


public 
killCell(cellID: *) this method is experimental.


public 
makeBox(bottomLeft: ArrayCoordinate[], boxSize: number[], pixels: ArrayCoordinate[]): ArrayCoordinate[] Helper method to return a rectangle (or in 3D: box) of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. 

public 
makeCircle(center: ArrayCoordinate[], radius: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] Helper method to return a circle (in 3D: sphere) of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. 

public 
makeLine(dimension: number, coordinateValue: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] Helper method to return an entire plane or line of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. 

public 
makePlane(dim: number, coordinateValue: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] Deprecated method, please use makeLine instead. 

public 
Seed a new cell at a random position. 

public 
seedCellAt(kind: CellKind, p: ArrayCoordinate): CellId 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:
Name  Type  Attribute  Description 
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 makeLine and assignCellPixels methods). 
Public Members
Public Methods
public assignCellPixels(voxels: ArrayCoordinate[], cellkind: CellKind, newID: CellId) source
Helper method that assigns all pixels in a given array to a cell of a given cellkind: changes the pixels defined by voxels (array of coordinates p) into the given cellKind and a corresponding cellID.
Params:
Name  Type  Attribute  Description 
voxels  ArrayCoordinate[]  Array of pixels to change. 

cellkind  CellKind  cellkind to change these pixels into. 

newID  CellId 

(Optional) id of the cell to assign the pixels to; if this is unspecified, a new cellID is generated for this purpose. 
Example:
let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let myLine = gm.makeLine( 0, 2 )
gm.assignCellPixels( myLine, 1 )
public changeKind(voxels: *, cellkind: *, newid: *) source
Abrogated; this is now assignCellPixels. *
Params:
Name  Type  Attribute  Description 
voxels  *  
cellkind  *  
newid  * 
public divideCell(id: CellId): CellId source
Let cell "id" divide by splitting it along a line perpendicular to its major axis.
Params:
Name  Type  Attribute  Description 
id  CellId  the id of the cell that needs to divide. 
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 divideCellTorus(id: CellId): CellId source
Params:
Name  Type  Attribute  Description 
id  CellId  the id of the cell that needs to divide. 
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
Params:
Name  Type  Attribute  Description 
cellID  * 
public makeBox(bottomLeft: ArrayCoordinate[], boxSize: number[], pixels: ArrayCoordinate[]): ArrayCoordinate[] source
Helper method to return a rectangle (or in 3D: box) of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. (See also makeLine and makeCircle). The method takes an existing array of coordinates (which can be empty) and adds the pixels of the specified rectangle/box to it. See assignCellPixels for a method that sets such a pixel set to a new value.
The box/rectangle is specified by its bottom left corner (x,y,z) and size (dx, dy, dz).
Params:
Name  Type  Attribute  Description 
bottomLeft  ArrayCoordinate[]  the coordinate of the bottom left corner of the rectangle/box. 

boxSize  number[]  the size of the rectangle in each dimension: [dx,dy,dz]. 

pixels  ArrayCoordinate[] 

(Optional) existing array of pixels; if given, the line will be added to this set. 
Example:
let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let rect = gm.makeBox( [50,50], [10,10] )
gm.assignCellPixels( rect, 1 )
public makeCircle(center: ArrayCoordinate[], radius: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] source
Helper method to return a circle (in 3D: sphere) of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. (See also makeLine and makeBox). The method takes an existing array of coordinates (which can be empty) and adds the pixels of the specified circle/sphere to it. See assignCellPixels for a method that sets such a pixel set to a new value.
The circle/sphere is specified by its center (x,y,z) and radius.
Params:
Name  Type  Attribute  Description 
center  ArrayCoordinate[]  the coordinate of the center of the circle/sphere. 

radius  number  the radius of the circle/sphere. 

pixels  ArrayCoordinate[] 

(Optional) existing array of pixels; if given, the circle/sphere pixels will be added to this set. 
Example:
let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let circ = gm.makeCircle( [50,50], 10 )
gm.assignCellPixels( circ, 1 )
public makeLine(dimension: number, coordinateValue: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] source
Helper method to return an entire plane or line of pixels; can be used in conjunction with assignCellPixels to assign all these pixels to a given CellId at once. (See also makeBox and makeCircle). The method takes an existing array of coordinates (which can be empty) and adds the pixels of the specified plane to it. See assignCellPixels 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. In 3D, this returns a plane.
Params:
Name  Type  Attribute  Description 
dimension  number  the dimension to fix the coordinate of: 0 = x, 1 = y, 2 = z. (E.g. for a straight vertical line, we fix the xcoordinate). 

coordinateValue  number  the value of the coordinate in the fixed dimension; location of the plane. (E.g. for our straight vertical line, the xvalue where the line should be placed). 

pixels  ArrayCoordinate[] 

(Optional) existing array of pixels; if given, the line will be added to this set. 
Example:
let C = new CPM.CPM( [10,10], {T:20, J:[[0,20],[20,10]]} )
let gm = new CPM.GridManipulator( C )
let myLine = gm.makeLine( 0, 2 )
gm.assignCellPixels( myLine, 1 )
public makePlane(dim: number, coordinateValue: number, pixels: ArrayCoordinate[]): ArrayCoordinate[] source
Deprecated method, please use makeLine instead. Old method just links to the new method for backwardscompatibility.
Params:
Name  Type  Attribute  Description 
dim  number  the dimension to fix the coordinate of: 0 = x, 1 = y, 2 = z. (E.g. for a straight vertical line, we fix the xcoordinate). 

coordinateValue  number  the value of the coordinate in the fixed dimension; location of the plane. (E.g. for our straight vertical line, the xvalue where the line should be placed). 

pixels  ArrayCoordinate[] 

(Optional) existing array of pixels; if given, the line will be added to this set. 
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:
Name  Type  Attribute  Description 
kind  CellKind  what kind of cell should be seeded? This determines the CPM parameters that will be used for that cell. 

max_attempts  number 

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. 
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:
Name  Type  Attribute  Description 
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. 
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 )
}
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:
Name  Type  Attribute  Description 
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 )
}