Jet
v1.3.3
|
3-D array class. More...
#include <jet/array3.h>
Public Types | |
typedef std::vector< T > | ContainerType |
typedef ContainerType::iterator | Iterator |
typedef ContainerType::const_iterator | ConstIterator |
Public Member Functions | |
Array () | |
Constructs zero-sized 3-D array. More... | |
Array (const Size3 &size, const T &initVal=T()) | |
Array (size_t width, size_t height, size_t depth, const T &initVal=T()) | |
Array (const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst) | |
Constructs 3-D array with given initializer list lst . More... | |
Array (const Array &other) | |
Copy constructor. More... | |
Array (Array &&other) | |
Move constructor. More... | |
void | set (const T &value) |
Sets entire array with given value . More... | |
void | set (const Array &other) |
Copies given array other to this array. More... | |
void | set (const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst) |
void | clear () |
Clears the array and resizes to zero. More... | |
void | resize (const Size3 &size, const T &initVal=T()) |
Resizes the array with size and fill the new element with initVal . More... | |
void | resize (size_t width, size_t height, size_t depth, const T &initVal=T()) |
T & | at (size_t i) |
Returns the reference to the i-th element. More... | |
const T & | at (size_t i) const |
Returns the const reference to the i-th element. More... | |
T & | at (const Point3UI &pt) |
Returns the reference to the element at (pt.x, pt.y, pt.z). More... | |
const T & | at (const Point3UI &pt) const |
Returns the const reference to the element at (pt.x, pt.y, pt.z). More... | |
T & | at (size_t i, size_t j, size_t k) |
Returns the reference to the element at (i, j, k). More... | |
const T & | at (size_t i, size_t j, size_t k) const |
Returns the const reference to the element at (i, j, k). More... | |
Size3 | size () const |
Returns the size of the array. More... | |
size_t | width () const |
Returns the width of the array. More... | |
size_t | height () const |
Returns the height of the array. More... | |
size_t | depth () const |
Returns the depth of the array. More... | |
T * | data () |
Returns the raw pointer to the array data. More... | |
Iterator | begin () |
Returns the begin iterator of the array. More... | |
ConstIterator | begin () const |
Returns the begin const iterator of the array. More... | |
Iterator | end () |
Returns the end iterator of the array. More... | |
ConstIterator | end () const |
Returns the end const iterator of the array. More... | |
const T *const | data () const |
Returns the const raw pointer to the array data. More... | |
ArrayAccessor3< T > | accessor () |
Returns the array accessor. More... | |
ConstArrayAccessor3< T > | constAccessor () const |
Returns the const array accessor. More... | |
void | swap (Array &other) |
Swaps the content of the array with other array. More... | |
template<typename Callback > | |
void | forEach (Callback func) const |
Iterates the array and invoke given func for each index. More... | |
template<typename Callback > | |
void | forEachIndex (Callback func) const |
Iterates the array and invoke given func for each index. More... | |
template<typename Callback > | |
void | parallelForEach (Callback func) |
Iterates the array and invoke given func for each index in parallel. More... | |
template<typename Callback > | |
void | parallelForEachIndex (Callback func) const |
Iterates the array and invoke given func for each index in parallel using multi-threading. More... | |
T & | operator[] (size_t i) |
Returns the reference to the i-th element. More... | |
const T & | operator[] (size_t i) const |
Returns the const reference to the i-th element. More... | |
T & | operator() (const Point3UI &pt) |
Returns the reference to the element at (pt.x, pt.y, pt.z). More... | |
const T & | operator() (const Point3UI &pt) const |
Returns the const reference to the element at (pt.x, pt.y, pt.z). More... | |
T & | operator() (size_t i, size_t j, size_t k) |
Returns the reference to the element at (i, j, k). More... | |
const T & | operator() (size_t i, size_t j, size_t k) const |
Returns the const reference to the element at (i, j, k). More... | |
Array & | operator= (const T &value) |
Sets entire array with given value . More... | |
Array & | operator= (const Array &other) |
Copies given array other to this array. More... | |
Array & | operator= (Array &&other) |
Move assignment. More... | |
Array & | operator= (const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst) |
operator ArrayAccessor3< T > () | |
Casts to array accessor. More... | |
operator ConstArrayAccessor3< T > () const | |
Casts to const array accessor. More... | |
3-D array class.
This class represents 3-D array data structure. Internally, the 3-D data is mapped to a linear array such that (i, j, k) element is actually stroed at (i + width * (j + height * k))th element of the linear array. This mapping means iterating i first, j and k next will give better performance such as:
T | - Type to store in the array. |
typedef ContainerType::const_iterator jet::Array< T, 3 >::ConstIterator |
typedef std::vector<T> jet::Array< T, 3 >::ContainerType |
typedef ContainerType::iterator jet::Array< T, 3 >::Iterator |
jet::Array< T, 3 >::Array | ( | ) |
Constructs zero-sized 3-D array.
|
explicit |
Constructs 3-D array with given size
and fill it with initVal
.
size | Initial size of the array. |
initVal | Initial value of each array element. |
|
explicit |
Constructs 3-D array with size width
x height
x depth
and fill it with initVal
.
width | Initial width of the array. |
height | Initial height of the array. |
depth | Initial depth of the array. |
initVal | Initial value of each array element. |
jet::Array< T, 3 >::Array | ( | const std::initializer_list< std::initializer_list< std::initializer_list< T >>> & | lst | ) |
Constructs 3-D array with given initializer list lst
.
This constructor will build 3-D array with given initializer list lst
such as
Note the initializer also has 3-D structure. The code above will construct 4 x 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
jet::Array< T, 3 >::Array | ( | const Array< T, 3 > & | other | ) |
Copy constructor.
jet::Array< T, 3 >::Array | ( | Array< T, 3 > && | other | ) |
Move constructor.
ArrayAccessor3<T> jet::Array< T, 3 >::accessor | ( | ) |
Returns the array accessor.
T& jet::Array< T, 3 >::at | ( | const Point3UI & | pt | ) |
Returns the reference to the element at (pt.x, pt.y, pt.z).
const T& jet::Array< T, 3 >::at | ( | const Point3UI & | pt | ) | const |
Returns the const reference to the element at (pt.x, pt.y, pt.z).
T& jet::Array< T, 3 >::at | ( | size_t | i | ) |
Returns the reference to the i-th element.
This function returns the reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + width * (y + height * z) (x, y and z are the 3-D coordinates of the element).
const T& jet::Array< T, 3 >::at | ( | size_t | i | ) | const |
Returns the const reference to the i-th element.
This function returns the reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + width * (y + height * z) (x, y and z are the 3-D coordinates of the element).
T& jet::Array< T, 3 >::at | ( | size_t | i, |
size_t | j, | ||
size_t | k | ||
) |
Returns the reference to the element at (i, j, k).
const T& jet::Array< T, 3 >::at | ( | size_t | i, |
size_t | j, | ||
size_t | k | ||
) | const |
Returns the const reference to the element at (i, j, k).
Iterator jet::Array< T, 3 >::begin | ( | ) |
Returns the begin iterator of the array.
ConstIterator jet::Array< T, 3 >::begin | ( | ) | const |
Returns the begin const iterator of the array.
void jet::Array< T, 3 >::clear | ( | ) |
Clears the array and resizes to zero.
ConstArrayAccessor3<T> jet::Array< T, 3 >::constAccessor | ( | ) | const |
Returns the const array accessor.
T* jet::Array< T, 3 >::data | ( | ) |
Returns the raw pointer to the array data.
const T* const jet::Array< T, 3 >::data | ( | ) | const |
Returns the const raw pointer to the array data.
size_t jet::Array< T, 3 >::depth | ( | ) | const |
Returns the depth of the array.
Iterator jet::Array< T, 3 >::end | ( | ) |
Returns the end iterator of the array.
ConstIterator jet::Array< T, 3 >::end | ( | ) | const |
Returns the end const iterator of the array.
void jet::Array< T, 3 >::forEach | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index.
This function iterates the array elements and invoke the callback function func
. The callback function takes array's element as its input. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
void jet::Array< T, 3 >::forEachIndex | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index.
This function iterates the array elements and invoke the callback function func
. The callback function takes three parameters which are the (i, j, j) indices of the array. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
size_t jet::Array< T, 3 >::height | ( | ) | const |
Returns the height of the array.
jet::Array< T, 3 >::operator ArrayAccessor3< T > | ( | ) |
Casts to array accessor.
jet::Array< T, 3 >::operator ConstArrayAccessor3< T > | ( | ) | const |
Casts to const array accessor.
T& jet::Array< T, 3 >::operator() | ( | const Point3UI & | pt | ) |
Returns the reference to the element at (pt.x, pt.y, pt.z).
const T& jet::Array< T, 3 >::operator() | ( | const Point3UI & | pt | ) | const |
Returns the const reference to the element at (pt.x, pt.y, pt.z).
T& jet::Array< T, 3 >::operator() | ( | size_t | i, |
size_t | j, | ||
size_t | k | ||
) |
Returns the reference to the element at (i, j, k).
const T& jet::Array< T, 3 >::operator() | ( | size_t | i, |
size_t | j, | ||
size_t | k | ||
) | const |
Returns the const reference to the element at (i, j, k).
Array& jet::Array< T, 3 >::operator= | ( | Array< T, 3 > && | other | ) |
Move assignment.
Array& jet::Array< T, 3 >::operator= | ( | const Array< T, 3 > & | other | ) |
Copies given array other
to this array.
Array& jet::Array< T, 3 >::operator= | ( | const std::initializer_list< std::initializer_list< std::initializer_list< T >>> & | lst | ) |
Copies given initializer list lst
to this array.
This function copies given initializer list lst
to the array such as
Note the initializer also has 3-D structure. The code above will construct 4 x 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
Array& jet::Array< T, 3 >::operator= | ( | const T & | value | ) |
Sets entire array with given value
.
T& jet::Array< T, 3 >::operator[] | ( | size_t | i | ) |
Returns the reference to the i-th element.
This function returns the reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + width * (y + height * z) (x, y and z are the 3-D coordinates of the element).
const T& jet::Array< T, 3 >::operator[] | ( | size_t | i | ) | const |
Returns the const reference to the i-th element.
This function returns the const reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + width * (y + height * z) (x, y and z are the 3-D coordinates of the element).
void jet::Array< T, 3 >::parallelForEach | ( | Callback | func | ) |
Iterates the array and invoke given func
for each index in parallel.
This function iterates the array elements and invoke the callback function func
. The callback function takes array's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.
void jet::Array< T, 3 >::parallelForEachIndex | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index in parallel using multi-threading.
This function iterates the array elements and invoke the callback function func
in parallel using multi-threading. The callback function takes two parameters which are the (i, j, k) indices of the array. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
void jet::Array< T, 3 >::resize | ( | const Size3 & | size, |
const T & | initVal = T() |
||
) |
Resizes the array with size
and fill the new element with initVal
.
void jet::Array< T, 3 >::resize | ( | size_t | width, |
size_t | height, | ||
size_t | depth, | ||
const T & | initVal = T() |
||
) |
Resizes the array with size width
x height
and fill the new element with initVal
.
void jet::Array< T, 3 >::set | ( | const Array< T, 3 > & | other | ) |
Copies given array other
to this array.
void jet::Array< T, 3 >::set | ( | const std::initializer_list< std::initializer_list< std::initializer_list< T >>> & | lst | ) |
Copies given initializer list lst
to this array.
This function copies given initializer list lst
to the array such as
Note the initializer also has 3-D structure. The code above will construct 4 x 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
void jet::Array< T, 3 >::set | ( | const T & | value | ) |
Sets entire array with given value
.
Size3 jet::Array< T, 3 >::size | ( | ) | const |
Returns the size of the array.
void jet::Array< T, 3 >::swap | ( | Array< T, 3 > & | other | ) |
Swaps the content of the array with other
array.
size_t jet::Array< T, 3 >::width | ( | ) | const |
Returns the width of the array.