本文整理汇总了C++中Box2f::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Box2f::Add方法的具体用法?C++ Box2f::Add怎么用?C++ Box2f::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2f
的用法示例。
在下文中一共展示了Box2f::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: img
void QtOutline2Rasterizer::rasterize(RasterizedOutline2 &poly,
float scale,
int rast_i,
int rotationNum,
int cellSize)
{
float rotRad = M_PI*2.0f*float(rast_i) / float(rotationNum);
//get polygon's BB, rotated according to the input parameter
Box2f bb;
vector<Point2f> pointvec = poly.getPoints();
for(size_t i=0;i<pointvec.size();++i) {
Point2f pp=pointvec[i];
pp.Rotate(rotRad);
bb.Add(pp);
}
///CREATE ITS GRID. The grid has to be a multiple of CELLSIZE because this grid's cells have size CELLSIZE
//we'll make so that sizeX and sizeY are multiples of CELLSIZE:
//1) we round it to the next integer
//2) add the number which makes it a multiple of CELLSIZE (only if it's not multiple already)
int sizeX = (int)ceil(bb.DimX()*scale);
int sizeY = (int)ceil(bb.DimY()*scale);
if (sizeX % cellSize != 0) sizeX += (cellSize - ((int)ceil(bb.DimX()*scale) % cellSize));
if (sizeY % cellSize != 0) sizeY += (cellSize - ((int)ceil(bb.DimY()*scale) % cellSize));
//security measure: add a dummy column/row thus making the image bigger, and crop it afterwards
//(if it hasn't been filled with anything)
//this is due to the fact that if we have a rectangle which has bb 39.xxx wide, then it won't fit in a 40px wide QImage!! The right side will go outside of the image!! :/
sizeX+=cellSize;
sizeY+=cellSize;
QImage img(sizeX,sizeY,QImage::Format_RGB32);
QColor backgroundColor(Qt::transparent);
img.fill(backgroundColor);
///SETUP OF DRAWING PROCEDURE
QPainter painter;
painter.begin(&img);
QBrush br;
br.setStyle(Qt::SolidPattern);
QPen qp;
qp.setWidthF(0);
qp.setColor(Qt::yellow);
painter.setBrush(br);
painter.setPen(qp);
painter.resetTransform();
painter.translate(QPointF(-(bb.min.X()*scale) , -(bb.min.Y()*scale) ));
painter.rotate(math::ToDeg(rotRad));
painter.scale(scale,scale);
//create the polygon to print it
QVector<QPointF> points;
vector<Point2f> newpoints = poly.getPoints();
for (size_t i = 0; i < newpoints.size(); i++) {
points.push_back(QPointF(newpoints[i].X(), newpoints[i].Y()));
}
painter.drawPolygon(QPolygonF(points));
//CROPPING: it is enough to check for the (end - cellSize - 1)th row/col of pixels, if they're all black we can eliminate the last 8columns/rows of pixels
bool cropX = true;
bool cropY = true;
for (int j=0; j<img.height(); j++) {
const uchar* line = img.scanLine(j);
if (j == img.height() - (cellSize - 1) - 1 ) {
for (int x=0; x<img.width(); x++) {
if (((QRgb*)line)[x] != backgroundColor.rgb()) {
cropY = false;
break;
}
}
}
else {
if (((QRgb*)line)[img.width() - (cellSize - 1) - 1] != backgroundColor.rgb()) {
cropX = false;
break;
}
}
if (!cropY) break;
}
if (cropX || cropY) {
painter.end();
img = img.copy(0, 0, img.width() - cellSize * cropX, img.height() - cellSize * cropY);
painter.begin(&img);
painter.setBrush(br);
painter.setPen(qp);
}
//draw the poly for the second time, this time it is centered to the image
img.fill(backgroundColor);
painter.resetTransform();
painter.translate(QPointF(-(bb.min.X()*scale) + (img.width() - ceil(bb.DimX()*scale))/2.0, -(bb.min.Y()*scale) + (img.height() - ceil(bb.DimY()*scale))/2.0));
painter.rotate(math::ToDeg(rotRad));
//.........这里部分代码省略.........