Class AbstractGrid3D
- All Implemented Interfaces:
Serializable
,Grid3D
- Direct Known Subclasses:
DenseGrid3D
,DoubleGrid3D
,IntGrid3D
,ObjectGrid3D
Grid3D foo = ... ; foo.tx(4); // will not get inlined AbstractGrid3D bar = ...; bar.tx(4); // WILL get inlined
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuildMap
(int size) Creates a map of the provided size (or any size it likes if ANY_SIZE is passed in).Creates a Map which is a copy of another.protected void
checkBounds
(Grid3D other) final int
Get the heightfinal int
Get the lengthvoid
getMooreLocations
(int x, int y, int z, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) invalid input: '<'= dist.void
getNeighborsHamiltonianDistance
(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos) Deprecated.void
getNeighborsMaxDistance
(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos) Deprecated.void
getRadialLocations
(int x, int y, int z, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, IntBag xPos, IntBag yPos, IntBag zPos) Gets all neighbors overlapping with a spherical region centered at (X,Y,Z) and with a radius of dist.void
getRadialLocations
(int x, int y, int z, double dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Gets all neighbors overlapping with a spherical region centered at (X,Y,Z) and with a radius of dist.void
getVonNeumannLocations
(int x, int y, int z, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) invalid input: '<'= dist.final int
getWidth()
Get the widthprotected boolean
protected void
removeOrigin
(int x, int y, int z, IntBag xPos, IntBag yPos, IntBag zPos) protected void
removeOriginToroidal
(int x, int y, int z, IntBag xPos, IntBag yPos, IntBag zPos) final int
stx
(int x) Simple [and fast] toroidal x.final int
sty
(int y) Simple [and fast] toroidal y.final int
stz
(int z) Simple [and fast] toroidal z.final int
stz
(int z, int length) final int
tx
(int x) Toroidal x.final int
ty
(int y) Toroidal y.final int
tz
(int z) Toroidal z.
-
Field Details
-
width
public int width -
height
public int height -
length
public int length
-
-
Constructor Details
-
AbstractGrid3D
public AbstractGrid3D()
-
-
Method Details
-
getWidth
public final int getWidth()Description copied from interface:Grid3D
Get the width -
getHeight
public final int getHeight()Description copied from interface:Grid3D
Get the height -
getLength
public final int getLength()Description copied from interface:Grid3D
Get the length -
buildMap
Description copied from interface:Grid3D
Creates a Map which is a copy of another. By default, HashMap is used. -
buildMap
Description copied from interface:Grid3D
Creates a map of the provided size (or any size it likes if ANY_SIZE is passed in). By default, HashMap is used. -
tx
public final int tx(int x) Description copied from interface:Grid3D
Toroidal x. The following definition:
final int length = this.length;
if (z >= 0) return (z % length);
final int length2 = (z % length) + length;
if (length2 < length) return length2;
return 0;
... produces the correct code and is 27 bytes, so it's likely to be inlined in Hotspot for 1.4.1. -
ty
public final int ty(int y) Description copied from interface:Grid3D
Toroidal y. The following definition:
final int length = this.length;
if (z >= 0) return (z % length);
final int length2 = (z % length) + length;
if (length2 invalid input: '<' length) return length2;
return 0;
... produces the correct code and is 27 bytes, so it's likely to be inlined in Hotspot for 1.4.1. -
tz
public final int tz(int z) Description copied from interface:Grid3D
Toroidal z. The following definition:
final int length = this.length;
if (z >= 0) return (z % length);
final int length2 = (z % length) + length;
if (length2 invalid input: '<' length) return length2;
return 0;
... produces the correct code and is 27 bytes, so it's likely to be inlined in Hotspot for 1.4.1. -
stx
public final int stx(int x) Description copied from interface:Grid3D
Simple [and fast] toroidal x. Use this if the values you'd pass in never stray beyond (-width ... width * 2) not inclusive. It's a bit faster than the full toroidal computation as it uses if statements rather than two modulos. The following definition:
{ int width = this.width; if (x >= 0) { if (x invalid input: '<' width) return x; return x - width; } return x + width; }
...produces the shortest code (24 bytes) and is inlined in Hotspot for 1.4.1. However in most cases removing the int width = this.width; is likely to be a little faster if most objects are usually within the toroidal region. -
sty
public final int sty(int y) Description copied from interface:Grid3D
Simple [and fast] toroidal y. Use this if the values you'd pass in never stray beyond (-height ... height * 2) not inclusive. It's a bit faster than the full toroidal computation as it uses if statements rather than two modulos. The following definition:
{ int height = this.height; if (y >= 0) { if (y invalid input: '<' height) return y ; return y - height; } return y + height; }
...produces the shortest code (24 bytes) and is inlined in Hotspot for 1.4.1. However in most cases removing the int height = this.height; is likely to be a little faster if most objects are usually within the toroidal region. -
stz
public final int stz(int z) Description copied from interface:Grid3D
Simple [and fast] toroidal z. Use this if the values you'd pass in never stray beyond (-length ... length * 2) not inclusive. It's a bit faster than the full toroidal computation as it uses if statements rather than two modulos. The following definition:
{ int length = this.length; if (z >= 0) { if (z invalid input: '<' length) return z ; return z - length; } return z + length; }
...produces the shortest code (24 bytes) and is inlined in Hotspot for 1.4.1. However in most cases removing the int length = this.length; is likely to be a little faster if most objects are usually within the toroidal region. -
stz
public final int stz(int z, int length) -
removeOrigin
-
removeOriginToroidal
-
getNeighborsMaxDistance
public void getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos) Deprecated.Description copied from interface:Grid3D
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) invalid input: '<'= dist. This region forms a cube 2*dist+1 cells across, centered at (X,Y,Z). If dist==1, this is equivalent to the twenty-six neighbors surrounding (X,Y,Z), plus (X,Y) itself. Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so this function is deprecated: instead you should use the other version of this function which has more functionality. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y,z) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsMaxDistance(x,y,dist,toroidal ? Grid3D.TOROIDAL : Grid3D.BOUNDED, true, xPos, yPos, zPos);
- Specified by:
getNeighborsMaxDistance
in interfaceGrid3D
-
getMooreLocations
public void getMooreLocations(int x, int y, int z, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Description copied from interface:Grid3D
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) invalid input: '<'= dist. This region forms a cube 2*dist+1 cells across, centered at (X,Y,Z). If dist==1, this is equivalent to the twenty-six neighbors surrounding (X,Y,Z), plus (X,Y) itself. Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.This function may be run in one of three modes: Grid3D.BOUNDED, Grid3D.UNBOUNDED, and GrideD.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid3D permits this but ObjectGrid3D and DoubleGrid3D and IntGrid3D and DenseGrid3D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y,z) point at the center of the neighborhood -- in the neighborhood results.
- Specified by:
getMooreLocations
in interfaceGrid3D
-
getNeighborsHamiltonianDistance
public void getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos) Deprecated.Description copied from interface:Grid3D
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) invalid input: '<'= dist. This region forms an octohedron 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y,Y). If dist==1 this is equivalent to the six neighbors above, below, left, and right, front, and behind (X,Y,Z)), plus (X,Y,Z) itself. Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.This function may only run in two modes: toroidal or bounded. Unbounded lookup is not permitted, and so this function is deprecated: instead you should use the other version of this function which has more functionality. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
The origin -- that is, the (x,y,z) point at the center of the neighborhood -- is always included in the results.
This function is equivalent to: getNeighborsHamiltonianDistance(x,y,dist,toroidal ? Grid3D.TOROIDAL : Grid3D.BOUNDED, true, xPos, yPos, zPos);
- Specified by:
getNeighborsHamiltonianDistance
in interfaceGrid3D
-
getVonNeumannLocations
public void getVonNeumannLocations(int x, int y, int z, int dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Description copied from interface:Grid3D
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) invalid input: '<'= dist. This region forms an octohedron 2*dist+1 cells from point to opposite point inclusive, centered at (X,Y,Y). If dist==1 this is equivalent to the six neighbors above, below, left, and right, front, and behind (X,Y,Z)), plus (X,Y,Z) itself. Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first. null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.This function may be run in one of three modes: Grid3D.BOUNDED, Grid3D.UNBOUNDED, and GrideD.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid3D permits this but ObjectGrid3D and DoubleGrid3D and IntGrid3D and DenseGrid3D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y,z) point at the center of the neighborhood -- in the neighborhood results.
- Specified by:
getVonNeumannLocations
in interfaceGrid3D
-
getRadialLocations
public void getRadialLocations(int x, int y, int z, double dist, int mode, boolean includeOrigin, IntBag xPos, IntBag yPos, IntBag zPos) Description copied from interface:Grid3D
Gets all neighbors overlapping with a spherical region centered at (X,Y,Z) and with a radius of dist. The measurement rule is Grid3D.ANY, meaning those cells which overlap at all with the region. The region is closed, meaning that that points which touch on the outer surface of the sphere will be considered members of the region.Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first.
This function may be run in one of three modes: Grid3D.BOUNDED, Grid3D.UNBOUNDED, and GrideD.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid3D permits this but ObjectGrid3D and DoubleGrid3D and IntGrid3D and DenseGrid3D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y,z) point at the center of the neighborhood -- in the neighborhood results.
- Specified by:
getRadialLocations
in interfaceGrid3D
-
getRadialLocations
public void getRadialLocations(int x, int y, int z, double dist, int mode, boolean includeOrigin, int measurementRule, boolean closed, IntBag xPos, IntBag yPos, IntBag zPos) Description copied from interface:Grid3D
Gets all neighbors overlapping with a spherical region centered at (X,Y,Z) and with a radius of dist. If measurementRule is Grid3D.CENTER, then the measurement rule will be those cells whose centers overlap with the region. If measurementRule is Grid3D.ALL, then the measurement rule will be those cells which entirely overlap with the region. If measurementrule is Grid3D.ANY, then the measurement rule will be those cells which overlap at all with the region. If closed is true, then the region will be considered "closed", that is, that points which touch on the outer surface of the circle will be considered members of the region. If closed is open, then the region will be considered "open", that is, that points which touch on the outer surface of the circle will NOT be considered members of the region.Places each x, y, and z value of these locations in the provided IntBags xPos, yPos, and zPos, clearing the bags first.
This function may be run in one of three modes: Grid3D.BOUNDED, Grid3D.UNBOUNDED, and GrideD.TOROIDAL. If "bounded", then the neighbors are restricted to be only those which lie within the box ranging from (0,0,0) to (width, height,length), that is, the width and height of the grid. If "unbounded", then the neighbors are not so restricted. Note that unbounded neighborhood lookup only makes sense if your grid allows locations to actually be outside this box. For example, SparseGrid3D permits this but ObjectGrid3D and DoubleGrid3D and IntGrid3D and DenseGrid3D do not. Finally if "toroidal", then the environment is assumed to be toroidal, that is, wrap-around, and neighbors are computed in this fashion. Toroidal locations will not appear multiple times: specifically, if the neighborhood distance is so large that it wraps completely around the width or height of the box, neighbors will not be counted multiple times. Note that to ensure this, subclasses may need to resort to expensive duplicate removal, so it's not suggested you use so unreasonably large distances.
You can also opt to include the origin -- that is, the (x,y,z) point at the center of the neighborhood -- in the neighborhood results.
- Specified by:
getRadialLocations
in interfaceGrid3D
-
checkBounds
-
isDistributed
protected boolean isDistributed()
-