void GLWidget::paintGL() { glClearColor(1.0, 1.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); switch (type) { case 0: drawPoints() ; break; case 1: drawLines(); break; case 2: drawLineStrip(); break; case 3: drawLineLoop(); break; case 4: drawTriangles(); break; case 5: drawTriangleStrip(); break; case 6: drawTriangleFan(); break; case 7: drawQuads(); break; case 8: drawQuadStrip(); break; case 9: drawPolygons(); break; default: break; } }
void drawPolygonsToMasks() { //imageWithMask = matImage.clone(); doorMask = cv::Mat::zeros(480, 640, CV_8UC3); exclusionMask = cv::Mat::zeros(480, 640, CV_8UC3); checkpointMaskSmall = cv::Mat::zeros(480, 640, CV_8UC3); checkpointMaskMedium = cv::Mat::zeros(480, 640, CV_8UC3); checkpointMaskLarge = cv::Mat::zeros(480, 640, CV_8UC3); drawCheckPointCircles(); drawPolygons("exclusionPolygons", exclusionPolygons, cv::Scalar(255,45,70)); drawPolygons("doorPolygons", doorPolygons, cv::Scalar(63,232,41)); //drawPolygon(polygon, cv::Scalar(255,218,56)); }
void BoardView::paintEvent(QPaintEvent *event) { const QRect& rectange = event->rect(); const float cellSize = calculateCellSize(rectange, m_height, m_width); const float tableWidth = cellSize * m_width; const float tableHeight = cellSize * m_height; QPixmap pixmap(QSize(tableWidth + 1, tableHeight + 1)); pixmap.fill(Qt::white); QPainter pixPainter(&pixmap); pixPainter.setRenderHint(QPainter::Antialiasing); pixPainter.setPen(QPen(Qt::black, 1)); for (int i = cellSize, k = m_width * cellSize; i < k; i += cellSize) pixPainter.drawLine(i, 0, i, pixmap.height()); for (int i = cellSize, k = m_height * cellSize; i < k; i += cellSize) pixPainter.drawLine(0, i, pixmap.width(), i); pixPainter.setPen(QPen(Qt::black, 3)); pixPainter.drawRect(0, 0, pixmap.width(), pixmap.height()); fillPolygon(pixPainter, cellSize); drawLastPoint(pixPainter, cellSize); drawPolygons(pixPainter, cellSize); drawUnderMousePoint(pixPainter, cellSize); QPainter painter(this); const int dx =(rectange.width() - tableWidth) / 2; const int dy =(rectange.height() - tableHeight) / 2; painter.drawPixmap(dx, dy, pixmap); }
void drawSerialRobot2D(const Vector<dim> &config, const SerialRobot &robot, cv::Mat &image, const Vector2i &offset, Vector3i colorPoint, int lineType = CV_AA) { Logging::trace("start drawing of SerialRobot2D", "Drawing2D"); if (robot.getBaseModel()) drawPolygons(image, robot.getBaseModel()->m_mesh, robot.getPose(), offset, colorPoint, lineType); auto linkModel = robot.getLinkModels(); auto AsLinks = robot.getLinkTrafos(config); for (size_t i = 0; i < AsLinks.size(); ++i) { drawPolygons(image, linkModel[i]->m_mesh, AsLinks[i], offset, colorPoint, lineType); cv::Point point(AsLinks[i].translation()[0] + offset[0], AsLinks[i].translation()[1] + offset[1]); cv::circle(image, point, 3, cv::Scalar(0, 0, 0), 3); } cv::Point point(robot.getPose().translation()[0] + offset[0], robot.getPose().translation()[1] + offset[1]); cv::circle(image, point, 6, cv::Scalar(0, 0, 0), 6); }
/*! * \brief Draw a triangle path with the passed triangles and posses in an image * \author Sascha Kaden * \param[in] vector of transformations * \param[in] vector of triangles * \param[in,out] image * \param[in] color of the triangle lines * \param[in] thickness of the lines * \date 2016-05-25 */ void drawTrianglePath(cv::Mat &image, const std::vector<Vector3> configs, const Mesh mesh, const Vector2i &offset, Vector3i colorPoint, int lineType) { if (configs.empty()) return; Logging::trace("start drawing of triangles", "Drawing2D"); for (auto &config : configs) { auto T = util::toTransform(util::Vecd(config[0], config[1], 0, 0, 0, config[2])); drawPolygons(image, mesh, T, offset, colorPoint, lineType); } }
/*! * \see drawBoundingBoxes(QPainter *aPainter, QPen *aPen) * \see drawPolygons(QPainter *aPainter, QPen *aPen) * * It contains drawing of the confirmed and not confirmed selections either. */ void ImageHolder::paintEvent(QPaintEvent *anEvent) { QLabel::paintEvent(anEvent); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); //painter.setRenderHint(QPainter::SmoothPixmapTransform); QPen pen; if (NoTool != tool_) { pen.setWidth(1); pen.setColor(QColor(Qt::black)); pen.setStyle(Qt::DashLine); painter.setPen(pen); if (BoundingBoxTool == tool_) { /* scaling */ QRect bbox = bounding_box_.rect; QPoint bboxTopLeft = bbox.topLeft() * scale_; QPoint bboxBottomRight = bbox.bottomRight() * scale_; bbox.setTopLeft(bboxTopLeft); bbox.setBottomRight(bboxBottomRight); painter.drawRect(bbox); } else if (PolygonTool == tool_) { /* scaling */ QPoint point; QPolygon poly = polygon_.poly; for (int i = 0; i < poly.size(); i++) { point.setX(poly.at(i).x()); point.setY(poly.at(i).y()); point *= scale_; poly.remove(i); poly.insert(i, point); } painter.drawPolygon(poly); } } /* drawing bounding boxes */ drawBoundingBoxes(&painter, &pen); drawPolygons(&painter, &pen); }
void drawObject( tmatrix mo, short obj) { short i, pf; for( i=0; i< olist[ obj].n; i++) { pf = olist[ obj].f+i; setColor( flist[ pf].color); drawPolygons( flist[ pf].p); } // // the last poly drawn is the key face // // vertexes are still in the stack // // circle them in red if the object is in focus // if (( obj == c[qx][qy][2]) && cursor) // { // setColor( 13); // gLine( vlist[1].x, vlist[1].y, vlist[2].x, vlist[2].y); // gLine( vlist[2].x, vlist[2].y, vlist[3].x, vlist[3].y); // gLine( vlist[3].x, vlist[3].y, vlist[4].x, vlist[4].y); // gLine( vlist[4].x, vlist[4].y, vlist[1].x, vlist[1].y); // gLine( vlist[1].x, vlist[1].y, vlist[3].x, vlist[3].y); // gLine( vlist[2].x, vlist[2].y, vlist[4].x, vlist[4].y); // } }// drawObject
void Storage::paintEvent(QPaintEvent *anEvent) { QLabel::paintEvent(anEvent); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); //painter.setRenderHint(QPainter::SmoothPixmapTransform); QPen pen; if (NoTool != tool_) { pen.setWidth(5); pen.setColor(QColor(Qt::white)); pen.setStyle(Qt::DashLine); painter.setPen(pen); if (BoundingBoxTool == tool_) { /* с учётом масштаба */ QRect bbox = rect.getCoordinates(); QPoint bboxTopLeft = bbox.topLeft() * scale_; QPoint bboxBottomRight = bbox.bottomRight() * scale_; bbox.setTopLeft(bboxTopLeft); bbox.setBottomRight(bboxBottomRight); painter.drawRect(bbox); } else if (EllipseTool == tool_) { /* с учётом масштаба */ QRect elli = ell.getCoordinates().normalized(); QPoint ellTopLeft = elli.topLeft() * scale_; QPoint ellBottomRight = elli.bottomRight() * scale_; elli.setTopLeft(ellTopLeft); elli.setBottomRight(ellBottomRight); if(1 < elli.height() && 1 < elli.width() ) { painter.drawEllipse(elli); } // painter.drawRect(ell); } else if (ArrowTool == tool_) { /* с учётом масштаба */ QLineF line = arrow.getCoordinates(); QPointF p1 = line.p1() * scale_; QPointF p2 = line.p2() * scale_; line.setP1(p1); line.setP2(p2); if(1 < line.length()) { double angle = ::acos(line.dx() / line.length()); qreal Pi = atan(1)*4; if (line.dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line.p1() + QPointF(sin(angle + Pi / 3) * arrow_size_, cos(angle + Pi / 3) * arrow_size_); QPointF arrowP2 = line.p1() + QPointF(sin(angle + Pi - Pi / 3) * arrow_size_, cos(angle + Pi - Pi / 3) * arrow_size_); QPolygonF arrowTop; arrowTop.clear(); arrowTop << line.p1() << arrowP1 << arrowP2; painter.drawLine(line); painter.drawPolygon(arrowTop);///111 qDebug() << "arrowTop" << arrowTop; arrow_top_ = arrowTop; } } else if (PolygonTool == tool_) { /* с учётом масштаба */ QPoint point; QPolygon pol = poly.getCoordinates(); for (int i = 0; i < pol.size(); i++) { point.setX(pol.at(i).x()); point.setY(pol.at(i).y()); point *= scale_; pol.remove(i); pol.insert(i, point); } painter.drawPolygon(pol); } } /* рисуем фигуры */ drawBoundingBoxes(&painter, &pen); drawPolygons(&painter, &pen); drawEllipses(&painter, &pen); drawArrows(&painter, &pen); }
void show_3d_cube(void){ int16_t ys=0,xs=0; float tp[24]; int pp[16]; float camz = 2.0; int x,y,xx,yy,j,i=0; float cosT; float sinT; float cosP; float sinP; float cosTcosP; float cosTsinP; float sinTcosP; float sinTsinP; int scaleFactor = MAX_Y_3D/4; float near = 3; float nearToObj; float x0,y0,z0; float fac; int xo; int yo; float rotation[3] = { 0.0, 0.0, 0.0 }; float rot_speed[3] = { 0.04, -0.08, 0.033 }; while(1) { i++; for(j=0;j<MAX_X_3D*MAX_Y_3D;j++) frame[j]=0; // Checkerboard background xo = 25.0*sin(10*i/100.0)*cos(6*i/100.0); yo = 25.0*sin(5*i/100.0)*cos(7.5*i/100.0); for (x=0;x<MAX_Y_3D;x++) { xx = (50+x+xo)% 32; for (y=0;y<MAX_X_3D;++y) { yy = (50+y+yo)% 32; if ((xx<16 && yy<16) || (xx>16 && yy>16)) { frame[x*MAX_Y_3D+y]=WHITE; } } } cosT = cos(rotation[0]); sinT = sin(rotation[0]); cosP = cos(rotation[1]); sinP = sin(rotation[1]); cosTcosP = cosT*cosP; cosTsinP = cosT*sinP; sinTcosP = sinT*cosP; sinTsinP = sinT*sinP; nearToObj = 1.5 + 3.0*sin(5*i/100.0); for (j=0;j<nbPts;++j) { x0 = cube[3*j+0]; y0 = cube[3*j+1]; z0 = cube[3*j+2]; tp[3*j+0] = cosT*x0 + sinT*z0; tp[3*j+1] = -sinTsinP*x0 + cosP*y0 + cosTsinP*z0; tp[3*j+2] = camz + cosTcosP*z0 - sinTcosP*x0 - sinP*y0; fac = scaleFactor * near * 1.0f / (tp[3*j+2]+near+nearToObj); pp[2*j+0] = (int)(MAX_Y_3D/2.0f + fac*tp[3*j+0] + 0.5 ); pp[2*j+1] = (int)(MAX_Y_3D/2.0f + fac*tp[3*j+1] + 0.5 ); } drawPolygons( tp, pp ); S6B33BG_FillPixel(xs,ys,xs+MAX_X_3D-1,ys+MAX_Y_3D-1,frame); for (j=0;j<3;++j) rotation[j] += rot_speed[j]; DWT_Delay(ADCConvertedValue[1]*20); } }
void show_3d_cube(void){ ////////////////////////////////////////////////////////////////////////// // 3D CUBE ////////////////////////////////////////////////////////////////////////// // adapted code from: // https://github.com/majestik666/Beagle_GPIO/blob/master/Beagle_GPIO_Nokia6100_test_3d.cc int16_t ys=24,xs=8; float tp[24]; int pp[16]; float camz = 2.0; int x,y,xx,yy,j,i=0; float cosT; float sinT; float cosP; float sinP; float cosTcosP; float cosTsinP; float sinTcosP; float sinTsinP; int scaleFactor = MAX_Y_3D/4; float near = 3; float nearToObj; float x0,y0,z0; float fac; int xo; int yo; float rotation[3] = { 0.0, 0.0, 0.0 }; float rot_speed[3] = { 0.04, -0.08, 0.033 }; while(1) { i++; for(j=0;j<MAX_X_3D*MAX_Y_3D;j++) frame[j]=0; // Checkerboard background xo = 25.0*sin(10*i/100.0)*cos(6*i/100.0); yo = 25.0*sin(5*i/100.0)*cos(7.5*i/100.0); for (x=0;x<MAX_Y_3D;x++) { xx = (50+x+xo)% 32; for (y=0;y<MAX_X_3D;++y) { yy = (50+y+yo)% 32; if ((xx<16 && yy<16) || (xx>16 && yy>16)) { frame[x*MAX_Y_3D+y]=WHITE; } } } cosT = cos(rotation[0]); sinT = sin(rotation[0]); cosP = cos(rotation[1]); sinP = sin(rotation[1]); cosTcosP = cosT*cosP; cosTsinP = cosT*sinP; sinTcosP = sinT*cosP; sinTsinP = sinT*sinP; nearToObj = 1.5 + 3.0*sin(5*i/100.0); for (j=0;j<nbPts;++j) { x0 = cube[3*j+0]; y0 = cube[3*j+1]; z0 = cube[3*j+2]; tp[3*j+0] = cosT*x0 + sinT*z0; tp[3*j+1] = -sinTsinP*x0 + cosP*y0 + cosTsinP*z0; tp[3*j+2] = camz + cosTcosP*z0 - sinTcosP*x0 - sinP*y0; fac = scaleFactor * near * 1.0f / (tp[3*j+2]+near+nearToObj); pp[2*j+0] = (int)(MAX_Y_3D/2.0f + fac*tp[3*j+0] + 0.5 ); pp[2*j+1] = (int)(MAX_Y_3D/2.0f + fac*tp[3*j+1] + 0.5 ); } drawPolygons( tp, pp ); HD66773R_FillPixel(xs,ys,xs+MAX_X_3D-1,ys+MAX_Y_3D-1,frame); for (j=0;j<3;++j) rotation[j] += rot_speed[j]; } }