qlaserdata.cpp
Go to the documentation of this file.
00001 #include <QGraphicsScene>
00002 #include <QPainter>
00003 #include <QStyleOption>
00004 
00005 #include "qlaserdata.h"
00006 #include "qlaserdata.moc"
00007 
00008 
00009 QLaserData::QLaserData(LDP ld): ld(ld)
00010 {
00011         this->countour = createCountour();
00012         double *p = ld->estimate;
00013         setPos(QPointF(p[0],p[1]));
00014         rotate(CSM::rad2deg(p[2]));
00015 }
00016 
00017 QRectF QLaserData::boundingRect() const
00018 {
00019         return countour.boundingRect();
00020 }
00021 
00022 QPainterPath QLaserData::shape() const
00023 {
00024         return countour;
00025 }
00026 
00027 QPainterPath QLaserData::createCountour() {
00028         ld_compute_cartesian(ld);
00029         struct stroke_sequence sequence[ld->nrays];
00030         compute_stroke_sequence(ld, sequence, 100, 0.1);
00031         
00032         QPainterPath path;
00033         for(int i=0;i<ld->nrays;i++) {
00034                 if(sequence[i].valid==0) continue;
00035                 double *p = sequence[i].p;
00036                 if(sequence[i].begin_new_stroke)
00037                         path.moveTo(p[0], p[1]);
00038                 else
00039                         path.lineTo(p[0], p[1]);
00040         }
00041         return path;
00042 }
00043 
00044 void QLaserData::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00045 {
00046          // Body
00047 //              painter->setBrush(color);
00048 /*       painter->drawEllipse(-10, -20, 20, 40);
00049 
00050          // Eyes
00051          painter->setBrush(Qt::white);
00052          painter->drawEllipse(-10, -17, 8, 8);
00053          painter->drawEllipse(2, -17, 8, 8);
00054 
00055          // Nose
00056          painter->setBrush(Qt::black);
00057          painter->drawEllipse(QRectF(-2, -22, 4, 4));
00058 
00059 
00060          // Ears
00061                 painter->setBrush(scene()->collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red);
00062          painter->drawEllipse(-17, -12, 16, 16);
00063          painter->drawEllipse(1, -12, 16, 16);
00064 */
00065          // Tail
00066          painter->setPen(Qt::black);
00067          painter->setBrush(Qt::NoBrush);
00068 /*       painter->setBrush(Qt::red);*/
00069          painter->drawPath(countour);
00070 }
00071 
00072 void QLaserData::timerEvent(QTimerEvent *)
00073 {
00074 
00075   //    rotate(dx);
00076 //              setPos(mapToParent(0, -(3 + sin(speed) * 3)));
00077 }


csm
Author(s): Andrea Censi
autogenerated on Mon Jan 16 2017 03:48:29