xvWidgets
Polygon.hpp
1 #pragma once
2 
3 #include <list>
4 #include <opencv2/core.hpp>
5 #include "Widget.hpp"
6 #include "Point.hpp"
7 
8 namespace xv{
9 
15 class Polygon : public Widget, public std::vector<Point>
16 {
17 public:
20 
21 #pragma region constructors
22 
24  Polygon();
25 
27  //Polygon(const std::list<Point>& v) : std::list<Point>(v){};
28 #pragma endregion constructors
29 
31  bool operator == (const Polygon &b) {
32  if (this->m_undefined && b.m_undefined)
33  return true;//if both are undefined they are considered equal
34  return isEqual(*this, b);
35  };
36 
38  bool operator != (const Polygon &b) {
39  if (this->m_undefined && b.m_undefined)
40  return false; //if both are undefined they are considered equal
41 
42  if (this->m_undefined == !b.m_undefined)
43  return true; //opposite undefined state
44 
45  //compare as a gui_point_t_
46  return !isEqual(*this, b);
47  };
48 
50  virtual void setPosition(gui_point_t position);
51 private:
52  void paint(const cv::Mat&);
53  void paintAddPointButton(const Point&, const cv::Mat& image);
54  void onMouseMove(const gui_point_t&);
55  void onMouseDown(const gui_point_t&);
56  void onMouseUp(const gui_point_t&);
57  void setMouseOver(bool mouseOver);
58  void defineContours();
59  static bool isEqual(const Polygon&, const Polygon&);
60 
61  Point m_centerPoint;
62 
63  void setDefaultPoints();
64  gui_point_t getMiddlePoint();
65  void shiftPosition(gui_point_t);
66 };
67 
68 }
Widget that represents a point.
Definition: Point.hpp:13
bool operator!=(const Polygon &b)
Checks if 2 Polygons are different.
Definition: Polygon.hpp:38
virtual gui_point_t position()
Get the current position.
bool operator==(const Polygon &b)
Creates polygon from a list of points.
Definition: Polygon.hpp:31
Definition: Angle.hpp:8
bool m_undefined
Definition: Widget.hpp:138
Polygon()
Default constructor. Create a Polygon in undefined state.
Widget that represents a polygon defined by a set of points.
Definition: Polygon.hpp:15
static Polygon UNDEFINED
Represents a Polygon for which points were not yet set.
Definition: Polygon.hpp:19
Base class for all Widgets.
Definition: Widget.hpp:40
virtual void setPosition(gui_point_t position)
Moves the widget.