1 #include "hokuyoscan.h"
5 #include "PlaygroundScene.h"
9 HokuyoScan::HokuyoScan() : QGraphicsItem(), showShapeDetect(false)
11 memset(&data, 0, sizeof(data));
12 memset(&sick_data, 0, sizeof(sick_data));
15 HokuyoScan::~HokuyoScan()
19 QRectF HokuyoScan::boundingRect() const
22 tl = PlaygroundScene::world2scene(QPointF(-3, -3));
23 br = PlaygroundScene::world2scene(QPointF(+3, +3));
24 return QRectF(tl, br);
27 void HokuyoScan::paintShapeDetect(QPainter * painter)
31 std::vector<Shape_detect::Line> lines;
32 std::vector<Shape_detect::Arc> arcs;
34 sd.prepare(data.data);
35 sd.line_detect(lines);
40 painter->setBrush(QBrush(Qt::NoBrush));
44 for (unsigned i = 0; i < lines.size(); i++)
45 painter->drawLine(lines[i].a.x, lines[i].a.y,
46 lines[i].b.x, lines[i].b.y);
51 painter->setPen(pen2);
53 for (unsigned i = 0; i < arcs.size(); i++) {
54 Shape_detect::Arc *a = &arcs[i];
55 painter->drawPoint(QPoint(a->center.x, a->center.y));
56 painter->drawEllipse(QRectF(a->center.x - a->radius, a->center.y - a->radius,
57 2*a->radius, 2*a->radius));
61 void HokuyoScan::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
65 QPointF points[SICK_ARRAY_SIZE + 1];
66 unsigned point_num = 0;
69 painter->setPen(QPen(Qt::blue));
70 color = QColor(Qt::red);
72 painter->setBrush(QBrush(color));
74 for (unsigned i=0; i < SICK_ARRAY_SIZE; i++) {
75 d = sick_data.data[i];
77 ang = SICK_INDEX_TO_RAD(i);
79 if((ang<(-SICK_RANGE_ANGLE_LEFT/180.0*M_PI))||((ang>(SICK_RANGE_ANGLE_RIGHT/180.0*M_PI)))) {
89 points[0] = QPointF(0, 0);
93 x = d * cos(SICK_INDEX_TO_RAD(i));
94 y = d * sin(SICK_INDEX_TO_RAD(i));
96 points[point_num] = QPointF(x, y);
99 painter->drawPolygon(points, point_num);
103 painter->drawPolygon(points, point_num);
106 paintShapeDetect(painter);
110 void HokuyoScan::setPosition(double x, double y, double phi)
112 // Store position to be used when new data arrives
118 void HokuyoScan::newScan(struct sick_scan_type *scan)
121 pos = PlaygroundScene::world2scene(pos);
123 setTransform(QTransform().rotateRadians(phi).translate(SICK_CENTER_OFFSET_MM, 0));
127 update(boundingRect());