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
An abstract class for multidimensional uniform grids.
The grid is infinite with given cell size (only occupied cells are remembered in a map).
-
Constructor Summary
ConstructorsConstructorDescriptionUniformGridImpl
(double cellSize) Constructor.UniformGridImpl
(double cellSize, Collection<V> objects, Function<? super V, ? extends K> mapFunc) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the grid, i.e., removes all stored values.Returns objects stored in the cell of given location in space.getAdjacentCells
(K loc) Computes the cell for given location and then all its neighbors.getAll()
Returns all objects stored in the grid.double
Returns cell size.getClosest
(K loc) Returns all objects that can be closer that the cell size.getGrid()
Returns non-empty cells (in random order)protected abstract L
locationToCell
(K loc) Takes a location in space and return coordinates of the corresponding cell.int
Returns number of non-empty cells.boolean
Removes an object located in the spacefinal void
Stores given objects into the grid.void
Stores an object located in given 3D position in the grid.
-
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 storedmapFunc
- 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 interfaceUniformGrid<L,
K> - Returns:
- cell size
-
numOccupiedCells
public int numOccupiedCells()Description copied from interface:UniformGrid
Returns number of non-empty cells.- Specified by:
numOccupiedCells
in interfaceUniformGrid<L,
K> - Returns:
- number of non-empty cells.
-
getNonEmptyCells
Description copied from interface:UniformGrid
Returns non-empty cells (in random order)- Specified by:
getNonEmptyCells
in interfaceUniformGrid<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 interfaceUniformGrid<L,
K>
-
store
Description copied from interface:UniformGrid
Stores an object located in given 3D position in the grid.- Specified by:
store
in interfaceUniformGrid<L,
K> - Parameters:
loc
- 3D location of the object. Must not benull
object
- Object to store.
-
store
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 interfaceUniformGrid<L,
K> - Parameters:
objects
- Objects to be storedmapFunc
- A function that computes a space location from an object
-
get
Description copied from interface:UniformGrid
Returns objects stored in the cell of given location in space.- Specified by:
get
in interfaceUniformGrid<L,
K> - Parameters:
loc
- location in space- Returns:
- objects stored in the cell or empty collection
-
getAll
Description copied from interface:UniformGrid
Returns all objects stored in the grid.- Specified by:
getAll
in interfaceUniformGrid<L,
K> - Returns:
- all objects stored in the grid
-
remove
Description copied from interface:UniformGrid
Removes an object located in the space- Specified by:
remove
in interfaceUniformGrid<L,
K> - Parameters:
loc
- Object's location in spaceobject
- Object to be removed- Returns:
true
if the objects was found and removed,false
otherwise.
-
getClosest
Description copied from interface:UniformGrid
Returns all objects that can be closer that the cell size.- Specified by:
getClosest
in interfaceUniformGrid<L,
K> - Parameters:
loc
- location in space- Returns:
- objects that can be closer that the cell size or empty collection.
-
locationToCell
Takes a location in space and return coordinates of the corresponding cell.- Parameters:
loc
- Location in space- Returns:
- coordinates of the corresponding cell
-
getAdjacentCells
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
-