OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
array.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_CORE_ARRAY_HPP
2 #define OPENPOSE_CORE_ARRAY_HPP
3 
4 #include <memory> // std::shared_ptr
5 #include <vector>
6 #include <opencv2/core/core.hpp> // cv::Mat
8 
9 namespace op
10 {
19  template<typename T>
20  class Array
21  {
22  public:
23  // ------------------------------ Constructors and Data Allocator Functions ------------------------------ //
30  explicit Array(const int size);
31 
38  explicit Array(const std::vector<int>& sizes = {});
39 
47  Array(const int size, const T value);
48 
56  Array(const std::vector<int>& sizes, const T value);
57 
65  Array(const int size, T* const dataPtr);
66 
74  Array(const std::vector<int>& sizes, T* const dataPtr);
75 
88  Array(const Array<T>& array, const int index, const bool noCopy = false);
89 
98  Array<T>(const Array<T>& array);
99 
106  Array<T>& operator=(const Array<T>& array);
107 
114 
121  Array<T>& operator=(Array<T>&& array);
122 
130  Array<T> clone() const;
131 
138  void reset(const int size);
139 
147  void reset(const std::vector<int>& sizes = {});
148 
156  void reset(const int size, const T value);
157 
166  void reset(const std::vector<int>& sizes, const T value);
167 
173  void setFrom(const cv::Mat& cvMat);
174 
180  void setTo(const T value);
181 
182 
183 
184  // ------------------------------ Data Information Functions ------------------------------ //
189  inline bool empty() const
190  {
191  return (mVolume == 0);
192  }
193 
199  inline std::vector<int> getSize() const
200  {
201  return mSize;
202  }
203 
210  int getSize(const int index) const;
211 
217  std::string printSize() const;
218 
223  inline size_t getNumberDimensions() const
224  {
225  return mSize.size();
226  }
227 
233  inline size_t getVolume() const
234  {
235  return mVolume;
236  }
237 
247  size_t getVolume(const int indexA, const int indexB = -1) const;
248 
254  std::vector<int> getStride() const;
255 
260  int getStride(const int index) const;
261 
262 
263 
264  // ------------------------------ Data Access Functions And Operators ------------------------------ //
271  inline T* getPtr()
272  {
273  return pData; // spData.get()
274  }
275 
280  inline const T* getConstPtr() const
281  {
282  return pData; // spData.get()
283  }
284 
290  inline T* getPseudoConstPtr() const
291  {
292  return pData; // spData.get()
293  }
294 
307  const cv::Mat& getConstCvMat() const;
308 
316  cv::Mat& getCvMat();
317 
326  inline T& operator[](const int index)
327  {
328  #ifdef NDEBUG
329  return pData[index]; // spData.get()[index]
330  #else
331  return at(index);
332  #endif
333  }
334 
342  inline const T& operator[](const int index) const
343  {
344  #ifdef NDEBUG
345  return pData[index]; // spData.get()[index]
346  #else
347  return at(index);
348  #endif
349  }
350 
359  inline T& operator[](const std::vector<int>& indexes)
360  {
361  return operator[](getIndex(indexes));
362  }
363 
371  inline const T& operator[](const std::vector<int>& indexes) const
372  {
373  return operator[](getIndex(indexes));
374  }
375 
383  inline T& at(const int index)
384  {
385  return commonAt(index);
386  }
387 
395  inline const T& at(const int index) const
396  {
397  return commonAt(index);
398  }
399 
407  inline T& at(const std::vector<int>& indexes)
408  {
409  return at(getIndexAndCheck(indexes));
410  }
411 
419  inline const T& at(const std::vector<int>& indexes) const
420  {
421  return at(getIndexAndCheck(indexes));
422  }
423 
436  const std::string toString() const;
437 
438  private:
439  std::vector<int> mSize;
440  size_t mVolume;
441  std::shared_ptr<T> spData;
442  T* pData; // pData is a wrapper of spData. Used for Pybind11 binding.
443  std::pair<bool, cv::Mat> mCvMatData;
444 
452  int getIndex(const std::vector<int>& indexes) const;
453 
461  int getIndexAndCheck(const std::vector<int>& indexes) const;
462 
468  T& commonAt(const int index) const;
469 
470  void resetAuxiliary(const std::vector<int>& sizes, T* const dataPtr = nullptr);
471  };
472 
473  // Static methods
474  OVERLOAD_C_OUT(Array)
475 }
476 
477 #endif // OPENPOSE_CORE_ARRAY_HPP
const cv::Mat & getConstCvMat() const
Array< T > clone() const
std::array< T, N > array
Definition: cl2.hpp:594
T & operator[](const std::vector< int > &indexes)
Definition: array.hpp:359
T & at(const int index)
Definition: array.hpp:383
void setFrom(const cv::Mat &cvMat)
std::vector< int > getStride() const
Array< T > & operator=(const Array< T > &array)
size_t getNumberDimensions() const
Definition: array.hpp:223
const T & at(const std::vector< int > &indexes) const
Definition: array.hpp:419
void setTo(const T value)
const T & at(const int index) const
Definition: array.hpp:395
#define OVERLOAD_C_OUT(className)
Definition: macros.hpp:61
T * getPtr()
Definition: array.hpp:271
bool empty() const
Definition: array.hpp:189
size_t getVolume() const
Definition: array.hpp:233
cv::Mat & getCvMat()
T & operator[](const int index)
Definition: array.hpp:326
void reset(const int size)
const T & operator[](const std::vector< int > &indexes) const
Definition: array.hpp:371
Definition: array.hpp:20
const T * getConstPtr() const
Definition: array.hpp:280
const std::string toString() const
Array(const int size)
std::string printSize() const
const T & operator[](const int index) const
Definition: array.hpp:342
T & at(const std::vector< int > &indexes)
Definition: array.hpp:407
std::vector< int > getSize() const
Definition: array.hpp:199
T * getPseudoConstPtr() const
Definition: array.hpp:290
std::string string
Definition: cl2.hpp:574