CanvasCV: CanvasCV-doxygen/src/canvascv/shapes/rectangle.h Source File
CanvasCV  1.0.0
rectangle.h
1 #ifndef RECTANGLE_H
2 #define RECTANGLE_H
3 
4 #include "compoundshape.h"
5 #include "handle.h"
6 
7 namespace canvascv
8 {
9 
15 class Rectangle : public CompoundShape
16 {
17 public:
18 
20  cv::RotatedRect getRect() const;
21 
23  void setRect(const cv::RotatedRect &rect);
24 
25  virtual bool keyPressed(int &key);
26 
28  bool isPointInRectangle(cv::Point pos)
29  {
30  std::vector<Point> pts(4);
31  pts[0] = (*pt1)();
32  pts[1] = (*pt2)();
33  pts[2] = (*pt3)();
34  pts[3] = (*pt4)();
35  return cv::pointPolygonTest(pts, pos, false) >= 0;
36  }
37 
38  virtual bool isAtPos(const cv::Point &pos)
39  {
40  return isPointInRectangle(pos);
41  }
42 
43  virtual std::list<Handle *> getConnectionTargets();
44 
45  virtual void translate(const cv::Point &offset);
46 
47  virtual const char *getType() const;
48 
49  static const char * type;
50 
51 protected:
52  friend class ShapeFactory;
53  template <class T> friend class ShapeFactoryT;
54 
55  Rectangle(const cv::Point &pos);
56 
57  virtual void draw(cv::Mat &canvas);
58  virtual bool mousePressed(const cv::Point &pos, bool onCreate = false);
59  virtual bool mouseMoved(const cv::Point &pos);
60  virtual bool mouseReleased(const cv::Point &pos);
61  virtual const string &getEditStatusMsg() const;
62 
63 private:
64  void recalcRect(const cv::Point &pos, bool rotated = false, float offset = 0);
65 
66  void updatePoints();
67 
68  void registerCBs();
69 
70  Handle* pt1;
71  Handle* pt2;
72  Handle* pt3;
73  Handle* pt4;
74  Handle* rotate1;
75  Handle* rotate2;
76  Handle* rotate3;
77  Handle* rotate4;
78  Handle* center;
79  float width;
80  float height;
81  float angle; // in radians
82  bool selfUpdate;
83 
84  virtual void writeInternals(cv::FileStorage &fs) const;
85  virtual void readInternals(const cv::FileNode &node);
86 
87  virtual void reloadPointers(const std::list<Shape*> &lst, std::list<Shape*>::const_iterator &i);
88 };
89 
90 }
91 #endif // RECTANGLE_H
The ShapeFactory class.
Definition: shapefactory.h:24
virtual bool mouseMoved(const cv::Point &pos)
mouseMoved
virtual bool mouseReleased(const cv::Point &pos)
mouseReleased
The CompoundShape class.
Definition: compoundshape.h:20
The ShapeFactoryT class.
Definition: shapefactory.h:45
void setRect(const cv::RotatedRect &rect)
set this shape from the OpenCV representation
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
virtual bool isAtPos(const cv::Point &pos)
returns true if shape is at pos, false otherwise
Definition: rectangle.h:38
The Rectangle class.
Definition: rectangle.h:15
virtual bool keyPressed(int &key)
keyPressed will be called by Canvas for active shapes
virtual bool mousePressed(const cv::Point &pos, bool onCreate=false)
mousePressed
bool isPointInRectangle(cv::Point pos)
returns true if pos is in the rectangle representated by this shape
Definition: rectangle.h:28
cv::RotatedRect getRect() const
get the OpenCV representation of this shape
virtual const char * getType() const
getType is always implemented by derived to return the same static pointer per shape.
virtual std::list< Handle * > getConnectionTargets()
getConnectionTargets
virtual void draw(cv::Mat &canvas)
draw shape on the canvas
The Handle class.
Definition: handle.h:19