import CoarseGrid from 'Artistoo/src/grid/CoarseGrid.js'
public class | source

CoarseGrid

Extends:

GridGrid2D → CoarseGrid

This class encapsulates a lower-resolution grid and makes it visible as a higher-resolution grid. Only exact subsampling by a constant factor per dimension is supported.

This class is useful when combining information of grids of different sizes. This is often the case for chemotaxis, where we let diffusion occur on a lower resolution grid to speed things up. This class then allows you to obtain chemokine information from the low resolution chemokine grid using coordinates from the linked, higher resolution model grid.

Example:

Linear interpolation on a low resolution chemokine grid
let CPM = require( "path/to/build" )

// Define a grid with float values for chemokine values, and set the middle pixel
let chemogrid = new CPM.Grid2D( [50,50], [true,true], "Float32" )
chemogrid.setpix( [99,99], 100 )

// Make a coarse grid at 5x as high resolution, which is then 500x500 pixels.
let coarsegrid = new CPM.CoarseGrid( chemogrid, 5 )

// Use interpolation. Pixels close to the midpoint won't have the exact same
// value of either 100 or 0, but something inbetween.
let p1 = [250,250], p2 = [250,251]
console.log( "p1 : " + coarsegrid.pixt(p1) + ", p2 : " + coarsegrid.pixt(p2) )
// p1 : 100, p2 : 80 

// Or draw it to see this. Compare these two:
let Cim1 = new CPM.Canvas( coarsegrid )
Cim1.drawField()
let Cim2 = new CPM.Canvas( chemogrid, {zoom:5} )
Cim2.drawField()

Constructor Summary

Public Constructor
public

constructor(grid: Grid2D, upscale: number)

The constructor of class CoarseGrid takes a low resolution grid as input and a factor 'upscale', which is how much bigger the dimensions of the high resolution grid are (must be a constant factor).

Member Summary

Public Members
public

Size of the new grid in all dimensions.

public

The original, low-resolution grid.

Private Members
private

The upscale factor (a positive integer number).

Method Summary

Public Methods
public

This method takes as input a coordinate on the bigger grid, and 'adds' additional value to it by adding the proper amount to the corresponding positions on the low resolution grid.

public

The pixt method takes as input a coordinate on the bigger grid, and maps it to the corresponding value on the resized small grid via bilinear interpolation.

Inherited Summary

From class Grid
private get

Return the array this._pixelArray, which should be set in the grid subclass.

private set

Set or update the private this._pixelArray.

public
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

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

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

Multiply all pixel values on the grid with a constant factor r.

public

The neigh method returns the neighborhood of a pixel p.

public abstract

A method to compute the Neumann neighborhood should be implemented in the Grid subclass if the laplacian (see below) is used.

public abstract

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

* pixels(): Pixel

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

This iterator returns locations all pixels including background.

public

The pixt method finds the current value of a pixel p on the grid.

public

The pixti method finds the current value of a pixel i on the grid.

public

The setpix method changes the value of a pixel p on the grid to t.

public

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.

From class Grid2D
public
private

Array with values for each pixel stored at the position of its IndexCoordinate.

public

Method to compute the gradient at location i on the grid (location given as an IndexCoordinate).

public

Method for conversion from an IndexCoordinate to an ArrayCoordinate.

public

Return array of IndexCoordinate of von Neumann-4 neighbor pixels of the pixel at coordinate i.

public

Return array of IndexCoordinate of Moore-8 neighbor pixels of the pixel at coordinate i.

public

Method for conversion from an ArrayCoordinate to an IndexCoordinate.

public

* pixels(): Pixel

This iterator returns locations and values of all non-zero pixels.

public

This iterator returns locations and values of all pixels.

Public Constructors

public constructor(grid: Grid2D, upscale: number) source

The constructor of class CoarseGrid takes a low resolution grid as input and a factor 'upscale', which is how much bigger the dimensions of the high resolution grid are (must be a constant factor).

Override:

Grid2D#constructor

Params:

NameTypeAttributeDescription
grid Grid2D

the grid to scale up; currently only supports the Grid2D class.

upscale number

The (integer) factor to magnify the original grid with.

Public Members

public extents: GridSize source

Size of the new grid in all dimensions.

Override:

Grid#extents

public grid: Grid2D source

The original, low-resolution grid.

Private Members

private upscale: number source

The upscale factor (a positive integer number).

Public Methods

public addValue(p: ArrayCoordinate, value: number) source

This method takes as input a coordinate on the bigger grid, and 'adds' additional value to it by adding the proper amount to the corresponding positions on the low resolution grid.

Params:

NameTypeAttributeDescription
p ArrayCoordinate

array coordinates on the high resolution grid.

value number

value that should be added to this position.

public pixt(p: ArrayCoordinate): number source

The pixt method takes as input a coordinate on the bigger grid, and maps it to the corresponding value on the resized small grid via bilinear interpolation. This prevents artefacts from the lower resolution of the second grid: the [upscale x upscale] pixels that map to the same pixel in the low resolution grid do not get the same value.

Override:

Grid#pixt

Params:

NameTypeAttributeDescription
p ArrayCoordinate

array coordinates on the high resolution grid.

Return:

number

interpolated value from the low resolution grid at this position.