CGPdocs

Grid helpers

Offsets between 2D/3D indices and linear storage, and operations on fixed-size grids.

Construct 2

int2 index_grid_from_offset(int offset, int N1)
source

Index (k1,k2) of a linear offset in a 2D grid of first dimension N1 (inverse of offset_grid).

int3 index_grid_from_offset(int offset, int N1, int N2)
source

Index (k1,k2,k3) of a linear offset in a 3D grid of dimensions N1 x N2 (inverse of offset_grid).

Compute 7

template <int N1>
std::pair<int,int> index_grid_from_offset_stack(int offset)

Index pair (k1,k2) of a linear offset in a 2D grid whose first dimension N1 is known at compile time.

template <typename T, int N1, int N2, int N3>
grid_stack_2D<T,N1,N3> multiply_matrix(
    grid_stack_2D<T,N1,N2> const& a,
    grid_stack_2D<T,N2,N3> const& b
)

Matrix product of an N1xN2 grid and an N2xN3 grid, giving an N1xN3 grid.

offset_grid

4 overloads
int offset_grid(int k1, int k2, int N1)
source

Linear offset k1 + N1*k2 of index (k1,k2) in a 2D grid of first dimension N1.

int offset_grid(int2 const& k, int N1)
source

Linear offset k.x + N1*k.y of a 2D index in a grid of first dimension N1.

int offset_grid(int k1, int k2, int k3, int N1, int N2)
source

Linear offset k1 + N1*(k2 + N2*k3) of index (k1,k2,k3) in a 3D grid of dimensions N1 x N2 x N3.

int offset_grid(int3 const& k, int N1, int N2)
source

Linear offset of a 3D index in a grid of dimensions N1 x N2 x N3.

template <int N1>
size_t offset_grid_stack(int k1, int k2)

Linear offset k1 + N1*k2 of index (k1,k2) in a 2D grid whose first dimension N1 is known at compile time.

Convert 2

template <typename T, int N1, int N2>
std::string str(
    grid_stack_2D<T,N1,N2> const& v,
    std::string const& separator = " ",
    std::string const& begin = "",
    std::string const& end = ""
)

Text representation of all elements in storage order, joined by separator and surrounded by begin and end.

template <typename T, int N1, int N2>
std::string type_str(grid_stack_2D<T,N1,N2> const&)

Type name as a string, e.g. "grid_stack_2D<float,3,3>".

Access 3

template <typename T, int N1, int N2>
void check_index_bounds(int index1, int index2, grid_stack_2D<T,N1,N2> const& data)

Raises an error if (x,y) is outside [0,N1-1]x[0,N2-1]; no-op when CGP_NO_DEBUG is defined.

template <int idx1, int idx2, typename T, int N1, int N2>
T const& element(grid_stack_2D<T,N1,N2> const& data)
T& element(grid_stack_2D<T,N1,N2>& data)

Element (idx1,idx2) with indices checked at compile time (static_assert).

template <typename Ta, typename Tb, int Na1, int Na2, int Nb1, int Nb2>
bool is_equal(grid_stack_2D<Ta,Na1,Na2> const& a, grid_stack_2D<Tb,Nb1,Nb2> const& b)

Equality of two fixed-size grids: same dimensions and element-wise equal values (approximate for floating-point).

Other 14

operator*

3 overloads
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)
source

Element-wise product of two grids (not a matrix product, see multiply_matrix).

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, float b)
source

Grid with each element multiplied by a scalar.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(float a, grid_stack_2D<T,N1,N2> const& b)
source

Grid with each element multiplied by a scalar.

operator*=

2 overloads
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)
source

Multiplies by a grid element-wise in place.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, float b)
source

Multiplies each element by a scalar in place.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator+(
    grid_stack_2D<T,N1,N2> const& a,
    grid_stack_2D<T,N1,N2> const& b
)

Element-wise sum of two grids.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator+=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)

Adds a grid element-wise in place.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator-(
    grid_stack_2D<T,N1,N2> const& a,
    grid_stack_2D<T,N1,N2> const& b
)

Element-wise difference of two grids.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator-=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)

Subtracts a grid element-wise in place.

operator/

2 overloads
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)
source

Element-wise quotient of two grids.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, float b)
source

Grid with each element divided by a scalar.

operator/=

2 overloads
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)
source

Divides by a grid element-wise in place.

template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, float b)
source

Divides each element by a scalar in place.

template <typename T, int N1, int N2>
std::ostream& operator<<(std::ostream& s, grid_stack_2D<T,N1,N2> const& v)

Writes all elements of the grid to the stream, in storage order separated by spaces.

CGP - Computer Graphics Programming.