URL: https://graphicscomputing.fr/cgp/reference/grid_2D/
Description: 2D grid container (dynamic size).

# grid_2D

2D grid container (dynamic size).

Fields:

- `int2 dimension` - Number of elements (Nx, Ny) along each of the two directions.
- `numarray<T> data` - Elements stored contiguously as a 1D numarray, the element (k1,k2) at offset k1 + Nx*k2.

Functions taking it:

- `std::string type_str(grid_2D<T> const&)` - Type name as a string, e.g. "grid_2D<float>".
- `std::string str(grid_2D<T> 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.
- `bool is_equal(grid_2D<T1> const& a, grid_2D<T2> const& b)` - Returns true if both grids have the same dimension and equal elements (approximate comparison for floating-point values).
- `void check_index_bounds(int index1, int index2, grid_2D<T> const& data)` - Raises an error if (x,y) is outside the grid dimensions; no-op when CGP_NO_DEBUG is defined.
- `void convert(image_structure const& in, grid_2D<vec3>& out)` - Convert an RGB or RGBA image into a grid_2D of vec3 colors in [0,1], dropping the alpha channel.
- `T interpolation_bilinear(grid_2D<T> const& value, float x, float y)` - Bilinear interpolation of a grid_2D at continuous index coordinates (x,y), each in [0, dimension-1).
- `GLuint opengl_load_texture_image(grid_2D<vec3> const& im, GLint wrap_s = GL_CLAMP_TO_EDGE, GLint wrap_t = GL_CLAMP_TO_EDGE)` - Upload a grid of vec3 colors as a new mipmapped 2D OpenGL texture (32-bit float RGB) with the given wrap modes, returning its id.
- `void opengl_update_texture_image(GLuint texture_id, grid_2D<vec3> const& im)` - Overwrite the content of an existing 2D texture with a grid of vec3 colors of the same size and regenerate its mipmaps.

Operators:

- `std::ostream& operator<<(std::ostream& s, grid_2D<T> const& v)` - Writes all elements of the grid to the stream, in storage order separated by spaces.
- `grid_2D<T>& operator+=(grid_2D<T>& a, grid_2D<T> const& b)` - Adds a grid element-wise in place; dimensions must match (asserted in debug).
- `grid_2D<T>& operator+=(grid_2D<T>& a, T const& b)` - Adds a value to each element in place.
- `grid_2D<T> operator+(grid_2D<T> const& a, grid_2D<T> const& b)` - Element-wise sum of two grids; dimensions must match (asserted in debug).
- `grid_2D<T> operator+(grid_2D<T> const& a, T const& b)` - Grid with a value added to each element.
- `grid_2D<T> operator+(T const& a, grid_2D<T> const& b)` - Grid with a value added to each element.
- `grid_2D<T>& operator-=(grid_2D<T>& a, grid_2D<T> const& b)` - Subtracts a grid element-wise in place; dimensions must match (asserted in debug).
- `grid_2D<T>& operator-=(grid_2D<T>& a, T const& b)` - Subtracts a value from each element in place.
- `grid_2D<T> operator-(grid_2D<T> const& a, grid_2D<T> const& b)` - Element-wise difference of two grids; dimensions must match (asserted in debug).
- `grid_2D<T> operator-(grid_2D<T> const& a, T const& b)` - Grid with a value subtracted from each element.
- `grid_2D<T> operator-(T const& a, grid_2D<T> const& b)` - Grid of a value minus each element.
- `grid_2D<T>& operator*=(grid_2D<T>& a, grid_2D<T> const& b)` - Multiplies by a grid element-wise in place; dimensions must match (asserted in debug).
- `grid_2D<T>& operator*=(grid_2D<T>& a, float b)` - Multiplies each element by a scalar in place.
- `grid_2D<T> operator*(grid_2D<T> const& a, grid_2D<T> const& b)` - Element-wise product of two grids; dimensions must match (asserted in debug).
- `grid_2D<T> operator*(grid_2D<T> const& a, float b)` - Grid with each element multiplied by a scalar.
- `grid_2D<T> operator*(float a, grid_2D<T> const& b)` - Grid with each element multiplied by a scalar.
- `grid_2D<T>& operator/=(grid_2D<T>& a, grid_2D<T> const& b)` - Divides by a grid element-wise in place; dimensions must match (asserted in debug).
- `grid_2D<T>& operator/=(grid_2D<T>& a, float b)` - Divides each element by a scalar in place.
- `grid_2D<T> operator/(grid_2D<T> const& a, grid_2D<T> const& b)` - Element-wise quotient of two grids; dimensions must match (asserted in debug).
- `grid_2D<T> operator/(grid_2D<T> const& a, float b)` - Grid with each element divided by a scalar.
