Jet  v1.3.3
Public Member Functions | List of all members
jet::ConstArrayAccessor< T, 3 > Class Template Reference

3-D read-only array accessor class. More...

#include <jet/array_accessor3.h>

Public Member Functions

 ConstArrayAccessor ()
 Constructs empty 3-D read-only array accessor. More...
 
 ConstArrayAccessor (const Size3 &size, const T *const data)
 
 ConstArrayAccessor (size_t width, size_t height, size_t depth, const T *const data)
 
 ConstArrayAccessor (const ArrayAccessor< T, 3 > &other)
 Constructs a read-only array accessor from read/write accessor. More...
 
 ConstArrayAccessor (const ConstArrayAccessor &other)
 Copy constructor. More...
 
const T & at (size_t i) const
 Returns the const reference to the i-th element. More...
 
const T & at (const Point3UI &pt) const
 Returns the const reference to the element at (pt.x, pt.y, pt.z). 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...
 
const T *const begin () const
 Returns the begin iterator of the array. More...
 
const T *const end () const
 Returns the end iterator of the array. 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...
 
const T *const data () const
 Returns the raw pointer to the array data. 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 parallelForEachIndex (Callback func) const
 Iterates the array and invoke given func for each index in parallel using multi-threading. More...
 
size_t index (const Point3UI &pt) const
 Returns the linear index of the given 3-D coordinate (pt.x, pt.y, pt.z). More...
 
size_t index (size_t i, size_t j, size_t k) const
 Returns the linear index of the given =3-D coordinate (i, j, k). More...
 
const T & operator[] (size_t i) const
 Returns the const reference to the i-th element. More...
 
const T & operator() (const Point3UI &pt) const
 Returns the const reference to the element at (pt.x, pt.y, pt.z). More...
 
const T & operator() (size_t i, size_t j, size_t k) const
 Returns the reference to the element at (i, j, k). More...
 

Detailed Description

template<typename T>
class jet::ConstArrayAccessor< T, 3 >

3-D read-only array accessor class.

This class represents 3-D read-only array accessor. Array accessor provides array-like data read/write functions, but does not handle memory management. Thus, it is more like a random access iterator, but with multi-dimension support.Similar to Array<T, 3>, this class interprets a linear array as a 3-D array using i-major indexing.

See also
Array<T, 3>

Constructor & Destructor Documentation

◆ ConstArrayAccessor() [1/5]

template<typename T >
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor ( )

Constructs empty 3-D read-only array accessor.

◆ ConstArrayAccessor() [2/5]

template<typename T >
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor ( const Size3 size,
const T *const  data 
)

Constructs a read-only array accessor that wraps given array.

Parameters
sizeSize of the 3-D array.
dataRaw array pointer.

◆ ConstArrayAccessor() [3/5]

template<typename T >
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor ( size_t  width,
size_t  height,
size_t  depth,
const T *const  data 
)

Constructs a read-only array accessor that wraps given array.

Parameters
widthWidth of the 3-D array.
heightHeight of the 3-D array.
depthDepth of the 3-D array.
dataRaw array pointer.

◆ ConstArrayAccessor() [4/5]

template<typename T >
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor ( const ArrayAccessor< T, 3 > &  other)
explicit

Constructs a read-only array accessor from read/write accessor.

◆ ConstArrayAccessor() [5/5]

template<typename T >
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor ( const ConstArrayAccessor< T, 3 > &  other)

Copy constructor.

Member Function Documentation

◆ at() [1/3]

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::at ( const Point3UI pt) const

Returns the const reference to the element at (pt.x, pt.y, pt.z).

◆ at() [2/3]

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::at ( size_t  i) const

Returns the const reference to the i-th element.

◆ at() [3/3]

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::at ( size_t  i,
size_t  j,
size_t  k 
) const

Returns the const reference to the element at (i, j, k).

◆ begin()

template<typename T >
const T* const jet::ConstArrayAccessor< T, 3 >::begin ( ) const

Returns the begin iterator of the array.

◆ data()

template<typename T >
const T* const jet::ConstArrayAccessor< T, 3 >::data ( ) const

Returns the raw pointer to the array data.

◆ depth()

template<typename T >
size_t jet::ConstArrayAccessor< T, 3 >::depth ( ) const

Returns the depth of the array.

◆ end()

template<typename T >
const T* const jet::ConstArrayAccessor< T, 3 >::end ( ) const

Returns the end iterator of the array.

◆ forEach()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
ConstArrayAccessor<int, 3> acc(2, 3, 2, data);
for (size_t k = 0; k < acc.depth(); ++k) {
for (size_t j = 0; j < acc.height(); ++j) {
for (size_t i = 0; i < acc.width(); ++i) {
func(i, j, k);
}
}
}

Below is the sample usage:

int data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
ConstArrayAccessor<int, 3> acc(2, 3, 2, data);
acc.forEach([](int elem) {
printf("%d\n", elem);
});

◆ forEachIndex()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
ConstArrayAccessor<int, 3> acc(2, 3, 2, data);
for (size_t k = 0; k < acc.depth(); ++k) {
for (size_t j = 0; j < acc.height(); ++j) {
for (size_t i = 0; i < acc.width(); ++i) {
func(i, j, k);
}
}
}

Below is the sample usage:

int data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
ConstArrayAccessor<int, 3> acc(2, 3, 2, data);
acc.forEachIndex([&](size_t i, size_t j, size_t k) {
acc(i, j, k) = 4.f * i + 7.f * j + 3.f * k + 1.5f;
});

◆ height()

template<typename T >
size_t jet::ConstArrayAccessor< T, 3 >::height ( ) const

Returns the height of the array.

◆ index() [1/2]

template<typename T >
size_t jet::ConstArrayAccessor< T, 3 >::index ( const Point3UI pt) const

Returns the linear index of the given 3-D coordinate (pt.x, pt.y, pt.z).

◆ index() [2/2]

template<typename T >
size_t jet::ConstArrayAccessor< T, 3 >::index ( size_t  i,
size_t  j,
size_t  k 
) const

Returns the linear index of the given =3-D coordinate (i, j, k).

◆ operator()() [1/2]

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::operator() ( const Point3UI pt) const

Returns the const reference to the element at (pt.x, pt.y, pt.z).

◆ operator()() [2/2]

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::operator() ( size_t  i,
size_t  j,
size_t  k 
) const

Returns the reference to the element at (i, j, k).

◆ operator[]()

template<typename T >
const T& jet::ConstArrayAccessor< T, 3 >::operator[] ( size_t  i) const

Returns the const reference to the i-th element.

◆ parallelForEachIndex()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
ConstArrayAccessor<int, 3> acc(2, 3, 2, data);
acc.parallelForEachIndex([&](size_t i, size_t j, size_t k) {
acc(i, j, k) *= 2;
});

◆ size()

template<typename T >
Size3 jet::ConstArrayAccessor< T, 3 >::size ( ) const

Returns the size of the array.

◆ width()

template<typename T >
size_t jet::ConstArrayAccessor< T, 3 >::width ( ) const

Returns the width of the array.


The documentation for this class was generated from the following file:
jet::ConstArrayAccessor< T, 3 >::data
const T *const data() const
Returns the raw pointer to the array data.