Class UniformGridImpl<L,K,V>

java.lang.Object
cz.fidentis.analyst.data.grid.impl.UniformGridImpl<L,K,V>
Type Parameters:
L - grid cells' multidimensional indices, e.g., Tuple2i, Tuple3i, Tuple4i, etc.
K - grid's location in multidimensional space, i.e., Tuple2d, Tuple3d, Tuple4d, etc.
V - the type of elements to be stored in the grid
All Implemented Interfaces:
UniformGrid<K,V>
Direct Known Subclasses:
UniformGrid3dImpl, UniformGrid4dImpl

public abstract class UniformGridImpl<L,K,V> extends Object implements UniformGrid<K,V>
An abstract class for multidimensional uniform grids. The grid is infinite with given cell size (only occupied cells are remembered in a map).
  • Constructor Details

    • UniformGridImpl

      public UniformGridImpl(double cellSize)
      Constructor.
      Parameters:
      cellSize - Cell size. Must be bigger that one.
    • UniformGridImpl

      public UniformGridImpl(double cellSize, Collection<V> objects, Function<? super V,? extends K> mapFunc)
      Constructor. As the mapping function, use (MeshPoint mp) -> mp.getPosition() or (Point3d p) -> p, for instance.
      Parameters:
      cellSize - Cell size. Must be bigger that one.
      objects - Objects to be stored
      mapFunc - A function that computes a space location from an object
  • Method Details

    • getCellSize

      public double getCellSize()
      Description copied from interface: UniformGrid
      Returns cell size.
      Specified by:
      getCellSize in interface UniformGrid<L,K>
      Returns:
      cell size
    • numOccupiedCells

      public int numOccupiedCells()
      Description copied from interface: UniformGrid
      Returns number of non-empty cells.
      Specified by:
      numOccupiedCells in interface UniformGrid<L,K>
      Returns:
      number of non-empty cells.
    • getNonEmptyCells

      public List<List<V>> getNonEmptyCells()
      Description copied from interface: UniformGrid
      Returns non-empty cells (in random order)
      Specified by:
      getNonEmptyCells in interface UniformGrid<L,K>
      Returns:
      non-empty cells
    • clear

      public void clear()
      Description copied from interface: UniformGrid
      Clear the grid, i.e., removes all stored values.
      Specified by:
      clear in interface UniformGrid<L,K>
    • store

      public void store(K loc, V object)
      Description copied from interface: UniformGrid
      Stores an object located in given 3D position in the grid.
      Specified by:
      store in interface UniformGrid<L,K>
      Parameters:
      loc - 3D location of the object. Must not be null
      object - Object to store.
    • store

      public final void store(Collection<V> objects, Function<? super V,? extends K> mapFunc)
      Description copied from interface: UniformGrid
      Stores given objects into the grid. As the mapping function, use (MeshPoint mp) -> mp.getPosition() or (Point3d p) -> p, for instance.
      Specified by:
      store in interface UniformGrid<L,K>
      Parameters:
      objects - Objects to be stored
      mapFunc - A function that computes a space location from an object
    • get

      public List<V> get(K loc)
      Description copied from interface: UniformGrid
      Returns objects stored in the cell of given location in space.
      Specified by:
      get in interface UniformGrid<L,K>
      Parameters:
      loc - location in space
      Returns:
      objects stored in the cell or empty collection
    • getAll

      public List<V> getAll()
      Description copied from interface: UniformGrid
      Returns all objects stored in the grid.
      Specified by:
      getAll in interface UniformGrid<L,K>
      Returns:
      all objects stored in the grid
    • remove

      public boolean remove(K loc, V object)
      Description copied from interface: UniformGrid
      Removes an object located in the space
      Specified by:
      remove in interface UniformGrid<L,K>
      Parameters:
      loc - Object's location in space
      object - Object to be removed
      Returns:
      true if the objects was found and removed, false otherwise.
    • getClosest

      public List<V> getClosest(K loc)
      Description copied from interface: UniformGrid
      Returns all objects that can be closer that the cell size.
      Specified by:
      getClosest in interface UniformGrid<L,K>
      Parameters:
      loc - location in space
      Returns:
      objects that can be closer that the cell size or empty collection.
    • locationToCell

      protected abstract L locationToCell(K loc)
      Takes a location in space and return coordinates of the corresponding cell.
      Parameters:
      loc - Location in space
      Returns:
      coordinates of the corresponding cell
    • getAdjacentCells

      protected abstract List<L> getAdjacentCells(K loc)
      Computes the cell for given location and then all its neighbors.
      Parameters:
      loc - Location in space
      Returns:
      the cell for given location and then all its neighbors.
    • getGrid

      protected Map<L,List<V>> getGrid()