grid_3D
3D grid container (dynamic size).
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 dimension | Number of elements (Nx, Ny, Nz) along each of the three directions. |
numarray<T> data | Elements 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) constT& 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) constT& 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) const | Returns 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) const | Returns 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) constT& 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) constT& 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
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.
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.
Functions returning a grid_3D
None.
Operators
Show the 20 operators (+, -, *, ==, ...)
template <typename T>
grid_3D<T> operator*(grid_3D<T> const& a, grid_3D<T> const& b)sourceElement-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)sourceGrid with each element multiplied by a scalar.
template <typename T>
grid_3D<T> operator*(float a, grid_3D<T> const& b)sourceGrid with each element multiplied by a scalar.
template <typename T>
grid_3D<T>& operator*=(grid_3D<T>& a, grid_3D<T> const& b)sourceMultiplies 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)sourceMultiplies each element by a scalar in place.
template <typename T>
grid_3D<T> operator+(grid_3D<T> const& a, grid_3D<T> const& b)sourceElement-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)sourceGrid with a value added to each element.
template <typename T>
grid_3D<T> operator+(T const& a, grid_3D<T> const& b)sourceGrid with a value added to each element.
template <typename T>
grid_3D<T>& operator+=(grid_3D<T>& a, grid_3D<T> const& b)sourceAdds 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)sourceAdds a value to each element in place.
template <typename T>
grid_3D<T> operator-(grid_3D<T> const& a, grid_3D<T> const& b)sourceElement-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)sourceGrid with a value subtracted from each element.
template <typename T>
grid_3D<T> operator-(T const& a, grid_3D<T> const& b)sourceGrid of a value minus each element.
template <typename T>
grid_3D<T>& operator-=(grid_3D<T>& a, grid_3D<T> const& b)sourceSubtracts 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)sourceSubtracts a value from each element in place.
template <typename T>
grid_3D<T> operator/(grid_3D<T> const& a, grid_3D<T> const& b)sourceElement-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)sourceGrid with each element divided by a scalar.
template <typename T>
grid_3D<T>& operator/=(grid_3D<T>& a, grid_3D<T> const& b)sourceDivides 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)sourceDivides 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.