// Move the selected point void CanvasPicker::move(const QPoint &pos) { if ( !d_selectedCurve ) return; QVector<double> xData(d_selectedCurve->dataSize()); QVector<double> yData(d_selectedCurve->dataSize()); for ( int i = 0; i < (int)d_selectedCurve->dataSize(); i++ ) { if ( i == d_selectedPoint ) { xData[i] = plot()->invTransform( d_selectedCurve->xAxis(), pos.x()); yData[i] = plot()->invTransform( d_selectedCurve->yAxis(), pos.y()); } else { const QPointF sample = d_selectedCurve->sample(i); xData[i] = sample.x(); yData[i] = sample.y(); } } d_selectedCurve->setSamples(xData, yData); plot()->replot(); showCursor(true); }
void LineSegmentPlot::updateDataLimits() { qDebug() << Q_FUNC_INFO; int xLen = xSize(), yLen = ySize(), endXLen = m_endX.size(), endYLen = m_endY.size(); int N = qMin( qMin(xLen, yLen), qMin(endXLen, endYLen) ); m_dataSize = N; qreal minX = Inf, maxX = -Inf, minY = Inf, maxY = -Inf; // Calculate the y limits RangeValues yrng = ArrayUtil::limits(yData()); minY = yrng.min; maxY = yrng.max; yrng = ArrayUtil::limits(m_endY); minY = qMin(minY, yrng.min); maxY = qMax(maxY, yrng.max); RangeValues xrng = ArrayUtil::limits(xData()); minX = xrng.min; maxX = xrng.max; xrng = ArrayUtil::limits(m_endX); minX = qMin(minX, xrng.min); maxX = qMax(maxX, xrng.max); QRectF newLim; newLim.setLeft(minX); newLim.setTop(minY); newLim.setRight(maxX); newLim.setBottom(maxY); setDataLimits(newLim); }
void LinePlot::scaleCurves(QwtPlotCurve *curve) { /// multiple curves based on units const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList(); QwtPlotCurve *plotCurve; QwtPlotItemIterator itPlotItem; int curveCount = numberOfCurves(); switch (curveCount) { case 0: { curve->setYAxis(QwtPlot::yLeft); m_qwtPlot->enableAxis(QwtPlot::yRight, false); break; } case 1: { curve->setYAxis(QwtPlot::yRight); m_qwtPlot->enableAxis(QwtPlot::yRight, true); break; } default: //scale m_qwtPlot->enableAxis(QwtPlot::yRight, false); // find min, max of all curves // scale int i; for ( itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem) { if ( (*itPlotItem)->rtti() == QwtPlotItem::Rtti_PlotCurve) { plotCurve = (QwtPlotCurve*) (*itPlotItem); if ((plotCurve->minYValue() != 0) || (plotCurve->maxYValue() != 1)) { QwtArray<double> xData(plotCurve->dataSize()); QwtArray<double> yData(plotCurve->dataSize()); for (i = 0; i < plotCurve->dataSize(); i++) { xData[i] = plotCurve->x(i); yData[i] = (plotCurve->y(i) - plotCurve->minYValue())/ (plotCurve->maxYValue() - plotCurve->minYValue()); } // reset data plotCurve->setTitle(plotCurve->title().text() + "[" + QString::number(plotCurve->minYValue()) + ", " + QString::number(plotCurve->maxYValue()) + "]"); plotCurve->setData(xData,yData); } } } break; } }
writeTimeData::writeTimeData ( const fileName& pathName, const word& nameFile, const List< Pair<scalar> >& data, const label& dummy ) { fileName writeFile(pathName/nameFile); scalarField xData(data.size()); scalarField yData(data.size()); forAll(data, d) { xData[d] = data[d].first(); yData[d] = data[d].second(); }
// Move the selected point void CanvasPicker::move( const QPoint &pos ) { if ( !d_selectedCurve ) return; QVector<double> xData( d_selectedCurve->dataSize() ); QVector<double> yData( d_selectedCurve->dataSize() ); for ( int i = 0; i < static_cast<int>( d_selectedCurve->dataSize() ); i++ ) { if ( i == d_selectedPoint ) { xData[i] = plot()->invTransform( d_selectedCurve->xAxis(), pos.x() ); yData[i] = plot()->invTransform( d_selectedCurve->yAxis(), pos.y() ); } else { const QPointF sample = d_selectedCurve->sample( i ); xData[i] = sample.x(); yData[i] = sample.y(); } } d_selectedCurve->setSamples( xData, yData ); /* Enable QwtPlotCanvas::ImmediatePaint, so that the canvas has been updated before we paint the cursor on it. */ QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( plot()->canvas() ); plotCanvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, true ); plot()->replot(); plotCanvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false ); showCursor( true ); }
//MAIN RENDER CODE ================================================ void DataGrid::render() { //vector<T> xData(_xData); //Assign xData to non-const so we can pass by const reference. // Add the border if flagged if (flags & (int)o_t::BORDER) { addBorder(); const int shrink = 4; plotArea.setSize(plotArea.getWidth()-shrink, plotArea.getHeight()-shrink); plotArea.translate(shrink/2, shrink/2); } // Add the title if flagged if (flags & (int)o_t::TITLE) { addTitle(); } // Abort if series vec is empty if (series.getNumSeries()==0){ cout << "No data series available, aborting. \n"; return; } // get ranges const float xMin = series.getXmin(); const float xMax = series.getXmax(); const float yMin = series.getYmin(); const float yMax = series.getYmax(); // Another way of aliasing - pointless here bu I <3 lambdas // To use this alternative, replace xMin with xMin() below // auto xMin = [&](){return series.getXmin();}; // Add the y-axis if flagged if (flags & (int)o_t::YAXIS) { const int yaxWidth = 10; Rectangle rAx = Rectangle(plotArea.getTL(), yaxWidth, plotArea.getHeight()); addYAxis(yMin, yMax, rAx); // Shift the plot area plotArea.setWidth(plotArea.getWidth()-yaxWidth); plotArea.translate(yaxWidth, 0); } // Add simple x-axis indicators if requested if (flags & (int)o_t::XAXIS) { addXAxis(xMin, xMax, plotArea); } for (size_t ii=0; ii<series.getNumSeries(); ++ii){ // Warn if input is messed up vector<float> xData(series.getXdata(ii)); vector<float> yData(series.getYdata(ii)); if (xData.size()!=yData.size()) { cout << "WARNING: x and y data size mismatch, not plotting.\n"; return; } for(size_t nn=0; nn<xData.size(); ++nn){ int intX = mapVal( xData[nn], xMin, xMax, plotArea.getLeft(), plotArea.getRight() ); // Notice the subtle reversal of yMax and yMin here so data flipped the correct way int intY = mapVal( yData[nn], yMax, yMin, plotArea.getTop(), plotArea.getBtm() ); addPoint(Point(intX, intY), series.getMarker(ii) ); } } // Add the legend if flagged if (flags & (int)o_t::LEGEND) { addLegend(); } } // End of rendering function
void QSGDefaultImageNode::updateGeometry() { Q_ASSERT(!m_targetRect.isEmpty()); const QSGTexture *t = m_material.texture(); if (!t) { QSGGeometry *g = geometry(); g->allocate(4); g->setDrawingMode(GL_TRIANGLE_STRIP); memset(g->vertexData(), 0, g->sizeOfVertex() * 4); } else { QRectF sourceRect = t->normalizedTextureSubRect(); QRectF innerSourceRect(sourceRect.x() + m_innerSourceRect.x() * sourceRect.width(), sourceRect.y() + m_innerSourceRect.y() * sourceRect.height(), m_innerSourceRect.width() * sourceRect.width(), m_innerSourceRect.height() * sourceRect.height()); bool hasMargins = m_targetRect != m_innerTargetRect; int floorLeft = qFloor(m_subSourceRect.left()); int ceilRight = qCeil(m_subSourceRect.right()); int floorTop = qFloor(m_subSourceRect.top()); int ceilBottom = qCeil(m_subSourceRect.bottom()); int hTiles = ceilRight - floorLeft; int vTiles = ceilBottom - floorTop; bool hasTiles = hTiles != 1 || vTiles != 1; bool fullTexture = innerSourceRect == QRectF(0, 0, 1, 1); #ifdef QT_OPENGL_ES_2 QOpenGLContext *ctx = QOpenGLContext::currentContext(); bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); QSize size = t->textureSize(); bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); bool wrapSupported = npotSupported || !isNpot; #else bool wrapSupported = true; #endif // An image can be rendered as a single quad if: // - There are no margins, and either: // - the image isn't repeated // - the source rectangle fills the entire texture so that texture wrapping can be used, // and NPOT is supported if (!hasMargins && (!hasTiles || (fullTexture && wrapSupported))) { QRectF sr; if (!fullTexture) { sr = QRectF(innerSourceRect.x() + (m_subSourceRect.left() - floorLeft) * innerSourceRect.width(), innerSourceRect.y() + (m_subSourceRect.top() - floorTop) * innerSourceRect.height(), m_subSourceRect.width() * innerSourceRect.width(), m_subSourceRect.height() * innerSourceRect.height()); } else { sr = QRectF(m_subSourceRect.left() - floorLeft, m_subSourceRect.top() - floorTop, m_subSourceRect.width(), m_subSourceRect.height()); } if (m_mirror) { qreal oldLeft = sr.left(); sr.setLeft(sr.right()); sr.setRight(oldLeft); } if (m_antialiasing) { QSGGeometry *g = geometry(); Q_ASSERT(g != &m_geometry); g->allocate(8, 14); g->setDrawingMode(GL_TRIANGLE_STRIP); SmoothVertex *vertices = reinterpret_cast<SmoothVertex *>(g->vertexData()); float delta = float(qAbs(m_targetRect.width()) < qAbs(m_targetRect.height()) ? m_targetRect.width() : m_targetRect.height()) * 0.5f; float sx = float(sr.width() / m_targetRect.width()); float sy = float(sr.height() / m_targetRect.height()); for (int d = -1; d <= 1; d += 2) { for (int j = 0; j < 2; ++j) { for (int i = 0; i < 2; ++i, ++vertices) { vertices->x = m_targetRect.x() + i * m_targetRect.width(); vertices->y = m_targetRect.y() + j * m_targetRect.height(); vertices->u = sr.x() + i * sr.width(); vertices->v = sr.y() + j * sr.height(); vertices->dx = (i == 0 ? delta : -delta) * d; vertices->dy = (j == 0 ? delta : -delta) * d; vertices->du = (d < 0 ? 0 : vertices->dx * sx); vertices->dv = (d < 0 ? 0 : vertices->dy * sy); } } } Q_ASSERT(vertices - g->vertexCount() == g->vertexData()); static const quint16 indices[] = { 0, 4, 1, 5, 3, 7, 2, 6, 0, 4, 4, 6, 5, 7 }; Q_ASSERT(g->sizeOfIndex() * g->indexCount() == sizeof(indices)); memcpy(g->indexDataAsUShort(), indices, sizeof(indices)); } else { m_geometry.allocate(4); m_geometry.setDrawingMode(GL_TRIANGLE_STRIP); QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_targetRect, sr); } } else { int hCells = hTiles; int vCells = vTiles; if (m_innerTargetRect.width() == 0) hCells = 0; if (m_innerTargetRect.left() != m_targetRect.left()) ++hCells; if (m_innerTargetRect.right() != m_targetRect.right()) ++hCells; if (m_innerTargetRect.height() == 0) vCells = 0; if (m_innerTargetRect.top() != m_targetRect.top()) ++vCells; if (m_innerTargetRect.bottom() != m_targetRect.bottom()) ++vCells; QVarLengthArray<X, 32> xData(2 * hCells); QVarLengthArray<Y, 32> yData(2 * vCells); X *xs = xData.data(); Y *ys = yData.data(); if (m_innerTargetRect.left() != m_targetRect.left()) { xs[0].x = m_targetRect.left(); xs[0].tx = sourceRect.left(); xs[1].x = m_innerTargetRect.left(); xs[1].tx = innerSourceRect.left(); xs += 2; } if (m_innerTargetRect.width() != 0) { xs[0].x = m_innerTargetRect.left(); xs[0].tx = innerSourceRect.x() + (m_subSourceRect.left() - floorLeft) * innerSourceRect.width(); ++xs; float b = m_innerTargetRect.width() / m_subSourceRect.width(); float a = m_innerTargetRect.x() - m_subSourceRect.x() * b; for (int i = floorLeft + 1; i <= ceilRight - 1; ++i) { xs[0].x = xs[1].x = a + b * i; xs[0].tx = innerSourceRect.right(); xs[1].tx = innerSourceRect.left(); xs += 2; } xs[0].x = m_innerTargetRect.right(); xs[0].tx = innerSourceRect.x() + (m_subSourceRect.right() - ceilRight + 1) * innerSourceRect.width(); ++xs; } if (m_innerTargetRect.right() != m_targetRect.right()) { xs[0].x = m_innerTargetRect.right(); xs[0].tx = innerSourceRect.right(); xs[1].x = m_targetRect.right(); xs[1].tx = sourceRect.right(); xs += 2; } Q_ASSERT(xs == xData.data() + xData.size()); if (m_mirror) { float leftPlusRight = m_targetRect.left() + m_targetRect.right(); int count = xData.size(); xs = xData.data(); for (int i = 0; i < count >> 1; ++i) qSwap(xs[i], xs[count - 1 - i]); for (int i = 0; i < count; ++i) xs[i].x = leftPlusRight - xs[i].x; } if (m_innerTargetRect.top() != m_targetRect.top()) { ys[0].y = m_targetRect.top(); ys[0].ty = sourceRect.top(); ys[1].y = m_innerTargetRect.top(); ys[1].ty = innerSourceRect.top(); ys += 2; } if (m_innerTargetRect.height() != 0) { ys[0].y = m_innerTargetRect.top(); ys[0].ty = innerSourceRect.y() + (m_subSourceRect.top() - floorTop) * innerSourceRect.height(); ++ys; float b = m_innerTargetRect.height() / m_subSourceRect.height(); float a = m_innerTargetRect.y() - m_subSourceRect.y() * b; for (int i = floorTop + 1; i <= ceilBottom - 1; ++i) { ys[0].y = ys[1].y = a + b * i; ys[0].ty = innerSourceRect.bottom(); ys[1].ty = innerSourceRect.top(); ys += 2; } ys[0].y = m_innerTargetRect.bottom(); ys[0].ty = innerSourceRect.y() + (m_subSourceRect.bottom() - ceilBottom + 1) * innerSourceRect.height(); ++ys; } if (m_innerTargetRect.bottom() != m_targetRect.bottom()) { ys[0].y = m_innerTargetRect.bottom(); ys[0].ty = innerSourceRect.bottom(); ys[1].y = m_targetRect.bottom(); ys[1].ty = sourceRect.bottom(); ys += 2; } Q_ASSERT(ys == yData.data() + yData.size()); if (m_antialiasing) { QSGGeometry *g = geometry(); Q_ASSERT(g != &m_geometry); g->allocate(hCells * vCells * 4 + (hCells + vCells - 1) * 4, hCells * vCells * 6 + (hCells + vCells) * 12); g->setDrawingMode(GL_TRIANGLES); SmoothVertex *vertices = reinterpret_cast<SmoothVertex *>(g->vertexData()); memset(vertices, 0, g->vertexCount() * g->sizeOfVertex()); quint16 *indices = g->indexDataAsUShort(); // The deltas are how much the fuzziness can reach into the image. // Only the border vertices are moved by the vertex shader, so the fuzziness // can't reach further into the image than the closest interior vertices. float leftDx = xData.at(1).x - xData.at(0).x; float rightDx = xData.at(xData.size() - 1).x - xData.at(xData.size() - 2).x; float topDy = yData.at(1).y - yData.at(0).y; float bottomDy = yData.at(yData.size() - 1).y - yData.at(yData.size() - 2).y; float leftDu = xData.at(1).tx - xData.at(0).tx; float rightDu = xData.at(xData.size() - 1).tx - xData.at(xData.size() - 2).tx; float topDv = yData.at(1).ty - yData.at(0).ty; float bottomDv = yData.at(yData.size() - 1).ty - yData.at(yData.size() - 2).ty; if (hCells == 1) { leftDx = rightDx *= 0.5f; leftDu = rightDu *= 0.5f; } if (vCells == 1) { topDy = bottomDy *= 0.5f; topDv = bottomDv *= 0.5f; } // This delta is how much the fuzziness can reach out from the image. float delta = float(qAbs(m_targetRect.width()) < qAbs(m_targetRect.height()) ? m_targetRect.width() : m_targetRect.height()) * 0.5f; quint16 index = 0; ys = yData.data(); for (int j = 0; j < vCells; ++j, ys += 2) { xs = xData.data(); bool isTop = j == 0; bool isBottom = j == vCells - 1; for (int i = 0; i < hCells; ++i, xs += 2) { bool isLeft = i == 0; bool isRight = i == hCells - 1; SmoothVertex *v = vertices + index; quint16 topLeft = index; for (int k = (isTop || isLeft ? 2 : 1); k--; ++v, ++index) { v->x = xs[0].x; v->u = xs[0].tx; v->y = ys[0].y; v->v = ys[0].ty; } quint16 topRight = index; for (int k = (isTop || isRight ? 2 : 1); k--; ++v, ++index) { v->x = xs[1].x; v->u = xs[1].tx; v->y = ys[0].y; v->v = ys[0].ty; } quint16 bottomLeft = index; for (int k = (isBottom || isLeft ? 2 : 1); k--; ++v, ++index) { v->x = xs[0].x; v->u = xs[0].tx; v->y = ys[1].y; v->v = ys[1].ty; } quint16 bottomRight = index; for (int k = (isBottom || isRight ? 2 : 1); k--; ++v, ++index) { v->x = xs[1].x; v->u = xs[1].tx; v->y = ys[1].y; v->v = ys[1].ty; } appendQuad(&indices, topLeft, topRight, bottomLeft, bottomRight); if (isTop) { vertices[topLeft].dy = vertices[topRight].dy = topDy; vertices[topLeft].dv = vertices[topRight].dv = topDv; vertices[topLeft + 1].dy = vertices[topRight + 1].dy = -delta; appendQuad(&indices, topLeft + 1, topRight + 1, topLeft, topRight); } if (isBottom) { vertices[bottomLeft].dy = vertices[bottomRight].dy = -bottomDy; vertices[bottomLeft].dv = vertices[bottomRight].dv = -bottomDv; vertices[bottomLeft + 1].dy = vertices[bottomRight + 1].dy = delta; appendQuad(&indices, bottomLeft, bottomRight, bottomLeft + 1, bottomRight + 1); } if (isLeft) { vertices[topLeft].dx = vertices[bottomLeft].dx = leftDx; vertices[topLeft].du = vertices[bottomLeft].du = leftDu; vertices[topLeft + 1].dx = vertices[bottomLeft + 1].dx = -delta; appendQuad(&indices, topLeft + 1, topLeft, bottomLeft + 1, bottomLeft); } if (isRight) { vertices[topRight].dx = vertices[bottomRight].dx = -rightDx; vertices[topRight].du = vertices[bottomRight].du = -rightDu; vertices[topRight + 1].dx = vertices[bottomRight + 1].dx = delta; appendQuad(&indices, topRight, topRight + 1, bottomRight, bottomRight + 1); } } } Q_ASSERT(index == g->vertexCount()); Q_ASSERT(indices - g->indexCount() == g->indexData()); } else { m_geometry.allocate(hCells * vCells * 4, hCells * vCells * 6); m_geometry.setDrawingMode(GL_TRIANGLES); QSGGeometry::TexturedPoint2D *vertices = m_geometry.vertexDataAsTexturedPoint2D(); ys = yData.data(); for (int j = 0; j < vCells; ++j, ys += 2) { xs = xData.data(); for (int i = 0; i < hCells; ++i, xs += 2) { vertices[0].x = vertices[2].x = xs[0].x; vertices[0].tx = vertices[2].tx = xs[0].tx; vertices[1].x = vertices[3].x = xs[1].x; vertices[1].tx = vertices[3].tx = xs[1].tx; vertices[0].y = vertices[1].y = ys[0].y; vertices[0].ty = vertices[1].ty = ys[0].ty; vertices[2].y = vertices[3].y = ys[1].y; vertices[2].ty = vertices[3].ty = ys[1].ty; vertices += 4; } } quint16 *indices = m_geometry.indexDataAsUShort(); for (int i = 0; i < 4 * vCells * hCells; i += 4) appendQuad(&indices, i, i + 1, i + 2, i + 3); } } } markDirty(DirtyGeometry); m_dirtyGeometry = false; }
void SvgView::loadPlan(vlePlan *plan) { qWarning() << "SvgView::loadPlan"; if ( mTplHeader.isNull() ) { // ToDo : improve error handling qWarning() << "SvgView::loadPlan() Template error"; return; } // Compute the height of a group if (mTplHeader.hasAttribute("height")) mGroupHeight = mTplHeader.attribute("height").toDouble(); else mGroupHeight = 100; // Compute size of the whole plan int planHeight = mGroupHeight * (1 + plan->countGroups()); int planWidth = (mMaxWidth * mZoomLevel); // Create SVG document QDomDocument planSVG("xml"); // Create root element QDomElement e = planSVG.createElement("svg"); e.setAttribute("width", QString(planWidth)); e.setAttribute("height", QString(planHeight)); e.setAttribute("viewBox", QString("0 0 %1 %2").arg(planWidth).arg(planHeight)); e.setAttribute("version", "1.1"); QDate dateStart = plan->dateStart(); QDate dateEnd = plan->dateEnd(); int nbDays = dateStart.daysTo(dateEnd); // In the plan duration is more than 1500 days if (nbDays > mMaxWidth) { // Update "pixel-per-day" to avoid very large picture qreal widgetSize = mMaxWidth; mPixelPerDay = (widgetSize / nbDays); } if (plan != mPlan) { qWarning() << "Plan period is from" << dateStart.toString("dd/MM/yyyy") << "to" << dateEnd.toString("dd/MM/yyyy") << "(" << nbDays<< "days)" << "[" << mPixelPerDay << "pixel per day]"; } // First insert the time rule QDomElement timeGrp = mTplHeader.cloneNode().toElement(); updateField(timeGrp, "{{name}}", ""); updatePos (timeGrp, 0, 0); updateAttr (timeGrp, "header_background", "width", QString::number(planWidth)); float yLen = (mPixelPerDay * 365 * mZoomLevel); // Show Weeks if (yLen > 2000) { QDate r; if (dateStart.daysInMonth() == 1) r.setDate(dateStart.year(), dateStart.month(), dateStart.day()); else r.setDate(dateStart.year(), dateStart.month() + 1, 1); while (r < dateEnd) { QDomElement newTimeStep = mTplTime.cloneNode().toElement(); if (yLen < 5000) updateField(newTimeStep, "{{name}}", r.toString("dd/MM") ); else updateField(newTimeStep, "{{name}}", r.toString("dd/MM/yy") ); updateAttr (newTimeStep, "step_block", "width", QString::number(4)); int offset = dateStart.daysTo(r); int aPos = (offset * mPixelPerDay * mZoomLevel); updatePos(newTimeStep, aPos, 0); timeGrp.appendChild(newTimeStep); r = r.addDays(7); } } // Show month else if (yLen > 500) { QDate r; if (dateStart.daysInMonth() == 1) r.setDate(dateStart.year(), dateStart.month(), dateStart.day()); else r.setDate(dateStart.year(), dateStart.month() + 1, 1); while (r < dateEnd) { QDomElement newTimeStep = mTplTime.cloneNode().toElement(); if (yLen < 1000) updateField(newTimeStep, "{{name}}", r.toString("MMM") ); else updateField(newTimeStep, "{{name}}", r.toString("MMM yy") ); updateAttr (newTimeStep, "step_block", "width", QString::number(4)); int offset = dateStart.daysTo(r); int aPos = (offset * mPixelPerDay * mZoomLevel); updatePos(newTimeStep, aPos, 0); timeGrp.appendChild(newTimeStep); r = r.addMonths(1); } } // Show Year else { QDate r; if (dateStart.dayOfYear() == 1) r.setDate(dateStart.year(), dateStart.month(), dateStart.day()); else r.setDate(dateStart.year() + 1, 1, 1); while (r < dateEnd) { QDomElement newTimeStep = mTplTime.cloneNode().toElement(); updateField(newTimeStep, "{{name}}", QString::number(r.year()) ); updateAttr (newTimeStep, "step_block", "width", QString::number(4)); int offset = dateStart.daysTo(r); int aPos = (offset * mPixelPerDay * mZoomLevel); updatePos(newTimeStep, aPos, 0); timeGrp.appendChild(newTimeStep); r = r.addYears(1); } } e.appendChild(timeGrp); // Insert all the known groups for (int i=0; i < plan->countGroups(); i++) { vlePlanGroup *planGroup = plan->getGroup(i); vlePlanActivity *prevActivity = 0; int prevLen = 0; int prevOffset = 0; // Create a new Group QDomElement newGrp = mTplHeader.cloneNode().toElement(); updateField(newGrp, "{{name}}", planGroup->getName()); updatePos (newGrp, 0, ((i + 1) * mGroupHeight)); updateAttr (newGrp, "header_background", "width", QString::number(planWidth)); for (int j = 0; j < planGroup->count(); j++) { vlePlanActivity *planActivity = planGroup->getActivity(j); QDate actStart = planActivity->dateStart(); QDate actEnd = planActivity->dateEnd(); qreal actLength = (mPixelPerDay * actStart.daysTo(actEnd) * mZoomLevel); if (actLength < 1) actLength = 1; QDomElement newAct = mTplTask.cloneNode().toElement(); updateField(newAct, "{{name}}", planActivity->getName()); updateAttr (newAct, "activity_block", "width", QString::number(actLength)); QString cfgColor("#00edda"); QString activityClass = planActivity->getClass(); if ( ! activityClass.isEmpty() ) { QString cfg = getConfig("color", activityClass); if ( ! cfg.isEmpty() ) cfgColor = cfg; } QString fillStyle = QString(";fill:%1").arg(cfgColor); updateAttr (newAct, "activity_block", "style", fillStyle, false); int date = dateStart.daysTo(planActivity->dateStart()); int aPos = (date * mPixelPerDay * mZoomLevel); if (prevActivity) { if (prevLen > aPos) { if (prevOffset < 40) prevOffset += 15; updateAttr(newAct, "activity_name", "y", QString::number(prevOffset)); } else prevOffset = 15; } updatePos(newAct, aPos, 0); newGrp.appendChild(newAct); prevActivity = planActivity; prevLen = aPos + (planActivity->getName().size() * 8); } e.appendChild(newGrp); } planSVG.appendChild( e ); QByteArray data; QTextStream stream(&data); planSVG.save(stream, QDomNode::EncodingFromTextStream); #ifdef PLAN_OUT QFile File("planOut.svg"); File.open( QIODevice::WriteOnly ); QTextStream TextStream(&File); planSVG.save(TextStream, 0); File.close(); mFilename = "planOut.svg"; #else mFilename.clear(); #endif mPlan = plan; QXmlStreamReader xData(data); mSvgRenderer->load(&xData); refresh(); }
QSGGeometry *QSGBasicInternalImageNode::updateGeometry(const QRectF &targetRect, const QRectF &innerTargetRect, const QRectF &sourceRect, const QRectF &innerSourceRect, const QRectF &subSourceRect, QSGGeometry *geometry, bool mirror, bool antialiasing) { int floorLeft = qFloor(subSourceRect.left()); int ceilRight = qCeil(subSourceRect.right()); int floorTop = qFloor(subSourceRect.top()); int ceilBottom = qCeil(subSourceRect.bottom()); int hTiles = ceilRight - floorLeft; int vTiles = ceilBottom - floorTop; int hCells = hTiles; int vCells = vTiles; if (innerTargetRect.width() == 0) hCells = 0; if (innerTargetRect.left() != targetRect.left()) ++hCells; if (innerTargetRect.right() != targetRect.right()) ++hCells; if (innerTargetRect.height() == 0) vCells = 0; if (innerTargetRect.top() != targetRect.top()) ++vCells; if (innerTargetRect.bottom() != targetRect.bottom()) ++vCells; QVarLengthArray<X, 32> xData(2 * hCells); QVarLengthArray<Y, 32> yData(2 * vCells); X *xs = xData.data(); Y *ys = yData.data(); if (innerTargetRect.left() != targetRect.left()) { xs[0].x = targetRect.left(); xs[0].tx = sourceRect.left(); xs[1].x = innerTargetRect.left(); xs[1].tx = innerSourceRect.left(); xs += 2; } if (innerTargetRect.width() != 0) { xs[0].x = innerTargetRect.left(); xs[0].tx = innerSourceRect.x() + (subSourceRect.left() - floorLeft) * innerSourceRect.width(); ++xs; float b = innerTargetRect.width() / subSourceRect.width(); float a = innerTargetRect.x() - subSourceRect.x() * b; for (int i = floorLeft + 1; i <= ceilRight - 1; ++i) { xs[0].x = xs[1].x = a + b * i; xs[0].tx = innerSourceRect.right(); xs[1].tx = innerSourceRect.left(); xs += 2; } xs[0].x = innerTargetRect.right(); xs[0].tx = innerSourceRect.x() + (subSourceRect.right() - ceilRight + 1) * innerSourceRect.width(); ++xs; } if (innerTargetRect.right() != targetRect.right()) { xs[0].x = innerTargetRect.right(); xs[0].tx = innerSourceRect.right(); xs[1].x = targetRect.right(); xs[1].tx = sourceRect.right(); xs += 2; } Q_ASSERT(xs == xData.data() + xData.size()); if (mirror) { float leftPlusRight = targetRect.left() + targetRect.right(); int count = xData.size(); xs = xData.data(); for (int i = 0; i < count >> 1; ++i) qSwap(xs[i], xs[count - 1 - i]); for (int i = 0; i < count; ++i) xs[i].x = leftPlusRight - xs[i].x; } if (innerTargetRect.top() != targetRect.top()) { ys[0].y = targetRect.top(); ys[0].ty = sourceRect.top(); ys[1].y = innerTargetRect.top(); ys[1].ty = innerSourceRect.top(); ys += 2; } if (innerTargetRect.height() != 0) { ys[0].y = innerTargetRect.top(); ys[0].ty = innerSourceRect.y() + (subSourceRect.top() - floorTop) * innerSourceRect.height(); ++ys; float b = innerTargetRect.height() / subSourceRect.height(); float a = innerTargetRect.y() - subSourceRect.y() * b; for (int i = floorTop + 1; i <= ceilBottom - 1; ++i) { ys[0].y = ys[1].y = a + b * i; ys[0].ty = innerSourceRect.bottom(); ys[1].ty = innerSourceRect.top(); ys += 2; } ys[0].y = innerTargetRect.bottom(); ys[0].ty = innerSourceRect.y() + (subSourceRect.bottom() - ceilBottom + 1) * innerSourceRect.height(); ++ys; } if (innerTargetRect.bottom() != targetRect.bottom()) { ys[0].y = innerTargetRect.bottom(); ys[0].ty = innerSourceRect.bottom(); ys[1].y = targetRect.bottom(); ys[1].ty = sourceRect.bottom(); ys += 2; } Q_ASSERT(ys == yData.data() + yData.size()); if (antialiasing) { QSGGeometry *g = geometry; Q_ASSERT(g); g->allocate(hCells * vCells * 4 + (hCells + vCells - 1) * 4, hCells * vCells * 6 + (hCells + vCells) * 12); g->setDrawingMode(QSGGeometry::DrawTriangles); SmoothVertex *vertices = reinterpret_cast<SmoothVertex *>(g->vertexData()); memset(vertices, 0, g->vertexCount() * g->sizeOfVertex()); quint16 *indices = g->indexDataAsUShort(); // The deltas are how much the fuzziness can reach into the image. // Only the border vertices are moved by the vertex shader, so the fuzziness // can't reach further into the image than the closest interior vertices. float leftDx = xData.at(1).x - xData.at(0).x; float rightDx = xData.at(xData.size() - 1).x - xData.at(xData.size() - 2).x; float topDy = yData.at(1).y - yData.at(0).y; float bottomDy = yData.at(yData.size() - 1).y - yData.at(yData.size() - 2).y; float leftDu = xData.at(1).tx - xData.at(0).tx; float rightDu = xData.at(xData.size() - 1).tx - xData.at(xData.size() - 2).tx; float topDv = yData.at(1).ty - yData.at(0).ty; float bottomDv = yData.at(yData.size() - 1).ty - yData.at(yData.size() - 2).ty; if (hCells == 1) { leftDx = rightDx *= 0.5f; leftDu = rightDu *= 0.5f; } if (vCells == 1) { topDy = bottomDy *= 0.5f; topDv = bottomDv *= 0.5f; } // This delta is how much the fuzziness can reach out from the image. float delta = float(qAbs(targetRect.width()) < qAbs(targetRect.height()) ? targetRect.width() : targetRect.height()) * 0.5f; quint16 index = 0; ys = yData.data(); for (int j = 0; j < vCells; ++j, ys += 2) { xs = xData.data(); bool isTop = j == 0; bool isBottom = j == vCells - 1; for (int i = 0; i < hCells; ++i, xs += 2) { bool isLeft = i == 0; bool isRight = i == hCells - 1; SmoothVertex *v = vertices + index; quint16 topLeft = index; for (int k = (isTop || isLeft ? 2 : 1); k--; ++v, ++index) { v->x = xs[0].x; v->u = xs[0].tx; v->y = ys[0].y; v->v = ys[0].ty; } quint16 topRight = index; for (int k = (isTop || isRight ? 2 : 1); k--; ++v, ++index) { v->x = xs[1].x; v->u = xs[1].tx; v->y = ys[0].y; v->v = ys[0].ty; } quint16 bottomLeft = index; for (int k = (isBottom || isLeft ? 2 : 1); k--; ++v, ++index) { v->x = xs[0].x; v->u = xs[0].tx; v->y = ys[1].y; v->v = ys[1].ty; } quint16 bottomRight = index; for (int k = (isBottom || isRight ? 2 : 1); k--; ++v, ++index) { v->x = xs[1].x; v->u = xs[1].tx; v->y = ys[1].y; v->v = ys[1].ty; } appendQuad(&indices, topLeft, topRight, bottomLeft, bottomRight); if (isTop) { vertices[topLeft].dy = vertices[topRight].dy = topDy; vertices[topLeft].dv = vertices[topRight].dv = topDv; vertices[topLeft + 1].dy = vertices[topRight + 1].dy = -delta; appendQuad(&indices, topLeft + 1, topRight + 1, topLeft, topRight); } if (isBottom) { vertices[bottomLeft].dy = vertices[bottomRight].dy = -bottomDy; vertices[bottomLeft].dv = vertices[bottomRight].dv = -bottomDv; vertices[bottomLeft + 1].dy = vertices[bottomRight + 1].dy = delta; appendQuad(&indices, bottomLeft, bottomRight, bottomLeft + 1, bottomRight + 1); } if (isLeft) { vertices[topLeft].dx = vertices[bottomLeft].dx = leftDx; vertices[topLeft].du = vertices[bottomLeft].du = leftDu; vertices[topLeft + 1].dx = vertices[bottomLeft + 1].dx = -delta; appendQuad(&indices, topLeft + 1, topLeft, bottomLeft + 1, bottomLeft); } if (isRight) { vertices[topRight].dx = vertices[bottomRight].dx = -rightDx; vertices[topRight].du = vertices[bottomRight].du = -rightDu; vertices[topRight + 1].dx = vertices[bottomRight + 1].dx = delta; appendQuad(&indices, topRight, topRight + 1, bottomRight, bottomRight + 1); } } } Q_ASSERT(index == g->vertexCount()); Q_ASSERT(indices - g->indexCount() == g->indexData()); } else { if (!geometry) { geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), hCells * vCells * 4, hCells * vCells * 6, QSGGeometry::UnsignedShortType); } else { geometry->allocate(hCells * vCells * 4, hCells * vCells * 6); } geometry->setDrawingMode(QSGGeometry::DrawTriangles); QSGGeometry::TexturedPoint2D *vertices = geometry->vertexDataAsTexturedPoint2D(); ys = yData.data(); for (int j = 0; j < vCells; ++j, ys += 2) { xs = xData.data(); for (int i = 0; i < hCells; ++i, xs += 2) { vertices[0].x = vertices[2].x = xs[0].x; vertices[0].tx = vertices[2].tx = xs[0].tx; vertices[1].x = vertices[3].x = xs[1].x; vertices[1].tx = vertices[3].tx = xs[1].tx; vertices[0].y = vertices[1].y = ys[0].y; vertices[0].ty = vertices[1].ty = ys[0].ty; vertices[2].y = vertices[3].y = ys[1].y; vertices[2].ty = vertices[3].ty = ys[1].ty; vertices += 4; } } quint16 *indices = geometry->indexDataAsUShort(); for (int i = 0; i < 4 * vCells * hCells; i += 4) appendQuad(&indices, i, i + 1, i + 2, i + 3); } return geometry; }
CubeMapTexture* CubeMapTexture::Load(int size) { CubeMapTexture* cubeMap = new CubeMapTexture(); Texture::SetActiveTextureUnit(0); cubeMap->Bind(); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0)); GL_C(glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)); struct RGBA { GLubyte r; GLubyte g; GLubyte b; GLubyte a; }; RGBA green; green.r = 0;green.g = 255;green.b = 0;green.a = 255; RGBA red; red.r = 255;red.g = 0;red.b = 0;red.a = 255; std::vector<RGBA> testData(size * size * sizeof(RGBA), green ); std::vector<RGBA> xData(size * size * sizeof(RGBA), red); for(int i = 0; i < 6; ++i) { std::vector<RGBA> d = i % 2 == 0 ? testData : xData; glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA8 , size,size, 0, GL_RGBA, GL_UNSIGNED_BYTE, /*&d[0]*/ nullptr); /* GL_C(glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )); GL_C(glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )); */ // GL_C(glGenerateMipmap(m_target)); } /* GL_C(glFinish() ); GL_C(glFlush() ); }*/ // cubeMap->SetTextureClamping(); // cubeMap->SetTextureWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); // cubeMap->GenerateMipmap(); // cubeMap->Unbind(); return cubeMap; }