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 )
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 |
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 |
divideCell(id: CellId): CellId 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 |
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 makePlane and changeKind methods). |
Public Members
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:
Name | Type | Attribute | Description |
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:
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 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:
Name | Type | Attribute | Description |
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. |
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:
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 )
}