opensurgsim
Classes | Public Member Functions | Protected Types | Protected Attributes | List of all members
SurgSim::DataStructures::Grid< T, N > Class Template Reference

n-dimensional grid structure with uniform non-cubic cells This data structure is useful to search for neighbors in a given range (the size of each cell) More...

#include <Grid.h>

Inheritance diagram for SurgSim::DataStructures::Grid< T, N >:
MockGrid< T, N >

Classes

struct  CellContent
 Data structure for a cell's content (the list of elements and the list of all the neighbors) More...
 
class  NDIdHash
 Enable the NDId to be used as a key in an unordered map. More...
 

Public Member Functions

 Grid (const Eigen::Matrix< double, N, 1 > &cellSize, const Eigen::AlignedBox< double, N > &bounds)
 Constructor. More...
 
virtual ~Grid ()
 Destructor.
 
void reset ()
 Reset the grid content and the neighbors' mapping.
 
template<class Derived >
void addElement (const T element, const Eigen::MatrixBase< Derived > &position)
 Add an element in the grid. More...
 
const std::vector< T > & getNeighbors (const T &element)
 Retrieve an elements' neighbors. More...
 
template<class Derived >
const std::vector< T > & getNeighbors (const Eigen::MatrixBase< Derived > &position)
 Retrieve the neighbors of a location. More...
 

Protected Types

typedef Eigen::Matrix< int, N, 1 > NDId
 The type of the n-dimensional cell Id.
 

Protected Attributes

std::unordered_map< NDId, CellContent, NDIdHashm_activeCells
 Active cells (referenced by their ids (spatial hashing)) with their content.
 
std::unordered_map< T, NDIdm_cellIds
 Mapping from element to cell id containing the element.
 
Eigen::Matrix< double, N, 1 > m_size
 Size of each cell (same on all dimension)
 
Eigen::AlignedBox< double, N > m_aabb
 Grid min and max.
 
bool m_neighborsDirtyFlag
 Does the neighbors needs to be recomputed ?
 

Detailed Description

template<typename T, size_t N>
class SurgSim::DataStructures::Grid< T, N >

n-dimensional grid structure with uniform non-cubic cells This data structure is useful to search for neighbors in a given range (the size of each cell)

Template Parameters
TElement type to be stored
NThe dimension of the grid (i.e. 2 => 2D, 3 => 3D)

Constructor & Destructor Documentation

§ Grid()

template<typename T , size_t N>
SurgSim::DataStructures::Grid< T, N >::Grid ( const Eigen::Matrix< double, N, 1 > &  cellSize,
const Eigen::AlignedBox< double, N > &  bounds 
)

Constructor.

Parameters
cellSizeThe size of each cell in dimension N (i.e. cells are not necessarily cubic).
boundsThe dimension-N boundaries of the space covered by the grid.

Member Function Documentation

§ addElement()

template<typename T , size_t N>
template<class Derived >
void SurgSim::DataStructures::Grid< T, N >::addElement ( const T  element,
const Eigen::MatrixBase< Derived > &  position 
)

Add an element in the grid.

Parameters
elementto be added at this position
positionof the element in the n-D space
Note
If the position is outside of the grid, the element is simply not added to the grid

Flag that the neighbors list will need to be recomputed on the next access

§ getNeighbors() [1/2]

template<typename T , size_t N>
const std::vector< T > & SurgSim::DataStructures::Grid< T, N >::getNeighbors ( const T &  element)

Retrieve an elements' neighbors.

Parameters
elementThe element for which the neighbors are requested
Returns
The element's neighbors list (including the element itself)

§ getNeighbors() [2/2]

template<typename T , size_t N>
template<class Derived >
const std::vector< T > & SurgSim::DataStructures::Grid< T, N >::getNeighbors ( const Eigen::MatrixBase< Derived > &  position)

Retrieve the neighbors of a location.

Parameters
positionThe position for which the neighbors are requested
Returns
The neighbors for this position, i.e. all the elements in the positions cell and all surrounding cells

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