本文整理汇总了C++中QRectF类的典型用法代码示例。如果您正苦于以下问题:C++ QRectF类的具体用法?C++ QRectF怎么用?C++ QRectF使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRectF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseMoveEvent
void BlurItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsRectItem::mouseMoveEvent(event);
const QPointF pos = event->scenePos();
QRectF r;
r.setTopLeft(m_point);
r.setBottomRight(event->scenePos());
if (r.width() < 0) {
r.setLeft(pos.x());
r.setRight(m_point.x());
}
if (r.height() < 0) {
r.setTop(pos.y());
r.setBottom(m_point.y());
}
r = r.intersected(m_item->scene()->sceneRect());
setRect(r);
setSelected(true);
m_item->setOffset(r.topLeft());
reload(m_pixmap);
}
示例2: render
void PDF::render(const QRectF& texCoords)
{
if (!pdfPage_)
return;
// get on-screen and full rectangle corresponding to the window
const QRectF screenRect = GLWindow::getProjectedPixelRect(true);
const QRectF fullRect = GLWindow::getProjectedPixelRect(false);
// if we're not visible or we don't have a valid SVG, we're done...
if(screenRect.isEmpty())
{
// TODO clear existing FBO for this OpenGL window
return;
}
// generate texture corresponding to the visible part of these texture coordinates
generateTexture(screenRect, fullRect, texCoords);
if(!texture_.isValid())
return;
// figure out what visible region is for screenRect, a subregion of [0, 0, 1, 1]
const float xp = (screenRect.x() - fullRect.x()) / fullRect.width();
const float yp = (screenRect.y() - fullRect.y()) / fullRect.height();
const float wp = screenRect.width() / fullRect.width();
const float hp = screenRect.height() / fullRect.height();
// Render the entire texture on a (scaled) unit textured quad
glPushMatrix();
glTranslatef(xp, yp, 0);
glScalef(wp, hp, 1.f);
drawUnitTexturedQuad();
glPopMatrix();
}
示例3: renderCode128
void renderCode128(OROPage * page, const QRectF & r, const QString & _str, ORBarcodeData * bc)
{
QVector<int> str;
int i = 0;
// create the list.. if the list is empty then just set a start code and move on
if(_str.isEmpty())
str.push_back(104);
else
{
int rank_a = 0;
int rank_b = 0;
int rank_c = 0;
QChar c;
for(i = 0; i < _str.length(); i++)
{
c = _str.at(i);
rank_a += (code128Index(c, SETA) != -1 ? 1 : 0);
rank_b += (code128Index(c, SETB) != -1 ? 1 : 0);
rank_c += (c >= '0' && c <= '9' ? 1 : 0);
}
if(rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4))
{
// every value in the is a digit so we are going to go with mode C
// and we have an even number or we have more than 4 values
i = 0;
if((rank_c % 2) == 1)
{
str.push_back(104); // START B
c = _str.at(0);
str.push_back(code128Index(c, SETB));
str.push_back(99); // MODE C
i = 1;
}
else
str.push_back(105); // START C
for(i = i; i < _str.length(); i+=2)
{
char a, b;
c = _str.at(i);
a = c.toLatin1();
a -= 48;
c = _str.at(i+1);
b = c.toLatin1();
b -= 48;
str.push_back(int((a * 10) + b));
}
}
else
{
// start in the mode that had the higher number of hits and then
// just shift into the opposite mode as needed
int set = ( rank_a > rank_b ? SETA : SETB );
str.push_back(( rank_a > rank_b ? 103 : 104 ));
int v = -1;
for(i = 0; i < _str.length(); i++)
{
c = _str.at(i);
v = code128Index(c, set);
if(v == -1)
{
v = code128Index(c, (set == SETA ? SETB : SETA));
if(v != -1)
{
str.push_back(98); // SHIFT
str.push_back(v);
}
}
else
str.push_back(v);
}
}
}
// calculate and append the checksum value to the list
int checksum = str.at(0);
for(i = 1; i < str.size(); i++)
checksum += (str.at(i) * i);
checksum = checksum % 103;
str.push_back(checksum);
// lets determine some core attributes about this barcode
qreal bar_width = bc->narrowBarWidth;
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if(quiet_zone < 0.1)
quiet_zone = 0.1;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height();
// how long is the value we need to encode?
int val_length = str.size() - 2; // we include start and checksum in are list so
// subtract them out for our calculations
// L = (11C + 35)X
//.........这里部分代码省略.........
示例4: parentRect
void HighlightItem::reposition(const QRectF & rect)
{
QRectF pr = rect.isNull() ? parentRect() : rect;
QGraphicsItem::setPos((int)(pr.left() + m_xn * pr.width()), (int)(pr.top() + m_yn * pr.height()));
}
示例5: glClear
void TimelineGL::paintGL() {
glReady = true;
if(!Global::viewerGL->glReady) {
Global::viewerSortChanged = true;
Global::viewerGL->glReady = true;
}
//Efface
GLbitfield clearFlag = GL_COLOR_BUFFER_BIT;
if(format().stencil()) clearFlag |= GL_STENCIL_BUFFER_BIT;
if(format().depth()) clearFlag |= GL_DEPTH_BUFFER_BIT;
glClear(clearFlag);
qglClearColor(Global::colorTextBlack);
QRectF _drawingBoundingRect;
scroll = scroll + ( scrollDest - scroll) / (Global::inertie);
showLegend = showLegend + ((qreal)showLegendDest - showLegend) / (Global::inertie);
showLinkedRenders = showLinkedRenders + ((qreal)showLinkedRendersDest - showLinkedRenders) / (Global::inertie);
showLinkedTags = showLinkedTags + ((qreal)showLinkedTagsDest - showLinkedTags) / (Global::inertie);
showHashedTags = showHashedTags + ((qreal)showHashedTagsDest - showHashedTags) / (Global::inertie);
tagSnap = tagSnap + ((qreal)tagSnapDest - tagSnap) / (Global::inertie);
tagSnapSlow = tagSnapSlow + ((qreal)tagSnapSlowDest - tagSnapSlow) / (Global::inertie * 2);
visibleRect = QRectF(scroll, size());
glScissor(Global::timelineHeaderSize.width(), 0, width() - Global::timelineHeaderSize.width(), height());
glPushMatrix();
glTranslatef(qRound(-scroll.x()), qRound(-scroll.y()), 0);
if(Global::timeline) _drawingBoundingRect = _drawingBoundingRect.united(Global::timeline ->paintTimeline(true));
if(Global::currentProject) _drawingBoundingRect = _drawingBoundingRect.united(Global::currentProject->paintTimeline(true));
if(Global::timeline) _drawingBoundingRect = _drawingBoundingRect.united(Global::timeline ->paintTimeline());
if(Global::currentProject) _drawingBoundingRect = _drawingBoundingRect.united(Global::currentProject->paintTimeline());
glPopMatrix();
drawingBoundingRect = _drawingBoundingRect;
Global::breathing = Global::breathing + (Global::breathingDest - Global::breathing) / 50.;
if(( Global::breathing > 0.90) && (Global::breathingDest == 1)) Global::breathingDest = 0;
else if((Global::breathing < 0.10) && (Global::breathingDest == 0)) Global::breathingDest = 1;
Global::breathingFast = Global::breathingFast + (Global::breathingFastDest - Global::breathingFast) / 20.;
if(( Global::breathingFast > 0.90) && (Global::breathingFastDest == 1)) Global::breathingFastDest = 0;
else if((Global::breathingFast < 0.10) && (Global::breathingFastDest == 0)) Global::breathingFastDest = 1;
Global::breathingPics = Global::breathingPics + (Global::breathingPicsDest - Global::breathingPics) / 200.;
if(( Global::breathingPics > 0.90) && (Global::breathingPicsDest == 1)) Global::breathingPicsDest = 0;
else if((Global::breathingPics < 0.10) && (Global::breathingPicsDest == 0)) Global::breathingPicsDest = 1;
if(showLegend > 0.01) {
//Background
qreal legendBaseSize = qBound(200., height() * 0.75, 400.);
QRectF legendRect = QRectF(width() - legendBaseSize * 1.2, height() - showLegend * legendBaseSize, legendBaseSize * 1.2, legendBaseSize);
qglColor(Global::colorAlternateStrong);
GlRect::drawRect(legendRect);
//Circles
legendBaseSize *= 0.8;
glPushMatrix();
glTranslatef(qRound(legendRect.center().x()), qRound(legendRect.center().y()), 0);
qreal angle = -M_PI/2, angleStep = 0;
glBegin(GL_QUAD_STRIP);
QMapIterator<QString, QPair<QColor, qreal> > colorForMetaIterator(Global::colorForMeta);
while(colorForMetaIterator.hasNext()) {
colorForMetaIterator.next();
angleStep = 2 * M_PI * colorForMetaIterator.value().second * showLegend;
qreal legendRadiusL = legendBaseSize;
qreal legendRadiusS = legendBaseSize * 0.8;
qglColor(colorForMetaIterator.value().first);
for(qreal angleSmooth = angle ; angleSmooth <= angle + angleStep ; angleSmooth += 0.01) {
glVertex2f(qCos(angleSmooth) * legendRadiusL/2, qSin(angleSmooth) * legendRadiusL/2);
glVertex2f(qCos(angleSmooth) * legendRadiusS/2, qSin(angleSmooth) * legendRadiusS/2);
}
angle += angleStep;
}
glEnd();
//Text
legendBaseSize *= 1.1;
angle = -M_PI/2;
QMapIterator<QString, QPair<QColor, qreal> > colorForMetaIteratorText(Global::colorForMeta);
while(colorForMetaIteratorText.hasNext()) {
colorForMetaIteratorText.next();
angleStep = 2*M_PI * colorForMetaIteratorText.value().second * showLegend;
angle += angleStep/2;
QString tagCategory = QString("%1 (%2%)").arg(colorForMetaIteratorText.key().toUpper()).arg(qFloor(colorForMetaIteratorText.value().second * 100));
QPoint pt(qCos(angle) * legendBaseSize/2, qSin(angle) * legendBaseSize/2);
QColor color = Qt::white;
color.setAlpha(colorForMetaIteratorText.value().first.alpha());
//Draw text
qglColor(color);
bool textFound = false;
if(categories.count() > 1000)
categories.clear();
foreach(GlText category, categories) {
if(category.text == tagCategory) {
category.drawText(pt - QPoint(category.size.width() / 2, 0));
textFound = true;
//.........这里部分代码省略.........
示例6: setGeometry
//! [4]
void LayoutItem::setGeometry(const QRectF &geom)
{
prepareGeometryChange();
QGraphicsLayoutItem::setGeometry(geom);
setPos(geom.topLeft());
}
示例7: switch
QPainterPath OrthogonalRenderer::shape(const MapObject *object) const
{
QPainterPath path;
if (!object->cell().isEmpty()) {
path.addRect(boundingRect(object));
} else {
switch (object->shape()) {
case MapObject::Rectangle: {
const QRectF bounds = object->bounds();
const QRectF rect(tileToPixelCoords(bounds.topLeft()),
tileToPixelCoords(bounds.bottomRight()));
if (rect.isNull()) {
path.addEllipse(rect.topLeft(), 20, 20);
} else {
path.addRoundedRect(rect, 10, 10);
}
break;
}
case MapObject::Polygon:
case MapObject::Polyline: {
const QPointF &pos = object->position();
const QPolygonF polygon = object->polygon().translated(pos);
const QPolygonF screenPolygon = tileToPixelCoords(polygon);
if (object->shape() == MapObject::Polygon) {
path.addPolygon(screenPolygon);
} else {
for (int i = 1; i < screenPolygon.size(); ++i) {
path.addPolygon(lineToPolygon(screenPolygon[i - 1],
screenPolygon[i]));
}
path.setFillRule(Qt::WindingFill);
}
break;
}
case MapObject::Ellipse: {
const QRectF bounds = object->bounds();
const QRectF rect(tileToPixelCoords(bounds.topLeft()),
tileToPixelCoords(bounds.bottomRight()));
if (rect.isNull()) {
path.addEllipse(rect.topLeft(), 20, 20);
} else {
path.addEllipse(rect);
}
break;
}
}
}
return path;
}
示例8: rect
void OrthogonalRenderer::drawMapObject(QPainter *painter,
const MapObject *object,
const QColor &color) const
{
painter->save();
const QRectF bounds = object->bounds();
QRectF rect(tileToPixelCoords(bounds.topLeft()),
tileToPixelCoords(bounds.bottomRight()));
painter->translate(rect.topLeft());
rect.moveTopLeft(QPointF(0, 0));
if (!object->cell().isEmpty()) {
const Cell &cell = object->cell();
CellRenderer(painter).render(cell, QPointF(),
CellRenderer::BottomLeft);
if (testFlag(ShowTileObjectOutlines)) {
const QRect rect = cell.tile->image().rect();
QPen pen(Qt::SolidLine);
pen.setCosmetic(true);
painter->setPen(pen);
painter->drawRect(rect);
pen.setStyle(Qt::DotLine);
pen.setColor(color);
painter->setPen(pen);
painter->drawRect(rect);
}
} else {
const qreal lineWidth = objectLineWidth();
const qreal scale = painterScale();
const qreal shadowDist = (lineWidth == 0 ? 1 : lineWidth) / scale;
const QPointF shadowOffset = QPointF(shadowDist * 0.5,
shadowDist * 0.5);
QPen linePen(color, lineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
linePen.setCosmetic(true);
QPen shadowPen(linePen);
shadowPen.setColor(Qt::black);
QColor brushColor = color;
brushColor.setAlpha(50);
const QBrush fillBrush(brushColor);
painter->setRenderHint(QPainter::Antialiasing);
switch (object->shape()) {
case MapObject::Rectangle: {
if (rect.isNull())
rect = QRectF(QPointF(-10, -10), QSizeF(20, 20));
const QFontMetrics fm = painter->fontMetrics();
QString name = fm.elidedText(object->name(), Qt::ElideRight,
rect.width() + 2);
// Draw the shadow
painter->setPen(shadowPen);
painter->drawRect(rect.translated(shadowOffset));
if (!name.isEmpty())
painter->drawText(QPointF(0, -4 - lineWidth / 2) + shadowOffset, name);
painter->setPen(linePen);
painter->setBrush(fillBrush);
painter->drawRect(rect);
if (!name.isEmpty())
painter->drawText(QPointF(0, -4 - lineWidth / 2), name);
break;
}
case MapObject::Polyline: {
QPolygonF screenPolygon = tileToPixelCoords(object->polygon());
painter->setPen(shadowPen);
painter->drawPolyline(screenPolygon.translated(shadowOffset));
painter->setPen(linePen);
painter->setBrush(fillBrush);
painter->drawPolyline(screenPolygon);
break;
}
case MapObject::Polygon: {
QPolygonF screenPolygon = tileToPixelCoords(object->polygon());
painter->setPen(shadowPen);
painter->drawPolygon(screenPolygon.translated(shadowOffset));
painter->setPen(linePen);
painter->setBrush(fillBrush);
painter->drawPolygon(screenPolygon);
break;
}
case MapObject::Ellipse: {
if (rect.isNull())
rect = QRectF(QPointF(-10, -10), QSizeF(20, 20));
//.........这里部分代码省略.........
示例9: pictureSize
QSizeF QgsLayoutItemPicture::applyItemSizeConstraint( const QSizeF &targetSize )
{
QSizeF currentPictureSize = pictureSize();
QSizeF newSize = targetSize;
if ( mResizeMode == QgsLayoutItemPicture::Clip )
{
mPictureWidth = targetSize.width();
mPictureHeight = targetSize.height();
}
else
{
if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
{
QSizeF targetImageSize;
if ( qgsDoubleNear( mPictureRotation, 0.0 ) )
{
targetImageSize = currentPictureSize;
}
else
{
//calculate aspect ratio of bounds of rotated image
QTransform tr;
tr.rotate( mPictureRotation );
QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) );
targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() );
}
//if height has changed more than width, then fix width and set height correspondingly
//else, do the opposite
if ( std::fabs( rect().width() - targetSize.width() ) <
std::fabs( rect().height() - targetSize.height() ) )
{
newSize.setHeight( targetImageSize.height() * newSize.width() / targetImageSize.width() );
}
else
{
newSize.setWidth( targetImageSize.width() * newSize.height() / targetImageSize.height() );
}
}
else if ( mResizeMode == FrameToImageSize )
{
if ( !( currentPictureSize.isEmpty() ) )
{
QgsLayoutSize sizeMM = mLayout->convertFromLayoutUnits( currentPictureSize, QgsUnitTypes::LayoutMillimeters );
newSize.setWidth( sizeMM.width() * 25.4 / mLayout->context().dpi() );
newSize.setHeight( sizeMM.height() * 25.4 / mLayout->context().dpi() );
}
}
//find largest scaling of picture with this rotation which fits in item
if ( mResizeMode == Zoom || mResizeMode == ZoomResizeFrame )
{
QRectF rotatedImageRect = QgsLayoutUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ),
QRectF( 0, 0, newSize.width(), newSize.height() ), mPictureRotation );
mPictureWidth = rotatedImageRect.width();
mPictureHeight = rotatedImageRect.height();
}
else
{
mPictureWidth = newSize.width();
mPictureHeight = newSize.height();
}
if ( newSize != targetSize )
{
emit changed();
}
}
return newSize;
}
示例10: QPoint
//protected
void MapGraphicsView::doTileLayout()
{
//Calculate the center point and polygon of the viewport in QGraphicsScene coordinates
const QPointF centerPointQGS = _childView->mapToScene(_childView->width()/2.0,
_childView->height()/2.0);
QPolygon viewportPolygonQGV;
viewportPolygonQGV << QPoint(0,0) << QPoint(0,_childView->height()) << QPoint(_childView->width(),_childView->height()) << QPoint(_childView->width(),0);
const QPolygonF viewportPolygonQGS = _childView->mapToScene(viewportPolygonQGV);
const QRectF boundingRect = viewportPolygonQGS.boundingRect();
//We exaggerate the bounding rect for some purposes!
QRectF exaggeratedBoundingRect = boundingRect;
exaggeratedBoundingRect.setSize(boundingRect.size()*2.0);
exaggeratedBoundingRect.moveCenter(boundingRect.center());
//We'll mark tiles that aren't being displayed as free so we can use them
QQueue<MapTileGraphicsObject *> freeTiles;
QSet<QPointF> placesWhereTilesAre;
foreach(MapTileGraphicsObject * tileObject, _tileObjects)
{
if (!tileObject->isVisible() || !exaggeratedBoundingRect.contains(tileObject->pos()))
{
freeTiles.enqueue(tileObject);
tileObject->setVisible(false);
}
else
placesWhereTilesAre.insert(tileObject->pos());
}
const quint16 tileSize = _tileSource->tileSize();
const quint32 tilesPerRow = sqrt((long double)_tileSource->tilesOnZoomLevel(this->zoomLevel()));
const quint32 tilesPerCol = tilesPerRow;
const qint32 perSide = qMax(boundingRect.width()/tileSize,
boundingRect.height()/tileSize) + 3;
const qint32 xc = qMax((qint32)0,
(qint32)(centerPointQGS.x() / tileSize) - perSide/2);
const qint32 yc = qMax((qint32)0,
(qint32)(centerPointQGS.y() / tileSize) - perSide/2);
const qint32 xMax = qMin((qint32)tilesPerRow,
xc + perSide);
const qint32 yMax = qMin(yc + perSide,
(qint32)tilesPerCol);
for (qint32 x = xc; x < xMax; x++)
{
for (qint32 y = yc; y < yMax; y++)
{
const QPointF scenePos(x*tileSize + tileSize/2,
y*tileSize + tileSize/2);
bool tileIsThere = false;
if (placesWhereTilesAre.contains(scenePos))
tileIsThere = true;
if (tileIsThere)
continue;
//Just in case we're running low on free tiles, add one
if (freeTiles.isEmpty())
{
MapTileGraphicsObject * tileObject = new MapTileGraphicsObject(tileSize);
tileObject->setTileSource(_tileSource);
_tileObjects.insert(tileObject);
_childScene->addItem(tileObject);
freeTiles.enqueue(tileObject);
}
//Get the first free tile and make it do its thing
MapTileGraphicsObject * tileObject = freeTiles.dequeue();
if (tileObject->pos() != scenePos)
tileObject->setPos(scenePos);
if (tileObject->isVisible() != true)
tileObject->setVisible(true);
tileObject->setTile(x,y,this->zoomLevel());
}
}
//If we've got a lot of free tiles left over, delete some of them
while (freeTiles.size() > 2)
{
MapTileGraphicsObject * tileObject = freeTiles.dequeue();
_tileObjects.remove(tileObject);
_childScene->removeItem(tileObject);
delete tileObject;
}
}
示例11: sceneRect
void StartScene::adjustItems()
{
QRectF startSceneRect = sceneRect();
QRectF logoPixmapRect = logo->boundingRect();
logo->setPos(startSceneRect.width() / 2 - logoPixmapRect.width() * 0.5,
startSceneRect.height() / 2 - logoPixmapRect.height() * 1.05);
for (int i = 0, n = buttons.length(); i < n; ++i) {
Button *const &button = buttons.at(i);
QRectF btnRect = button->boundingRect();
if (i < 4) {
button->setPos(startSceneRect.width() / 2 - btnRect.width() - 7,
(i - 1) * (btnRect.height() * 1.2) + startSceneRect.height() / 2 + 40);
}
else {
button->setPos(startSceneRect.width() / 2 + 7,
(i - 5) * (btnRect.height() * 1.2) + startSceneRect.height() / 2 + 40);
}
}
QRectF websiteTextRect = website_text->boundingRect();
website_text->setPos(startSceneRect.width() / 2 + websiteTextRect.width(),
startSceneRect.height() / 2 + 8.5 * websiteTextRect.height());
if (server_log) {
server_log->move(startSceneRect.width() / 2 - server_log->width() / 2,
startSceneRect.height() / 2 - server_log->height() / 2 + logo->boundingRect().height() / 4);
}
}
示例12: objectsBoundingRect
QRectF ObjectLayer::objectsBoundingRect() const {
QRectF boundingRect;
foreach (const MapObject *object, mObjects) {
boundingRect = boundingRect.united(object->bounds());
}
示例13: dumpRect
void QGIView::dumpRect(char* text, QRectF r) {
Base::Console().Message("DUMP - %s - rect: (%.3f,%.3f) x (%.3f,%.3f)\n",text,
r.left(),r.top(),r.right(),r.bottom());
}
示例14: interval
/*!
Set a the "rectangle of interest"
QwtPlotSeriesItem defines the current area of the plot canvas
as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).
If interval().isValid() == false the x values are calculated
in the interval rect.left() -> rect.right().
\sa rectOfInterest()
*/
void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect )
{
d_rectOfInterest = rect;
d_intervalOfInterest = QwtInterval(
rect.left(), rect.right() ).normalized();
}
示例15: set
void QxrdHistogramDialog::recalculateHistogram()
{
QxrdHistogramDialogSettingsPtr set(m_HistogramDialogSettings);
if (set && m_Image) {
QxrdExperimentPtr expt(m_Experiment);
if (expt) {
QTime tic;
tic.start();
QRectF rect = set->get_HistogramRect();
int nsum = m_Image->get_SummedExposures();
if (nsum < 1) {
nsum = 1;
}
QxrdAcquisitionPtr acq(expt->acquisition());
double satlev = 60000;
if (acq) {
satlev = acq->get_OverflowLevel();
}
double min = 0, max = satlev*nsum;
const int nbins=1000;
QcepDoubleVector x0(nbins), h0(nbins), h1(nbins);
for (int i=0; i<nbins; i++) {
// double x = min+i*(max-min)/1000.0;
x0[i] = i*100.0/(double)nbins;
h0[i] = 0;
h1[i] = 0;
}
int width = m_Image->get_Width();
int height= m_Image->get_Height();
double *data = m_Image->data();
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
double v = *data++;
int n;
if (v<min) {
n=0;
} else if (v>max) {
n=nbins-1;
} else {
n=(nbins-1)*(v-min)/(max-min);
}
if (n<0) {
n=0;
}
if (n>=nbins) {
n=nbins-1;
}
h0[n]++;
if (rect.contains(i,j)) {
h1[n]++;
}
}
}
m_HistogramPlot->detachItems();
QwtPlotPiecewiseCurve *pc0 = new QwtPlotPiecewiseCurve(m_HistogramPlot, "Entire Image");
pc0->setSamples(x0, h0);
pc0->setPen(QPen(Qt::red));
pc0->attach(m_HistogramPlot);
QwtPlotPiecewiseCurve *pc1 = new QwtPlotPiecewiseCurve(m_HistogramPlot,
tr("[%1,%2]-[%3,%4]")
.arg(rect.left()).arg(rect.bottom())
.arg(rect.right()).arg(rect.top()));
pc1->setSamples(x0, h1);
pc1->setPen(QPen(Qt::darkRed));
pc1->attach(m_HistogramPlot);
m_HistogramPlot->replot();
if (qcepDebug(DEBUG_HISTOGRAM)) {
expt -> printMessage(tr("Histogram of data took %1 msec").arg(tic.elapsed()));
}
}
//.........这里部分代码省略.........