Struct NeighbourId#
Defined in File NDSpacialInfoTypes.h
Struct Documentation#
-
struct NeighbourId#
A type identifying a neighboring direction
A neighbor is identified by using a Position value at each dimension, where the Position can be
FRONT,MIDorBACKFRONT: the neighbor is in the front in this dimensionMID: the neighbor is at the same pos in this dimensionBACK: the neighbor is at the back in this dimension
To retrieve the Position value at each dimension, use the subscript operator.
To iterate through all the neighbor dimension, use the
firstIdstatic method to get the initial neighbor and then get subsequence ones using the++operator. To check whether the next neighbor exist, use thehasNextNeighbourmethod.for (auto neighborId = NeighbourId::firstId(3); neighborId.hasNextNeighbour(); neighborId++) { // do something ... }
Note
This is a very lightweight type, so copying it is very efficient.
Public Functions
-
inline NeighbourId(const Dimension dimensions, const Index flattenId)#
Initialize a NeighbourId using the flattened id
The flattened id is a single integer calculated by treating the Position values at each dimension as a base-3 encoding and convert to base-10 representation.
-
inline NeighbourId(const std::initializer_list<Position> &list)#
Initialize a NeighbourId by directly providing the Position value at each dimension
- Parameters:
list – A brace init list specifying the Position value at each dimension
-
inline Position operator[](const Index dimIndex) const noexcept#
Get the Position value at a certain dimension
-
inline void setPosAtDim(const Index dimIndex, const Position pos) noexcept#
Update the Position value at a certain dimension
-
inline NeighbourId oppositeNeighbourId() const noexcept#
Get the identity of the neighbor at the opposite direction
-
inline bool operator==(const NeighbourId &other) const noexcept#
-
NeighbourId operator++()#
-
inline bool hasNextNeighbour() const noexcept#
Check whether there is a subsequence neighbor after the current one
Public Static Functions
-
static inline NeighbourId firstId(const Dimension dimensions)#
Construct the first neighbor id with the smallest flattened id
-
static inline NeighbourId lastId(const Dimension dimensions)#
Construct the last neighbor id with the largest flattened id
Note that the NeighbourId returned by this function is still a valid one
Friends
-
friend std::ostream &operator<<(std::ostream &os, const NeighbourId &neighbourId)#