DFace SDK  1.8.5
types.h
1 //
2 // Created by asy on 10/16/18.
3 //
4 
5 #ifndef DFACE_TYPES_H
6 #define DFACE_TYPES_H
7 #include <vector>
8 namespace dface {
9  using namespace std;
10 
15  template<typename _Tp> class Point_
16  {
17  public:
18  typedef _Tp value_type;
19 
21  Point_();
22  Point_(_Tp _x, _Tp _y);
23  Point_(const Point_& pt);
24 
25  Point_& operator = (const Point_& pt);
26 
28  _Tp dot(const Point_& pt) const;
30  double ddot(const Point_& pt) const;
32  double cross(const Point_& pt) const;
33 
37  _Tp x;
41  _Tp y;
42  };
43 
44 
45  template<typename _Tp> class Size_
46  {
47  public:
48  typedef _Tp value_type;
49 
51  Size_();
52  Size_(_Tp _width, _Tp _height);
53  Size_(const Size_& sz);
54  Size_(const Point_<_Tp>& pt);
55 
56  Size_& operator = (const Size_& sz);
58  _Tp area() const;
60  bool empty() const;
61 
62  _Tp width;
63  _Tp height;
64  };
65 
66 
67 
72  template<typename _Tp> class Rect_
73  {
74  public:
75  typedef _Tp value_type;
76 
78  Rect_();
79  Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
80  Rect_(const Rect_& r);
81  Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
82  Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
83 
84  Rect_& operator = ( const Rect_& r );
86  Point_<_Tp> tl() const;
88  Point_<_Tp> br() const;
89 
91  Size_<_Tp> size() const;
93  _Tp area() const;
95  bool empty() const;
96 
98  bool contains(const Point_<_Tp>& pt) const;
99 
103  _Tp x;
107  _Tp y;
111  _Tp width;
115  _Tp height;
116  };
117 
118 
119 
120 
121  template<typename _Tp> inline
123  : x(0), y(0) {}
124 
125  template<typename _Tp> inline
126  Point_<_Tp>::Point_(_Tp _x, _Tp _y)
127  : x(_x), y(_y) {}
128 
129  template<typename _Tp> inline
130  Point_<_Tp>::Point_(const Point_& pt)
131  : x(pt.x), y(pt.y) {}
132 
133 
134 
135  template<typename _Tp> inline
137  {
138  x = pt.x; y = pt.y;
139  return *this;
140  }
141 
142 
143 
144  template<typename _Tp> inline
146  : width(0), height(0) {}
147 
148  template<typename _Tp> inline
149  Size_<_Tp>::Size_(_Tp _width, _Tp _height)
150  : width(_width), height(_height) {}
151 
152  template<typename _Tp> inline
153  Size_<_Tp>::Size_(const Size_& sz)
154  : width(sz.width), height(sz.height) {}
155 
156  template<typename _Tp> inline
157  Size_<_Tp>::Size_(const Point_<_Tp>& pt)
158  : width(pt.x), height(pt.y) {}
159 
160 
161  template<typename _Tp> inline
163  {
164  width = sz.width; height = sz.height;
165  return *this;
166  }
167 
168  template<typename _Tp> inline
169  _Tp Size_<_Tp>::area() const
170  {
171  const _Tp result = width * height;
172  return result;
173  }
174 
175  template<typename _Tp> inline
176  bool Size_<_Tp>::empty() const
177  {
178  return width <= 0 || height <= 0;
179  }
180 
181 
182 
183  template<typename _Tp> inline
185  : x(0), y(0), width(0), height(0) {}
186 
187  template<typename _Tp> inline
188  Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height)
189  : x(_x), y(_y), width(_width), height(_height) {}
190 
191  template<typename _Tp> inline
192  Rect_<_Tp>::Rect_(const Rect_<_Tp>& r)
193  : x(r.x), y(r.y), width(r.width), height(r.height) {}
194 
195  template<typename _Tp> inline
196  Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz)
197  : x(org.x), y(org.y), width(sz.width), height(sz.height) {}
198 
199  template<typename _Tp> inline
200  Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
201  {
202  x = std::min(pt1.x, pt2.x);
203  y = std::min(pt1.y, pt2.y);
204  width = std::max(pt1.x, pt2.x) - x;
205  height = std::max(pt1.y, pt2.y) - y;
206  }
207 
208  template<typename _Tp> inline
210  {
211  x = r.x;
212  y = r.y;
213  width = r.width;
214  height = r.height;
215  return *this;
216  }
217 
218  template<typename _Tp> inline
220  {
221  return Point_<_Tp>(x,y);
222  }
223 
224  template<typename _Tp> inline
226  {
227  return Point_<_Tp>(x + width, y + height);
228  }
229 
230  template<typename _Tp> inline
232  {
233  return Size_<_Tp>(width, height);
234  }
235 
236  template<typename _Tp> inline
237  _Tp Rect_<_Tp>::area() const
238  {
239  const _Tp result = width * height;
240  return result;
241  }
242 
243  template<typename _Tp> inline
244  bool Rect_<_Tp>::empty() const
245  {
246  return width <= 0 || height <= 0;
247  }
248 
249 
250  template<typename _Tp> inline
251  bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const
252  {
253  return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height;
254  }
255 
256 
257 
258 
259 
260 
261 
262 }
263 
264 
265 #endif //DFACE_TYPES_H
Point_< _Tp > tl() const
the top-left corner
Definition: types.h:219
bool empty() const
true if empty
Definition: types.h:176
_Tp height
矩形高
Definition: types.h:115
_Tp x
矩形左上角x坐标值
Definition: types.h:103
Definition: common.h:37
Point_()
default constructor
Definition: types.h:122
_Tp area() const
area (width*height) of the rectangle
Definition: types.h:237
Size_< _Tp > size() const
size (width, height) of the rectangle
Definition: types.h:231
_Tp width
the width
Definition: types.h:62
bool empty() const
true if empty
Definition: types.h:244
Size_()
default constructor
Definition: types.h:145
bool contains(const Point_< _Tp > &pt) const
checks whether the rectangle contains the point
Definition: types.h:251
_Tp y
y坐标值
Definition: types.h:41
Point_< _Tp > br() const
the bottom-right corner
Definition: types.h:225
Definition: types.h:45
Rect_ 矩形表示模板类,常用于人脸边框, 整数型矩形参考dface::Rect(typdef Rect_<int> Rect) ...
Definition: types.h:72
_Tp area() const
the area (width*height)
Definition: types.h:169
Size 点表示模板类, 整数型点参考dface::Point(typdef Point_<int> Point)
Definition: types.h:15
_Tp height
the height
Definition: types.h:63
_Tp width
矩形宽
Definition: types.h:111
_Tp x
x坐标值
Definition: types.h:37
_Tp y
矩形左上角y坐标值
Definition: types.h:107
Rect_()
default constructor
Definition: types.h:184