Kinetic Visualization
 All Classes Functions Variables Pages
TransferPoints.h
1 #pragma once
2 #include "Clustering.h"
3 
4 #include <QObject>
5 #include <QRectF>
6 #include <QVector>
7 #include <QSizeF>
8 #include <QPen>
9 #include <QBrush>
10 #include <QPointF>
11 #include <QWidget>
12 #include <QColor>
13 
14 #include "GLM/gtx.hpp"
15 #include "GLM/gtc.hpp"
16 #include "GLM/gtx/type_ptr.hpp"
17 
18 #include "TPoint.h"
19 
20 class TFObjects
21 {
22 public:
23  int type;
24  glm::vec2 size;
25  glm::vec2 pos;
26  glm::vec2 scale;
27  int rotate;
28  QColor color;
29  QPainterPath path;
30 
31  glm::vec2 m;
32  glm::mat2 c;
33 };
34 
35 class TransferPoints : public QObject
36 {
37  Q_OBJECT
38 
39 public:
40  enum PointShape {
41  CircleShape,
42  RectangleShape
43  };
44 
45  enum LockType {
46  LockToLeft = 0x01,
47  LockToRight = 0x02,
48  LockToTop = 0x04,
49  LockToBottom = 0x08
50  };
51 
52  enum EventObjectType
53  {
54  Selection = 0,
55  DrawPoint = 1,
56  DrawEllipse = 2,
57  DrawRectangle = 3
58  };
59 
60  enum SortType {
61  NoSort,
62  XSort,
63  YSort
64  };
65 
66  enum ConnectionType {
67  NoConnection,
68  LineConnection,
69  CurveConnection
70  };
71 
75  TransferPoints(QWidget *widget, PointShape shape);
76 
81  bool eventFilter(QObject *object, QEvent *event);
82 
86  void paintPoints();
87 
91  inline QRectF boundingRect() const;
95  void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
96 
100  const QVector<TPoint>& points() const;
104  void setPoints(const QVector<TPoint> &points);
105 
109  QSizeF pointSize() const { return m_pointSize; }
113  void setPointSize(const QSizeF &size) { m_pointSize = size; }
114 
118  SortType sortType() const { return m_sortType; }
123  void setSortType(SortType sortType) { m_sortType = sortType; }
124 
129  ConnectionType connectionType() const { return m_connectionType; }
135  void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
136 
140  void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
144  void setShapePen(const QPen &pen) { m_pointPen = pen; }
148  void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
149 
154  void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
155 
159  void setEditable(bool editable) { m_editable = editable; }
163  bool editable() const { return m_editable; }
164 
165 
166 public slots:
170  void setEnabled(bool enabled);
171 
175  void setDisabled(bool disabled) { setEnabled(!disabled); }
176 
180  void changePointColor(QColor c) {p_color = c;}
181 
185  void updateHistogram(double* histogram, int size);
186 
190  void updateValues(glm::vec2* values, int size);
191 
197  void updateMode(int mode);
198 
199  void DoClustering(int K);
200 
201 
202  void updateActionObjectType(int type);
203 signals:
204 
208  void pointsChanged(int);
209 public:
210 
214  void firePointChange();
215 
216  std::vector<TFObjects> tf_objects;
217 
218 private:
222  inline QRectF pointBoundingRect(int i) const;
223 
227  inline QRectF insertBoundingRect(int i) const;
228 
234  void movePoint(int i, const TPoint &newPos, bool emitChange = true);
235 
237  QWidget* m_widget;
238 
240  QVector<TPoint>* m_points;
241 
243  QRectF m_bounds;
244 
246  PointShape m_shape;
248  SortType m_sortType;
250  ConnectionType m_connectionType;
252  QVector<uint> m_locks;
254  QSizeF m_pointSize;
256  int m_currentIndex;
257 
259  bool m_editable;
261  bool m_enabled;
262 
264  QPen m_pointPen;
266  QBrush m_pointBrush;
268  QPen m_connectionPen;
270  QColor p_color;
271 
273  double* hist;
275  int histSize;
276  //void drawHistogram(QPainter p);
277 
281  glm::vec2* valuesX;
282  // Stores Size
283  int sizeX;
284 
285  //Stores Mode
286  int m_mode;
287 
288  //Defines the current Operation for Actions
289  int m_action_type;
290 
291  QPainterPath drawing_path;
292  glm::vec2 start_rectangle;
293  glm::vec2 act_rectangle;
294  bool newAction;
295 };
296 
297 
298 inline QRectF TransferPoints::pointBoundingRect(int i) const
299 {
300  int mode = m_mode;
301  TPoint p = m_points[mode].at(i);
302  double w = m_pointSize.width();
303  double h = m_pointSize.height();
304  double x = p.x() - w / 2;
305  double y = p.y() - h / 2;
306  return QRectF(x, y, w, h);
307 }
308 
309 inline QRectF TransferPoints::insertBoundingRect(int i) const
310 {
311  int mode = m_mode;
312  TPoint p = m_points[mode].at(i);
313  double w = m_pointSize.width() * 2.0;
314  double h = m_pointSize.height() * 2.0;
315  double x = p.x() - w / 2;
316  double y = p.y() - h / 2;
317  return QRectF(x, y, w, h);
318 }
319 
320 inline QRectF TransferPoints::boundingRect() const
321 {
322  if (m_bounds.isEmpty())
323  return m_widget->rect();
324  else
325  return m_bounds;
326 };