CanvasCV: CanvasCV-doxygen/src/canvascv/shapes/polygon.h Source File
CanvasCV  1.0.0
polygon.h
1 #ifndef POLYGON_H
2 #define POLYGON_H
3 
4 #include "compoundshape.h"
5 #include "handle.h"
6 
7 namespace canvascv
8 {
9 
16 class Polygon : public CompoundShape
17 {
18 public:
19 
21  bool isPointInPoly(const cv::Point &pos) const
22  {
23  if (isReady())
24  {
25  return cv::pointPolygonTest(vertices, pos, false) >= 0;
26 
27  }
28  return false;
29  }
30 
37  template <typename _TP>
38  void getPoints(vector<Point_<_TP>> &out);
39 
40  virtual bool isAtPos(const cv::Point &pos)
41  {
42  return isPointInPoly(pos);
43  }
44  virtual std::list<Handle *> getConnectionTargets();
45 
46  virtual bool keyPressed(int &key);
47  virtual void translate(const cv::Point &offset);
48 
49  virtual const char *getType() const;
50 
51  static const char * type;
52 
53 protected:
54 
55  friend class ShapeFactory;
56  template <class T> friend class ShapeFactoryT;
57 
58  Polygon(const cv::Point &pos);
59 
60  virtual void draw(cv::Mat &canvas);
61  virtual bool mousePressed(const cv::Point &pos, bool onCreate = false);
62  virtual bool mouseMoved(const cv::Point &pos);
63  virtual bool mouseReleased(const cv::Point &pos);
64  virtual void lostFocus();
65  virtual const string &getCreateStatusMsg() const;
66  virtual const string &getEditStatusMsg() const;
67 private:
68 
69  virtual void reloadPointers(const std::list<Shape*> &lst, std::list<Shape*>::const_iterator &i);
70  std::list<Handle*> handles;
71  std::vector<cv::Point> vertices;
72 };
73 
74 template <typename _TP>
75 void Polygon::getPoints(vector<Point_<_TP> > &out)
76 {
77  out.clear();
78  for (Handle *handle : handles)
79  {
80  out.push_back((*handle)());
81  }
82 }
83 
84 }
85 
90 #endif // POLYGON_H
virtual bool mousePressed(const cv::Point &pos, bool onCreate=false)
mousePressed
The ShapeFactory class.
Definition: shapefactory.h:24
virtual bool isAtPos(const cv::Point &pos)
returns true if shape is at pos, false otherwise
Definition: polygon.h:40
virtual const char * getType() const
getType is always implemented by derived to return the same static pointer per shape.
void getPoints(vector< Point_< _TP >> &out)
getPoints
virtual bool keyPressed(int &key)
keyPressed will be called by Canvas for active shapes
virtual void draw(cv::Mat &canvas)
draw shape on the canvas
virtual bool mouseMoved(const cv::Point &pos)
mouseMoved
virtual void lostFocus()
lostFocus is called by Canvas if we&#39;re in it and just became non-active
The CompoundShape class.
Definition: compoundshape.h:20
The ShapeFactoryT class.
Definition: shapefactory.h:45
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
virtual std::list< Handle * > getConnectionTargets()
getConnectionTargets
virtual bool mouseReleased(const cv::Point &pos)
mouseReleased
bool isPointInPoly(const cv::Point &pos) const
returns true if pos is in the polygon
Definition: polygon.h:21
The Polygon class.
Definition: polygon.h:16
The Handle class.
Definition: handle.h:19