net.algart.model3d.common.movement.model
Class GridItemSet

java.lang.Object
  extended by net.algart.model3d.common.movement.model.SimpleItemSet
      extended by net.algart.model3d.common.movement.model.GridItemSet
All Implemented Interfaces:
ItemSet

public class GridItemSet
extends SimpleItemSet

Grid item set.

This implementation of ItemSet interface extends SimpleItemSet and provides better implementation of getPossibleInteractingIndexes(int[], int) method. Namely, this class works with 3D grid, consisting of dimX * dimY * dimZ cells (parallelepipeds with edges parallels to coordinate axes). For every cell, it supports the list of items, which have centers and interaction radii and the centers of which lie inside this cell. It helps getPossibleInteractingIndexes(int[], int) method to find all "neighbours" of the given item by analysing only a limited number of grid cells "near" the center of this item, namely at the distance depending on the interaction radius of the given item and the maximal from interaction radii of all items. As a result, if the items are distributed uniformly enough inside the grid and most of them implement HavingInteractionRadius interface, the performance of getPossibleInteractingIndexes(int[], int) method can be near O(1).

The grid, described above, is fully built by preprocess() method. I remind that you should call this method after any correction in the item set, in particular, after any changes of the coordinates of the centers.

Please see comments fo ItemSet interface about multithreading usage.

AlgART Laboratory 2010

Since:
JDK 1.5
Version:
1.0
Author:
Daniel Alievsky

Nested Class Summary
Modifier and Type Class and Description
static class GridItemSet.GridRangeStyle
          Method of calculating the grid bounds: which area of 3D space should be splitted into rectangular cells by GridItemSet.preprocess() method.
 
Constructor Summary
Constructor and Description
GridItemSet(int dimX, int dimY, int dimZ, GridItemSet.GridRangeStyle gridRangeStyle)
          Creates new instance of this class, working with the grid with dimX * dimY * dimZ cells.
GridItemSet(ItemListBuilder itemListBuilder, int dimX, int dimY, int dimZ, GridItemSet.GridRangeStyle gridRangeStyle)
          Creates new instance of this class, working with the grid with dimX * dimY * dimZ cells.
 
Method Summary
Modifier and Type Method and Description
 int getPossibleInteractingIndexes(int[] result, int itemIndex)
          This implementation analyses the set of grid cells, lying "near" the center of the specified item — in some sense, not farther than the sum of interaction radiis of the given item #itemIndex and the maximal from interaction radii of all items (for which this radius is defined and is not Double.POSITIVE_INFINITY).
 void preprocess()
          This implementation calls the same method of the superclass and then builds the grid, according to gridRangeStyle argument of the constructor.
 java.lang.String toString()
          Returns a brief string description of this object.
 
Methods inherited from class net.algart.model3d.common.movement.model.SimpleItemSet
add, addAll, get, getAll, getAll, removeItems, set, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridItemSet

public GridItemSet(ItemListBuilder itemListBuilder,
                   int dimX,
                   int dimY,
                   int dimZ,
                   GridItemSet.GridRangeStyle gridRangeStyle)
Creates new instance of this class, working with the grid with dimX * dimY * dimZ cells.

The gridRangeStyle specifies, what area of 3D-space should be splitted to cells.

The itemListBuilder argument specifies the builder, that will be used for creating the built-in java.util.List instance, which will really store all items.

Parameters:
itemListBuilder - the builder, that will be used for creating the java.util.List instance.
dimX - the number of cells along x axis.
dimY - the number of cells along y axis.
dimZ - the number of cells along z axis.
gridRangeStyle - the algorithm of determining grid bounds.
Throws:
java.lang.NullPointerException - if itemListBuilder or gridRangeStyle is null.
java.lang.IllegalArgumentException - if dimX<=0, dimY<=0, dimZ<=0, or if the product of these 3 numbers is greater than Integer.MAX_VALUE.

GridItemSet

public GridItemSet(int dimX,
                   int dimY,
                   int dimZ,
                   GridItemSet.GridRangeStyle gridRangeStyle)
Creates new instance of this class, working with the grid with dimX * dimY * dimZ cells. Equivalent to new GridItemSet(ItemListBuilder.DEFAULT, dimX, dimY, dimZ, gridRangeStyle).

Parameters:
dimX - the number of cells along x axis.
dimY - the number of cells along y axis.
dimZ - the number of cells along z axis.
gridRangeStyle - the algorithm of determining grid bounds.
Throws:
java.lang.NullPointerException - if itemListBuilder or gridRangeStyle is null.
java.lang.IllegalArgumentException - if dimX<=0, dimY<=0, dimZ<=0, or if the product of these 3 numbers is greater than Integer.MAX_VALUE.
Method Detail

getPossibleInteractingIndexes

public int getPossibleInteractingIndexes(int[] result,
                                         int itemIndex)
This implementation analyses the set of grid cells, lying "near" the center of the specified item — in some sense, not farther than the sum of interaction radiis of the given item #itemIndex and the maximal from interaction radii of all items (for which this radius is defined and is not Double.POSITIVE_INFINITY).

Specified by:
getPossibleInteractingIndexes in interface ItemSet
Overrides:
getPossibleInteractingIndexes in class SimpleItemSet
Parameters:
result - the indexes of "neighbours": items that can interact with the given item.
itemIndex - the index of the given item.
Returns:
the actual length K of the returned array: the required indexes are returned in the first K elements of the result.
Throws:
java.lang.NullPointerException - if result argument is null.
java.lang.IllegalStateException - if the length of result array is insufficient.
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= SimpleItemSet.size()).

preprocess

public void preprocess()
This implementation calls the same method of the superclass and then builds the grid, according to gridRangeStyle argument of the constructor.

This method reallocates memory if and only if it is the first call of this method or the number of items size() was changed since the last call of it.

Specified by:
preprocess in interface ItemSet
Overrides:
preprocess in class SimpleItemSet

toString

public java.lang.String toString()
Returns a brief string description of this object.

The result of this method may depend on implementation.

Overrides:
toString in class SimpleItemSet
Returns:
a brief string description of this object.