Package repast.simphony.valueLayer
Class GridValueLayer
- java.lang.Object
-
- repast.simphony.valueLayer.GridValueLayer
-
- All Implemented Interfaces:
IGridValueLayer
,ValueLayer
public class GridValueLayer extends Object implements IGridValueLayer
A grid value layer. Each cell in the grid is accessed via integer x, y, z, ... n coordinates and contains some numeric value. Each cell in the grid will contain a value regardless of whether or not it has been set yet. This default value can be set by the user.- Author:
- Nick Collier, Eric Tatara
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
dense
protected Dimensions
dims
protected String
name
protected int[]
origin
protected ValueLayerStore
store
protected int[]
stride
protected GridPointTranslator
translator
-
Constructor Summary
Constructors Constructor Description GridValueLayer(String name, boolean dense, int... dimensions)
Creates a GridValueLayer with the specified name, density, and dimensions.GridValueLayer(String name, boolean dense, GridPointTranslator translator, int... dimensions)
Creates a GridValueLayer with the specified name, density, translator, and dimensions.GridValueLayer(String name, double defaultValue, boolean dense, int... dimensions)
Creates a GridValueLayer with the specified name, density, defaultValue and dimensions.GridValueLayer(String name, double defaultValue, boolean dense, GridPointTranslator translator, int... dimensions)
Creates a GridValueLayer with the specified name, defaultValue, density, translator and dimensions.GridValueLayer(String name, double defaultValue, boolean dense, GridPointTranslator translator, int[] dimensions, int[] origin)
Creates a GridValueLayer with the specified name, defaultValue, density, translator and dimensions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
forEach(GridFunction function, GridPoint origin, int... extent)
Apply the specified function to each cell in the extent around the origin.double
get(double... coordinates)
Gets a value given the specified coordinates.Dimensions
getDimensions()
Gets the dimensions of this GridValueLayer.GridPointTranslator
getGridPointTranslator()
Retrieves the rule being used for controlling what happens at or beyond the borders of the value layer.String
getName()
Gets the name of this ValueLayer.protected int[]
getTransformedLocation(int... location)
void
set(double value, int... coordinate)
Sets the specified cell to the specified value.void
setGridPointTranslator(GridPointTranslator rule)
Sets the rule to use for controlling what happens at or beyond the borders of the value layer.int
size()
Return the number of entries in the value layer.
-
-
-
Field Detail
-
name
protected String name
-
store
protected ValueLayerStore store
-
stride
protected int[] stride
-
dims
protected Dimensions dims
-
origin
protected int[] origin
-
dense
protected boolean dense
-
translator
protected GridPointTranslator translator
-
-
Constructor Detail
-
GridValueLayer
public GridValueLayer(String name, boolean dense, int... dimensions)
Creates a GridValueLayer with the specified name, density, and dimensions. The default value of every cell in the grid will be 0. The default border behavior is strict.- Parameters:
name
- the name of the value layerdense
- if value layer will be densely populateddimensions
- the dimension of the value layer
-
GridValueLayer
public GridValueLayer(String name, double defaultValue, boolean dense, int... dimensions)
Creates a GridValueLayer with the specified name, density, defaultValue and dimensions. The default border behavior is strict.- Parameters:
name
- the name of the value layerdefaultValue
- the default value that each grid cell will contain if it has not been set yetdense
- if the value layer will be densely populateddimensions
- the dimension of the grid value layer
-
GridValueLayer
public GridValueLayer(String name, boolean dense, GridPointTranslator translator, int... dimensions)
Creates a GridValueLayer with the specified name, density, translator, and dimensions. The default border behavior is strict. The default value of every cell in the grid will be 0.- Parameters:
name
- the name of the value layerdefaultValue
- the default value that each grid cell will contain if it has not been set yetdense
- if the value layer will be densely populatedtranslator
- the translator useddimensions
- the dimension of the value layer
-
GridValueLayer
public GridValueLayer(String name, double defaultValue, boolean dense, GridPointTranslator translator, int... dimensions)
Creates a GridValueLayer with the specified name, defaultValue, density, translator and dimensions.- Parameters:
name
- the name of the value layerdefaultValue
- the default value that each grid cell will contain if it has not been set yetdense
- if value layer will be densely populatedtranslator
- the translator useddimensions
- the dimension of the value layer
-
GridValueLayer
public GridValueLayer(String name, double defaultValue, boolean dense, GridPointTranslator translator, int[] dimensions, int[] origin)
Creates a GridValueLayer with the specified name, defaultValue, density, translator and dimensions.- Parameters:
name
- the name of the value layerdefaultValue
- the default value that each grid cell will contain if it has not been set yetdense
- if value layer will be densely populatedtranslator
- the translator useddimensions
- the dimension of the value layer
-
-
Method Detail
-
forEach
public void forEach(GridFunction function, GridPoint origin, int... extent)
Apply the specified function to each cell in the extent around the origin. This includes the origin itself.- Parameters:
function
-origin
-extent
-
-
get
public double get(double... coordinates)
Gets a value given the specified coordinates. This assumes the coordinates are int x, y, z, n values.- Specified by:
get
in interfaceValueLayer
- Parameters:
coordinates
- the coordinates used to return the value.- Returns:
- a value given the specified coordinates.
-
set
public void set(double value, int... coordinate)
Sets the specified cell to the specified value.- Specified by:
set
in interfaceIGridValueLayer
- Parameters:
value
- the new value of the cellcoordinate
- the coordinate of the cell whose value we want to set
-
getName
public String getName()
Gets the name of this ValueLayer.- Specified by:
getName
in interfaceValueLayer
- Returns:
- the name of this ValueLayer.
-
getDimensions
public Dimensions getDimensions()
Gets the dimensions of this GridValueLayer.- Specified by:
getDimensions
in interfaceValueLayer
- Returns:
- the dimensions of this GridValueLayer.
-
getTransformedLocation
protected int[] getTransformedLocation(int... location)
-
getGridPointTranslator
public GridPointTranslator getGridPointTranslator()
Retrieves the rule being used for controlling what happens at or beyond the borders of the value layer.- Returns:
- the rule for handling out of bounds coordinates
-
setGridPointTranslator
public void setGridPointTranslator(GridPointTranslator rule)
Sets the rule to use for controlling what happens at or beyond the borders of the value layer.- Parameters:
rule
- the rule for handling out of bounds coordinates
-
size
public int size()
Return the number of entries in the value layer. For dense layers, this is the product of dimensions, eg x * y * z... For sparse layers, this is the number of entries in sparse storage.- Returns:
-
-