//---------------------------------------------------------------- // calcTextBBox // static void calcTextBBox(const Text & item, BBox & bbox, double maxWidth, double maxHeight) { QFont font = item.font_; double fontSize = item.fontSize_.get(); double supersample = item.supersample_.get(); font.setPointSizeF(fontSize * supersample); QFontMetricsF fm(font); QRectF maxRect(0.0, 0.0, maxWidth * supersample, maxHeight * supersample); int flags = item.textFlags(); QString text = getElidedText(maxWidth * supersample, item, fm, flags); QRectF rect = fm.boundingRect(maxRect, flags, text); bbox.x_ = rect.x() / supersample; bbox.y_ = rect.y() / supersample; bbox.w_ = rect.width() / supersample; bbox.h_ = rect.height() / supersample; }
void GFXGLDevice::setClipRect( const RectI &inRect ) { AssertFatal(mCurrentRT.isValid(), "GFXGLDevice::setClipRect - must have a render target set to do any rendering operations!"); // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); mClip = inRect; mClip.intersect(maxRect); // Create projection matrix. See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/ortho.html const F32 left = mClip.point.x; const F32 right = mClip.point.x + mClip.extent.x; const F32 bottom = mClip.extent.y; const F32 top = 0.0f; const F32 nearPlane = 0.0f; const F32 farPlane = 1.0f; const F32 tx = -(right + left)/(right - left); const F32 ty = -(top + bottom)/(top - bottom); const F32 tz = -(farPlane + nearPlane)/(farPlane - nearPlane); static Point4F pt; pt.set(2.0f / (right - left), 0.0f, 0.0f, 0.0f); mProjectionMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(top - bottom), 0.0f, 0.0f); mProjectionMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, -2.0f/(farPlane - nearPlane), 0.0f); mProjectionMatrix.setColumn(2, pt); pt.set(tx, ty, tz, 1.0f); mProjectionMatrix.setColumn(3, pt); // Translate projection matrix. static MatrixF translate(true); pt.set(0.0f, -mClip.point.y, 0.0f, 1.0f); translate.setColumn(3, pt); mProjectionMatrix *= translate; setMatrix(GFXMatrixProjection, mProjectionMatrix); MatrixF mTempMatrix(true); setViewMatrix( mTempMatrix ); setWorldMatrix( mTempMatrix ); // Set the viewport to the clip rect RectI viewport(mClip.point.x, mClip.point.y, mClip.extent.x, mClip.extent.y); setViewport(viewport); }
Rect FindContourAndGetMaxRect(Mat frame) { //add find contours Rect maxRect(0,0,1,1); int Max = 0,MaxIndex = 0; Mat temp = frame.clone(); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours( temp, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE); /// Draw contours vector<vector<Point> > hull( contours.size() ); for( int i = 0; i < contours.size(); i++ ) convexHull( Mat(contours[i]), hull[i], false ); Mat drawing = Mat::zeros( temp.size(), CV_8UC1 ); // double biggest_area = contourArea( hull[0],false); int most_important_area = 0; int max = 0; // cout <<"hull.size()" << hull.size() << endl; for( int i = 0; i < hull.size(); i++ ) { // approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); drawContours( drawing, hull, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy); // //find the biggest size // double contourarea = contourArea(contours[i],false); // if(biggest_area < contourarea){ // biggest_area = contourarea; // // cout << "biggest_area" << biggest_area << endl; // max = i; // } int temp_sum_pixels = SumAllPixelsInRect(frame, boundingRect(hull[i])); if(most_important_area < temp_sum_pixels) { most_important_area = temp_sum_pixels; max = i; } } if(hull.size() != 0){ maxRect = boundingRect(hull[max]); rectangle(drawing, maxRect.tl(), maxRect.br(), Scalar(255, 255, 255), 2); cout << "max rect " << maxRect << endl; } imshow("convex-hull",drawing); return maxRect; // return maxRect; }
void GFXD3D9Device::setClipRect( const RectI &inRect ) { // We transform the incoming rect by the view // matrix first, so that it can be used to pan // and scale the clip rect. // // This is currently used to take tiled screenshots. Point3F pos( inRect.point.x, inRect.point.y, 0.0f ); Point3F extent( inRect.extent.x, inRect.extent.y, 0.0f ); getViewMatrix().mulP( pos ); getViewMatrix().mulV( extent ); RectI rect( pos.x, pos.y, extent.x, extent.y ); // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); rect.intersect(maxRect); mClipRect = rect; F32 l = F32( mClipRect.point.x ); F32 r = F32( mClipRect.point.x + mClipRect.extent.x ); F32 b = F32( mClipRect.point.y + mClipRect.extent.y ); F32 t = F32( mClipRect.point.y ); // Set up projection matrix, static Point4F pt; pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f); mTempMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f); mTempMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, 1.0f, 0.0f); mTempMatrix.setColumn(2, pt); pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f); mTempMatrix.setColumn(3, pt); setProjectionMatrix( mTempMatrix ); // Set up world/view matrix mTempMatrix.identity(); setWorldMatrix( mTempMatrix ); setViewport( mClipRect ); }
int maximalRectangle(vector<vector<char>>& matrix) { int m=matrix.size(); if(m==0) return 0; int n=matrix.front().size(); int mmax=0; vector<int> heights(n,0); for(int i=0;i<m;++i) { for(int j=0;j<n;++j) { if(matrix[i][j]=='1') { heights[j]++; } else heights[j]=0; } mmax=max(mmax,maxRect(heights)); } return mmax; }
void GFXD3D9Device::setClipRect( const RectI &inRect ) { // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); RectI rect = inRect; rect.intersect(maxRect); mClipRect = rect; F32 l = F32( mClipRect.point.x ); F32 r = F32( mClipRect.point.x + mClipRect.extent.x ); F32 b = F32( mClipRect.point.y + mClipRect.extent.y ); F32 t = F32( mClipRect.point.y ); // Set up projection matrix, static Point4F pt; pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f); mTempMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f); mTempMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, 1.0f, 0.0f); mTempMatrix.setColumn(2, pt); pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f); mTempMatrix.setColumn(3, pt); setProjectionMatrix( mTempMatrix ); // Set up world/view matrix mTempMatrix.identity(); setViewMatrix( mTempMatrix ); setWorldMatrix( mTempMatrix ); setViewport( mClipRect ); }
Rect MotionDetection::FindContourAndGetMaxRect(Mat frame) { //add find contours Rect maxRect(0,0,1,1); int Max = 0,MaxIndex = 0; Mat temp = frame.clone(); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours( temp, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE); /// Draw contours vector<vector<Point> > hull( contours.size() ); for( int i = 0; i < contours.size(); i++ ) convexHull( Mat(contours[i]), hull[i], false ); Mat drawing = Mat::zeros( temp.size(), temp.type() ); // double smallest_area = contourArea( contours[0],false); for( int i = 0; i< contours.size(); i++ ) { // approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); //drawContours( drawing, contours, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy); drawContours( drawing, hull, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy); Rect rect = boundingRect(hull[i]); rectangle(drawing, rect.tl(), rect.br(), Scalar(255, 255, 255), 1); int tempInt = SumAllPixelsInRect(frame,rect); if(tempInt > Max){ Max = tempInt; MaxIndex = i; } } //imshow(WINDOW_CONTOUR, drawing); if(contours.size() != 0){ maxRect = boundingRect(hull[MaxIndex]); } return maxRect; // return maxRect; }
/** Draws the label */ int MLabelObject::draw(FLStylePainter *p) { // Draw the pixmap if (!paintFunction.isEmpty()) { FLDomNodeInterface *dni = 0; QSArgumentList l; l << QVariant(text); if (!domNodeData.isNull()) { dni = new FLDomNodeInterface(domNodeData); l << dni; } QSArgument v = aqApp->call(paintFunction, l, 0); QSArgument::Type tp = v.type(); if (tp != QSArgument::Invalid) { QPixmap pix; if (tp == QSArgument::VoidPointer) { QPixmap *vPix = static_cast<QPixmap *>(v.ptr()); if (vPix) pix = *vPix; } else if (tp == QSArgument::Variant) pix = v.variant().toPixmap(); if (!pix.isNull() && drawPixmap(p, &pix)) return (changeHeight ? height : 0); } } if (pixmap && pixmap->isNull()) { delete pixmap; pixmap = 0; } else if (pixmap && drawPixmap(p, pixmap)) return (changeHeight ? height : 0); if (text.isEmpty()) { drawBase(p); return 0; } #if defined(Q_OS_MACX) FLStylePainter *pt = new FLStylePainter; int retVal = 0; uint originalHeight = height; QFont fnt; int tf; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; int nw = width * 4; int nh = height * 4; QPixmap pm(nw, nh); pm.fill(backgroundColor); pt->painter()->begin(&pm); fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize * 4); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); pt->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, nw, nh, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(pt); pt->painter()->setPen(foregroundColor); if (!transparent) { pt->painter()->setBackgroundColor(backgroundColor); pt->painter()->setBackgroundMode(Qt::OpaqueMode); } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)nw / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } pt->painter()->drawText(0, 0, nw, nh, tf, text); pt->painter()->end(); delete pt; drawPixmap(p, &pm); height = originalHeight; return retVal; #else int retVal = 0; uint originalHeight = height; QFont fnt; int tf; Qt::BGMode oldBgMode; QColor oldBgColor; bool restoreBg = false; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); p->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, width, height, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(p); p->painter()->setPen(foregroundColor); if (!transparent) { restoreBg = true; oldBgMode = p->painter()->backgroundMode(); oldBgColor = p->painter()->backgroundColor(); p->painter()->setBackgroundColor(backgroundColor); p->painter()->setBackgroundMode(Qt::OpaqueMode); } if (!p->drawText(text, tf, this)) { bool restore = false; if (p->errCode() == FLStylePainter::IdNotFound) { p->painter()->save(QObject::name()); p->applyTransforms(); p->painter()->translate(xpos, ypos); restore = true; } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)width / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } p->painter()->drawText(0, 0, width, height, tf, text); if (restore) p->painter()->restore(); } if (restoreBg) { p->painter()->setBackgroundMode(oldBgMode); p->painter()->setBackgroundColor(oldBgColor); } height = originalHeight; return retVal; #endif }
void MapGraphicsView::setStatusMessage(QString msg) { if(msg.isEmpty()) { m_statusLabel->setPixmap(QPixmap()); m_statusLabel->hide(); return; } m_statusLabel->show(); if(Qt::mightBeRichText(msg)) { QTextDocument doc; doc.setHtml(msg); msg = doc.toPlainText(); } QImage tmp(1,1,QImage::Format_ARGB32_Premultiplied); QPainter tmpPainter(&tmp); QFont font("");//"", 20); tmpPainter.setFont(font); QRectF maxRect(0, 0, (qreal)width(), (qreal)height() * .25); QRectF boundingRect = tmpPainter.boundingRect(maxRect, Qt::TextWordWrap | Qt::AlignHCenter, msg); boundingRect.adjust(0, 0, tmpPainter.font().pointSizeF() * 3, tmpPainter.font().pointSizeF() * 1.25); QImage labelImage(boundingRect.size().toSize(), QImage::Format_ARGB32_Premultiplied); memset(labelImage.bits(), 0, labelImage.byteCount()); QPainter p(&labelImage); QColor bgColor(0, 127, 254, 180); #ifdef Q_OS_ANDROID bgColor = bgColor.lighter(300); #endif p.setPen(QPen(Qt::white, 2.5)); p.setBrush(bgColor); p.drawRoundedRect(labelImage.rect().adjusted(0,0,-1,-1), 3., 3.); QImage txtImage(boundingRect.size().toSize(), QImage::Format_ARGB32_Premultiplied); memset(txtImage.bits(), 0, txtImage.byteCount()); QPainter tp(&txtImage); tp.setPen(Qt::white); tp.setFont(font); tp.drawText(QRectF(QPointF(0,0), boundingRect.size()), Qt::TextWordWrap | Qt::AlignHCenter | Qt::AlignVCenter, msg); tp.end(); double ss = 8.; p.drawImage((int)-ss,(int)-ss, ImageUtils::addDropShadow(txtImage, ss)); p.end(); #ifdef Q_OS_ANDROID m_statusLabel->setPixmap(QPixmap::fromImage(labelImage)); #else m_statusLabel->setPixmap(QPixmap::fromImage(ImageUtils::addDropShadow(labelImage, ss))); #endif }