sim.field.grid
Class ObjectGrid3D

java.lang.Object
  extended bysim.field.grid.AbstractGrid3D
      extended bysim.field.grid.ObjectGrid3D
All Implemented Interfaces:
Grid3D, java.io.Serializable

public class ObjectGrid3D
extends AbstractGrid3D

A wrapper for 3D arrays of Objects.

This object expects that the 3D arrays are rectangular. You are encouraged to access the array directly. The object implements all of the Grid3D interface. See Grid3D for rules on how to properly implement toroidal grids.

The width and height and length (z dimension) of the object are provided to avoid having to say field[x].length, etc.

We very strongly encourage you to examine SparseGrid3D first to see if it's more appropriate to your task. If you need arbitrary numbers of Objects to be able to occupy the same location in the grid, or if you have very few Objects and a very large grid, or if your space is unbounded, you should probably use SparseGrid3D instead.

See Also:
Serialized Form

Field Summary
 java.lang.Object[][][] field
           
 
Fields inherited from class sim.field.grid.AbstractGrid3D
height, length, width
 
Constructor Summary
ObjectGrid3D(int width, int height, int length)
           
ObjectGrid3D(int width, int height, int length, java.lang.Object initialValue)
           
ObjectGrid3D(ObjectGrid3D values)
           
 
Method Summary
 Bag clear()
          Sets all the locations in the grid to null, and returns in a Bag all stored objects (including duplicates but not null values).
 java.lang.Object get(int x, int y, int z)
           
 Bag getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
          Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) <= dist.
 Bag getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
          Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) <= dist.
 void set(int x, int y, int z, java.lang.Object val)
           
 ObjectGrid3D setTo(java.lang.Object thisObj)
           
 ObjectGrid3D setTo(ObjectGrid3D values)
           
 
Methods inherited from class sim.field.grid.AbstractGrid3D
getHeight, getLength, getNeighborsHamiltonianDistance, getNeighborsMaxDistance, getWidth, stx, sty, stz, tx, ty, tz
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

field

public java.lang.Object[][][] field
Constructor Detail

ObjectGrid3D

public ObjectGrid3D(int width,
                    int height,
                    int length)

ObjectGrid3D

public ObjectGrid3D(int width,
                    int height,
                    int length,
                    java.lang.Object initialValue)

ObjectGrid3D

public ObjectGrid3D(ObjectGrid3D values)
Method Detail

set

public final void set(int x,
                      int y,
                      int z,
                      java.lang.Object val)

get

public final java.lang.Object get(int x,
                                  int y,
                                  int z)

setTo

public final ObjectGrid3D setTo(java.lang.Object thisObj)

clear

public final Bag clear()
Sets all the locations in the grid to null, and returns in a Bag all stored objects (including duplicates but not null values). You are free to modify the Bag.


setTo

public final ObjectGrid3D setTo(ObjectGrid3D values)

getNeighborsMaxDistance

public final Bag getNeighborsMaxDistance(int x,
                                         int y,
                                         int z,
                                         int dist,
                                         boolean toroidal,
                                         Bag result,
                                         IntBag xPos,
                                         IntBag yPos,
                                         IntBag zPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) <= 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. Then places into the result Bag the objects at each of those locations clearning it first. Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.


getNeighborsHamiltonianDistance

public final Bag getNeighborsHamiltonianDistance(int x,
                                                 int y,
                                                 int z,
                                                 int dist,
                                                 boolean toroidal,
                                                 Bag result,
                                                 IntBag xPos,
                                                 IntBag yPos,
                                                 IntBag zPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) <= 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. Then places into the result Bag the objects at each of those locations clearning it first. Returns the result Bag (constructing one if null had been passed in). null may be passed in for the various bags, though it is more efficient to pass in a 'scratch bag' for each one.