OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator 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 
66  Array<T>(const Array<T>& array);
67 
74  Array<T>& operator=(const Array<T>& array);
75 
81  Array<T>(Array<T>&& array);
82 
89  Array<T>& operator=(Array<T>&& array);
90 
98  Array<T> clone() const;
99 
106  void reset(const int size);
107 
115  void reset(const std::vector<int>& sizes = {});
116 
124  void reset(const int size, const T value);
125 
134  void reset(const std::vector<int>& sizes, const T value);
135 
141  void setFrom(const cv::Mat& cvMat);
142 
148  void setTo(const T value);
149 
150 
151 
152  // ------------------------------ Data Information Functions ------------------------------ //
157  inline bool empty() const
158  {
159  return (mVolume == 0);
160  }
161 
167  inline std::vector<int> getSize() const
168  {
169  return mSize;
170  }
171 
177  std::string printSize() const;
178 
185  int getSize(const int index) const;
186 
191  inline size_t getNumberDimensions() const
192  {
193  return mSize.size();
194  }
195 
201  inline size_t getVolume() const
202  {
203  return mVolume;
204  }
205 
213  size_t getVolume(const int indexA, const int indexB) const;
214 
215 
216 
217  // ------------------------------ Data Access Functions And Operators ------------------------------ //
224  inline T* getPtr()
225  {
226  return spData.get();
227  }
228 
233  inline const T* getConstPtr() const
234  {
235  return spData.get();
236  }
237 
250  const cv::Mat& getConstCvMat() const;
251 
259  cv::Mat& getCvMat();
260 
269  inline T& operator[](const int index)
270  {
271  #ifdef NDEBUG
272  return spData.get()[index];
273  #else
274  return at(index);
275  #endif
276  }
277 
285  inline const T& operator[](const int index) const
286  {
287  #ifdef NDEBUG
288  return spData.get()[index];
289  #else
290  return at(index);
291  #endif
292  }
293 
302  inline T& operator[](const std::vector<int>& indexes)
303  {
304  return operator[](getIndex(indexes));
305  }
306 
314  inline const T& operator[](const std::vector<int>& indexes) const
315  {
316  return operator[](getIndex(indexes));
317  }
318 
326  inline T& at(const int index)
327  {
328  return commonAt(index);
329  }
330 
338  inline const T& at(const int index) const
339  {
340  return commonAt(index);
341  }
342 
350  inline T& at(const std::vector<int>& indexes)
351  {
352  return at(getIndexAndCheck(indexes));
353  }
354 
362  inline const T& at(const std::vector<int>& indexes) const
363  {
364  return at(getIndexAndCheck(indexes));
365  }
366 
379  const std::string toString() const;
380 
381  private:
382  std::vector<int> mSize;
383  size_t mVolume;
384  std::shared_ptr<T> spData;
385  std::pair<bool, cv::Mat> mCvMatData;
386 
394  int getIndex(const std::vector<int>& indexes) const;
395 
403  int getIndexAndCheck(const std::vector<int>& indexes) const;
404 
410  T& commonAt(const int index) const;
411 
416  void setCvMatFromSharedPtr();
417  };
418 
419  // Static methods
420  OVERLOAD_C_OUT(Array)
421 }
422 
423 #endif // OPENPOSE_CORE_ARRAY_HPP
const cv::Mat & getConstCvMat() const
Array< T > clone() const
T & operator[](const std::vector< int > &indexes)
Definition: array.hpp:302
T & at(const int index)
Definition: array.hpp:326
void setFrom(const cv::Mat &cvMat)
Array< T > & operator=(const Array< T > &array)
size_t getNumberDimensions() const
Definition: array.hpp:191
const T & at(const std::vector< int > &indexes) const
Definition: array.hpp:362
void setTo(const T value)
const T & at(const int index) const
Definition: array.hpp:338
#define OVERLOAD_C_OUT(className)
Definition: macros.hpp:51
T * getPtr()
Definition: array.hpp:224
bool empty() const
Definition: array.hpp:157
size_t getVolume() const
Definition: array.hpp:201
cv::Mat & getCvMat()
T & operator[](const int index)
Definition: array.hpp:269
void reset(const int size)
const T & operator[](const std::vector< int > &indexes) const
Definition: array.hpp:314
Definition: array.hpp:20
const T * getConstPtr() const
Definition: array.hpp:233
const std::string toString() const
Array(const int size)
std::string printSize() const
const T & operator[](const int index) const
Definition: array.hpp:285
T & at(const std::vector< int > &indexes)
Definition: array.hpp:350
std::vector< int > getSize() const
Definition: array.hpp:167