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

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

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

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)
 Constructor specifying bounding box (min and max points) and number of bins. More...
 
 UniformGrid (const BoxType &bbox, const int *res)
 Constructor specifying bounding box and number of bins. More...
 
 ~UniformGrid ()
 Destructor: present for symmetry with constructor. More...
 
int getBinIndex (const PointType &pt) const
 Returns the index of the bin containing the specified point. More...
 
int getNumBins () const
 Returns the number of bins in this UniformGrid. More...
 
bool isBinEmpty (int index) const
 Returns whether the bin specified by index is empty. More...
 
std::vector< T > & getBinContents (int index)
 Returns the contents of the bin indicated by index. More...
 
const std::vector< T > & getBinContents (int index) const
 Returns the contents of the bin indicated by index. More...
 
bool isValidIndex (int index) const
 Returns true if index is valid; that is, refers to a valid bin. More...
 
const std::vector< int > getBinsForBbox (const BoxType &BB) const
 Returns the indices of the bins for a given bounding box. More...
 
void clear (int index)
 Clears the bin indicated by index. More...
 
void insert (const BoxType &BB, const T &obj)
 Inserts obj into each bin overlapped by BB. More...
 

Protected Member Functions

 UniformGrid ()
 The default constructor should not be used, so it is protected. More...
 

Detailed Description

template<typename T, int NDIMS>
class axom::spin::UniformGrid< T, NDIMS >

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

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>
using axom::spin::UniformGrid< T, NDIMS >::BoxType = primal::BoundingBox<double, NDIMS>

The type used for specifying spatial extent of the contents.

◆ PointType

template<typename T, int NDIMS>
using axom::spin::UniformGrid< T, NDIMS >::PointType = primal::Point<double, NDIMS>

The type used to query the index.

Member Enumeration Documentation

◆ anonymous enum

template<typename T, int NDIMS>
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>
axom::spin::UniformGrid< T, NDIMS >::UniformGrid ( const double *  lower_bound,
const double *  upper_bound,
const int *  res 
)

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.

References axom::spin::rectangular_lattice_from_bounding_box(), and SLIC_ASSERT.

◆ UniformGrid() [2/3]

template<typename T , int NDIMS>
axom::spin::UniformGrid< T, NDIMS >::UniformGrid ( const BoxType bbox,
const int *  res 
)

Constructor specifying bounding box and number of bins.

References axom::spin::rectangular_lattice_from_bounding_box(), axom::primal::BoundingBox< T, NDIMS >::scale(), and SLIC_ASSERT.

◆ ~UniformGrid()

template<typename T , int NDIMS>
axom::spin::UniformGrid< T, NDIMS >::~UniformGrid ( )

Destructor: present for symmetry with constructor.

◆ UniformGrid() [3/3]

template<typename T , int NDIMS>
axom::spin::UniformGrid< T, NDIMS >::UniformGrid ( )
protected

The default constructor should not be used, so it is protected.

References SLIC_ASSERT.

Member Function Documentation

◆ getBinIndex()

template<typename T , int NDIMS>
int axom::spin::UniformGrid< T, NDIMS >::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.

References axom::primal::BoundingBox< T, NDIMS >::contains(), and axom::spin::UniformGrid< T, NDIMS >::INVALID_BIN_INDEX.

◆ getNumBins()

template<typename T , int NDIMS>
int axom::spin::UniformGrid< T, NDIMS >::getNumBins ( ) const

Returns the number of bins in this UniformGrid.

◆ isBinEmpty()

template<typename T , int NDIMS>
bool axom::spin::UniformGrid< T, NDIMS >::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.

References axom::spin::UniformGrid< T, NDIMS >::isValidIndex().

◆ getBinContents() [1/2]

template<typename T , int NDIMS>
std::vector< T > & axom::spin::UniformGrid< T, NDIMS >::getBinContents ( int  index)

Returns the contents of the bin indicated by index.

It is an error if index is invalid.

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

References axom::spin::UniformGrid< T, NDIMS >::isValidIndex(), and SLIC_ASSERT.

◆ getBinContents() [2/2]

template<typename T , int NDIMS>
const std::vector< T > & axom::spin::UniformGrid< T, NDIMS >::getBinContents ( int  index) const

Returns the contents of the bin indicated by index.

It is an error if index is invalid. This is the const version.

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

References axom::spin::UniformGrid< T, NDIMS >::isValidIndex(), and SLIC_ASSERT.

◆ isValidIndex()

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

Returns true if index is valid; that is, refers to a valid bin.

The region of space indexed by this UniformGrid is divided into bins. Each bin has a unique integer index. If an integer is greater than or equal to zero and less than or equal to the greatest bin index, this method will return true. Otherwise, the integer does not refer to any bin and this method will return false.

Referenced by axom::spin::UniformGrid< T, NDIMS >::clear(), axom::spin::UniformGrid< T, NDIMS >::getBinContents(), and axom::spin::UniformGrid< T, NDIMS >::isBinEmpty().

◆ getBinsForBbox()

template<typename T , int NDIMS>
const std::vector< int > axom::spin::UniformGrid< T, NDIMS >::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(), axom::primal::BoundingBox< T, NDIMS >::getMin(), and axom::primal::BoundingBox< T, NDIMS >::intersectsWith().

Referenced by axom::spin::UniformGrid< T, NDIMS >::insert().

◆ clear()

template<typename T , int NDIMS>
void axom::spin::UniformGrid< T, NDIMS >::clear ( int  index)

Clears the bin indicated by index.

No-op if index is invalid.

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

References axom::spin::UniformGrid< T, NDIMS >::isValidIndex(), and SLIC_CHECK.

◆ insert()

template<typename T, int NDIMS>
void axom::spin::UniformGrid< T, NDIMS >::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 axom::utilities::clampVal(), axom::spin::UniformGrid< T, NDIMS >::getBinsForBbox(), axom::spin::RectangularLattice< NDIMS, SpaceCoordType, CellCoordType >::gridCell(), and SLIC_ASSERT.


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