QGraphicsItem* CGraphicsDiamondItem::createItem() { QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent); drawPen(pItem); drawBrush(pItem); qreal x; qreal y; qreal w; qreal h; x = GET_VALUE(x).toFloat(); y = GET_VALUE(y).toFloat(); w = GET_VALUE(w).toFloat(); h = GET_VALUE(h).toFloat(); QPolygonF d; d.append(QPointF(x + w/2,y)); d.append(QPointF(x + w,y + h/2)); d.append(QPointF(x + w/2,y + h)); d.append(QPointF(x,y + h/2)); pItem->setPolygon(d); return pItem; }
void MainWindow::on_btn_start_clicked() { rsim->reset(); scene->clear(); graphicalInit(); ui->liste_tributs_1->clear(); ui->liste_tributs_2->clear(); g_billes.clear(); photos_g.clear(); outlight_g.clear(); int n = ui->nbilles_dial->value(); for(int i=0;i<n;i++) { if(i%2 == 0) { ui->liste_tributs_1->addItem("Palmer?"); } else if(i%2 == 1) { ui->liste_tributs_2->addItem("Palmer?"); } } rsim->start(n); QVector<b2Body*> b=rsim->getBalls(); for(int i=0;i<b.size();i++) { QGraphicsEllipseItem* g_bille = scene->addEllipse(-10,-10,35,35,QPen(), QBrush(QColor(200,86,23))); g_billes.append(g_bille); QGraphicsPixmapItem* p = scene->addPixmap(unknown); if(n<= 12) { p->setScale(0.5f); int total_height = (ceil(b.size()/2.0))*150+40; p->setPos(i%2==0? -540 : 520-100, -total_height/2+(i/2)*150); } else { float scale = 0.5*12/(float)n; p->setScale(scale); float height = 150*12/(float) n; int total_height = (ceil(b.size()/2.0))*height+40; p->setPos(i%2==0? -540 : 520-100*12/(float)n, -total_height/2+(i/2)*height); } photos_g.append(p); QVector<QPointF> points; points.append(QPointF(0,0)); points.append(QPointF(1500,0)); points.append(QPointF(1500*cos(1/48.0*2*3.14159),1500*sin(1/48.0*2*3.14159))); QGraphicsPolygonItem* outlight = scene->addPolygon(QPolygonF(points),QPen(QColor(255,255,255,128)),QBrush(QColor(255,192+(rand()%64 - 32),0,96))); outlight->setZValue(-1); outlight->setTransformOriginPoint(QPointF(0,0)); outlight->setVisible(false); outlight_g.append(outlight); } }
void ShapeFormulaNode::AddPolygon(QVector<QPointF>& points, QColor& color) { QGraphicsPolygonItem* i = new QGraphicsPolygonItem(points, item); i->setBrush(QBrush(color)); ((QGraphicsItemGroup*)item)->addToGroup(i); item->update(); }
void MainWindow::slotAddPolygonItem() //在场景中加入一个多边形图元 { QVector<QPoint> v; v<<QPoint(30,-15)<<QPoint(0,-30)<<QPoint(-30,-15)<<QPoint(-30,15)<<QPoint(0,30)<<QPoint(30,15); QGraphicsPolygonItem *item = new QGraphicsPolygonItem(QPolygonF(v)); item->setBrush(QColor(qrand()%256,qrand()%256,qrand()%256)); item->setFlag(QGraphicsItem::ItemIsMovable); scene->addItem(item); item->setPos((qrand()%int(scene->sceneRect().width()))-200,(qrand()%int(scene->sceneRect().height()))-200); }
void PlayerIndicator::unhighlight(){ if(highlightedPlayer == -1 || highlightedPlayer >= (int)playerList.size()){ return; } Player* targetPlayer = playerList.at(highlightedPlayer); QGraphicsPolygonItem* polyItem = playerTriangles.at(highlightedPlayer); polyItem->setScale(1); QBrush brush(QColor(targetPlayer->playerColorSet->getFillColor())); polyItem->setBrush(brush); highlightedPlayer = -1; }
void rce::gui::RImageMarkerScene:: setAllPolygonsVisible(bool value) { for(auto it = polygonItems_.begin(); it != polygonItems_.end(); ++it) { QGraphicsPolygonItem *item = it.value(); item->setVisible(value); } }
QGraphicsPolygonItem * KiviatView::addMarker(float position) { QPolygonF polygon; for(int i=0; i<axisCount; i++) polygon << calcPosition(i,position); QGraphicsPolygonItem * polyItem = scene.addPolygon(polygon); polyItem->setZValue(0); return polyItem; }
void Editor::onMapReady() { myUi->graphicsView->scene()->setSceneRect(0, 0, myGame->generator()->width(), myGame->generator()->height()); for (unsigned int i = 0; i < myGame->generator()->regions().size(); i++) { QPolygonF qring, sqring; auto ring = boost::geometry::exterior_ring(myGame->generator()->regions()[i].poly); boost::geometry::convert(ring, qring); boost::geometry::simplify(qring, sqring, 1); QPen pen; pen.setColor(QColor(0,0,0)); pen.setStyle(Qt::PenStyle::DashLine); QBrush brush; brush.setStyle(Qt::BrushStyle::SolidPattern); std::string colour = myGame->biomes()[myGame->generator()->regions()[i].biome]->jsonValue["mapColour"].asString(); pen.setColor(QColor(colour.c_str())); brush.setColor(QColor(colour.c_str())); QGraphicsPolygonItem * pi = new RegionPolygonItem(this); pi->setPen(pen); pi->setBrush(brush); pi->setPolygon(sqring); QPolygonF convex; boost::geometry::convex_hull(sqring, convex); double area = boost::geometry::area(convex); pi->setZValue(-area); pi->setData(0, i); pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsFocusable, true); pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsSelectable, true); myUi->graphicsView->scene()->addItem(pi); } }
void rce::gui::RImageMarkerScene:: setPolygonBrushAndPen(quint32 id, const QBrush &brush, const QPen &pen) { auto it = polygonItems_.find(id); if(it != polygonItems_.end()) { QGraphicsPolygonItem *polygonItem = it.value(); polygonItem->setBrush(brush); polygonItem->setPen(pen); } }
void PlayerIndicator::highlightPlayer(Player* targetPlayer){ int highlightNext = findPlayer(targetPlayer); if(highlightNext != -1){ if(highlightedPlayer == highlightNext){ return; } unhighlight(); QGraphicsPolygonItem* polyItem = playerTriangles.at(highlightNext); polyItem->setScale(SCALE); QBrush brush(QColor(targetPlayer->playerColorSet->getHighlightColor())); polyItem->setBrush(brush); highlightedPlayer = highlightNext; } }
QGraphicsItem* CGraphicsTriangleItem::createItem() { QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent); drawPen(pItem); drawBrush(pItem); QPolygonF d; d.append(QPointF(-GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2)); d.append(QPointF(GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2)); d.append(QPointF(0,-GET_VALUE(h).toDouble()/2)); pItem->setPolygon(d); return pItem; }
QGraphicsItem *Sector::render(double radius, double arcWidth) const { QPen pen; QBrush brush; ColorToBrushAndPen(color, pen, brush); QPolygonF polygon = createPolygonArc(radius, arcWidth, startAngle, endAngle); QGraphicsPolygonItem *polygonItem = new QGraphicsPolygonItem(polygon); polygonItem->setFillRule(Qt::OddEvenFill); polygonItem->setPen(pen); polygonItem->setBrush(brush); return polygonItem; }
QPolygonF rce::gui::RImageMarkerScene:: getPolygonShape(quint32 id) { auto it = polygonItems_.find(id); if(it != polygonItems_.end()) { QGraphicsPolygonItem *item = it.value(); QPolygonF polygon = item->polygon(); openPolygon(polygon); return polygon; } else { return QPolygonF(); } }
void VisualizationWorkstationExtensionPlugin::addSegmentationsToViewer() { if (_lst) { std::vector<std::shared_ptr<Annotation> > tmp = _lst->getAnnotations(); float scl = _viewer->getSceneScale(); for (std::vector<std::shared_ptr<Annotation> >::iterator it = tmp.begin(); it != tmp.end(); ++it) { QPolygonF poly; std::vector<Point> coords = (*it)->getCoordinates(); for (std::vector<Point>::iterator pt = coords.begin(); pt != coords.end(); ++pt) { poly.append(QPointF(pt->getX()*scl, pt->getY()*scl)); } QGraphicsPolygonItem* cur = new QGraphicsPolygonItem(poly); cur->setBrush(QBrush()); cur->setPen(QPen(QBrush(QColor("red")), 1.)); _viewer->scene()->addItem(cur); cur->setZValue(std::numeric_limits<float>::max()); _polygons.append(cur); } } }
void NodeBackDropPrivate::setColorInternal(const QColor& color) { _publicInterface->setBrush(color); if (isSelected) { float r,g,b; appPTR->getCurrentSettings()->getDefaultSelectedNodeColor(&r, &g, &b); QColor selCol; selCol.setRgbF(r, g, b); header->setBrush(selCol); resizeHandle->setBrush(selCol); } else { QColor brightenColor; brightenColor.setRgbF(Natron::clamp(color.redF() * 1.2), Natron::clamp(color.greenF() * 1.2), Natron::clamp(color.blueF() * 1.2)); header->setBrush(brightenColor); resizeHandle->setBrush(brightenColor); } }
QGraphicsItem* CGraphicsPolygonItem::createItem() { QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent); drawPen(pItem); drawBrush(pItem); QPolygonF d; QStringList lstPath = GET_VALUE(d).split(' '); int iCount = lstPath.size(); for (int j = 0; j < iCount; j++) { QStringList lstPoint = lstPath[j].split(','); d.append(QPointF(lstPoint[0].toDouble(), lstPoint[1].toDouble())); lstPoint.clear(); } pItem->setPolygon(d); return pItem; }
void Dialog::setMap(QPolygonF *poly) { QPen pen(Qt::green); pen.setWidth(0); QGraphicsPolygonItem* item = new QGraphicsPolygonItem(*poly); item->setPen(pen); item->setBrush(QBrush(Qt::darkGreen)); //, Qt::BDiagPattern) item->setZValue(-1); QMatrix m; m.scale(1, -1); // m.translate(60, -90); item->setMatrix(m); // QRectF bounds = item->sceneBoundingRect(); QRectF bounds = item->boundingRect(); // qDebug() << "Bounds: " << bounds; // qDebug() << "Bounds center: " << bounds.center(); qreal viewHeight = myView->viewport()->rect().height(); qreal sceneHeight = bounds.height(); qreal ratio = 460 / sceneHeight; //FIXME: Get actual height instead // qDebug() << "View/Scene ratio: " << ratio << " hv:" << viewHeight << " hs: " << sceneHeight; myView->setProperty("scale", ratio / 1.5); myView->centerItems(bounds.center()); myView->setSceneRect(QRect(0, 0, 1, 1)); //To synchronize model and view center myView->addMap(poly); // myView->addItem(item); // polyItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); //Boost? }
void rce::gui::RImageMarkerScene:: editPolygon(quint32 id) { auto it = polygonItems_.find(id); if(it != polygonItems_.end()) { finishCurrentMode(); mode_ = DrawPolygonMode; QGraphicsPolygonItem *polygonItem = it.value(); drawnItem_ = polygonItem; QPolygonF polygon = polygonItem->polygon(); openPolygon(polygon); drawnPolyobject_ = polygon; drawnItemID_ = id; addManipulationHandles(); } }
void rce::gui::RImageMarkerScene:: addPolygonObject(const QPolygonF &polygon, const QBrush &brush, const QPen &pen, quint32 id) { // remove old if exists deletePolygon(id); // create new QPolygonF closedPolygon = polygon; closePolygon(closedPolygon); QGraphicsPolygonItem *newItem = addPolygon(closedPolygon, pen, brush); newItem->setData(RCE_ITEM_TYPE_DATA_INDEX, PolygonType); newItem->setData(RCE_ITEM_ID_DATA_INDEX, id); newItem->setZValue(1); polygonItems_[id] = newItem; }
void KMapScene::updateObstacles() { QGraphicsPolygonItem *cell; QVector<QPoint> curve1(0); int colorValue = 0, cellNum = 0; int r, s; QPen penForBlackLine (Qt::black); penForBlackLine.setWidth (2); for (r = 0; r < cellsOfRadius; r++) { for (s = 0; s < cellsOfRing; s++) { int sPlusOne = s==cellsOfRing-1 ? 0 : s+1; QPoint x0 ( gridImgH[r][s], gridImgV[r][s]); QPoint x1 ( gridImgH[r+1][s], gridImgV[r+1][s]); QPoint x2 ( gridImgH[r+1][sPlusOne], gridImgV[r+1][sPlusOne]); QPoint x3 ( gridImgH[r][sPlusOne], gridImgV[r][sPlusOne]); curve1.clear(); curve1.append (x0); curve1.append (x1); curve1.append (x2); curve1.append (x3); cell = cellsList.at (cellNum); cell->setPolygon (QPolygon (curve1) ); cell->setPen(penForBlackLine); if(!smallMap){ colorValue = ColorMax - PolarGrid[r][s] * ColorMax; cell->setBrush (QColor (colorValue, colorValue, colorValue) ); }else{ colorValue = ColorMax - PolarGrid[r][s] * ColorMax; cell->setBrush (QColor (0, 0, colorValue) ); } cellNum++; } } cout << smallMap << endl; }
void KMapScene::updateObstacles (bool initialization) { QGraphicsPolygonItem *cell; QVector<QPoint> curve1 (0); int colorValue = 0, cellNum = 0; int r, s; for (r = 0; r < TotalRings ; r++) { for (s = 0; s < N; s++) { QPoint x0 ( gridImgH[r][s], gridImgV[r][s]); QPoint x1 ( gridImgH[ (r+1) ][s], gridImgV[ (r+1) ][s]); QPoint x2 ( gridImgH[ (r+1) ][wrapTo (s+1, N) ], gridImgV[ (r+1) ][wrapTo (s+1, N) ]); QPoint x3 ( gridImgH[r][wrapTo (s+1, N) ], gridImgV[r][wrapTo (s+1, N) ]); curve1.clear(); curve1.append (x0); curve1.append (x1); curve1.append (x2); curve1.append (x3); colorValue = ColorMax - PolarGrid[present][r][s] * ColorMax; if (initialization) { cell = staticCellsList.at (cellNum); } else { cell = cellsList.at (cellNum); } cell->setPolygon (QPolygon (curve1) ); if (r == InnerRing ) { cell->setBrush (QBrush (Qt::white) ); } else { cell->setBrush (QColor (colorValue, colorValue, colorValue) ); } cellNum++; } } }
// draw an arrowhead QGraphicsPolygonItem* GAction::makeArrowHead(const GVEdge& e, const QColor& color) { // arrow pointing to the right QPointF p = e.path.pointAtPercent(1); QPointF* q = new QPointF(p.x() - 8, p.y() - 5); QPointF* r = new QPointF(p.x() - 8, p.y() + 5); QPolygonF polygon; polygon.push_back(p); polygon.push_back(*q); polygon.push_back(*r); // rotate arrow QMatrix matrix; matrix.translate(p.x(), p.y()); matrix.rotate(-e.path.angleAtPercent(1)); matrix.translate(-p.x(), -p.y()); polygon = matrix.map(polygon); // turn into QGraphicsPolygonItem QGraphicsPolygonItem* res = new QGraphicsPolygonItem (polygon, display); res->setPen(QPen(color)); res->setBrush(QBrush(color)); return res; }
void Main::addPolygon() { const int size = int(canvas.width()/2); Q3PointArray pa(6); pa[0] = QPoint(0,0); pa[1] = QPoint(size,size/5); pa[2] = QPoint(size*4/5,size); pa[3] = QPoint(size/6,size*5/4); pa[4] = QPoint(size*3/4,size*3/4); pa[5] = QPoint(size*3/4,size/4); QGraphicsPolygonItem* i = canvas.addPolygon(pa); i->setFlag(QGraphicsItem::ItemIsMovable); i->setPen(Qt::NoPen); i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) ); i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height())); i->setZValue(qrand()%256); }
void TransformableGraphicsGuide::update() { if (isVisible()) { FigureEditor::EditMode mode = editor->mode(); bool scaleMode( mode == FigureEditor::Scale ); topRightRect.setVisible(scaleMode); topLeftRect.setVisible(scaleMode); bottomRightRect.setVisible(scaleMode); bottomLeftRect.setVisible(scaleMode); if (scaleMode) { QPointF cen; QPolygonF poly; if (editor->hasSelection()) { QGraphicsPolygonItem* item = editor->selection(); if (item == 0) return; cen = mapFromScene(editor->selectionTransformPos()); poly = mapFromScene(item->polygon()); } else { QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(parentItem()); cen = editor->triangleTransformPos(); poly = item->polygon(); } QRectF f( poly.boundingRect() ); qreal xmax = qMax(qAbs(f.left() - cen.x()), qAbs(f.right() - cen.x())); qreal ymax = qMax(qAbs(f.top() - cen.y()), qAbs(f.bottom() - cen.y())); QPointF pmax(xmax, ymax); QRectF r(pmax, -pmax); r.moveCenter(cen); outerRect = r; QRectF l = parentItem()->mapRectFromScene(QRectF(QPointF(0.0, 0.0), QSizeF(10, 10))); QPen pen( editor->guideColor() ); l.moveBottomLeft(r.topRight()); topRightRect.setPen(pen); topRightRect.setRect(l); l.moveBottomRight(r.topLeft()); topLeftRect.setPen(pen); topLeftRect.setRect(l); l.moveTopLeft(r.bottomRight()); bottomRightRect.setPen(pen); bottomRightRect.setRect(l); l.moveTopRight(r.bottomLeft()); bottomLeftRect.setPen(pen); bottomLeftRect.setRect(l); } else if (mode == FigureEditor::Rotate) { QGraphicsPolygonItem* item; QPointF cen; QPolygonF poly; if (editor->hasSelection()) { item = editor->selection(); if (item == 0) return; cen = mapFromScene(editor->selectionTransformPos()); poly = mapFromScene(item->polygon()); } else { item = dynamic_cast<QGraphicsPolygonItem*>(parentItem()); poly = item->polygon(); cen = editor->triangleTransformPos(); } qreal rmax = 0.0; foreach (QPointF p, poly) { QLineF l(p, cen); qreal len(l.length()); if (len > rmax) rmax = len; } qreal height = rmax * 2.0; outerRect = QRectF(cen.x() - rmax, cen.y() - rmax, height, height); }
void MatrixElement::reconfigure(timeT time, timeT duration, int pitch, int velocity) { const RulerScale *scale = m_scene->getRulerScale(); int resolution = m_scene->getYResolution(); double x0 = scale->getXForTime(time); double x1 = scale->getXForTime(time + duration); m_width = x1 - x0; m_velocity = velocity; // if the note has TIED_FORWARD or TIED_BACK properties, draw it with a // different fill pattern bool tiedNote = (event()->has(BaseProperties::TIED_FORWARD) || event()->has(BaseProperties::TIED_BACKWARD)); Qt::BrushStyle brushPattern = (tiedNote ? Qt::Dense2Pattern : Qt::SolidPattern); QColor colour; if (event()->has(BaseProperties::TRIGGER_SEGMENT_ID)) { //!!! Using gray for trigger events and events from other, non-active // segments won't work. This should be handled some other way, with a // color outside the range of possible velocity choices, which probably // leaves some kind of curious light blue or something colour = Qt::cyan; } else { colour = DefaultVelocityColour::getInstance()->getColour(velocity); } colour.setAlpha(160); double fres(resolution); if (m_drum) { fres = resolution + 1; QGraphicsPolygonItem *item = dynamic_cast<QGraphicsPolygonItem *>(m_item); if (!item) { delete m_item; item = new QGraphicsPolygonItem; m_item = item; m_scene->addItem(m_item); } QPolygonF polygon; polygon << QPointF(0, 0) << QPointF(fres/2, fres/2) << QPointF(0, fres) << QPointF(-fres/2, fres/2) << QPointF(0, 0); item->setPolygon(polygon); item->setPen (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0)); item->setBrush(QBrush(colour, brushPattern)); } else { QGraphicsRectItem *item = dynamic_cast<QGraphicsRectItem *>(m_item); if (!item) { delete m_item; item = new QGraphicsRectItem; m_item = item; m_scene->addItem(m_item); } float width = m_width; if (width < 1) width = 1; QRectF rect(0, 0, width, fres + 1); item->setRect(rect); item->setPen (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0)); item->setBrush(QBrush(colour, brushPattern)); } setLayoutX(x0); m_item->setData(MatrixElementData, QVariant::fromValue((void *)this)); // set the Y position taking m_pitchOffset into account, subtracting the // opposite of whatever the originating segment transpose was // std::cout << "TRANSPOSITION TEST: event pitch: " // << (pitch ) << " m_pitchOffset: " << m_pitchOffset // << std::endl; m_item->setPos(x0, (127 - pitch - m_pitchOffset) * (resolution + 1)); // set a tooltip explaining why this event is drawn in a different pattern if (tiedNote) m_item->setToolTip(QObject::tr("This event is tied to another event.")); }
void repere::Teste() { QPolygonF box1; box1 << QPointF(50,50)<< QPointF(80,50)<< QPointF(80,60)<< QPointF(70,60)<< QPointF(70,70)<< QPointF(50,70); QGraphicsPolygonItem *P; P=Scene->addPolygon(box1,QPen(Qt::darkGray),QBrush(Qt::darkGray)); QPolygonF box2; box2 << QPointF(20,20)<< QPointF(51,20)<< QPointF(51,51)<< QPointF(20,51); QGraphicsPolygonItem *P2; P2=Scene->addPolygon(box2,QPen(Qt::red),QBrush(Qt::red)); //P->collidingItems() qDebug()<< P->collidesWithItem(P2); QPainterPath s,s2,s3; s= P->shape(); s2=P2->shape(); //Scene->addPath(s,QPen(Qt::magenta),QBrush(Qt::yellow)); Scene->addText("o")->setPos(85,85); QGraphicsLineItem *l; l=Scene->addLine(90,65,70,65,QPen(Qt::red)); s2=l->shape(); qDebug()<< "intersects: "<<s.intersects(s2); //qDebug()<< "intersected: "<<s.intersected(s2); s3=s.intersected(s2); Scene->addLine(50,65,50,65,QPen(Qt::green)); Scene->addLine(70,65,70,65,QPen(Qt::green)); qDebug()<< "intersected2:"<<P->shape().intersected(l->shape()).elementAt(1)<<s3.elementAt(1); qDebug()<< "intersected a:"<<P->shape().intersected(l->shape()); qDebug()<< "intersected b:"<<l->shape().intersected(P->shape()); vector<QGraphicsPolygonItem*> obstaculos; obstaculos.push_back(P); obstaculos.push_back(P2); /* QImage *image = new QImage(QSize(400,400),QImage::Format_ARGB32); image->fill(QColor(Qt::white).rgb()); QPainter *pngPainter = new QPainter(image); pngPainter->setRenderHint(QPainter::Antialiasing); Scene->render(pngPainter); pngPainter->end(); image->setText(); //image->save(nom+".png","PNG",100); */ }
void FormView::showSetting(Setting setting) { QGraphicsScene *s = scene(); s->clear(); resetTransform(); int scale_fac = 10; int spacing = 20; int planeWidth = setting.get_problem()->get_plane_width()*scale_fac; int planeHeight = setting.get_problem()->get_plane_height()*scale_fac; QRectF bound; for (int i=0; i<setting.get_number_of_planes(); ++i) { int x_offset = i*(planeWidth+spacing)+(spacing/2); int y_offset = (spacing/2); QRectF plane(x_offset,y_offset,planeWidth, planeHeight); s->addRect(plane,QPen(), QBrush(QColor(188, 198, 204),Qt::SolidPattern)); for (int j=0; j<setting.get_plane_at(i)->get_number_of_forms(); ++j) { QPolygonF polygon; Form form; setting.get_plane_at(i)->get_form_at(j, form); vector<Point> points_of_current_form = *(form.get_points()); for (int k=0; k<points_of_current_form.size(); ++k){ Point point = points_of_current_form[k]; polygon.push_back(QPointF(point.get_x()*scale_fac, point.get_y()*scale_fac)); } QGraphicsPolygonItem * polyitem = s->addPolygon(polygon, QPen(QColor(Qt::red)), QBrush(Qt::SolidPattern)); polyitem->setPos(x_offset, y_offset); bound = polygon.boundingRect(); } } float realwidth = container->width() - 50; float width = setting.get_number_of_planes()*(planeWidth+spacing); float realheight = container->height() - 50; float height = planeHeight+spacing; s->setSceneRect(0,0,width,height); float relw = 1; if(width > 0){ relw = realwidth / width; } float relh = 1; if(height > 0){ relh = realheight / height; } float rel = relw; if(relh < relw){ rel = relh; } scale(rel,rel); }
void cbSimulator::showGraph(int id) { unsigned int w,c; QGraphicsPolygonItem *wallCanvas; QGraphicsRectItem *grCanvas; if(id<1 || id > (int)robots.size()) { cerr << "Cannot show graph of robot " << id << "\n"; return; } labCanvasWidth=(int)(lab->Width()*30); labCanvasHeight=(int)(lab->Height()*30); labScene=new QGraphicsScene(0, 0, labCanvasWidth,labCanvasHeight); labView=new cbGraphView(labScene,this); labView->viewport()->setMouseTracking(true); QPolygon *pa; for(w=1; w<lab->nWalls();w++) { vector<cbPoint> &corners=lab->Wall(w)->Corners(); //pa.resize(corners.size()); pa = new QPolygon(corners.size()); for(c=0; c<corners.size();c++) pa->setPoint(c,(int)(corners[c].X()*labCanvasWidth/lab->Width()), (int)(labCanvasHeight-corners[c].Y()*labCanvasHeight/lab->Height()) ); wallCanvas = new QGraphicsPolygonItem(0, labScene); wallCanvas->setPolygon(*pa); wallCanvas->setBrush(QBrush(Qt::black)); wallCanvas->setVisible(true); } unsigned int x,y; double distMax=0.0; //grAux=graph; Tentativa de optimizacao for(x = 0; x < GRIDSIZE; x++) for(y = 0; y < GRIDSIZE; y++) { *grAux=*graph; //grAux->resetInitState(); Tentativa de optimizacao - testes indicam que fica muito mais lento!! //grAux->writeGraph(); cbPoint p((0.5+x)*lab->Width()/GRIDSIZE, (GRIDSIZE-0.5-y)*lab->Height()/GRIDSIZE); grAux->addFinalPoint(id,p); distGrid[x][y]=grAux->dist(id); if(distGrid[x][y] < 2000 && distGrid[x][y]>distMax) distMax=distGrid[x][y]; } // fprintf(stderr,"distmax=%f labCanvasWidth=%d labCanvasHeight=%d\n", // distMax,labCanvasWidth,labCanvasHeight); for(x = 0; x < GRIDSIZE; x++) for(y = 0; y < GRIDSIZE; y++) { if(distGrid[x][y]<2000) { grCanvas = new QGraphicsRectItem(x*labCanvasWidth/GRIDSIZE,y*labCanvasHeight/GRIDSIZE, (x+1)*labCanvasWidth/GRIDSIZE - x*labCanvasWidth/GRIDSIZE, (y+1)*labCanvasHeight/GRIDSIZE -y*labCanvasHeight/GRIDSIZE, 0, labScene); QColor color((int)(0+distGrid[x][y]/distMax*250), (int)(0+distGrid[x][y]/distMax*250), (int)(0+distGrid[x][y]/distMax*250)); grCanvas->setBrush(QBrush(color)); grCanvas->setPen(QPen(color)); grCanvas->setVisible(true); //debug //distGrid[x][y]=(int)(0+distGrid[x][y]/distMax*250); } } labScene->update(); }
void ProfileGraphicsView::plot_depth_profile() { int i, incr; int sec, depth; struct plot_data *entry; int maxtime, maxdepth, marker, maxline; int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 }; /* Get plot scaling limits */ maxtime = get_maxtime(&gc.pi); maxdepth = get_maxdepth(&gc.pi); gc.maxtime = maxtime; /* Time markers: at most every 10 seconds, but no more than 12 markers. * We start out with 10 seconds and increment up to 30 minutes, * depending on the dive time. * This allows for 6h dives - enough (I hope) for even the craziest * divers - but just in case, for those 8h depth-record-breaking dives, * we double the interval if this still doesn't get us to 12 or fewer * time markers */ i = 0; while (maxtime / increments[i] > 12 && i < 7) i++; incr = increments[i]; while (maxtime / incr > 12) incr *= 2; gc.leftx = 0; gc.rightx = maxtime; gc.topy = 0; gc.bottomy = 1.0; last_gc = gc; QColor c = getColor(TIME_GRID); for (i = incr; i < maxtime; i += incr) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(i, 0), SCALEGC(i, 1)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } timeMarkers = new QGraphicsRectItem(); /* now the text on the time markers */ struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN}; if (maxtime < 600) { /* Be a bit more verbose with shorter dives */ for (i = incr; i < maxtime; i += incr) plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60, 2, 10, QChar('0')), timeMarkers); } else { /* Only render the time on every second marker for normal dives */ for (i = incr; i < maxtime; i += 2 * incr) plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers); } timeMarkers->setPos(0,0); scene()->addItem(timeMarkers); /* Depth markers: every 30 ft or 10 m*/ gc.leftx = 0; gc.rightx = 1.0; gc.topy = 0; gc.bottomy = maxdepth; switch (prefs.units.length) { case units::METERS: marker = 10000; break; case units::FEET: marker = 9144; break; /* 30 ft */ } maxline = qMax(gc.pi.maxdepth + marker, maxdepth * 2 / 3); c = getColor(DEPTH_GRID); for (i = marker; i < maxline; i += marker) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, i), SCALEGC(1, i)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } gc.leftx = 0; gc.rightx = maxtime; c = getColor(MEAN_DEPTH); /* Show mean depth */ if (! gc.printer) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, gc.pi.meandepth), SCALEGC(gc.pi.entry[gc.pi.nr - 1].sec, gc.pi.meandepth)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } #if 0 /* * These are good for debugging text placement etc, * but not for actual display.. */ if (0) { plot_smoothed_profile(gc, pi); plot_minmax_profile(gc, pi); } #endif /* Do the depth profile for the neat fill */ gc.topy = 0; gc.bottomy = maxdepth; entry = gc.pi.entry; QPolygonF p; QLinearGradient pat(0.0,0.0,0.0,scene()->height()); QGraphicsPolygonItem *neatFill = NULL; p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) p.append(QPointF(SCALEGC(entry->sec, entry->depth))); /* Show any ceiling we may have encountered */ if (prefs.profile_dc_ceiling) { for (i = gc.pi.nr - 1; i >= 0; i--, entry--) { if (!entry->in_deco) { /* not in deco implies this is a safety stop, no ceiling */ p.append(QPointF(SCALEGC(entry->sec, 0))); } else if (entry->stopdepth < entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } } pat.setColorAt(1, getColor(DEPTH_BOTTOM)); pat.setColorAt(0, getColor(DEPTH_TOP)); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setBrush(QBrush(pat)); neatFill->setPen(QPen(QBrush(Qt::transparent),0)); scene()->addItem(neatFill); /* if the user wants the deco ceiling more visible, do that here (this * basically draws over the background that we had allowed to shine * through so far) */ if (prefs.profile_dc_ceiling && prefs.profile_red_ceiling) { p.clear(); pat.setColorAt(0, getColor(CEILING_SHALLOW)); pat.setColorAt(1, getColor(CEILING_DEEP)); entry = gc.pi.entry; p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if (entry->in_deco && entry->stopdepth) { if (entry->stopdepth < entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } else { p.append(QPointF(SCALEGC(entry->sec, 0))); } } neatFill = new QGraphicsPolygonItem(); neatFill->setBrush(QBrush(pat)); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); scene()->addItem(neatFill); } /* finally, plot the calculated ceiling over all this */ if (prefs.profile_calc_ceiling) { pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); pat.setColorAt(1, getColor(CALC_CEILING_DEEP)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if (entry->ceiling) p.append(QPointF(SCALEGC(entry->sec, entry->ceiling))); else p.append(QPointF(SCALEGC(entry->sec, 0))); } p.append(QPointF(SCALEGC((entry-1)->sec, 0))); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); neatFill->setBrush(pat); scene()->addItem(neatFill); } /* plot the calculated ceiling for all tissues */ if (prefs.profile_calc_ceiling && prefs.calc_all_tissues) { int k; for (k=0; k<16; k++) { pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); pat.setColorAt(1, QColor(100, 100, 100, 50)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if ((entry->ceilings)[k]) p.append(QPointF(SCALEGC(entry->sec, (entry->ceilings)[k]))); else p.append(QPointF(SCALEGC(entry->sec, 0))); } p.append(QPointF(SCALEGC((entry-1)->sec, 0))); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setBrush(pat); scene()->addItem(neatFill); } } /* next show where we have been bad and crossed the dc's ceiling */ if (prefs.profile_dc_ceiling) { pat.setColorAt(0, getColor(CEILING_SHALLOW)); pat.setColorAt(1, getColor(CEILING_DEEP)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) p.append(QPointF(SCALEGC(entry->sec, entry->depth))); for (i-- , entry--; i >= 0; i--, entry--) { if (entry->in_deco && entry->stopdepth > entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } } neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); neatFill->setBrush(QBrush(pat)); scene()->addItem(neatFill); /* Now do it again for the velocity colors */ entry = gc.pi.entry; for (i = 1; i < gc.pi.nr; i++) { entry++; sec = entry->sec; /* we want to draw the segments in different colors * representing the vertical velocity, so we need to * chop this into short segments */ depth = entry->depth; QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(entry[-1].sec, entry[-1].depth), SCALEGC(sec, depth)); QPen pen(defaultPen); pen.setColor(getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + entry->velocity))); item->setPen(pen); scene()->addItem(item); } }