OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
op::Array< T > Class Template Reference

#include <array.hpp>

Public Member Functions

 Array (const int size)
 
 Array (const std::vector< int > &sizes={})
 
 Array (const int size, const T value)
 
 Array (const std::vector< int > &sizes, const T value)
 
 Array (const int size, T *const dataPtr)
 
 Array (const std::vector< int > &sizes, T *const dataPtr)
 
 Array (const Array< T > &array, const int index, const bool noCopy=false)
 
template<typename T2 >
 Array (const Array< T2 > &array)
 
 Array (const Array< T > &array)
 
Array< T > & operator= (const Array< T > &array)
 
 Array (Array< T > &&array)
 
Array< T > & operator= (Array< T > &&array)
 
Array< T > clone () const
 
void reset (const int size)
 
void reset (const std::vector< int > &sizes={})
 
void reset (const int size, const T value)
 
void reset (const std::vector< int > &sizes, const T value)
 
void reset (const int size, T *const dataPtr)
 
void reset (const std::vector< int > &sizes, T *const dataPtr)
 
void setFrom (const Matrix &cvMat)
 
void setTo (const T value)
 
bool empty () const
 
std::vector< int > getSize () const
 
int getSize (const int index) const
 
std::string printSize () const
 
size_t getNumberDimensions () const
 
size_t getVolume () const
 
size_t getVolume (const int indexA, const int indexB=-1) const
 
std::vector< int > getStride () const
 
int getStride (const int index) const
 
T * getPtr ()
 
const T * getConstPtr () const
 
T * getPseudoConstPtr () const
 
const MatrixgetConstCvMat () const
 
MatrixgetCvMat ()
 
T & operator[] (const int index)
 
const T & operator[] (const int index) const
 
T & operator[] (const std::vector< int > &indexes)
 
const T & operator[] (const std::vector< int > &indexes) const
 
T & at (const int index)
 
const T & at (const int index) const
 
T & at (const std::vector< int > &indexes)
 
const T & at (const std::vector< int > &indexes) const
 
const std::string toString () const
 

Detailed Description

template<typename T>
class op::Array< T >

Array<T>: The OpenPose Basic Raw Data Container This template class implements a multidimensional data array. It is our basic data container, analogous to Mat in OpenCV, Tensor in Torch/TensorFlow or Blob in Caffe. It wraps a Matrix and a std::shared_ptr, both of them pointing to the same raw data. I.e. they both share the same memory, so we can read and modify this data in both formats with no performance impact. Hence, it keeps high performance while adding high-level functions.

Definition at line 21 of file array.hpp.

Constructor & Destructor Documentation

◆ Array() [1/10]

template<typename T >
op::Array< T >::Array ( const int  size)
explicit

Array constructor. Equivalent to default constructor + reset(const int size).

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].

◆ Array() [2/10]

template<typename T >
op::Array< T >::Array ( const std::vector< int > &  sizes = {})
explicit

Array constructor. Equivalent to default constructor + reset(const std::vector<int>& size = {}).

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to new T[3*5*2].

◆ Array() [3/10]

template<typename T >
op::Array< T >::Array ( const int  size,
const T  value 
)

Array constructor. Equivalent to default constructor + reset(const int size, const T value).

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].
valueInitial value for each component of the Array.

◆ Array() [4/10]

template<typename T >
op::Array< T >::Array ( const std::vector< int > &  sizes,
const T  value 
)

Array constructor. Equivalent to default constructor + reset(const std::vector<int>& size, const T value).

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to: new T[3*5*2].
valueInitial value for each component of the Array.

◆ Array() [5/10]

template<typename T >
op::Array< T >::Array ( const int  size,
T *const  dataPtr 
)

Array constructor. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].
dataPtrPointer to the memory to be used by the Array.

◆ Array() [6/10]

template<typename T >
op::Array< T >::Array ( const std::vector< int > &  sizes,
T *const  dataPtr 
)

Array constructor. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to: new T[3*5*2].
dataPtrPointer to the memory to be used by the Array.

◆ Array() [7/10]

template<typename T >
op::Array< T >::Array ( const Array< T > &  array,
const int  index,
const bool  noCopy = false 
)

Array constructor.

Parameters
arrayArray<T> with the original data array to slice.
indexindicates the index of the array to extract.
noCopyindicates whether to perform a copy. Copy will never go to undefined behavior, however, if noCopy == true, then:
  1. It is faster, as no data copy is involved, but...
  2. If the Array array goes out of scope, then the resulting Array will provoke an undefined behavior.
  3. If the returned Array is modified, the information in the Array array will also be.
Returns
Array<T> with the same dimension than array expect the first dimension being 1. E.g., if array is {p,k,m}, the resulting Array<T> is {1,k,m}.

◆ Array() [8/10]

template<typename T >
template<typename T2 >
op::Array< T >::Array ( const Array< T2 > &  array)
inline

Array constructor. It manually copies the Array<T2> into the new Array<T>

Parameters
arrayArray<T2> with a format T2 different to the current Array type T.

Definition at line 96 of file array.hpp.

◆ Array() [9/10]

template<typename T >
op::Array< T >::Array ( const Array< T > &  array)

Copy constructor. It performs fast copy: For performance purpose, copying a Array<T> or Datum or cv::Mat just copies the reference, it still shares the same internal data. Modifying the copied element will modify the original one. Use clone() for a slower but real copy, similarly to cv::Mat and Array<T>.

Parameters
arrayArray to be copied.

◆ Array() [10/10]

template<typename T >
op::Array< T >::Array ( Array< T > &&  array)

Move constructor. It destroys the original Array to be moved.

Parameters
arrayArray to be moved.

Member Function Documentation

◆ at() [1/4]

template<typename T >
T& op::Array< T >::at ( const int  index)
inline

at() function Same functionality as operator[](const int index), but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters
indexThe desired memory location.
Returns
A editable reference to the data on the desired index location.

Definition at line 422 of file array.hpp.

◆ at() [2/4]

template<typename T >
const T& op::Array< T >::at ( const int  index) const
inline

at() function Same functionality as operator[](const int index) const, but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters
indexThe desired memory location.
Returns
A non-editable reference to the data on the desired index location.

Definition at line 434 of file array.hpp.

◆ at() [3/4]

template<typename T >
T& op::Array< T >::at ( const std::vector< int > &  indexes)
inline

at() function Same functionality as operator[](const std::vector<int>& indexes), but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters
indexesVector with the desired memory location.
Returns
A editable reference to the data on the desired index location.

Definition at line 446 of file array.hpp.

◆ at() [4/4]

template<typename T >
const T& op::Array< T >::at ( const std::vector< int > &  indexes) const
inline

at() function Same functionality as operator[](const std::vector<int>& indexes) const, but it always check whether the indexes are within the data bounds. Otherwise, it will throw an error.

Parameters
indexesVector with the desired memory location.
Returns
A non-editable reference to the data on the desired index location.

Definition at line 458 of file array.hpp.

◆ clone()

template<typename T >
Array<T> op::Array< T >::clone ( ) const

Clone function. Similar to cv::Mat::clone and Datum::clone. It performs a real but slow copy of the data, i.e., even if the copied element is modified, the original one is not.

Returns
The resulting Array.

◆ empty()

template<typename T >
bool op::Array< T >::empty ( ) const
inline

Check whether memory has been allocated.

Returns
True if no memory has been allocated, false otherwise.

Definition at line 228 of file array.hpp.

◆ getConstCvMat()

template<typename T >
const Matrix& op::Array< T >::getConstCvMat ( ) const

Return a Matrix wrapper to the data. It forbids the data to be modified. OpenCV only admits unsigned char, signed char, int, float & double. If the T class is not supported by OpenCV, it will throw an error. Note: Array<T> does not return an editable Matrix because some OpenCV functions reallocate memory and it would not longer point to the Array<T> instance. If you want to perform some OpenCV operation on the Array data, you can use: editedCvMat = array.getConstCvMat().clone(); // modify data array.setFrom(editedCvMat)

Returns
A const Matrix pointing to the data.

◆ getConstPtr()

template<typename T >
const T* op::Array< T >::getConstPtr ( ) const
inline

Similar to getPtr(), but it forbids the data to be edited.

Returns
A raw const pointer to the data.

Definition at line 319 of file array.hpp.

◆ getCvMat()

template<typename T >
Matrix& op::Array< T >::getCvMat ( )

Analogous to getConstCvMat, but in this case it returns a editable Matrix. Very important: Only allowed functions which do not provoke data reallocation. E.g., resizing functions will not work and they would provoke an undefined behavior and/or execution crashes.

Returns
A Matrix pointing to the data.

◆ getNumberDimensions()

template<typename T >
size_t op::Array< T >::getNumberDimensions ( ) const
inline

Return the total number of dimensions, equivalent to getSize().size().

Returns
The number of dimensions. If no memory is allocated, it returns 0.

Definition at line 262 of file array.hpp.

◆ getPseudoConstPtr()

template<typename T >
T* op::Array< T >::getPseudoConstPtr ( ) const
inline

Similar to getConstPtr(), but it allows the data to be edited. This function is only implemented for Pybind11 usage.

Returns
A raw pointer to the data.

Definition at line 329 of file array.hpp.

◆ getPtr()

template<typename T >
T* op::Array< T >::getPtr ( )
inline

Return a raw pointer to the data. Similar to: std::shared_ptr::get(). Note: if you modify the pointer data, you will directly modify it in the Array<T> instance too. If you know you do not want to modify the data, then use getConstPtr() instead.

Returns
A raw pointer to the data.

Definition at line 310 of file array.hpp.

◆ getSize() [1/2]

template<typename T >
std::vector<int> op::Array< T >::getSize ( ) const
inline

Return a vector with the size of each dimension allocated.

Returns
A std::vector<int> with the size of each dimension. If no memory has been allocated, it will return an empty std::vector.

Definition at line 238 of file array.hpp.

◆ getSize() [2/2]

template<typename T >
int op::Array< T >::getSize ( const int  index) const

Return a vector with the size of the desired dimension.

Parameters
indexDimension to check its size.
Returns
Size of the desired dimension. It will return 0 if the requested dimension is higher than the number of dimensions.

◆ getStride() [1/2]

template<typename T >
std::vector<int> op::Array< T >::getStride ( ) const

Return the stride or step size of the array. E.g., given and Array<T> of size 5x3, getStride() would return the following vector: {5x3sizeof(T), 3sizeof(T), sizeof(T)}.

◆ getStride() [2/2]

template<typename T >
int op::Array< T >::getStride ( const int  index) const

Return the stride or step size of the array at the index-th dimension. E.g., given and Array<T> of size 5x3, getStride(2) would return sizeof(T).

◆ getVolume() [1/2]

template<typename T >
size_t op::Array< T >::getVolume ( ) const
inline

Return the total number of elements allocated, equivalent to multiply all the components from getSize(). E.g., for a Array<T> of size = {2,5,3}, the volume or total number of elements is: 2x5x3 = 30.

Returns
The total volume of the allocated data. If no memory is allocated, it returns 0.

Definition at line 272 of file array.hpp.

◆ getVolume() [2/2]

template<typename T >
size_t op::Array< T >::getVolume ( const int  indexA,
const int  indexB = -1 
) const

Similar to getVolume(), but in this case it just returns the volume between the desired dimensions. E.g., for a Array<T> of size = {2,5,3}, the volume or total number of elements for getVolume(1,2) is 5x3 = 15.

Parameters
indexADimension where to start.
indexBDimension where to stop. If indexB == -1, then it will take up to the last dimension.
Returns
The total volume of the allocated data between the desired dimensions. If the index are out of bounds, it throws an error.

◆ operator=() [1/2]

template<typename T >
Array<T>& op::Array< T >::operator= ( Array< T > &&  array)

Move assignment. Similar to Array<T>(Array<T>&& array).

Parameters
arrayArray to be moved.
Returns
The resulting Array.

◆ operator=() [2/2]

template<typename T >
Array<T>& op::Array< T >::operator= ( const Array< T > &  array)

Copy assignment. Similar to Array<T>(const Array<T>& array).

Parameters
arrayArray to be copied.
Returns
The resulting Array.

◆ operator[]() [1/4]

template<typename T >
T& op::Array< T >::operator[] ( const int  index)
inline

[] operator Similar to the [] operator for raw pointer data. If debug mode is enabled, then it will check that the desired index is in the data range, and it will throw an exception otherwise (similar to the at operator).

Parameters
indexThe desired memory location.
Returns
A editable reference to the data on the desired index location.

Definition at line 365 of file array.hpp.

◆ operator[]() [2/4]

template<typename T >
const T& op::Array< T >::operator[] ( const int  index) const
inline

[] operator Same functionality as operator[](const int index), but it forbids modifying the value. Otherwise, const functions would not be able to call the [] operator.

Parameters
indexThe desired memory location.
Returns
A non-editable reference to the data on the desired index location.

Definition at line 381 of file array.hpp.

◆ operator[]() [3/4]

template<typename T >
T& op::Array< T >::operator[] ( const std::vector< int > &  indexes)
inline

[] operator Same functionality as operator[](const int index), but it lets the user introduce the multi-dimensional index. E.g., given a (10 x 10 x 10) array, array[11] is equivalent to array[{1,1,0}]

Parameters
indexesVector with the desired memory location.
Returns
A editable reference to the data on the desired index location.

Definition at line 398 of file array.hpp.

◆ operator[]() [4/4]

template<typename T >
const T& op::Array< T >::operator[] ( const std::vector< int > &  indexes) const
inline

[] operator Same functionality as operator[](const std::vector<int>& indexes), but it forbids modifying the value. Otherwise, const functions would not be able to call the [] operator.

Parameters
indexesVector with the desired memory location.
Returns
A non-editable reference to the data on the desired index location.

Definition at line 410 of file array.hpp.

◆ printSize()

template<typename T >
std::string op::Array< T >::printSize ( ) const

Return a string with the size of each dimension allocated.

Returns
A std::stringwith the size of each dimension. If no memory has been allocated, it will return an empty string.

◆ reset() [1/6]

template<typename T >
void op::Array< T >::reset ( const int  size)

Data allocation function. It allocates the required space for the memory (it does not initialize that memory).

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].

◆ reset() [2/6]

template<typename T >
void op::Array< T >::reset ( const int  size,
const T  value 
)

Data allocation function. Similar to reset(const int size), but initializing the data to the value specified by the second argument.

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].
valueInitial value for each component of the Array.

◆ reset() [3/6]

template<typename T >
void op::Array< T >::reset ( const int  size,
T *const  dataPtr 
)

Data allocation function. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters
sizeInteger with the number of T element to be allocated. E.g., size = 5 is internally similar to new T[5].
dataPtrPointer to the memory to be used by the Array.

◆ reset() [4/6]

template<typename T >
void op::Array< T >::reset ( const std::vector< int > &  sizes,
const T  value 
)

Data allocation function. Similar to reset(const std::vector<int>& size), but initializing the data to the value specified by the second argument.

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to new T[3*5*2].
valueInitial value for each component of the Array.

◆ reset() [5/6]

template<typename T >
void op::Array< T >::reset ( const std::vector< int > &  sizes,
T *const  dataPtr 
)

Data allocation function. Equivalent to default constructor, but it does not allocate memory, but rather use dataPtr.

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to: new T[3*5*2].
dataPtrPointer to the memory to be used by the Array.

◆ reset() [6/6]

template<typename T >
void op::Array< T >::reset ( const std::vector< int > &  sizes = {})

Data allocation function. Similar to reset(const int size), but it allocates a multi-dimensional array of dimensions each of the values of the argument.

Parameters
sizesVector with the size of each dimension. E.g., size = {3, 5, 2} is internally similar to new T[3*5*2].

◆ setFrom()

template<typename T >
void op::Array< T >::setFrom ( const Matrix cvMat)

Data allocation function. It internally allocates memory and copies the data of the argument to the Array allocated memory.

Parameters
cvMatMatrix to be copied.

◆ setTo()

template<typename T >
void op::Array< T >::setTo ( const T  value)

Data allocation function. It internally assigns all the allocated memory to the value indicated by the argument.

Parameters
valueValue for each component of the Array.

◆ toString()

template<typename T >
const std::string op::Array< T >::toString ( ) const

It returns a string with the whole array data. Useful for debugging. The format is: values separated by a space, and a enter for each dimension. E.g., For the Array{2, 2, 3}, it will print: Array<T>::toString(): x1 x2 x3 x4 x5 x6

x7 x8 x9 x10 x11 x12

Returns
A string with the array values in the above format.

The documentation for this class was generated from the following file: