Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
tab< T, DIM, MAP > Struct Template Reference

std::array wrapper for precomputed data with optional remapping of the indices. More...

#include <precompute.h>

Inherits array< T, std::accumulate(std::begin(DIM), std::end(DIM), 1, std::multiplies<>())>.

Public Types

using base_type = std::array< T, std::accumulate(std::begin(DIM), std::end(DIM), 1, std::multiplies<>())>
 
using value = T
 value type
 

Public Member Functions

template<typename RET , typename... Cs>
requires (sizeof...(Cs) == dim())
constexpr auto lookup (Cs &&... coords) const
 Lookup the value in the data structure given a set of coordinates for each dimension. Uses nearest neighbor lookup if the coordinates do not exactly correspond to an integer position in the data structure.
 
template<typename... Cs>
requires (sizeof...(Cs) == dim())
constexpr auto lookup (Cs &&... coords) const
 Lookup with the native type.
 
template<typename RET , typename... Cs>
requires (sizeof...(Cs) == dim())
constexpr auto interpolate (Cs &&... coords) const
 Lookup the value in the data structure given a set of coordinates. In contrast to 'lookup' this method will linearly interpolate the values of the corresponding neighoring integer indices. In 1D this is just a linear interpolation, in 2D this corresponds to a bilinear interpolation, etc... Thus DIM^2 lookup are interpolated.
 
template<typename... Cs>
requires (sizeof...(Cs) == dim())
constexpr auto interpolate (Cs &&... coords) const
 interpolate with the native type
 
Direct Access by indices (per dimension); throws exception if out of range!
template<typename... Is>
requires (sizeof...(Is) == dim())
T & operator() (Is &&... indices)
 
template<typename... Is>
requires (sizeof...(Is) == dim())
const T & operator() (Is &&... indices) const
 

Static Public Member Functions

static constexpr auto sizes (void)
 sizes of each dimension.
 
static constexpr auto dim (void)
 number of dimensions.
 

Private Member Functions

template<typename RET , typename I , typename Mask >
requires std::convertible_to<index_mask_t<I>, Mask>
constexpr auto _lookup (const std::array< I, dim()> &mapped, Mask &mask) const
 PRIVATE: given an array of indices and a mask, return the corresponding stored value and update the mask if the requested value lies inside the underlying std::array (true) or outside (false). When 'false' is return the lookup value will be clamped to lie inside the data-range.
 
template<typename RET , size_t IDX, typename A , typename Mask >
constexpr RET _interpolate (const A &mapped, Mask &mask) const
 PRIVATE: Similar to _lookup, except that the each value is the interpolation result of the floor and ceil of each index. (e.g., linear interpolation in 1D, bilinear in 2D, etc...)
 

Static Private Member Functions

template<typename... Cs>
requires (sizeof...(Cs) == dim())
static constexpr auto map (Cs &&... coord)
 PRIVATE method to map a coordinate to an array of indices.
 
template<typename I >
static constexpr auto index (const std::array< I, dim()> &mapped)
 PRIVATE: linearizes an array of indices (per dimension) to a single index in the underlying std::array. Indices outside the range are clamped to 0 or DIM-1.
 
template<typename I >
static constexpr auto valid (const std::array< I, dim()> &mapped)
 PRIVATE: returns false if any index lies outside the corresponding dimension's size.
 

Detailed Description

template<typename T, std::array DIM, typename... MAP>
requires (sizeof...(MAP) == DIM.size() || sizeof...(MAP) == 0)
struct bbm::tab< T, DIM, MAP >

std::array wrapper for precomputed data with optional remapping of the indices.

Template Parameters
T= underlying data type
DIM= array of size of each dimension. E.g., {2,3} yields a 2 x 3 data structure, where '3' is the inner dimension.
MAP= either left empty, or a functor that maps the coordinates to the indices. The number of functors needs to be either '0' (all are identity mappings) or DIM.size(). The functors, if provided, can take one coordinate at the time and map it to an index (one index per MAP), or it can take all coordinates at once, and map it to an index (one index per MAP). In both cases, the number of MAPs needs to equal to DIM.size().

Member Typedef Documentation

◆ base_type

using base_type = std::array<T, std::accumulate(std::begin(DIM), std::end(DIM), 1, std::multiplies<>())>

◆ value

using value = T

value type

Member Function Documentation

◆ _interpolate()

constexpr RET _interpolate ( const A &  mapped,
Mask &  mask 
) const
inlineconstexprprivate

PRIVATE: Similar to _lookup, except that the each value is the interpolation result of the floor and ceil of each index. (e.g., linear interpolation in 1D, bilinear in 2D, etc...)

◆ _lookup()

constexpr auto _lookup ( const std::array< I, dim()> &  mapped,
Mask &  mask 
) const
inlineconstexprprivate

PRIVATE: given an array of indices and a mask, return the corresponding stored value and update the mask if the requested value lies inside the underlying std::array (true) or outside (false). When 'false' is return the lookup value will be clamped to lie inside the data-range.

◆ dim()

static constexpr auto dim ( void  )
inlinestaticconstexpr

number of dimensions.

◆ index()

static constexpr auto index ( const std::array< I, dim()> &  mapped)
inlinestaticconstexprprivate

PRIVATE: linearizes an array of indices (per dimension) to a single index in the underlying std::array. Indices outside the range are clamped to 0 or DIM-1.

◆ interpolate() [1/2]

constexpr auto interpolate ( Cs &&...  coords) const
inlineconstexpr

Lookup the value in the data structure given a set of coordinates. In contrast to 'lookup' this method will linearly interpolate the values of the corresponding neighoring integer indices. In 1D this is just a linear interpolation, in 2D this corresponds to a bilinear interpolation, etc... Thus DIM^2 lookup are interpolated.

Template Parameters
RET= return type (must be specified)
Parameters
coords= a coordinate per dimension
Returns
a named tuple, with the resulting interpolated lookup "value" and a "valid" indicating whether the value is valid.

Note: the coordinate is first converted to indices with the MAP functors.

◆ interpolate() [2/2]

constexpr auto interpolate ( Cs &&...  coords) const
inlineconstexpr

interpolate with the native type

◆ lookup() [1/2]

constexpr auto lookup ( Cs &&...  coords) const
inlineconstexpr

Lookup the value in the data structure given a set of coordinates for each dimension. Uses nearest neighbor lookup if the coordinates do not exactly correspond to an integer position in the data structure.

Template Parameters
RET= return type (must be specified)
Parameters
coords= a coordinate per dimension
Returns
a named tuple, with the resulting lookup "value" and a "valid" indicating whether the value is valid.

Note: the coordinate is first converted to indices with the MAP functors.

◆ lookup() [2/2]

constexpr auto lookup ( Cs &&...  coords) const
inlineconstexpr

Lookup with the native type.

◆ map()

static constexpr auto map ( Cs &&...  coord)
inlinestaticconstexprprivate

PRIVATE method to map a coordinate to an array of indices.

◆ operator()() [1/2]

T & operator() ( Is &&...  indices)
inline

◆ operator()() [2/2]

const T & operator() ( Is &&...  indices) const
inline

◆ sizes()

static constexpr auto sizes ( void  )
inlinestaticconstexpr

sizes of each dimension.

◆ valid()

static constexpr auto valid ( const std::array< I, dim()> &  mapped)
inlinestaticconstexprprivate

PRIVATE: returns false if any index lies outside the corresponding dimension's size.


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