1 #include "hokuyoscan.h"
4 #include "PlaygroundScene.h"
8 HokuyoScan::HokuyoScan() : QGraphicsItem(), showShapeDetect(false)
10 memset(&data, 0, sizeof(data));
13 HokuyoScan::~HokuyoScan()
17 QRectF HokuyoScan::boundingRect() const
20 tl = PlaygroundScene::world2scene(QPointF(-3, -3));
21 br = PlaygroundScene::world2scene(QPointF(+3, +3));
22 return QRectF(tl, br);
25 void HokuyoScan::paintShapeDetect(QPainter * painter)
29 std::vector<Shape_detect::Line> lines;
30 std::vector<Shape_detect::Arc> arcs;
32 sd.prepare(data.data);
33 sd.line_detect(lines);
38 painter->setBrush(QBrush(Qt::NoBrush));
42 for (unsigned i = 0; i < lines.size(); i++)
43 painter->drawLine(lines[i].a.x, lines[i].a.y,
44 lines[i].b.x, lines[i].b.y);
49 painter->setPen(pen2);
51 for (unsigned i = 0; i < arcs.size(); i++) {
52 Shape_detect::Arc *a = &arcs[i];
53 painter->drawEllipse(QRectF(a->center.x - a->radius, a->center.y - a->radius,
54 2*a->radius, 2*a->radius));
58 void HokuyoScan::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
62 QPointF points[HOKUYO_ARRAY_SIZE + 1];
63 unsigned point_num = 0;
66 painter->setPen(QPen(Qt::blue));
67 color = QColor(Qt::red);
69 painter->setBrush(QBrush(color));
71 for (unsigned i=0; i < HOKUYO_ARRAY_SIZE; i++) {
74 ang = HOKUYO_INDEX_TO_RAD(i);
76 if((ang<(-HOKUYO_RANGE_ANGLE_LEFT/180.0*M_PI))||((ang>(HOKUYO_RANGE_ANGLE_RIGHT/180.0*M_PI)))) {
86 points[0] = QPointF(0, 0);
90 x = d * cos(HOKUYO_INDEX_TO_RAD(i));
91 y = d * sin(HOKUYO_INDEX_TO_RAD(i));
93 points[point_num] = QPointF(x, y);
96 painter->drawPolygon(points, point_num);
100 painter->drawPolygon(points, point_num);
103 paintShapeDetect(painter);
107 void HokuyoScan::setPosition(double x, double y, double phi)
109 // Store position to be used when new data arrives
115 void HokuyoScan::newScan(struct hokuyo_scan_type *scan)
118 pos = PlaygroundScene::world2scene(pos);
120 setTransform(QTransform().rotateRadians(phi).translate(HOKUYO_CENTER_OFFSET_MM, 0));
124 update(boundingRect());