sim.field.grid
Class SparseGrid3D

java.lang.Object
  extended bysim.field.SparseField
      extended bysim.field.grid.SparseGrid3D
All Implemented Interfaces:
java.io.Serializable

public class SparseGrid3D
extends SparseField

A storage facility for sparse objects in discrete 3D space, using HashMaps. SparseGrid3D differs from ObjectGrid3D in several respects:

Generally speaking, if you have a grid of objects, one per location, you should use an ObjectGrid3D. If you have a large grid occupied by a few objects, or those objects can pile up on the same grid location, you should use a SparseGrid3D.

In either case, you might consider storing the location of an object IN THE OBJECT ITSELF if you need to query for the object location often -- it's faster than the hashtable lookup in SparseGrid3D, and certainly faster than searching the entire array of an ObjectGrid3D.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class sim.field.SparseField
SparseField.LocationAndIndex
 
Field Summary
protected  int height
           
protected  int length
           
protected  int width
           
 
Fields inherited from class sim.field.SparseField
allObjects, LARGE_BAG_RATIO, locationAndIndexHash, MIN_BAG_SIZE, objectHash, removeEmptyBags, replaceLargeBags
 
Constructor Summary
SparseGrid3D(int width, int height, int length)
           
 
Method Summary
 int getHeight()
           
 int getLength()
           
 void getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
           
 void getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos)
           
 void getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
           
 void getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos)
           
 Int3D getObjectLocation(java.lang.Object obj)
           
 Double3D getObjectLocationAsDouble3D(java.lang.Object obj)
           
 Bag getObjectsAtLocation(int x, int y, int z)
           
 Bag getObjectsAtLocations(IntBag xPos, IntBag yPos, IntBag zPos, Bag result)
          For each location, puts all such objects into the result bag.
 int getWidth()
           
 Bag removeObjectsAtLocation(Int3D location)
           
 Bag removeObjectsAtLocation(int x, int y, int z)
           
 boolean setObjectLocation(java.lang.Object obj, Int3D location)
           
 boolean setObjectLocation(java.lang.Object obj, int x, int y, int z)
           
 int stx(int x)
           
 int sty(int y)
           
 int stz(int z)
           
 int tx(int x)
           
 int ty(int y)
           
 int tz(int z)
           
 
Methods inherited from class sim.field.SparseField
clear, exists, getAllObjects, getObjectIndex, getObjectsAtLocation, getObjectsAtLocations, getRawObjectLocation, iterator, locationBagIterator, remove, removeObjectsAtLocation, setObjectLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected int width

height

protected int height

length

protected int length
Constructor Detail

SparseGrid3D

public SparseGrid3D(int width,
                    int height,
                    int length)
Method Detail

getWidth

public final int getWidth()

getHeight

public final int getHeight()

getLength

public final int getLength()

tx

public final int tx(int x)

ty

public final int ty(int y)

tz

public final int tz(int z)

stx

public final int stx(int x)

sty

public final int sty(int y)

stz

public final int stz(int z)

getObjectsAtLocation

public final Bag getObjectsAtLocation(int x,
                                      int y,
                                      int z)

getObjectLocationAsDouble3D

public final Double3D getObjectLocationAsDouble3D(java.lang.Object obj)

getObjectLocation

public Int3D getObjectLocation(java.lang.Object obj)

removeObjectsAtLocation

public final Bag removeObjectsAtLocation(int x,
                                         int y,
                                         int z)

removeObjectsAtLocation

public Bag removeObjectsAtLocation(Int3D location)

setObjectLocation

public final boolean setObjectLocation(java.lang.Object obj,
                                       int x,
                                       int y,
                                       int z)

setObjectLocation

public boolean setObjectLocation(java.lang.Object obj,
                                 Int3D location)

getNeighborsMaxDistance

public final void getNeighborsMaxDistance(int x,
                                          int y,
                                          int z,
                                          int dist,
                                          boolean toroidal,
                                          IntBag xPos,
                                          IntBag yPos,
                                          IntBag zPos)

getNeighborsHamiltonianDistance

public final void getNeighborsHamiltonianDistance(int x,
                                                  int y,
                                                  int z,
                                                  int dist,
                                                  boolean toroidal,
                                                  IntBag xPos,
                                                  IntBag yPos,
                                                  IntBag zPos)

getNeighborsMaxDistance

public final void getNeighborsMaxDistance(int x,
                                          int y,
                                          int z,
                                          int dist,
                                          boolean toroidal,
                                          Bag result,
                                          IntBag xPos,
                                          IntBag yPos,
                                          IntBag zPos)

getNeighborsHamiltonianDistance

public final void getNeighborsHamiltonianDistance(int x,
                                                  int y,
                                                  int z,
                                                  int dist,
                                                  boolean toroidal,
                                                  Bag result,
                                                  IntBag xPos,
                                                  IntBag yPos,
                                                  IntBag zPos)

getObjectsAtLocations

public Bag getObjectsAtLocations(IntBag xPos,
                                 IntBag yPos,
                                 IntBag zPos,
                                 Bag result)
For each location, puts all such objects into the result bag. Returns the result bag. If the provided result bag is null, one will be created and returned.