TAMSVIZ
Visualization and annotation tool for ROS
image.cpp
1 // TAMSVIZ
2 // (c) 2020 Philipp Ruppel
3 
4 #include "image.h"
5 
6 #include "../core/log.h"
7 
8 #include <QPainterPath>
9 #include <QTransform>
10 
12  virtual void render() override {
13  if (controlPoints().empty()) {
14  shape = nullptr;
15  complete = false;
16  } else {
17  shape = std::make_shared<QPainterPath>();
18  shape->addPolygon(QPolygonF(QRectF(-10, -2, 20, 4))
19  .united(QPolygonF(QRectF(-2, -10, 4, 20))));
20  shape->translate(controlPoints().front().x(),
21  controlPoints().front().y());
22  complete = true;
23  }
24  }
25 };
27 
29  virtual void render() override {
30  if (controlPoints().size() < 2) {
31  shape = nullptr;
32  complete = false;
33  } else {
34  shape = std::make_shared<QPainterPath>();
35  double left =
36  std::min(controlPoints().at(0).x(), controlPoints().at(1).x());
37  double right =
38  std::max(controlPoints().at(0).x(), controlPoints().at(1).x());
39  double top =
40  std::min(controlPoints().at(0).y(), controlPoints().at(1).y());
41  double bottom =
42  std::max(controlPoints().at(0).y(), controlPoints().at(1).y());
43  shape->addRect(left, top, right - left, bottom - top);
44  complete = true;
45  }
46  }
47 };
49 
51  virtual void render() override {
52  shape = std::make_shared<QPainterPath>();
53  QVector<QPointF> points;
54  if (!controlPoints().empty()) {
55  for (auto &p : controlPoints()) {
56  points.push_back(QPointF(p.x(), p.y()));
57  }
58  {
59  auto p = controlPoints().front();
60  points.push_back(QPointF(p.x(), p.y()));
61  }
62  }
63  shape->addPolygon(points);
64  complete = ((controlPoints().size() > 3) &&
65  (controlPoints().front() == controlPoints().back()));
66  }
67 };
69 
71  virtual void render() override {
72  shape = std::make_shared<QPainterPath>();
73  QVector<QPointF> points;
74  if (!controlPoints().empty()) {
75  for (auto &p : controlPoints()) {
76  points.push_back(QPointF(p.x(), p.y()));
77  }
78  {
79  auto p = controlPoints().front();
80  points.push_back(QPointF(p.x(), p.y()));
81  }
82  }
83  shape->addPolygon(points);
84  complete = (controlPoints().size() >= 3);
85  }
86 };
88 
90  virtual void render() override {
91  shape = std::make_shared<QPainterPath>();
92  QVector<QPointF> points;
93  if (!controlPoints().empty()) {
94  for (auto &p : controlPoints()) {
95  points.push_back(QPointF(p.x(), p.y()));
96  }
97  {
98  auto p = controlPoints().front();
99  points.push_back(QPointF(p.x(), p.y()));
100  }
101  }
102  shape->addPolygon(points);
103  complete = (controlPoints().size() >= 4);
104  }
105 };
107 
109  virtual void render() override {
110  if (controlPoints().size() < 2) {
111  shape = nullptr;
112  complete = false;
113  } else {
114  shape = std::make_shared<QPainterPath>();
115  double cx = controlPoints().at(0).x();
116  double cy = controlPoints().at(0).y();
117  double r = (controlPoints().at(0) - controlPoints().at(1)).norm();
118  shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
119  complete = true;
120  }
121  }
122 };
124 
126  virtual void render() override {
127  if (controlPoints().size() < 2) {
128  shape = nullptr;
129  complete = false;
130  } else {
131  shape = std::make_shared<QPainterPath>();
132  double cx = (controlPoints().at(0).x() + controlPoints().at(1).x()) * 0.5;
133  double cy = (controlPoints().at(0).y() + controlPoints().at(1).y()) * 0.5;
134  double r = (controlPoints().at(0) - controlPoints().at(1)).norm() * 0.5;
135  shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
136  complete = true;
137  }
138  }
139 };
141 
143  virtual void render() override {
144  if (controlPoints().size() < 2) {
145  shape = nullptr;
146  complete = false;
147  } else {
148  shape = std::make_shared<QPainterPath>();
149  double left =
150  std::min(controlPoints().at(0).x(), controlPoints().at(1).x());
151  double right =
152  std::max(controlPoints().at(0).x(), controlPoints().at(1).x());
153  double top =
154  std::min(controlPoints().at(0).y(), controlPoints().at(1).y());
155  double bottom =
156  std::max(controlPoints().at(0).y(), controlPoints().at(1).y());
157  shape->addEllipse(left, top, right - left, bottom - top);
158  complete = true;
159  }
160  }
161 };
163 
165  virtual void constrain() override {
166  if (controlPoints().size() == 3) {
167  double r = (controlPoints().at(0) - controlPoints().at(2)).norm();
168  auto d = (controlPoints().at(0) - controlPoints().at(1)).normalized();
169  controlPoints().at(2) +=
170  d * d.dot(controlPoints().at(0) - controlPoints().at(2));
171  controlPoints().at(2) =
172  controlPoints().at(0) +
173  (controlPoints().at(2) - controlPoints().at(0)).normalized() * r;
174  }
175  }
176  virtual void render() override {
177  if (controlPoints().size() < 2) {
178  shape = nullptr;
179  complete = false;
180  } else if (controlPoints().size() == 2) {
181  shape = std::make_shared<QPainterPath>();
182  double cx = controlPoints().at(0).x();
183  double cy = controlPoints().at(0).y();
184  double r = (controlPoints().at(0) - controlPoints().at(1)).norm();
185  shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
186  complete = false;
187  } else {
188  shape = std::make_shared<QPainterPath>();
189  double width = (controlPoints().at(0) - controlPoints().at(1)).norm() * 2;
190  auto d = (controlPoints().at(0) - controlPoints().at(1)).normalized();
191  double height =
192  std::abs(Eigen::Vector2d(-d.y(), d.x())
193  .dot(controlPoints().at(0) - controlPoints().at(2))) *
194  2.0;
195  shape->addEllipse(-width * 0.5, -height * 0.5, width, height);
196  QTransform transform;
197  transform.translate(controlPoints().at(0).x(), controlPoints().at(0).y());
198  transform.rotate(
199  std::atan2(controlPoints().at(0).y() - controlPoints().at(1).y(),
200  controlPoints().at(0).x() - controlPoints().at(1).x()) *
201  (180.0 / M_PI));
202  *shape = transform.map(*shape);
203  complete = true;
204  }
205  }
206 };