AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy > Class Template Reference

A spatial index defined by origin, spacing, and resolution. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/latest/src/axom/spin/UniformGrid.hpp>

Inherits policy::DynamicGridStorage< T >.

Classes

struct  QueryObject
 

Public Types

enum  { INVALID_BIN_INDEX = -1 }
 A special value indicating any location not in the UniformGrid. More...
 
using BoxType = primal::BoundingBox< double, NDIMS >
 The type used for specifying spatial extent of the contents. More...
 
using PointType = primal::Point< double, NDIMS >
 The type used to query the index. More...
 

Public Member Functions

 UniformGrid (const double *lower_bound, const double *upper_bound, const int *res, int allocatorID=axom::execution_space< ExecSpace >::allocatorID())
 Constructor specifying bounding box (min and max points) and number of bins. More...
 
 UniformGrid (const BoxType &bbox, const int *res, int allocatorID=axom::execution_space< ExecSpace >::allocatorID())
 Constructor specifying bounding box and number of bins. More...
 
 UniformGrid (const primal::NumericArray< int, NDIMS > &res, axom::ArrayView< const BoxType > bboxes, axom::ArrayView< const T > objs, int allocatorID=axom::execution_space< ExecSpace >::allocatorID())
 Constructor specifying objects to initialize the UniformGrid with. More...
 
void initialize (axom::ArrayView< const BoxType > bboxes, axom::ArrayView< const T > objs)
 Reinitializes a UniformGrid with an array of objects and associated bounding boxes. More...
 
int getBinIndex (const PointType &pt) const
 Returns the index of the bin containing the specified point. More...
 
bool isBinEmpty (int index) const
 Returns whether the bin specified by index is empty. More...
 
const std::vector< int > getBinsForBbox (const BoxType &BB) const
 Returns the indices of the bins for a given bounding box. More...
 
void getCandidatesAsArray (axom::ArrayView< const BoxType > queryObjs, axom::ArrayView< IndexType > outOffsets, axom::ArrayView< IndexType > outCounts, axom::Array< IndexType > &outCandidates) const
 Returns a list of candidates in the vicinity of a set of query bounding boxes. More...
 
void insert (const BoxType &BB, const T &obj)
 Inserts obj into each bin overlapped by BB. More...
 
QueryObject getQueryObject () const
 

Detailed Description

template<typename T, int NDIMS, typename ExecSpace = axom::SEQ_EXEC, typename StoragePolicy = policy::DynamicGridStorage<T>>
class axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >

A spatial index defined by origin, spacing, and resolution.

Template Parameters
TThe type of object that this UniformGrid will hold
NDIMSThe UniformGrid dimensionality: supported values are 2 or 3
ExecSpaceThe execution space in which operations will take place

The UniformGrid class is parameterized on the type of object it will contain and the dimensionality of the grid. Currently the UniformGrid will index 2D and 3D space.

The UniformGrid divides space into a number of bins, extending in a block from an origin point and arranged in row-major order. Each bin extends over an axis-aligned rectangle or parallelepiped. The size of a bin is specified by the spacing constructor argument, and the number of bins is specified by the res constructor argument.

To use this class, a user will instantiate a UniformGrid and insert a number of objects (each with its own bounding box). The insert operation puts the object into some of the bins. The user may retrieve the bin index of any point, then retrieve any objects associated with the bin at that index.

Member Typedef Documentation

◆ BoxType

template<typename T , int NDIMS, typename ExecSpace = axom::SEQ_EXEC, typename StoragePolicy = policy::DynamicGridStorage<T>>
using axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::BoxType = primal::BoundingBox<double, NDIMS>

The type used for specifying spatial extent of the contents.

◆ PointType

template<typename T , int NDIMS, typename ExecSpace = axom::SEQ_EXEC, typename StoragePolicy = policy::DynamicGridStorage<T>>
using axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::PointType = primal::Point<double, NDIMS>

The type used to query the index.

Member Enumeration Documentation

◆ anonymous enum

template<typename T , int NDIMS, typename ExecSpace = axom::SEQ_EXEC, typename StoragePolicy = policy::DynamicGridStorage<T>>
anonymous enum

A special value indicating any location not in the UniformGrid.

Returned by getBinIndex() if that function is passed an exterior point. An error is thrown if getBinContents() is passed INVALID_BIN_INDEX. clear(INVALID_BIN_INDEX) is a no-op; isBinEmpty(INVALID_BIN_INDEX) returns true.

Enumerator
INVALID_BIN_INDEX 

Constructor & Destructor Documentation

◆ UniformGrid() [1/3]

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::UniformGrid ( const double *  lower_bound,
const double *  upper_bound,
const int *  res,
int  allocatorID = axom::execution_space<ExecSpace>::allocatorID() 
)

Constructor specifying bounding box (min and max points) and number of bins.

The lower and upper bounds are specified as double arrays. Each argument points to an array of at least length NDIMS. The nth element in each array specifies, for the nth dimension, the lower bound (inclusive), the upper bound (exclusive), and the number of bins. Thus, UniformGrid({0., 0.}, {2., 4.}, {2, 4}); defines an index extending from 0 up to 2 divided into two bins in the x-dimension and from 0 up to 4 divided into four bins in the y dimension.

◆ UniformGrid() [2/3]

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::UniformGrid ( const BoxType bbox,
const int *  res,
int  allocatorID = axom::execution_space<ExecSpace>::allocatorID() 
)

Constructor specifying bounding box and number of bins.

References SLIC_ASSERT.

◆ UniformGrid() [3/3]

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::UniformGrid ( const primal::NumericArray< int, NDIMS > &  res,
axom::ArrayView< const BoxType bboxes,
axom::ArrayView< const T >  objs,
int  allocatorID = axom::execution_space<ExecSpace>::allocatorID() 
)

Constructor specifying objects to initialize the UniformGrid with.

References axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::initialize().

Member Function Documentation

◆ initialize()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
void axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::initialize ( axom::ArrayView< const BoxType bboxes,
axom::ArrayView< const T >  objs 
)

◆ getBinIndex()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
int axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::getBinIndex ( const PointType pt) const

Returns the index of the bin containing the specified point.

If the specified point is outside the grid, the function returns a special value (INVALID_BIN_INDEX). Note that the upper boundaries of a UniformGrid are not in a bin. Thus, if a UniformGrid divides the region from (0., 0.) to (10., 10.) into 10 x 10 bins, the code getBinIndex(PointType::makePoint(10., 10.)) will return INVALID_BIN_INDEX,

Parameters
[in]ptThe point to query.

◆ isBinEmpty()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
bool axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::isBinEmpty ( int  index) const

Returns whether the bin specified by index is empty.

Returns true if index is invalid.

Parameters
[in]indexThe index of the bin to test.

◆ getBinsForBbox()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
const std::vector< int > axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::getBinsForBbox ( const BoxType BB) const

Returns the indices of the bins for a given bounding box.

This method returns the indices of the bins that intersect BB. Any part of BB that falls outside this UniformGrid is disregarded. If BB falls completely outside this UniformGrid, this method returns an empty list.

References axom::primal::BoundingBox< T, NDIMS >::getMax(), and axom::primal::BoundingBox< T, NDIMS >::getMin().

◆ getCandidatesAsArray()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
void axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::getCandidatesAsArray ( axom::ArrayView< const BoxType queryObjs,
axom::ArrayView< IndexType outOffsets,
axom::ArrayView< IndexType outCounts,
axom::Array< IndexType > &  outCandidates 
) const

Returns a list of candidates in the vicinity of a set of query bounding boxes.

Parameters
[in]queryObjsThe array of query objects
[out]outOffsetsOffsets into the candidates array for each query object
[out]outCountsThe number of candidates for each query object
[out]candidatesThe candidate IDs for each query object
Note
The output candidate array is allocated inside the function, using the given allocator ID passed in during implicit grid initialization.
Upon completion, the ith query point has:
  • counts[ i ] candidates
  • Stored in the candidates array in the following range: [ offsets[ i ], offsets[ i ]+counts[ i ] ]

References AXOM_LAMBDA, axom::Array< T, DIM, SPACE >::data(), axom::ArrayView< T, DIM, SPACE >::data(), axom::detail::getAllocatorID(), axom::Array< T, DIM, SPACE >::push_back(), axom::ArrayView< T, DIM, SPACE >::size(), SLIC_ASSERT, and axom::Array< T, DIM, SPACE >::view().

◆ insert()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
void axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::insert ( const BoxType BB,
const T &  obj 
)

Inserts obj into each bin overlapped by BB.

No error is signalled if BB falls partly or wholly outside the UniformGrid.

Parameters
[in]BBThe region in which to record obj
[in]objThe object to insert into any bins overlapped by BB

References SLIC_ASSERT.

◆ getQueryObject()

template<typename T , int NDIMS, typename ExecSpace , typename StoragePolicy >
UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::QueryObject axom::spin::UniformGrid< T, NDIMS, ExecSpace, StoragePolicy >::getQueryObject

The documentation for this class was generated from the following file: