//-------------------------------------------------------------------------------- void GLWidget::paintGL() { glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Vector3F viewPoint = scene.camera.Eye() + scene.camera.Focus(); // Camera position glLoadIdentity(); gluLookAt(scene.camera.Eye().X, scene.camera.Eye().Y, scene.camera.Eye().Z, viewPoint.X, viewPoint.Y, viewPoint.Z, scene.camera.Up().X, scene.camera.Up().Y, scene.camera.Up().Z); drawModel(); // Turn off lights glDisable(GL_LIGHTING); if (boundingBoxVisible_) drawBoundingBoxes(); if (cameraRayVisible_) drawCameraRay(); }
/** * \brief Find the pointer of the mouse during a move and update the view to see the rectangle evolution in real time * \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS **/ void QImageLabel::mouseMoving(int x2, int y2) { int w = imagesForLabel[*displayedImg-1]->width(); int h = imagesForLabel[*displayedImg-1]->height(); //If we release the mouse out of the image if(x2<0) x2=0; if(x2>w) x2=w-1; if(y2<0) y2=0; if(y2>h) y2=h-1; x2 = int(x2*ratio); y2 = int(y2*ratio); drawBoundingBoxes(); BoundingBox *tmp = bbs->at(bbs->size()-1); int x1 = tmp->x1(), y1 = tmp->y1(), temp; if( x1 > x2 ) { temp = x2; x2 = x1; x1 = temp; } if( y1 > y2 ) { temp = y2; y2 = y1; y1 = temp; } //Draw red rectangles if( *displayMode == "rectangles" ) { QRgb edgeCol = qRgb(255, 165, 0); //Orange for(int i=x1; i<=x2; i++) { imagesForLabel[*displayedImg-1]->setPixel(i, y1, edgeCol); imagesForLabel[*displayedImg-1]->setPixel(i, y2, edgeCol); } for(int j=y1; j<=y2; j++) { imagesForLabel[*displayedImg-1]->setPixel(x1, j, edgeCol); imagesForLabel[*displayedImg-1]->setPixel(x2, j, edgeCol); } } else if( *displayMode == "result" ) { QRgb resultCol = qRgb(0, 0, 0); //Black for(int i=x1; i<=x2; i++) for(int j=y1; j<=y2; j++) imagesForLabel[*displayedImg-1]->setPixel(i, j, resultCol); } //Update de view QPixmap img = QPixmap::fromImage(*imagesForLabel[*displayedImg-1]); if( ratio != 1 ) this->setPixmap(img.scaled(imagesForLabel[*displayedImg-1]->width()/ratio, imagesForLabel[*displayedImg-1]->height()/ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation)); else this->setPixmap(img); }
/** * \brief QImageLabel constructor * \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS * \param *img : pointer on the image to display * \param &width : reference to the width of the displayed image (after ratio change) * \param &height : reference to the height of the displayed image (after ratio change) * \param &boundingBoxes : reference for the list of boundingBoxes already created (we keep them from an image to an other) * \param *parent : parent of the QImageLabel **/ QImageLabel::QImageLabel(QVector<QImage*> imagesForLab, int &width, int &height, QVector<BoundingBox*>* boundingBoxes, QString &modifM, QString &displayM, int &displayedI, QWidget * parent ) : QLabel(parent) { bbs = boundingBoxes; modifMode = &modifM; displayMode = &displayM; displayedImg = &displayedI; imagesForLabel = imagesForLab; mouseX = 0, mouseY = 0; width = imagesForLabel[*displayedImg-1]->width(); height = imagesForLabel[*displayedImg-1]->height(); QDesktopWidget desktop; QRect mainScreenSize = desktop.availableGeometry(desktop.primaryScreen()); float desktopHeight = mainScreenSize.height(); float desktopWidth = mainScreenSize.width(); //Calculate a perfect ratio for display if( height > (desktopHeight-100) || width > desktopWidth ) { float ratioheight = height/(desktopHeight-100); float ratiowidth = width/desktopWidth; ratio = std::max(ratioheight, ratiowidth); width /= ratio; height = height/ratio; } else ratio = 1.0; //For the mouseMoveEvent (draw rectangles in real time) setMouseTracking(false); refreshMoveEvent = true; if( ratio != 1 ) { timer = new QTimer(); timer->connect(timer, SIGNAL(timeout()), this, SLOT(slot_enableMouseMoveUpdate())); timer->start(20); rectNotEnded = false; timerAfk = new QTimer(); timer->start(20); timer->connect(timer, SIGNAL(timeout()), this, SLOT(slot_forceMoveUpdate())); } for(int nbI=0; nbI<imagesForLabel.size(); nbI++) *imagesForLabel[nbI] = imagesForLabel[nbI]->convertToFormat(QImage::Format_RGB32); for(int nbI=0; nbI<imagesForLabel.size(); nbI++) initImgs.append(*imagesForLabel[nbI]); drawBoundingBoxes(); }
/*! * \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); }
/** * \brief Add the second point of a bounding box when we release the clic * \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS **/ void QImageLabel::mouseRelease(int x, int y) { int w = imagesForLabel[*displayedImg-1]->width(); int h = imagesForLabel[*displayedImg-1]->height(); //If we release the mouse out of the image if(x<0) x=0; if(x>w) x=w-1; if(y<0) y=0; if(y>h) y=h-1; x = int(x*ratio); y = int(y*ratio); BoundingBox *tmp = bbs->at(bbs->size()-1); //The BoundingBox box will be define by the upper left corner and the bottom right corner if( tmp->x1() < x ) tmp->setX2(x); else { tmp->setX2(tmp->x1()); tmp->setX1(x); } if( tmp->y1() < y ) tmp->setY2(y); else { tmp->setY2(tmp->y1()); tmp->setY1(y); } drawBoundingBoxes(); emit signal_bbNumberChanged(); rectNotEnded = false; }
/** * \brief Remove a BoudingBox * \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS **/ void QImageLabel::deleteRect(int x, int y) { x = int(x*ratio); y = int(y*ratio); for(int nbRect=0; nbRect<bbs->size(); nbRect++) { if( bbs->at(nbRect)->x1() < x && bbs->at(nbRect)->x2() > x && bbs->at(nbRect)->y1() < y && bbs->at(nbRect)->y2() > y ) { BoundingBox* tmp = bbs->at(nbRect); if( *modifMode == "All" ) { if( (tmp->isForAll() && !tmp->notIn().contains(*displayedImg)) || (!tmp->isForAll() && tmp->imgNumber()==*displayedImg) ) { delete tmp; bbs->remove(nbRect); nbRect--; //We continue the loop cause the clic can affect more than one boundingbox } } else if( *modifMode == "ThisOne" ) { if( tmp->isForAll() && !tmp->notIn().contains(*displayedImg) ) tmp->addToNotIn(*displayedImg); else if( !tmp->isForAll() && tmp->imgNumber()==*displayedImg ) { delete tmp; bbs->remove(nbRect); nbRect--; } } } } drawBoundingBoxes(); emit signal_bbNumberChanged(); }
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); }