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 
84  Array<T>(const Array<T>& array);
85 
93 
100 
107  Array<T>& operator=(Array<T>&& array);
108 
116  Array<T> clone() const;
117 
124  void reset(const int size);
125 
133  void reset(const std::vector<int>& sizes = {});
134 
142  void reset(const int size, const T value);
143 
152  void reset(const std::vector<int>& sizes, const T value);
153 
159  void setFrom(const cv::Mat& cvMat);
160 
166  void setTo(const T value);
167 
168 
169 
170  // ------------------------------ Data Information Functions ------------------------------ //
175  inline bool empty() const
176  {
177  return (mVolume == 0);
178  }
179 
185  inline std::vector<int> getSize() const
186  {
187  return mSize;
188  }
189 
196  int getSize(const int index) const;
197 
203  std::string printSize() const;
204 
209  inline size_t getNumberDimensions() const
210  {
211  return mSize.size();
212  }
213 
219  inline size_t getVolume() const
220  {
221  return mVolume;
222  }
223 
231  size_t getVolume(const int indexA, const int indexB) const;
232 
238  std::vector<int> getStride() const;
239 
244  int getStride(const int index) const;
245 
246 
247 
248  // ------------------------------ Data Access Functions And Operators ------------------------------ //
255  inline T* getPtr()
256  {
257  return pData; // spData.get()
258  }
259 
264  inline const T* getConstPtr() const
265  {
266  return pData; // spData.get()
267  }
268 
274  inline T* getPybindPtr() const
275  {
276  return pData; // spData.get()
277  }
278 
291  const cv::Mat& getConstCvMat() const;
292 
300  cv::Mat& getCvMat();
301 
310  inline T& operator[](const int index)
311  {
312  #ifdef NDEBUG
313  return pData[index]; // spData.get()[index]
314  #else
315  return at(index);
316  #endif
317  }
318 
326  inline const T& operator[](const int index) const
327  {
328  #ifdef NDEBUG
329  return pData[index]; // spData.get()[index]
330  #else
331  return at(index);
332  #endif
333  }
334 
343  inline T& operator[](const std::vector<int>& indexes)
344  {
345  return operator[](getIndex(indexes));
346  }
347 
355  inline const T& operator[](const std::vector<int>& indexes) const
356  {
357  return operator[](getIndex(indexes));
358  }
359 
367  inline T& at(const int index)
368  {
369  return commonAt(index);
370  }
371 
379  inline const T& at(const int index) const
380  {
381  return commonAt(index);
382  }
383 
391  inline T& at(const std::vector<int>& indexes)
392  {
393  return at(getIndexAndCheck(indexes));
394  }
395 
403  inline const T& at(const std::vector<int>& indexes) const
404  {
405  return at(getIndexAndCheck(indexes));
406  }
407 
420  const std::string toString() const;
421 
422  private:
423  std::vector<int> mSize;
424  size_t mVolume;
425  std::shared_ptr<T> spData;
426  T* pData; // pData is a wrapper of spData. Used for Pybind11 binding.
427  std::pair<bool, cv::Mat> mCvMatData;
428 
436  int getIndex(const std::vector<int>& indexes) const;
437 
445  int getIndexAndCheck(const std::vector<int>& indexes) const;
446 
452  T& commonAt(const int index) const;
453 
454  void resetAuxiliary(const std::vector<int>& sizes, T* const dataPtr = nullptr);
455  };
456 
457  // Static methods
458  OVERLOAD_C_OUT(Array)
459 }
460 
461 #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:343
T & at(const int index)
Definition: array.hpp:367
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:209
const T & at(const std::vector< int > &indexes) const
Definition: array.hpp:403
void setTo(const T value)
const T & at(const int index) const
Definition: array.hpp:379
#define OVERLOAD_C_OUT(className)
Definition: macros.hpp:60
T * getPtr()
Definition: array.hpp:255
bool empty() const
Definition: array.hpp:175
size_t getVolume() const
Definition: array.hpp:219
cv::Mat & getCvMat()
T & operator[](const int index)
Definition: array.hpp:310
T * getPybindPtr() const
Definition: array.hpp:274
void reset(const int size)
const T & operator[](const std::vector< int > &indexes) const
Definition: array.hpp:355
Definition: array.hpp:20
const T * getConstPtr() const
Definition: array.hpp:264
const std::string toString() const
Array(const int size)
std::string printSize() const
const T & operator[](const int index) const
Definition: array.hpp:326
T & at(const std::vector< int > &indexes)
Definition: array.hpp:391
std::vector< int > getSize() const
Definition: array.hpp:185
std::string string
Definition: cl2.hpp:574