CGPdocs

grid_3D

3D grid container (dynamic size).

module 04_grid_containersource: grid_3D.hpp
Element (i, j, k) of a grid_3D is stored at offset i + dimension.x * (j + dimension.y * k): i varies fastest, then j, then k (slice after slice).
Element (i, j, k) of a grid_3D is stored at offset i + dimension.x * (j + dimension.y * k): i varies fastest, then j, then k (slice after slice). Tap to enlarge.

Fields and methods

Members of the struct grid_3D. Most of what you do with a CGP type goes through the free functions listed below.

Fields

int3 dimensionNumber of elements (Nx, Ny, Nz) along each of the three directions.
numarray<T> dataElements stored contiguously as a 1D numarray, the element (k1,k2,k3) at offset k1 + Nx*(k2 + Ny*k3).

Methods

grid_3D()Builds an empty grid of dimension (0,0,0).4 overloads src
grid_3D(int size)Builds a cubic grid of dimension (size, size, size) with value-initialized elements (size asserted non-negative). src
grid_3D(int3 const& size)Builds a grid of dimension (size.x, size.y, size.z) with value-initialized elements (sizes asserted non-negative). src
grid_3D(int size_1, int size_2, int size_3)Builds a grid of dimension (size_1, size_2, size_3) with value-initialized elements (sizes asserted non-negative). src
Builds a grid of dimension (size_1, size_2, size_3) holding a copy of a 1D buffer, whose size must be size_1*size_2*size_3 (asserted). src
Resizes the grid to the dimension (0,0,0), which removes all its elements. src
Total number of elements, Nx*Ny*Nz. src
Sets every element of the grid to the given value, keeping its dimension. src
void resize(int size)Resizes the grid to the cubic dimension (size, size, size); values are kept by 1D offset and new elements are value-initialized.3 overloads src
void resize(int3 const& size)Sets the dimension to size and resizes the 1D buffer; existing values are kept by 1D offset, not by (k1, k2, k3), and new elements are value-initialized. src
void resize(int size_1, int size_2, int size_3)Sets the dimension to (size_1, size_2, size_3) and resizes the 1D buffer; existing values are kept by 1D offset, not by (k1, k2, k3), and new elements are value-initialized. src
Returns a const reference to the element of index (x, y, z), stored at offset x + Nx*(y + Ny*z), with bound checking unless CGP_NO_DEBUG is defined. src
T const& operator()(int3 const& index) const
T& operator()(int3 const& index)
Returns a const reference to the element of index (x, y, z), stored at offset x + Nx*(y + Ny*z), with bound checking unless CGP_NO_DEBUG is defined.2 overloads src
T const& operator()(int k1, int k2, int k3) const
T& operator()(int k1, int k2, int k3)
Returns a const reference to the element of index (k1, k2, k3), stored at offset k1 + Nx*(k2 + Ny*k3), with bound checking unless CGP_NO_DEBUG is defined. src
int index_to_offset(int k1, int k2, int k3) constReturns the 1D offset k1 + Nx*(k2 + Ny*k3) of the index (k1, k2, k3), without bound checking.2 overloads src
int index_to_offset(int3 const& index) constReturns the 1D offset x + Nx*(y + Ny*z) of the index (x, y, z), without bound checking. src
Returns the 3D index (k1, k2, k3) of a 1D offset, inverse of index_to_offset (no bound checking). src
Returns a const iterator to the first element of the 1D buffer, in which the first index varies fastest. src
Returns a const iterator one past the last element of the 1D buffer. src
Returns a const iterator to the first element of the 1D buffer, in which the first index varies fastest. src
Returns a const iterator one past the last element of the 1D buffer. src
T const& coeff(int index) const
T& coeff(int index)
Returns a const reference to the element at the given 1D offset, without bound checking.2 overloads src
T const& coeff(int index1, int index2, int index3) const
T& coeff(int index1, int index2, int index3)
Returns a const reference to the element of index (k1, k2, k3), without bound checking. src

Functions taking a grid_3D

Compute 1

mesh marching_cube(grid_3D<float> const& field, spatial_domain_grid_3D const& domain, float iso)

Extracts the iso-surface of value iso of a field sampled on the grid domain (same dimension) as a new mesh whose triangles share their vertices, with normals computed by fill_empty_field.

Convert 2

str

genericsource
template <typename T>
std::string str(
    grid_3D<T> const& v,
    std::string const& separator = " ",
    std::string const& begin = "",
    std::string const& end = ""
)

Text representation of all elements in storage order, with a separator and optional begin/end strings.

template <typename T>
std::string type_str(grid_3D<T> const&)

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

Access 2

template <typename T>
void check_index_bounds(int index1, int index2, int index3, grid_3D<T> const& data)

Raises an error if (x,y,z) is outside the grid dimensions; no-op when CGP_NO_DEBUG is defined.

template <typename T1, typename T2>
bool is_equal(grid_3D<T1> const& a, grid_3D<T2> const& b)

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

Functions returning a grid_3D

None.

Operators

Show the 20 operators (+, -, *, ==, ...)

operator*

generic3 overloads
template <typename T>
grid_3D<T> operator*(grid_3D<T> const& a, grid_3D<T> const& b)
source

Element-wise product of two grids; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T> operator*(grid_3D<T> const& a, float b)
source

Grid with each element multiplied by a scalar.

template <typename T>
grid_3D<T> operator*(float a, grid_3D<T> const& b)
source

Grid with each element multiplied by a scalar.

operator*=

generic2 overloads
template <typename T>
grid_3D<T>& operator*=(grid_3D<T>& a, grid_3D<T> const& b)
source

Multiplies by a grid element-wise in place; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T>& operator*=(grid_3D<T>& a, float b)
source

Multiplies each element by a scalar in place.

operator+

generic3 overloads
template <typename T>
grid_3D<T> operator+(grid_3D<T> const& a, grid_3D<T> const& b)
source

Element-wise sum of two grids; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T> operator+(grid_3D<T> const& a, T const& b)
source

Grid with a value added to each element.

template <typename T>
grid_3D<T> operator+(T const& a, grid_3D<T> const& b)
source

Grid with a value added to each element.

operator+=

generic2 overloads
template <typename T>
grid_3D<T>& operator+=(grid_3D<T>& a, grid_3D<T> const& b)
source

Adds a grid element-wise in place; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T>& operator+=(grid_3D<T>& a, T const& b)
source

Adds a value to each element in place.

operator-

generic3 overloads
template <typename T>
grid_3D<T> operator-(grid_3D<T> const& a, grid_3D<T> const& b)
source

Element-wise difference of two grids; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T> operator-(grid_3D<T> const& a, T const& b)
source

Grid with a value subtracted from each element.

template <typename T>
grid_3D<T> operator-(T const& a, grid_3D<T> const& b)
source

Grid of a value minus each element.

operator-=

generic2 overloads
template <typename T>
grid_3D<T>& operator-=(grid_3D<T>& a, grid_3D<T> const& b)
source

Subtracts a grid element-wise in place; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T>& operator-=(grid_3D<T>& a, T const& b)
source

Subtracts a value from each element in place.

operator/

generic2 overloads
template <typename T>
grid_3D<T> operator/(grid_3D<T> const& a, grid_3D<T> const& b)
source

Element-wise quotient of two grids; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T> operator/(grid_3D<T> const& a, float b)
source

Grid with each element divided by a scalar.

operator/=

generic2 overloads
template <typename T>
grid_3D<T>& operator/=(grid_3D<T>& a, grid_3D<T> const& b)
source

Divides by a grid element-wise in place; dimensions must match (asserted in debug).

template <typename T>
grid_3D<T>& operator/=(grid_3D<T>& a, float b)
source

Divides each element by a scalar in place.

template <typename T>
std::ostream& operator<<(std::ostream& s, grid_3D<T> const& v)

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

CGP - Computer Graphics Programming.