All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
array.hpp
Go to the documentation of this file.
#ifndef OPENPOSE_CORE_ARRAY_HPP
#define OPENPOSE_CORE_ARRAY_HPP
#include <memory> // std::shared_ptr
#include <vector>
#include <opencv2/core/core.hpp> // cv::Mat
#include <openpose/core/macros.hpp>
namespace op
{
template<typename T>
class Array
{
public:
// ------------------------------ Constructors and Data Allocator Functions ------------------------------ //
explicit Array(const int size);
explicit 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);
Array<T>(const Array<T>& array);
Array<T>& operator=(const Array<T>& array);
Array<T>(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 setFrom(const cv::Mat& cvMat);
void setTo(const T value);
// ------------------------------ Data Information Functions ------------------------------ //
inline bool empty() const
{
return (mVolume == 0);
}
inline std::vector<int> getSize() const
{
return mSize;
}
int getSize(const int index) const;
std::string printSize() const;
inline size_t getNumberDimensions() const
{
return mSize.size();
}
inline size_t getVolume() const
{
return mVolume;
}
size_t getVolume(const int indexA, const int indexB = -1) const;
std::vector<int> getStride() const;
int getStride(const int index) const;
// ------------------------------ Data Access Functions And Operators ------------------------------ //
inline T* getPtr()
{
return pData; // spData.get()
}
inline const T* getConstPtr() const
{
return pData; // spData.get()
}
inline T* getPseudoConstPtr() const
{
return pData; // spData.get()
}
const cv::Mat& getConstCvMat() const;
cv::Mat& getCvMat();
inline T& operator[](const int index)
{
#ifdef NDEBUG
return pData[index]; // spData.get()[index]
#else
return at(index);
#endif
}
inline const T& operator[](const int index) const
{
#ifdef NDEBUG
return pData[index]; // spData.get()[index]
#else
return at(index);
#endif
}
inline T& operator[](const std::vector<int>& indexes)
{
return operator[](getIndex(indexes));
}
inline const T& operator[](const std::vector<int>& indexes) const
{
return operator[](getIndex(indexes));
}
inline T& at(const int index)
{
return commonAt(index);
}
inline const T& at(const int index) const
{
return commonAt(index);
}
inline T& at(const std::vector<int>& indexes)
{
return at(getIndexAndCheck(indexes));
}
inline const T& at(const std::vector<int>& indexes) const
{
return at(getIndexAndCheck(indexes));
}
const std::string toString() const;
private:
std::vector<int> mSize;
size_t mVolume;
std::shared_ptr<T> spData;
T* pData; // pData is a wrapper of spData. Used for Pybind11 binding.
std::pair<bool, cv::Mat> mCvMatData;
int getIndex(const std::vector<int>& indexes) const;
int getIndexAndCheck(const std::vector<int>& indexes) const;
T& commonAt(const int index) const;
void resetAuxiliary(const std::vector<int>& sizes, T* const dataPtr = nullptr);
};
// Static methods
OVERLOAD_C_OUT(Array)
}
#endif // OPENPOSE_CORE_ARRAY_HPP
op::Array::getConstCvMat
const cv::Mat & getConstCvMat() const
op::Array::clone
Array< T > clone() const
cl::array
std::array< T, N > array
Definition: cl2.hpp:594
op::Array::operator[]
T & operator[](const std::vector< int > &indexes)
Definition: array.hpp:359
op::Array::at
T & at(const int index)
Definition: array.hpp:383
op::Array::setFrom
void setFrom(const cv::Mat &cvMat)
op::Array::getStride
std::vector< int > getStride() const
op::Array::operator=
Array< T > & operator=(const Array< T > &array)
op::Array::getNumberDimensions
size_t getNumberDimensions() const
Definition: array.hpp:223
op::Array::at
const T & at(const std::vector< int > &indexes) const
Definition: array.hpp:419
op::Array::setTo
void setTo(const T value)
op::Array::at
const T & at(const int index) const
Definition: array.hpp:395
OVERLOAD_C_OUT
#define OVERLOAD_C_OUT(className)
Definition: macros.hpp:61
op::Array::getPtr
T * getPtr()
Definition: array.hpp:271
op::Array::empty
bool empty() const
Definition: array.hpp:189
op::Array::getVolume
size_t getVolume() const
Definition: array.hpp:233
op::Array::getCvMat
cv::Mat & getCvMat()
op::Array::operator[]
T & operator[](const int index)
Definition: array.hpp:326
op::Array::reset
void reset(const int size)
macros.hpp
op::Array::operator[]
const T & operator[](const std::vector< int > &indexes) const
Definition: array.hpp:371
op::Array
Definition: array.hpp:20
op::Array::getConstPtr
const T * getConstPtr() const
Definition: array.hpp:280
op::Array::toString
const std::string toString() const
op::Array::Array
Array(const int size)
op::Array::printSize
std::string printSize() const
op::Array::operator[]
const T & operator[](const int index) const
Definition: array.hpp:342
op::Array::at
T & at(const std::vector< int > &indexes)
Definition: array.hpp:407
op::Array::getSize
std::vector< int > getSize() const
Definition: array.hpp:199
op::Array::getPseudoConstPtr
T * getPseudoConstPtr() const
Definition: array.hpp:290
cl::string
std::string string
Definition: cl2.hpp:574