2 * MclPainter.cpp 08/01/26
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
8 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
13 #include "MclPainter.h"
16 MclPainter::MclPainter(struct mcl_model *mcl, int *displayCount)
18 background = QBrush(QColor(240, 220, 220));
20 this->displayCount = displayCount;
23 MclPainter::~MclPainter()
28 void MclPainter::paint(QPainter *painter, QPaintEvent *event)
30 struct mcl_laser *l = mcl_to_laser(mcl);
31 struct mcl_laser_state *parts = l->parts;
33 int count = mcl->count - *displayCount;
35 QRect rect = event->rect();
37 painter->fillRect(rect, background);
38 painter->setPen(QColor(20, 20, 20));
40 for (int i=count; i<mcl->count; i++) {
43 (qreal)(parts[i].x / PLAYGROUND_WIDTH_M * width),
44 (qreal)((PLAYGROUND_HEIGHT_M-parts[i].y)
45 / PLAYGROUND_HEIGHT_M * height));
47 // col = (int)(parts[i].weight * 128 + 50);
48 // col = (col > 255) ? 255 : col;
49 // col = (col < 0) ? 0 : col;
52 painter->setBrush(QColor(col, 40, 40));
53 painter->drawEllipse(0, 0, 10, 10);
55 -(qreal)(parts[i].x / PLAYGROUND_WIDTH_M * width),
56 -(qreal)((PLAYGROUND_HEIGHT_M-parts[i].y)
57 / PLAYGROUND_HEIGHT_M * height));
59 /* draw a line representing the robot's head */
61 (qreal)((parts[i].x / PLAYGROUND_WIDTH_M * width)+5),
62 (qreal)(((PLAYGROUND_HEIGHT_M-parts[i].y)
63 / PLAYGROUND_HEIGHT_M * height)+5));
64 painter->rotate(RAD2DEG(-parts[i].angle));
65 painter->drawLine(0, 0, 20, 0);
66 painter->rotate(RAD2DEG(parts[i].angle));
68 -(qreal)((parts[i].x / PLAYGROUND_WIDTH_M * width)+5),
69 -(qreal)(((PLAYGROUND_HEIGHT_M-parts[i].y)
70 / PLAYGROUND_HEIGHT_M * height)+5));
75 (qreal)(estimated.x / PLAYGROUND_WIDTH_M * width),
76 (qreal)((PLAYGROUND_HEIGHT_M-estimated.y)
77 / PLAYGROUND_HEIGHT_M * height));
79 painter->setBrush(QColor(40, 40, 255));
80 painter->drawEllipse(0, 0, 20, 20);
82 -(qreal)(estimated.x / PLAYGROUND_WIDTH_M * width),
83 -(qreal)((PLAYGROUND_HEIGHT_M-estimated.y)
84 / PLAYGROUND_HEIGHT_M * height));
86 /* draw a line representing the robot's head */
88 (qreal)((estimated.x / PLAYGROUND_WIDTH_M * width)+10),
89 (qreal)(((PLAYGROUND_HEIGHT_M-estimated.y)
90 / PLAYGROUND_HEIGHT_M * height)+10));
91 painter->rotate(RAD2DEG(-estimated.angle));
92 painter->drawLine(0, 0, 80, 0);
93 painter->rotate(RAD2DEG(estimated.angle));
95 -(qreal)((estimated.x / PLAYGROUND_WIDTH_M * width)+10),
96 -(qreal)(((PLAYGROUND_HEIGHT_M-estimated.y)
97 / PLAYGROUND_HEIGHT_M * height)+10));
100 void MclPainter::setSize(int width, int height)
103 this->height = height;
106 QSize MclPainter::size()
108 return QSize(width, height);