Go to the documentation of this file.
16 #ifndef SURGSIM_DATASTRUCTURES_GRID_H
17 #define SURGSIM_DATASTRUCTURES_GRID_H
20 #include <unordered_map>
27 namespace DataStructures
46 template <
typename T,
size_t N>
53 Grid(
const Eigen::Matrix<double, N, 1>& cellSize,
const Eigen::AlignedBox<double, N>& bounds);
65 template <
class Derived>
66 void addElement(
const T element,
const Eigen::MatrixBase<Derived>& position);
76 template <
class Derived>
77 const std::vector<T>&
getNeighbors(
const Eigen::MatrixBase<Derived>& position);
88 typedef Eigen::Matrix<int, N, 1>
NDId;
133 #endif // SURGSIM_DATASTRUCTURES_GRID_H
const std::vector< T > & getNeighbors(const T &element)
Retrieve an elements' neighbors.
Definition: Grid-inl.h:198
Templated function to compute a power of 3 at compile time (useful for template parameter)
Definition: Grid.h:32
size_t operator()(const NDId &nd) const
Definition: Grid-inl.h:97
Eigen::AlignedBox< double, N > m_aabb
Grid min and max.
Definition: Grid.h:107
void addElement(const T element, const Eigen::MatrixBase< Derived > &position)
Add an element in the grid.
Definition: Grid-inl.h:131
Data structure for a cell's content (the list of elements and the list of all the neighbors)
Definition: Grid.h:81
void reset()
Reset the grid content and the neighbors' mapping.
Definition: Grid-inl.h:117
bool isNdGreaterOrEqual(const NDId &a, const NDId &b)
Definition: Grid-inl.h:281
std::unordered_map< T, NDId > m_cellIds
Mapping from element to cell id containing the element.
Definition: Grid.h:101
Enable the NDId to be used as a key in an unordered map.
Definition: Grid.h:91
Definition: CompoundShapeToGraphics.cpp:29
std::vector< T > neighbors
Definition: Grid.h:84
Grid(const Eigen::Matrix< double, N, 1 > &cellSize, const Eigen::AlignedBox< double, N > &bounds)
Constructor.
Definition: Grid-inl.h:103
Eigen::Matrix< double, N, 1 > m_size
Size of each cell (same on all dimension)
Definition: Grid.h:104
bool m_neighborsDirtyFlag
Does the neighbors needs to be recomputed ?
Definition: Grid.h:110
void update()
Update the neighbors lists.
Definition: Grid-inl.h:156
std::vector< T > elements
Definition: Grid.h:83
std::unordered_map< NDId, CellContent, NDIdHash > m_activeCells
Active cells (referenced by their ids (spatial hashing)) with their content.
Definition: Grid.h:98
virtual ~Grid()
Destructor.
Definition: Grid-inl.h:112
Eigen::Matrix< int, N, 1 > NDId
The type of the n-dimensional cell Id.
Definition: Grid.h:88
n-dimensional grid structure with uniform non-cubic cells This data structure is useful to search for...
Definition: Grid.h:47
void getNeighborsCellIds(NDId cellId, std::array< NDId, powerOf3< N >::value > *cellsIds)
Retrieve the neighboring cells id (including this cell)
Definition: Grid-inl.h:257