BALL 1.5.0
Classes | List of all members
BALL::HashGrid3< Item > Class Template Reference

Three-dimensional Hash Grid Class. More...

#include <BALL/DATATYPE/hashGrid.h>

Classes

class  BoxIteratorTraits
 

Public Member Functions

Constructors and destructor
 HashGrid3 ()
 Default constructor. More...
 
 HashGrid3 (const Vector3 &origin, Size dimension_x, Size dimension_y, Size dimension_z, float spacing_x, float spacing_y, float spacing_z)
 
 HashGrid3 (const Vector3 &origin, Size dimension_x, Size dimension_y, Size dimension_z, float spacing)
 
 HashGrid3 (const Vector3 &origin, const Vector3 &size, float spacing)
 
 HashGrid3 (const HashGrid3 &grid, bool deep=true)
 Copy constructor. More...
 
virtual ~HashGrid3 ()
 Destructor. More...
 
virtual void clear ()
 Clears the whole grid. More...
 
void clear (Position x, Position y, Position z)
 Clears the HashGridBox3 at position (x, y, z) More...
 
void clear (const Vector3 &vector)
 Clears the HashGridBox3 at position vector More...
 
void destroy ()
 Destroys the grid (obsolete, only calls clear()) More...
 
void destroy (Position x, Position y, Position z)
 Destroys a box of the grid (obsolete, only calls clear()) More...
 
void destroy (const Vector3 &vector)
 Destroys a box of the grid (obsolete, only calls clear()) More...
 
Assignment
void set (const Vector3 &origin, const Vector3 &unit, Size dimension_x, Size dimension_y, Size dimension_z)
 assigns the content of a hash grid (obsolete) More...
 
void set (const Vector3 &origin, float unit, Size size)
 assigns the content of a hash grid (obsolete) More...
 
void set (const HashGrid3 &grid, bool deep=true)
 assigns the content of a hash grid (obsolete) More...
 
const HashGrid3operator= (const HashGrid3 &grid)
 Assignment operator. More...
 
void get (Vector3 &origin, Vector3 &unit, Size &dimension_x, Size &dimension_y, Size &dimension_z) const
 
void get (HashGrid3 &grid, bool deep=true) const
 
Accessors
Size countNonEmptyBoxes () const
 Counts the non-empty boxes of a grid. More...
 
Size getSize () const
 Returns the size of a grid, i. e. ????? More...
 
Vector3getOrigin ()
 Returns the origin of the grid. More...
 
const Vector3getOrigin () const
 Returns a const reference of the grid origin. More...
 
Vector3getUnit ()
 Returns the unit of the grid. More...
 
const Vector3getUnit () const
 Returns the unit of the grid (const version) More...
 
Size getSizeX () const
 Get the x dimension of the grid. More...
 
Size getSizeY () const
 Get the y dimension of the grid. More...
 
Size getSizeZ () const
 Get the z dimension of the grid. More...
 
HashGridBox3< Item > * getBox (Position x, Position y, Position z)
 Return the HashGridBox3 at position (x, y, z) More...
 
const HashGridBox3< Item > * getBox (Position x, Position y, Position z) const
 Return the HashGridBox3 at position (x, y, z) (const version) More...
 
HashGridBox3< Item > * getBox (const Vector3 &vector)
 Return the HashGridBox3 at position vector. More...
 
const HashGridBox3< Item > * getBox (const Vector3 &vector) const
 Return the HashGridBox3 at position vector (const version) More...
 
bool getIndices (const HashGridBox3< Item > &box, Position &x, Position &y, Position &z) const
 Get the position indices of a HashGridBox3. More...
 
void insert (Position x, Position y, Position z, const Item &item)
 Insert an item at position (x, y, z) More...
 
void insert (const Vector3 &vector, const Item &item)
 Insert an item at position vector More...
 
bool remove (Position x, Position y, Position z, const Item &item)
 Remove an item from position (x, y ,z) More...
 
bool remove (const Vector3 &vector, const Item &item)
 Remove an item from position vector More...
 
Miscellaneous
void host (Visitor< HashGrid3 > &visitor)
 
Predicates
bool operator== (const HashGrid3 &grid) const
 Equality operator. More...
 
bool operator!= (const HashGrid3 &grid) const
 Inequality operator. More...
 
bool isEmpty () const
 Tests, whether this is empty. More...
 
Debugging and Diagnostics
virtual bool isValid () const
 Validity check. More...
 
virtual void dump (std::ostream &s=std::cout, Size depth=0) const
 Dump the contents of a HashGrid3 to a stream. More...
 

External Iterators

typedef Position BoxIteratorPosition
 
typedef ForwardIterator< HashGrid3< Item >, HashGridBox3< Item >, BoxIteratorPosition, BoxIteratorTraitsBoxIterator
 
typedef ConstForwardIterator< HashGrid3< Item >, HashGridBox3< Item >, BoxIteratorPosition, BoxIteratorTraitsConstBoxIterator
 
class BoxIteratorTraits
 
BoxIterator beginBox ()
 
BoxIterator endBox ()
 
ConstBoxIterator beginBox () const
 
ConstBoxIterator endBox () const
 

Internal Iterators

bool apply (UnaryProcessor< Item > &processor)
 
bool apply (UnaryProcessor< HashGridBox3< Item > > &processor)
 
const Item * getClosestItem (const Vector3 &point, Size distance) const
 
static float calculateMinSpacing (LongIndex memory, const Vector3 &size)
 

Detailed Description

template<typename Item>
class BALL::HashGrid3< Item >

Three-dimensional Hash Grid Class.

This class is useful for quickly finding neighbors of or contacts between atoms and other objects that can be assigned a coordinate. Assuming uniform distribution of the points stored in the grid, this brings the asymptotic runtime of neighborhood queries down from O(n*m) to O(m).

The common use case for finding all objects with a distance <= d to a query point is as follows:

  1. Create a HashGrid with spacing d covering all required space (check your query domain too!).
  2. Insert all objects you want to check for neighborhood.
  3. Retrieve the box of a query point
  4. Iterate over all entries in all neighboring boxes and compute the acutal distance.
Warning
Setting up a HashGrid3 requires a considerable amount of time, as a cubic amount of memory cells need to be allocated and initialized. This is not problematic if the HashGrid3 seldomly changes and is often used for lookups. If, however, only few lookups are required using a HashGrid3 may actually deteriorate performance compared to a brute-force lookup.

Definition at line 754 of file hashGrid.h.

Member Typedef Documentation

◆ BoxIterator

template<typename Item >
typedef ForwardIterator<HashGrid3<Item>, HashGridBox3<Item>, BoxIteratorPosition, BoxIteratorTraits> BALL::HashGrid3< Item >::BoxIterator

Definition at line 1106 of file hashGrid.h.

◆ BoxIteratorPosition

template<typename Item >
typedef Position BALL::HashGrid3< Item >::BoxIteratorPosition

Definition at line 978 of file hashGrid.h.

◆ ConstBoxIterator

template<typename Item >
typedef ConstForwardIterator<HashGrid3<Item>, HashGridBox3<Item>, BoxIteratorPosition, BoxIteratorTraits> BALL::HashGrid3< Item >::ConstBoxIterator

Definition at line 1125 of file hashGrid.h.

Constructor & Destructor Documentation

◆ HashGrid3() [1/5]

template<typename Item >
BALL::HashGrid3< Item >::HashGrid3

Default constructor.

Definition at line 1165 of file hashGrid.h.

◆ HashGrid3() [2/5]

template<typename Item >
BALL::HashGrid3< Item >::HashGrid3 ( const Vector3 origin,
Size  dimension_x,
Size  dimension_y,
Size  dimension_z,
float  spacing_x,
float  spacing_y,
float  spacing_z 
)

Constructor using origin, dimensions, and spacings of the grid. It creates a hashgrid at origin with axis-dependant spacings.

If you want to define a HashGrid with a variable number of boxes, consider to use HashGrid3(const Vector3&, const Vector3&, float) instead.

Parameters
originThe origin of the HashGrid. This is the point with the lowest coordinate values in x-, y-, and z-direction.
dimension_xThe number of boxes on the x-axis.
dimension_yThe number of boxes on the y-axis.
dimension_zThe number of boxes on the z-axis.
spacing_xThe size of a single box on the x-axis.
spacing_yThe size of a single box on the y-axis.
spacing_zThe size of a single box on the z-axis.
See also
BALL::BoundingBoxProcessor::getLower() const

Definition at line 1175 of file hashGrid.h.

◆ HashGrid3() [3/5]

template<typename Item >
BALL::HashGrid3< Item >::HashGrid3 ( const Vector3 origin,
Size  dimension_x,
Size  dimension_y,
Size  dimension_z,
float  spacing 
)

Constructor using origin, dimensions, and a single spacing (only cubic grids)

This is a convenience overload for BALL::HashGrid3(const Vector3&, Size, Size, Size, float, float, float)

Definition at line 1189 of file hashGrid.h.

◆ HashGrid3() [4/5]

template<typename Item >
BALL::HashGrid3< Item >::HashGrid3 ( const Vector3 origin,
const Vector3 size,
float  spacing 
)

Constructor using two vectors and a single spacing. This constructor creates a hash grid at origin with spacing spacing. The vector size has to be relative to origin and defines the opposite corner of the grid, thereby setting the size of the grid.

Parameters
origina vector defining the origin of our cubic hash grid
sizea vector defining the opposite corner of the cubic grid
spacingthis float will be used as spacing in all three dimensions

Definition at line 1203 of file hashGrid.h.

◆ HashGrid3() [5/5]

template<typename Item >
BALL::HashGrid3< Item >::HashGrid3 ( const HashGrid3< Item > &  grid,
bool  deep = true 
)

Copy constructor.

Definition at line 1215 of file hashGrid.h.

◆ ~HashGrid3()

template<typename Item >
BALL::HashGrid3< Item >::~HashGrid3
virtual

Destructor.

Definition at line 1221 of file hashGrid.h.

Member Function Documentation

◆ apply() [1/2]

template<typename Item >
bool BALL::HashGrid3< Item >::apply ( UnaryProcessor< HashGridBox3< Item > > &  processor)

Definition at line 1699 of file hashGrid.h.

◆ apply() [2/2]

template<typename Item >
bool BALL::HashGrid3< Item >::apply ( UnaryProcessor< Item > &  processor)

Definition at line 1673 of file hashGrid.h.

◆ beginBox() [1/2]

template<typename Item >
BoxIterator BALL::HashGrid3< Item >::beginBox ( )
inline

Definition at line 1109 of file hashGrid.h.

◆ beginBox() [2/2]

template<typename Item >
ConstBoxIterator BALL::HashGrid3< Item >::beginBox ( ) const
inline

Definition at line 1128 of file hashGrid.h.

◆ calculateMinSpacing()

template<typename Item >
BALL_INLINE float BALL::HashGrid3< Item >::calculateMinSpacing ( LongIndex  memory,
const Vector3 size 
)
static

Calculate the minimum required spacing to build a HashGrid3 with the given size and less than the given memory consumption.

Parameters
memorythe amount of memory in bytes
sizethe diagonal of the grid
Returns
the minimal needed spacing

Definition at line 1456 of file hashGrid.h.

◆ clear() [1/3]

template<typename Item >
void BALL::HashGrid3< Item >::clear
virtual

Clears the whole grid.

Definition at line 1226 of file hashGrid.h.

◆ clear() [2/3]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::clear ( const Vector3 vector)

Clears the HashGridBox3 at position vector

Definition at line 1248 of file hashGrid.h.

◆ clear() [3/3]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::clear ( Position  x,
Position  y,
Position  z 
)

Clears the HashGridBox3 at position (x, y, z)

Definition at line 1236 of file hashGrid.h.

◆ countNonEmptyBoxes()

template<typename Item >
Size BALL::HashGrid3< Item >::countNonEmptyBoxes

Counts the non-empty boxes of a grid.

Definition at line 1348 of file hashGrid.h.

◆ destroy() [1/3]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::destroy

Destroys the grid (obsolete, only calls clear())

Definition at line 1260 of file hashGrid.h.

◆ destroy() [2/3]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::destroy ( const Vector3 vector)

Destroys a box of the grid (obsolete, only calls clear())

Definition at line 1274 of file hashGrid.h.

◆ destroy() [3/3]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::destroy ( Position  x,
Position  y,
Position  z 
)

Destroys a box of the grid (obsolete, only calls clear())

Definition at line 1267 of file hashGrid.h.

◆ dump()

template<typename Item >
void BALL::HashGrid3< Item >::dump ( std::ostream &  s = std::cout,
Size  depth = 0 
) const
virtual

Dump the contents of a HashGrid3 to a stream.

Definition at line 1625 of file hashGrid.h.

◆ endBox() [1/2]

template<typename Item >
BoxIterator BALL::HashGrid3< Item >::endBox ( )
inline

Definition at line 1115 of file hashGrid.h.

◆ endBox() [2/2]

template<typename Item >
ConstBoxIterator BALL::HashGrid3< Item >::endBox ( ) const
inline

Definition at line 1134 of file hashGrid.h.

◆ get() [1/2]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::get ( HashGrid3< Item > &  grid,
bool  deep = true 
) const

Definition at line 1341 of file hashGrid.h.

◆ get() [2/2]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::get ( Vector3 origin,
Vector3 unit,
Size dimension_x,
Size dimension_y,
Size dimension_z 
) const

Definition at line 1330 of file hashGrid.h.

◆ getBox() [1/4]

template<typename Item >
BALL_INLINE HashGridBox3< Item > * BALL::HashGrid3< Item >::getBox ( const Vector3 vector)

Return the HashGridBox3 at position vector.

Definition at line 1489 of file hashGrid.h.

◆ getBox() [2/4]

template<typename Item >
BALL_INLINE const HashGridBox3< Item > * BALL::HashGrid3< Item >::getBox ( const Vector3 vector) const

Return the HashGridBox3 at position vector (const version)

Definition at line 1505 of file hashGrid.h.

◆ getBox() [3/4]

template<typename Item >
BALL_INLINE HashGridBox3< Item > * BALL::HashGrid3< Item >::getBox ( Position  x,
Position  y,
Position  z 
)

Return the HashGridBox3 at position (x, y, z)

Definition at line 1466 of file hashGrid.h.

◆ getBox() [4/4]

template<typename Item >
BALL_INLINE const HashGridBox3< Item > * BALL::HashGrid3< Item >::getBox ( Position  x,
Position  y,
Position  z 
) const

Return the HashGridBox3 at position (x, y, z) (const version)

Definition at line 1482 of file hashGrid.h.

◆ getClosestItem()

template<typename Item >
const Item * BALL::HashGrid3< Item >::getClosestItem ( const Vector3 point,
Size  distance 
) const

Get the nearest item for a point

Parameters
distancenumber of adjacted boxes in each direction to search in

Definition at line 1412 of file hashGrid.h.

◆ getIndices()

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::getIndices ( const HashGridBox3< Item > &  box,
Position x,
Position y,
Position z 
) const

Get the position indices of a HashGridBox3.

Definition at line 1512 of file hashGrid.h.

◆ getOrigin() [1/2]

template<typename Item >
BALL_INLINE Vector3 & BALL::HashGrid3< Item >::getOrigin

Returns the origin of the grid.

Definition at line 1364 of file hashGrid.h.

◆ getOrigin() [2/2]

template<typename Item >
BALL_INLINE const Vector3 & BALL::HashGrid3< Item >::getOrigin

Returns a const reference of the grid origin.

Definition at line 1371 of file hashGrid.h.

◆ getSize()

template<typename Item >
BALL_INLINE Size BALL::HashGrid3< Item >::getSize

Returns the size of a grid, i. e. ?????

Definition at line 1357 of file hashGrid.h.

◆ getSizeX()

template<typename Item >
BALL_INLINE Size BALL::HashGrid3< Item >::getSizeX

Get the x dimension of the grid.

Definition at line 1392 of file hashGrid.h.

◆ getSizeY()

template<typename Item >
BALL_INLINE Size BALL::HashGrid3< Item >::getSizeY

Get the y dimension of the grid.

Definition at line 1399 of file hashGrid.h.

◆ getSizeZ()

template<typename Item >
BALL_INLINE Size BALL::HashGrid3< Item >::getSizeZ

Get the z dimension of the grid.

Definition at line 1406 of file hashGrid.h.

◆ getUnit() [1/2]

template<typename Item >
BALL_INLINE Vector3 & BALL::HashGrid3< Item >::getUnit

Returns the unit of the grid.

Definition at line 1378 of file hashGrid.h.

◆ getUnit() [2/2]

template<typename Item >
BALL_INLINE const Vector3 & BALL::HashGrid3< Item >::getUnit

Returns the unit of the grid (const version)

Definition at line 1385 of file hashGrid.h.

◆ host()

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::host ( Visitor< HashGrid3< Item > > &  visitor)

Definition at line 1578 of file hashGrid.h.

◆ insert() [1/2]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::insert ( const Vector3 vector,
const Item &  item 
)

Insert an item at position vector

Definition at line 1548 of file hashGrid.h.

◆ insert() [2/2]

template<typename Item >
BALL_INLINE void BALL::HashGrid3< Item >::insert ( Position  x,
Position  y,
Position  z,
const Item &  item 
)

Insert an item at position (x, y, z)

Definition at line 1535 of file hashGrid.h.

◆ isEmpty()

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::isEmpty

Tests, whether this is empty.

Definition at line 1609 of file hashGrid.h.

◆ isValid()

template<typename Item >
bool BALL::HashGrid3< Item >::isValid
virtual

Validity check.

Definition at line 1615 of file hashGrid.h.

◆ operator!=()

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::operator!= ( const HashGrid3< Item > &  grid) const

Inequality operator.

Definition at line 1602 of file hashGrid.h.

◆ operator=()

template<typename Item >
BALL_INLINE const HashGrid3< Item > & BALL::HashGrid3< Item >::operator= ( const HashGrid3< Item > &  grid)

Assignment operator.

Definition at line 1321 of file hashGrid.h.

◆ operator==()

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::operator== ( const HashGrid3< Item > &  grid) const

Equality operator.

Definition at line 1585 of file hashGrid.h.

◆ remove() [1/2]

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::remove ( const Vector3 vector,
const Item &  item 
)

Remove an item from position vector

Definition at line 1569 of file hashGrid.h.

◆ remove() [2/2]

template<typename Item >
BALL_INLINE bool BALL::HashGrid3< Item >::remove ( Position  x,
Position  y,
Position  z,
const Item &  item 
)

Remove an item from position (x, y ,z)

Definition at line 1560 of file hashGrid.h.

◆ set() [1/3]

template<typename Item >
void BALL::HashGrid3< Item >::set ( const HashGrid3< Item > &  grid,
bool  deep = true 
)

assigns the content of a hash grid (obsolete)

Definition at line 1304 of file hashGrid.h.

◆ set() [2/3]

template<typename Item >
void BALL::HashGrid3< Item >::set ( const Vector3 origin,
const Vector3 unit,
Size  dimension_x,
Size  dimension_y,
Size  dimension_z 
)

assigns the content of a hash grid (obsolete)

Definition at line 1280 of file hashGrid.h.

◆ set() [3/3]

template<typename Item >
void BALL::HashGrid3< Item >::set ( const Vector3 origin,
float  unit,
Size  size 
)

assigns the content of a hash grid (obsolete)

Definition at line 1293 of file hashGrid.h.

Friends And Related Function Documentation

◆ BoxIteratorTraits

template<typename Item >
friend class BoxIteratorTraits
friend

Definition at line 1100 of file hashGrid.h.