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
7 
8 namespace op
9 {
18  template<typename T>
19  class Array
20  {
21  public:
22  // -------------------------------------------------- Constructors and Data Allocator Functions -------------------------------------------------- //
28  explicit Array(const int size);
29 
35  explicit Array(const std::vector<int>& sizes = {});
36 
43  Array(const int size, const T value);
44 
51  Array(const std::vector<int>& sizes, const T value);
52 
60  Array<T>(const Array<T>& array);
61 
68  Array<T>& operator=(const Array<T>& array);
69 
75  Array<T>(Array<T>&& array);
76 
83  Array<T>& operator=(Array<T>&& array);
84 
91  Array<T> clone() const;
92 
98  void reset(const int size);
99 
105  void reset(const std::vector<int>& sizes = {});
106 
113  void reset(const int size, const T value);
114 
121  void reset(const std::vector<int>& sizes, const T value);
122 
128  void setFrom(const cv::Mat& cvMat);
129 
135  void setTo(const T value);
136 
137 
138 
139  // -------------------------------------------------- Data Information Functions -------------------------------------------------- //
144  inline bool empty() const
145  {
146  return (mVolume == 0);
147  }
148 
153  inline std::vector<int> getSize() const
154  {
155  return mSize;
156  }
157 
163  int getSize(const int index) const;
164 
169  inline size_t getNumberDimensions() const
170  {
171  return mSize.size();
172  }
173 
179  inline size_t getVolume() const
180  {
181  return mVolume;
182  }
183 
189  size_t getVolume(const int indexA, const int indexB) const;
190 
191 
192 
193  // -------------------------------------------------- Data Access Functions And Operators -------------------------------------------------- //
200  inline T* getPtr()
201  {
202  return spData.get();
203  }
204 
209  inline const T* getConstPtr() const
210  {
211  return spData.get();
212  }
213 
224  const cv::Mat& getConstCvMat() const;
225 
232  cv::Mat& getCvMat();
233 
241  inline T& operator[](const int index)
242  {
243  #ifdef NDEBUG
244  return spData.get()[index];
245  #else
246  return at(index);
247  #endif
248  }
249 
256  inline const T& operator[](const int index) const
257  {
258  #ifdef NDEBUG
259  return spData.get()[index];
260  #else
261  return at(index);
262  #endif
263  }
264 
272  inline T& operator[](const std::vector<int>& indexes)
273  {
274  return operator[](getIndex(indexes));
275  }
276 
283  inline const T& operator[](const std::vector<int>& indexes) const
284  {
285  return operator[](getIndex(indexes));
286  }
287 
294  inline T& at(const int index)
295  {
296  return commonAt(index);
297  }
298 
305  inline const T& at(const int index) const
306  {
307  return commonAt(index);
308  }
309 
316  inline T& at(const std::vector<int>& indexes)
317  {
318  return at(getIndexAndCheck(indexes));
319  }
320 
327  inline const T& at(const std::vector<int>& indexes) const
328  {
329  return at(getIndexAndCheck(indexes));
330  }
331 
344  const std::string toString() const;
345 
346  private:
347  std::vector<int> mSize;
348  size_t mVolume;
349  std::shared_ptr<T> spData;
350  std::pair<bool, cv::Mat> mCvMatData;
351 
358  int getIndex(const std::vector<int>& indexes) const;
359 
366  int getIndexAndCheck(const std::vector<int>& indexes) const;
367 
373  T& commonAt(const int index) const;
374 
378  void setCvMatFromSharedPtr();
379  };
380 }
381 
382 #endif // OPENPOSE_CORE_ARRAY_HPP
const cv::Mat & getConstCvMat() const
Array< T > clone() const
T & operator[](const std::vector< int > &indexes)
Definition: array.hpp:272
T & at(const int index)
Definition: array.hpp:294
void setFrom(const cv::Mat &cvMat)
Array< T > & operator=(const Array< T > &array)
size_t getNumberDimensions() const
Definition: array.hpp:169
const T & at(const std::vector< int > &indexes) const
Definition: array.hpp:327
void setTo(const T value)
const T & at(const int index) const
Definition: array.hpp:305
T * getPtr()
Definition: array.hpp:200
bool empty() const
Definition: array.hpp:144
size_t getVolume() const
Definition: array.hpp:179
cv::Mat & getCvMat()
T & operator[](const int index)
Definition: array.hpp:241
void reset(const int size)
const T & operator[](const std::vector< int > &indexes) const
Definition: array.hpp:283
Definition: array.hpp:19
const T * getConstPtr() const
Definition: array.hpp:209
const std::string toString() const
Array(const int size)
const T & operator[](const int index) const
Definition: array.hpp:256
T & at(const std::vector< int > &indexes)
Definition: array.hpp:316
std::vector< int > getSize() const
Definition: array.hpp:153